We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Database Types Storage
Free preview: the first 2 parts of this 8-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Database Types Storage
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
You need to find the 10 closest vectors to your query among 500 million stored vectors, each with 1,536 dimensions. Exact KNN means 500 million distance calculations, roughly 770 billion floating-point operations. Even on modern hardware, that's seconds per query.
Your users expect results in under 50 milliseconds.
(ANN) algorithms solve this by cleverly organizing vectors so that searching requires examining only a tiny fraction of the dataset. The trade-off: results might miss a few true nearest neighbors (95-99% recall), but the speed improvement is 1,000x or more.
This isn't a theoretical compromise. In practice, the vectors ANN misses are the borderline cases, items that are almost equally distant as the true nearest neighbors. For recommendation engines, semantic search, and , this difference is imperceptible to users.
The three most important ANN algorithms in production today are , IVF, and LSH. Each makes fundamentally different trade-offs, and understanding them lets you choose the right one for your scale and latency requirements.
Hierarchical Navigable Small World is the most popular ANN algorithm in production today. Used by Pinecone, Weaviate, Qdrant, pgvector, and .
The idea: Build a multi-layer graph where each vector is a node. Nearby vectors are connected by edges. The top layer has few nodes with long-range connections (express lanes). Lower layers have more nodes with shorter connections. The bottom layer has all nodes.
Building the graph:
Searching:
Think of it as navigating a city. Start on the highway (top layer, big jumps), take the exit to a main road (middle layers), then navigate side streets (bottom layer) to reach your destination.
Key parameters:
| Metric | |
|---|---|
| Query time | Sub-millisecond to low milliseconds |
| Build time | Hours for hundreds of millions of vectors |
| Memory | High (graph structure + vectors) |
| Recall@10 | 95-99%+ (tunable via ef_search) |
| Update support | Good, can add/remove nodes |
Weakness: Memory. The graph itself can be as large as the vector data. For 1 billion vectors, you might need 200+ GB just for the graph structure on top of the vector storage.