Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Pick HNSW when latency and recall matter and memory is cheap (sub 100M vectors). Pick IVF (usually IVF-PQ) when scale is huge or memory is the binding cost.
Imagine you have a giant photo library and you want to find similar photos to one you just took. **HNSW** is like building a smart web of links between photos: every photo points to a few of its most similar neighbors, and a few of those neighbors point to far-away clusters. When you search, you hop along the links, getting closer and closer to matches in just a few jumps. It is very fast but the link directory takes up a lot of room. **IVF** is like sorting all your photos into labeled bins first. When you search, you only open a few bins that look promising. That is slower per search but the bins take far less storage, and you can shrink each photo into a tiny thumbnail to save even more space.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: HNSW graph mechanics + IVF partitioning + Product Quantization composition + memory and recall tradeoffs + 2026 production choices (Pinecone, Weaviate, Qdrant, Milvus).
| Property | HNSW | IVF (often IVF-PQ) |
|---|---|---|
| Index type | Hierarchical graph | Partitioned (k-means) inverted file |
| Latency at high recall | Sub millisecond | 1-10 ms typical |
| Memory overhead | ~2-4x raw vectors | Small; PQ shrinks vectors 10-50x |
| Sweet spot scale | 1M to 100M vectors | 100M to billions |
| Recall ceiling | 0.99+ achievable | 0.85-0.95 typical at low cost |
| Build time | Slow (O(N log N)) | Faster (k-means + assign) |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Picking HNSW for billion scale corpora without budgeting the memory blowup; the graph index alone can dwarf the raw vector storage.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.