πŸ—ΊοΈ Learn Vector Databases the school way

The library sorted by meaning β€” the machine under semantic search, RAG and agent memory. Taught the school way: a real mini vector DB in the repo (~70 lines, pure Python, zero dependencies) that you read in full β€” including one honest, deliberate failure that explains why learned embeddings exist.

πŸ”’ embeddingsπŸ“ cosine πŸƒ kNN & HNSWβœ‚οΈ chunking 🏷️ metadata filtersπŸ“– RAG🏬 the landscape

πŸ’‘ Part 1 β€” THE IDEA (1–4)

  • keywords match strings; meaning needs seats πŸ—ΊοΈ
  • text β†’ coordinates: the toy way and the real way
  • similarity = direction (normalize, then dot) 🧭
  • millions of seats: the friendship map (HNSW) πŸƒ

πŸ”§ Part 2 β€” FOR REAL (5–8)

  • read the database whole: 70 honest lines πŸ”¬
  • scissors & stickers: chunking is the quality lever βœ‚οΈ
  • RAG end to end, with YOUR page-finder πŸ“–
  • pgvector β†’ Pinecone: picking without a bake-off 🏬
# the 60-second wow β€” search by meaning, filters, and one honest failure:
git clone https://github.com/BaluRaut/learn-vectordb-school.git && cd learn-vectordb-school
python3 vectordb/demo.py

πŸ—ΊοΈ The big picture β€” one diagram, both worlds

Click for the 4K version.

The big picture: the idea (seats, similarity, neighbors) and the practice (build, chunking, RAG, landscape)

πŸŽ“ The 8 lessons

One git branch = one idea; branch 05 contains lessons 01–05. The natural deep-dive after the AI course's embeddings (L04) and RAG (L10) lessons β€” and the memory layer of the Agents school.

1

πŸ—ΊοΈ Why vector DBs

The library sorted by MEANING β€” keywords match strings, not ideas.lesson-01-why-vector-dbRead lesson β†’See the diagram β†—
2

πŸ”’ Text to vectors

Giving every text a seat β€” our honest toy vs learned embeddings.lesson-02-text-to-vectorsRead lesson β†’See the diagram β†—
3

πŸ“ Similarity

Direction beats distance β€” and the normalize-then-dot trick.lesson-03-similarityRead lesson β†’See the diagram β†—
4

πŸƒ Nearest neighbors

Asking everyone vs the friendship map (HNSW) β€” the recall dial.lesson-04-nearest-neighborsRead lesson β†’See the diagram β†—
5

πŸ”¬ Build a vector DB

70 honest lines: embed, cosine, store, filter, top-k.lesson-05-build-a-vector-dbRead lesson β†’See the diagram β†—
6

βœ‚οΈ Chunking & metadata

Cards and colored stickers β€” the quality lever bigger than any index.lesson-06-chunking-metadataRead lesson β†’See the diagram β†—
7

πŸ“– RAG wiring

The open-book exam, end to end β€” with OUR page-finder.lesson-07-rag-wiringRead lesson β†’See the diagram β†—
8

🏬 The landscape

pgvector, Pinecone, Chroma, FAISS β€” picking without a bake-off.lesson-08-landscapeRead lesson β†’See the diagram β†—
🏬 The showcase: the product landscape β€” pgvector, Pinecone-class, Chroma/Qdrant/LanceDB, FAISS, and your-old-store-with-new-tricks β€” compared honestly, with the boring pick order.

πŸ“ The lesson diagrams β€” follow the numbers

Blue = the idea, green = for real. Also on a standalone page.

1 πŸ—ΊοΈ Why vector DBs

The library sorted by MEANING β€” keywords match strings, not ideas.

πŸ“‡ keyword catalog'kind to animals' β†’match exact strings β†’βŒ 'Every Living Thing' missedstrings, not meaning1πŸ—ΊοΈ the meaning hall β€” a vector DB1 seat the question(embed it)2 find nearest seatsfast, at any scale3 βœ… 'Every Living Thing'zero shared words!2store millions of seats Β· return the k nearest Β· with stickers 🏷️ β€” that's the whole product

Read full lesson 01 β†’

2 πŸ”’ Text to vectors

Giving every text a seat β€” our honest toy vs learned embeddings.

πŸ”€ toy: count wordshash each word β†’ bump 1 of256 buckets β†’ normalize😬 nearsighted: shared WORDS'pupils' β‰  'students' (0.00!)1🧠 real: embedding modela trained network β†’ 768-3072dims where directions = MEANINGβœ… 'pupils' sits beside 'students'across phrasing & languages2πŸ—ΊοΈ the DB doesn't carevectors in, neighbors out β€”embed() is ONE swappablefunction (lesson 05)3⚠️ the same-model rule: query and documents must use the SAME embedder β€” change it β†’ re-embed everything

Read full lesson 02 β†’

3 πŸ“ Similarity

Direction beats distance β€” and the normalize-then-dot trick.

🧭 cosine: compare DIRECTIONS10-page robot essay & 1-line robot notepoint the SAME way β†’ 0.95 βœ… siblingsmeaning is a direction; length is volume πŸ“’1πŸ“ distance: compare POSITIONSthe essay 'stands far' from the note β†’fooled by length β€” wrong verdict for text2⚑ the trick: normalize at WRITE time β†’ cosine = plain dot product at READ timeone line, hardware-fast β€” our cosine() is just sum(xΒ·y) because _normalize already ran3

Read full lesson 03 β†’

4 πŸƒ Nearest neighbors

Asking everyone vs the friendship map (HNSW) β€” the recall dial.

🚢 brute force - exactcompare with ALL N seatsN=7k: fine Β· N=7M: πŸ’€1πŸ—ΊοΈ HNSW - friendship maplocal friends + pen-pals acrossthe hall β†’ log-ish greedy hops2🏘️ IVF - neighborhoodspre-cluster districts; searchonly the nearest few3🎯 the recall dial: speed ↔ % of TRUE neighbors found95-99% recall at 100-1000Γ— speedup is the standard trade β€” benchmarks without recall numbers are marketing4

Read full lesson 04 β†’

5 πŸ”¬ Build a vector DB

70 honest lines: embed, cosine, store, filter, top-k.

1 πŸ”’ embed()hash words β†’ 256 dims β†’normalize Β· ← swap for amodel call HEREembedder and store areseparate jobs β€” by design12 πŸ“ cosine()one line: dot product(normalize made it cheap)23 πŸ—„οΈ MiniVectorDBadd: embed + store(id, vector, TEXT, stickers)search: filter 🏷️ FIRST β†’score β†’ sort β†’ top-kmissing on purpose: persistence,deletes, ANN β€” your homework3~70 lines, zero dependencies β€” a database you can hold entirely in your head

Read full lesson 05 β†’

6 βœ‚οΈ Chunking & metadata

Cards and colored stickers β€” the quality lever bigger than any index.

πŸ“š 400-page bookcan't sit in one chairβœ‚οΈ chunking - the craftnatural seams Β· self-contained Β·~hundreds of tokens Β· 10-15% overlap πŸ”1πŸ—‚οΈ cards + stickers 🏷️room:3A Β· kind:rules Β·source:handbook-p12 (receipts!)2❌ too big: five topics, one murky seat❌ too small: '…it must be returned' β€” WHAT must?chunking moves quality 2-5Γ— Β· indexes move it 1.1Γ—3🀝 hybrid searchmeaning-search misses 'E-4012'; keywords misssynonyms β€” run BOTH, merge (RRF)4

Read full lesson 06 β†’

7 πŸ“– RAG wiring

The open-book exam, end to end β€” with OUR page-finder.

πŸ—‚οΈ index time - once, on changedocs β†’ βœ‚οΈ chunk β†’ πŸ”’ embed β†’ πŸ—„οΈ store(re-index tonight, 'knows' it tomorrow)1❓ question time - every queryembed the question (SAME model) β†’ search k=4(+ stickers 🏷️) β†’ optional rerank 🧐2πŸͺ‘ the desk: cards + 'answer ONLY from these, cite ids'β†’ βœ… grounded answer with receipts 🧾 (AI school L08-L10, now with YOUR page-finder)debugging drill: bad answer? print the CARDS first β€” retrieval bug β‰  generation bug3

Read full lesson 07 β†’

8 🏬 The landscape

pgvector, Pinecone, Chroma, FAISS β€” picking without a bake-off.

🐘 pgvectorthe library you already have β€”SQL + vectors, one backup1☁️ managed - Pinecone & cothe rented hall β€” scale withoutops (the AWS build-vs-rent call)2πŸ§ͺ Chroma Β· Qdrant Β· LanceDBthe lab bench β€” developer-first,embedded to mid-scale3βš™οΈ FAISS Β· hnswlibengine blocks, not databases β€”max control, zero ops help4πŸ”Ž your old store, new tricksOpenSearch/Redis/Mongo grewa vector column β€” one less system5the boring pick order: pgvector β†’ embedded lab bench β†’ managed/self-hosted at real scale Β· <100k vectors? a loop is fine πŸ˜„

Read full lesson 08 β†’

Start Lesson 01 β†’ 🏬 The landscape πŸ“ All 8 lesson diagrams πŸ§ͺ Quiz πŸ—“οΈ Study plan 🧠 The AI course