Vector Databases 2024: HNSW vs. DiskANN vs. IVF — Benchmarks and Trade-offs
The Hook
You’re choosing a vector DB. Pinecone, Weaviate, Qdrant, Milvus, Chroma — all claim “fast ANN search.” But under the hood, they use HNSW, DiskANN, or IVF. The index algorithm determines your RAM bill, query latency, and recall at scale. Here’s the 2024 benchmark reality.
The Thesis
Index algorithm > vector DB brand. All vector DBs wrap the same three index types: HNSW (memory-hungry, high recall), DiskANN (disk-native, 95% recall at 10% RAM), IVF (fast, recall drops at scale). Your choice should be index-first, vendor-second.
The Science
The Three Index Types
| Index | Principle | RAM/1M vecs (768-dim) | Recall@10 | Latency (p99) | Best For |
|---|---|---|---|---|---|
| HNSW | Hierarchical graph, greedy walk | ~4-8 GB | 0.95-0.99 | 1-5 ms | High recall, <10M vecs |
| DiskANN | Graph + PQ compression on SSD | ~0.5-1 GB | 0.90-0.97 | 5-20 ms | 10M-1B vecs, RAM-constrained |
| IVF | K-means clusters + inverted lists | ~1-2 GB | 0.80-0.95 | 2-10 ms | High throughput, >100M vecs |
HNSW (Hierarchical Navigable Small World)
Algorithm: Multi-layer graph. Top layer = sparse express lanes. Bottom layer = dense connections. Greedy walk from top → bottom.
Parameters:
M(max connections): 16-64 (higher = better recall, more RAM)efConstruction: 100-500 (build quality)efSearch: 50-500 (query quality)
RAM formula: ~1.5 * M * dim * 4 bytes * num_vectors
DiskANN (Microsoft, 2021)
Innovation: Graph stored on SSD + Product Quantization (PQ) compression.
Mechanism:
- Build HNSW in memory
- Compress vectors with PQ (8-16 bytes/vec vs 3072 bytes)
- Store graph on SSD, PQ codes in RAM
- Query: load PQ codes → approximate search → re-rank with full vectors from SSD
Result: 10-20× RAM reduction, 95% recall retained.
IVF (Inverted File Index)
Algorithm: K-means clustering → assign vectors to centroids → inverted lists per centroid.
Query: Find nearest centroids → search only those lists.
Parameters:
nlist: number of centroids (1000-100000)nprobe: centroids to search at query time
Trade-off: Higher nlist = smaller lists = faster search but lower recall (boundary errors).
The Benchmarks (ANN Benchmarks, 2024)
1M Vectors, 768-dim (OpenAI embeddings)
| Index | Recall@10 | QPS (1 thread) | RAM | Build Time |
|---|---|---|---|---|
| HNSW (M=32, ef=200) | 0.98 | 1,200 | 4.2 GB | 8 min |
| DiskANN (PQ=8bit) | 0.96 | 800 | 0.8 GB | 15 min |
| IVF (nlist=4096, nprobe=32) | 0.92 | 2,500 | 1.5 GB | 3 min |
100M Vectors, 768-dim
| Index | Recall@10 | QPS | RAM | Notes |
|---|---|---|---|---|
| HNSW | 0.97 | 200 | 400 GB | RAM-prohibitive |
| DiskANN | 0.95 | 150 | 8 GB | Production choice |
| IVF (nlist=65536) | 0.93 | 1,000 | 50 GB | High throughput |
The Decision Matrix
| Scenario | Choose |
|---|---|
| <1M vectors, max recall, RAM available | HNSW (Qdrant, Weaviate, Milvus) |
| 10M-1B vectors, RAM constrained | DiskANN (Milvus, SPANN) |
| >100M vectors, high throughput, recall >0.9 | IVF (Milvus, Vald) |
| Hybrid: hot vectors in RAM, cold on disk | DiskANN + HNSW tiering |
| Embedding dimension >1536 | DiskANN (PQ scales better) |
The Protocol: Choose Your Index
Step 1: Estimate Scale
vectors = docs * chunks_per_doc
dim = embedding_dim (768, 1024, 1536, 3072)
ram_gb = vectors * dim * 4 * overhead_factor
Step 2: Choose Index
| Vectors | RAM Budget | Recommended |
|---|---|---|
| <1M | >8 GB | HNSW |
| 1M-10M | >8 GB | HNSW |
| 10M-100M | <32 GB | DiskANN |
| >100M | <100 GB | DiskANN / IVF |
Step 3: Tune Parameters
HNSW:
# High recall
M = 32
ef_construction = 200
ef_search = 100
DiskANN:
# Balanced
pq_bits = 8
num_threads = 8
search_list = 100
IVF:
nlist = 4096 # sqrt(vectors) * 4
nprobe = 32 # 0.5-1% of nlist
The Counterpoint
- HNSW dominates <10M: Simpler, faster, well-tested
- DiskANN complexity: Build pipeline more complex; fewer managed services
- IVF boundary errors: Vectors near centroid boundaries lost unless nprobe high
- Filtered search: HNSW + metadata filtering = slow; IVF + filtering = faster
Practical Takeaway
Start with HNSW (Qdrant default). Monitor RAM. At 10M+ vectors or RAM pressure → migrate to DiskANN (Milvus) or IVF (Milvus/Vald). The index algorithm matters more than the vendor.
Sources: Malkov & Yashunin (2018) HNSW; Subramanya et al. (2021) DiskANN; Johnson et al. (2019) FAISS/IVF; ANN Benchmarks (2024); Pinecone/Weaviate/Qdrant/Milvus benchmarks (2024); FAISS documentation.