HNSW Parameters: M, efConstruction and efSearch Tuning
A practical guide to tuning HNSW parameters: what M, efConstruction and efSearch do, how they trade memory, build time, recall and latency.
Published on • November 22, 2026
AI Assistant

Introduction
HNSW gives you three knobs — M, efConstruction, and efSearch — that control the entire memory / build-time / recall / latency budget of your index. Tuning them blindly wastes memory or recall; tuning them deliberately gets you exactly the trade-off your application needs.
The Three Knobs
M — connectivity per node
M is the maximum number of neighbours each node keeps on the base layer (upper layers use M/2 in the original design).
- Higher M → denser graph → better recall and shorter paths, but more memory and slower builds
- Typical range: 8–64; 16–48 covers most workloads (16 is FAISS/Qdrant’s common default; 30+ suits high-recall RAG)
- Memory cost: roughly
M × 4–8 bytes × nfor the graph alone (plus upper layers) — at M=16 this can rival the vector data itself
efConstruction — build quality
During insertion, efConstruction is the size of the dynamic candidate list used to select the M neighbours.
- Higher efConstruction → better-quality edges → better recall at any efSearch, but slower index builds
- Typical range: 100–500 (200 is a common default)
- Rule of thumb: set
efConstruction ≥ efSearch; beyond ~400–800 the gains flatten while build time keeps climbing
efSearch — query-time search depth
At query time, efSearch is the size of the candidate list explored on the base layer. Results are truncated to k from the efSearch best found.
- Higher efSearch → deeper exploration → higher recall, higher latency
- Typical range: 10–512; often 64–256 for production RAG
- Key advantage: it can be changed per query — no rebuild needed. Great for “cheap browse, expensive rerank” pipelines
A Worked Tuning Path
- Baseline:
M=16,efConstruction=200,efSearch=64. Measure recall@10 against exact ground truth and p95 latency. - Recall short? First raise
efSearch(runtime-only, zero rebuild). If still short, raiseMand rebuild. - Latency too high with acceptable recall? Lower
efSearch; only then consider reducingM. - Build too slow? Lower
efConstructionto ~100 and re-measure — recall often barely moves. - Memory pressure? Lower
Mfirst (graph size scales linearly), or add quantisation (HNSW + PQ/HNSW+int8).
Rough Defaults by Workload
| Workload | M | efConstruction | efSearch |
|---|---|---|---|
| Interactive search, low latency | 8–16 | 100–200 | 32–64 |
| General purpose | 16 | 200 | 64–128 |
| High-recall RAG / rerank pipelines | 32–48 | 200–400 | 128–256 |
Conclusion
M sets the graph’s memory and structural quality, efConstruction sets build quality, and efSearch sets per-query recall vs latency. Tune in that order of cost: adjust efSearch first (free at runtime), then pay for rebuilds with M/efConstruction — and always validate against exact ground truth.