Evidence label: deterministic synthetic model. This page builds a real Hierarchical Navigable Small World graph in JavaScript: it samples vectors, assigns exponential levels with mL = 1/ln(M), inserts each vector with an efConstruction beam and the neighbour-diversity heuristic, and answers queries with greedy upper-layer descent and a layer-0 beam of width efSearch. Recall is computed against brute force. The data are synthetic and small, and latency is an estimate derived from distance counts, so all figures are illustrative calculations.
Play the lab
How to play
Move M, efConstruction and efSearch and watch recall@10, distance computations and the estimated p95 latency. Changing efSearch only re-runs the queries in a real system, while changing M or efConstruction would require a rebuild; the lab rebuilds instantly so you can compare. Use the data dimension menu to see how the same settings behave on harder data, and the filter strategy menu together with the metadata filter event to compare post-filtering with filtering during traversal.
Missions unlock in order. Load a mission setup, fix it, and earn more stars for the cheaper solution: fewer distances per query, a cheaper build, or higher recall within the budget. Try New random seed to confirm a setting is robust and not tuned to one dataset.
What the model assumes
Vectors have two visible coordinates in the unit square and, depending on the data dimension setting, extra hidden coordinates at 80% of that scale; the clustered event places data and queries in nine tight clusters. Layer 0 keeps up to 2M links and upper layers up to M. The latency estimate charges 0.25 ns per dimension plus 60 ns per distance at the chosen real dimension, plus a small fixed overhead. Memory follows an hnswlib-like layout: float32 vectors plus 4-byte links. Tombstoned vectors are traversed but never returned.
What it cannot tell you
With at most 2,000 vectors and 12 dimensions, the absolute numbers are far from a production index of millions of 768-dimension embeddings, where the same recall needs larger M and efSearch. The model ignores CPU caches, SIMD, concurrency, quantization, disk-based indexes and engine-specific filtering planners. Use it to understand the mechanism and the direction of each trade-off, then sweep your own index.
Read the full explanation
- HNSW Tuning for RAG: M, efSearch and the Recall Versus Latency Trade (companion article)
- Embedding Quantization: Binary and Int8 Vectors Without Losing Recall
- Permission-Aware RAG: Filtering by Access Control Without Destroying Recall
All AI in Production labs · Lab catalog
- Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs (Malkov and Yashunin)
- hnswlib: header-only C++/Python library for fast approximate nearest neighbors
- pgvector: open-source vector similarity search for Postgres
- The Faiss library (Douze et al., 2024)
- ANN-Benchmarks: A Benchmarking Tool for Approximate Nearest Neighbor Algorithms
- Qdrant documentation: indexing
Views are my own and do not represent any employer, past or present.