Student view, safe to present
Teaching deck, Notebook 05

Vector Databases

What happens after the embedding. We built vectors in Notebook 04. Now we need somewhere fast to search millions of them, and the answer is almost never "check every single one."
40 to 45 minutes FAISS, HNSW, IVF, Chroma, Pinecone Real recall and speed numbers
01 / 17
Where this fits

You have vectors now. Where do they live?

Documents
->
Chunk
->
Embed
->
Store & search
->
Retrieve
->
Generate
For the trainer

Point at the pipeline and say it plainly: embeddings are numbers sitting in RAM right now with nowhere to live. Today is just "where do they live, and how do we search them fast." Keep it that simple going in.

02 / 17
The problem, made visible

Checking every single vector

This is exact search. Every dot below is a stored vector. To answer the question, this approach compares it against every single one, no shortcuts.
Fine at a few hundred vectors. Once you're at millions, comparing against every single one starts taking real, noticeable time, on every question, every time.
For the trainer

Let this animation run for a few seconds before saying anything, the dots gently pulsing is meant to feel like "checking, checking, checking." Then say: this is called exact search, and it's exactly this simple, and exactly this slow at scale.

03 / 17
The fix

Approximate Nearest Neighbor, ANN for short

Instead of checking every vector, build a shortcut structure that finds the closest ones almost every time, in a fraction of the time. That's the entire idea behind every vector database.
Read every book
exact search, always correct, painfully slow at scale
Use the index
ANN search, almost always correct, fast
For the trainer

Library analogy works well here. Nobody reads every book to find one topic, they use the index card system. That index is a little imperfect but nobody cares because it's fast and right almost every time. FAISS, HNSW, and IVF are all just different ways of building that index.

04 / 17
The baseline, measured live

50,000 vectors, checked one by one

Before building any shortcut, we measured exact search itself. This is the ground truth every shortcut gets graded against.
0.255 ms per query 100% recall, by definition 50,000 vectors, 128 dimensions
For the trainer

Fifty thousand vectors sounds like nothing, and 0.255 milliseconds sounds fast. That's the trap. Ask the class what happens at 500 million vectors instead of 50,000. This is why exact search stops being an option long before you'd expect.

05 / 17
FAISS, tool one

HNSW, walking a map instead of scanning a list

HNSW builds a layered graph of connections between vectors. A search starts at the sparse top layer, takes a few long jumps, then drops into denser layers to home in on the answer, touching only a handful of vectors along the way.
Example question: "What's the refund window if I cancel my subscription?"
LAYER 2 few nodes LAYER 1 more nodes LAYER 0 every vector 1 2 3 fixed entry point the answer
path actually walked nodes never touched the answer
Why does it always start at node 1?

It's not chosen based on the question. One entry point gets fixed the moment the index is built, usually just whichever vector was added first. Every single search, no matter what's being asked, starts at that exact same node and greedily works outward from there.

Walking through the example above
  1. Start at node 1, the fixed entry point. Every question lands here first, including this one.
  2. Compare the question to node 1's neighbors. Node 2 is closer to "refund window," so jump there.
  3. No neighbor beats node 2 at this layer, so drop down and land on node 3, the closest match.
For the trainer

Read the three numbered steps out loud against the graph before saying anything else. Then ask the room the question they're probably already thinking: why node 1, why not somewhere closer to begin with. The answer is the callout, it's fixed at build time, the algorithm never picks a custom starting point per question.

06 / 17
HNSW's one knob

efSearch, how far you're willing to wander

Turn efSearch up and the walk explores more paths before stopping: slower, but closer to the exact answer.
efSearch=16
0.435 recall
efSearch=32
0.588 recall
efSearch=64
0.752 recall
efSearch=128
0.882 recall
efSearch=256
0.959 recall
For the trainer

Run this cell live, don't just show the bars. Ask someone to guess what happens at efSearch=256 before you scroll to the number. Watching it climb toward, but never quite reach, 100 percent is the whole lesson in one table.

07 / 17
FAISS, tool two

IVF, sort into neighborhoods first, then only visit the closest ones

Before any question ever arrives, IVF groups every vector into clusters. When a question comes in, it only searches inside the nearest couple of clusters and ignores the rest completely.
incoming question
searched, the question gets compared to these skipped, nothing inside gets touched at all the incoming question
For the trainer

Follow the two dashed lines from the question down to the two orange clusters, those are the only neighborhoods that get searched. The three gray circles off to the side are skipped completely, not one vector inside them gets compared. That's nprobe, literally how many of these circles you bother checking.

08 / 17
IVF's one knob

nprobe, how many neighborhoods you bother checking

nprobe=1
0.038 recall
nprobe=4
0.112 recall
nprobe=16
0.278 recall
nprobe=64
0.637 recall
nprobe=128
0.873 recall
For the trainer

Compare this to the HNSW numbers a couple of slides back. At a similar rough time budget, HNSW gets noticeably higher recall. Say plainly that this is why most vector databases default to HNSW today, IVF just doesn't win this comparison as often anymore.

09 / 17
The dial you're actually turning

Pick the operating point your product needs

There's no universal right answer. A support chatbot might be fine at 90 percent recall if it's instant. A legal search tool probably wants 99 percent and can tolerate a slower response.
Faster, less accurate
Slower, more accurate
For the trainer

Ask the room: would you rather your product be a little wrong sometimes and instant, or occasionally slow and always right. There's no correct answer, that's the point, the answer depends entirely on what you're building.

10 / 17
The part that confuses everyone

FAISS, Chroma, and Pinecone are the same engine, wrapped differently

All three search the same way underneath, usually HNSW. What changes is how much of the surrounding work is done for you.
hosting, scaling, someone else's servers
storage, metadata, filtering, persistence
ANN engine, HNSW
FAISS
hosting, scaling, someone else's servers
storage, metadata, filtering, persistence
ANN engine, HNSW
Chroma
hosting, scaling, someone else's servers
storage, metadata, filtering, persistence
ANN engine, HNSW
Pinecone
For the trainer

This is the single most useful slide in the whole notebook for clearing up confusion. FAISS is the bare engine you wire up yourself. Chroma wraps that engine with an actual small database around it, still yours to run. Pinecone wraps it again with someone else running the whole thing on their servers. Same bottom layer, every time.

11 / 17
Chroma, in practice

The engine, plus documents, filtering, and disk storage

Semantic search

Query: "How do I get my money back?" Top hit: the refund policy sentence, no shared words needed.

Metadata filtering

Same idea, but only search where topic is hr and year is 2024. This is how you enforce tenants and access rules in a real product.

For the trainer

The filtering demo is the one to slow down on. This is the feature that turns "cool vector search demo" into "something you could actually ship to a company with different customers and permissions."

12 / 17
Pinecone, in practice

The engine, plus somebody else running it for you

Same underlying idea again. Pinecone owns the infrastructure, scales automatically, and adds namespaces so one index can hold cleanly separated partitions.
query "how do I get my money back", filtered to billing top match score 0.357
For the trainer

Be honest about the trade here. Zero ops sounds free, it isn't, you're paying in dollars and in being locked into their platform instead of paying in engineering time. Frame it as a real decision, not a strictly better option.

13 / 17
Choosing a store

The engine is the same everywhere. The decision is ops.

OptionWhat it isReach for it when
FAISSIn-process libraryYou want raw control, or you're learning how ANN actually works
ChromaEmbedded databaseLocal dev, small to mid projects, you want filtering without a server
PineconeManaged serverlessProduction scale, zero ops, and the hosted cost is fine
pgvectorPostgres extensionYou already run Postgres, don't add a new system just for vectors
Qdrant / WeaviateSelf-host or managedStrong filtering or hybrid search, under roughly 50 million vectors
MilvusDistributed databaseBillions of vectors, and you have the ops team to run it
For the trainer

Someone always asks "which one is best." There isn't one. Answer with the question back: how many vectors, who's maintaining it, and what's the budget. That's the actual decision.

14 / 17
Suggested run of the session

Roughly 40 to 45 minutes

TimeSegment
0 to 5 minRecap embeddings, land "we need somewhere fast to search these"
5 to 10 minThe brute-force scan diagram, then the exact search baseline number
10 to 25 minHNSW graph diagram and its knob, then IVF cluster diagram and its knob
25 to 32 minThe layered stack diagram, FAISS versus Chroma versus Pinecone
32 to 40 minChroma and Pinecone demos, live if the API keys are set
40 to 45 minChoosing table, hand off to sparse retrieval
15 / 17
Questions to expect

What students usually ask here

Is Chroma just a worse version of Pinecone then?
No, it's a different trade, not a worse one. Chroma means you run it yourself with no ongoing cost beyond your own server. Pinecone means someone else runs it and you pay them instead. Neither is strictly better, they fit different situations.
Why not just always use exact search if my dataset is small?
You can, and FAISS's flat index is exactly that. The moment your corpus grows into the millions, exact search stops being practical, so many teams pick an ANN index from the start even at small scale, just to avoid a rewrite later.
Do I need to understand HNSW internals to use a vector database?
Not to use one, but you'll hit a wall the first time recall looks wrong and you don't know which knob to turn. Today's session is exactly that knob.
16 / 17
Next

Dense search has a blind spot

Notebook 06 shows exactly where dense embeddings fail, on a labeled corpus with known right answers, and why keyword search still earns its place in a real pipeline.

17 / 17