HNSW & Token Tuning
Exact HNSW M, ef_construct & Payload RAM Sizing Formula
Compute deterministic RAM requirements from vector count, embedding dimensions, bidirectional HNSW link pointers (M * 2 * 4B), and payload indexes.
Bytes/Vec = dim*4 + M*8 + 192B · 15% Segment Merge Margin
Breaking Down Every Byte Inside an HNSW Index
A vector database does not store raw floats alone. Each point holds dim * 4 bytes (fp32), plus roughly M * 2 * 4 bytes for upper- and base-layer HNSW neighbor lists, plus ~192 bytes for point IDs and indexed payload keys like user_id.
Accounting for 15% Segment Compaction Overhead
Qdrant and pgvector periodically merge immutable segments in the background. Always multiply steady-state HNSW RAM by 1.15x (or 1.25x on pgvector) so background optimization never triggers Linux OOM kills.
Measured Thresholds & Vector Stack Parameters
| HNSW Setting | RAM per 1M Vectors (Edges Only) | Recall & Latency Tradeoff |
|---|---|---|
| M=16, ef_construct=128 | +128 MB graph pointers | Best default for 97-99% recall@10 in agent memory |
| M=24, ef_construct=160 | +192 MB graph pointers | Recommended for 5M+ dense multi-tenant collections |
| M=32, ef_construct=200 | +256 MB graph pointers | Slower indexing; reserve for 3072d precision RAG |