Tuning Guidelines
For Real-Time Search Applications
Prioritize low latency over maximum recall:src/hnsw-realtime.ts
For High-Precision Applications
Prioritize accuracy over speed:src/hnsw-precision.ts
For Memory-Constrained Environments
Minimize memory footprint:src/hnsw-low-memory.ts
Dynamic efSearch
Adjust efSearch per-query based on requirements:src/dynamic-ef-search.ts
Recall vs Speed Trade-offs
Benchmarking Your Configuration
src/benchmark.ts
Common Issues
Poor Recall
If results aren’t relevant enough:- Increase
efSearchfor search-time improvement - Increase
MandefConstruction, then rebuild index
Slow Search
If search is too slow:- Decrease
efSearch - Consider lower
Mif memory allows
Slow Indexing
If bulk indexing is too slow:- Decrease
efConstruction - Consider building without HNSW, then enabling it
Recommended Starting Points
| Use Case | M | efConstruction | efSearch |
|---|---|---|---|
| Autocomplete | 12 | 100 | 20 |
| General search | 16 | 200 | 50 |
| High-precision | 24 | 400 | 100 |
| Maximum recall | 32 | 400 | 200 |
Related
HNSW Overview
Introduction to HNSW
HNSW Configuration
Parameter reference
Search Performance
General performance tips