Chapter 8 · Vector Databases
A normal database finds things by exact match. A vector database answers a completely different question — "give me the ones most similar to this."
The job
A vector database does one thing extremely well: it holds millions of high-dimensional vectors — the fingerprints from Chapter 7 — and searches them by similarity.
Keep millions of high-dimensional vectors on hand.
Pre-organize them so search doesn't start from scratch.
Return the closest vectors to a query — fast.
That single ability turns a pile of embeddings into a memory you can actually query.
The mismatch
A regular database is a master of exact questions — find the row where email equals this, orders between March and May. Exact match and range, and it's brilliantly fast because it can jump straight to the answer.
But "which vectors mean something similar?" isn't an exact question.
No stored vector is equal to your query. You want the closest points in a 1,000-dimensional space — a nearest-neighbor question, not a lookup.
The naive way
The obvious approach — compare the query to every single stored vector, then keep the smallest distances. With a thousand vectors that's fine.
With ten million, it's impossibly slow.
Checking them one-by-one on every search means waiting seconds for a single lookup. A vector database exists to make that search feel instant instead.
The whole idea in one picture
Grey dots are stored vectors; the pink dot is the query. Left: brute force touches every dot. Right: HNSW hops a few links and lands on the answer.
The big idea
HNSW — hierarchical navigable small world — pre-wires the vectors into a graph of short links. To search, you don't visit every point; you start somewhere and hop along edges toward the query, greedily getting closer each step.
Give up a tiny sliver of accuracy — it might occasionally miss the true nearest.
A massive speedup — roughly 40 comparisons vs. 5, and it only widens as data grows.
Approximate, but so close it doesn't matter — and fast enough to feel instant.
Measuring "close"
To find the nearest vectors, the database needs a way to score how close two of them are. For text, that's almost always cosine similarity — it measures the angle between two vectors, not the raw distance between their tips.
Two fingerprints pointing the same direction count as similar even if one is "longer" — exactly what you want when a short phrase and a long paragraph mean the same thing.
Closer angle = more similar meaning.
Coming up
Chapter 9 · Embeddings unpacks cosine similarity properly — the geometry, the intuition, and why the angle matters more than the length.
For now, hold the one-liner: closer angle = more similar meaning.
The landscape
They all do the same core job. They differ in how they're run, what extra tricks they add, and how far they scale. Here's the field, with a "reach for this when…" for each.
Managed cloud, no servers. Reach for production search without operating anything.
Vector and keyword search fused. Reach for hybrid retrieval from one engine.
Rust, blazingly fast, rich filtering. Reach for it when speed and metadata filters matter.
Easiest to start — runs local, zero setup. Reach for it to prototype and build fast.
Billions of vectors, enterprise scale. Reach for it when the dataset is enormous.
Adds vectors to PostgreSQL. Reach for it when you already run Postgres.
Don't overthink it
Runs locally, zero setup. You'll be doing similarity search in about five minutes.
Managed cloud or fast-and-filterable. Covers the vast majority of real projects.
That's the whole decision for most teams — start easy, move to production when it's real.
The one thing to remember
Fast, approximate similarity search is the machinery that makes RAG and agent memory practical at scale. Without it, "remember everything and recall what's relevant" would simply be too slow to use.
Chapter 8 in one breath
A vector database stores millions of vectors and answers one question fast: which are most similar to this? Brute force checks everything; HNSW hops a smart graph and checks a handful. Cosine is the yardstick.
Prototype on Chroma; ship on Pinecone or Qdrant.
Next up
We've built the memory that stores and searches the fingerprints. Next we open the fingerprints themselves — how embeddings are made, and the geometry of cosine similarity we kept promising.
Press S for speaker notes · F for fullscreen · → to advance.