Estimate the RAM cost of an HNSW index over 100M vectors at 1024 dimensions with M=32, including graph overhead.
Compute (show your math) the RAM cost of an HNSW index for 100M vectors at 1024 dimensions with M=32, float32 storage. Include both the vectors themselves and the graph edges. Note any practical assumptions a senior engineer would explicitly call out.
Per-vector: 4 * 1024 = 4096 bytes. Per-node edges: ~256 bytes at M=32 (2*M at base + hierarchy decay). Per-node total ~4352 bytes. 100M nodes ~= 435 GB. Pad ~20% for overhead, land ~500-525 GB.
Think of HNSW like a huge interconnected card catalogue that has to live entirely on a single desk. Each vector is 1024 numbers, each 4 bytes, so 4 KB per card. With 100 million cards that's 400 GB just for the cards themselves. The cross-reference web that lets the search hop quickly between cards adds another ~25 GB. Total: about 425-450 GB of raw cost, padded to ~500 GB for operating-system overhead. **The key catch:** all of it has to stay on the desk (RAM) because the search hops hundreds of times per query, and walking to a filing cabinet (disk) for each hop would destroy performance. Once you cross this threshold on a single machine, you switch to DiskANN (lives on SSD), IVF-PQ (squeezes vectors 100x), or shard across machines.
Detailed answer & concept explanation~5 min readEverything 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. 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.
5 min: walk through the per-node calculation (vector + graph), multiply to ~435 GB, name the RAM-residency requirement, add the ~20% production padding, and map the number to the DiskANN / IVF-PQ / sharding decision threshold.
| Architecture | Per-vector RAM | Per-vector SSD | Total for 100M @ 1024-dim | Per-query latency | Recall ceiling |
|---|---|---|---|---|---|
| HNSW (M=32, fp32) | ~4.35 KB | 0 | ~435 GB | <1 ms | ~0.97-0.99 |
| HNSW (M=32, SQ-int8) | ~1.35 KB | 0 | ~135 GB | <1 ms | ~0.96-0.98 |
| HNSW (M=32, BQ) | ~256 bytes | 0 | ~25 GB | <1 ms | ~0.92-0.97 (binary-aware) |
| IVF-PQ (pq_m=32) | ~32-64 bytes | 0 | ~5-10 GB | ~3-10 ms | ~0.85-0.92 |
| DiskANN | ~64-128 bytes (PQ) | ~4 KB | ~10 GB RAM + 400 GB SSD | ~5-15 ms | ~0.95-0.98 |
Real products, models, and research that use this idea.
- AWS r6i.x32large (1 TB RAM, ~$8/hr) is a typical instance choice for 100M-vector HNSW indexes.
- Pinecone serverless transparently transitions to disk-backed storage past similar thresholds, hiding the cost cliff from users.
- Milvus and Vespa both ship DiskANN as the recommended path at billion-scale.
- Glean, Notion, and other B2B RAG products at the 100M-vector scale typically run sharded HNSW on multiple r6i.4xlarge instances.
- ANN-Benchmarks routinely reports memory footprint alongside recall and latency, and the HNSW-at-M=32 numbers match the ~4.3 KB-per-vector estimate.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does the per-node graph cost change if we switch to int8 SQ for the vectors?
QWhy don't HNSW implementations use 8-byte (uint64) node IDs by default?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Forgetting that the full vectors must stay RAM-resident. HNSW graph traversal does distance computations at every hop, so any disk involvement would push per query latency from sub-millisecond to tens of milliseconds. This is what makes the ~400 GB number a hard constraint, not a soft one.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.