Parameter Reference
| Option | Default | Description |
|---|---|---|
M | 16 | Connections per node in layer > 0 (higher = better recall) |
M0 | 32 | Connections for layer 0 (typically M x 2) |
efConstruction | 200 | Candidate list size during construction |
efSearch | 50 | Candidate list size during search |
M (Max Connections)
Controls the number of connections each node has in the graph.src/hnsw-m-param.ts
M Impact
| M Value | Build Speed | Memory | Recall |
|---|---|---|---|
| 8 | Fast | Low | ~93% |
| 16 | Medium | Medium | ~96% |
| 32 | Slow | High | ~98% |
efConstruction
Controls build-time quality. Higher values = better graph structure but slower indexing.src/hnsw-ef-construction.ts
efConstruction Impact
| Value | Build Speed | Index Quality |
|---|---|---|
| 100 | Fast | Good |
| 200 | Medium | Very Good |
| 400 | Slow | Excellent |
efSearch
Controls search-time quality. Can be adjusted per-query:src/hnsw-ef-search.ts
efSearch Impact
| Value | Search Speed | Recall |
|---|---|---|
| 20 | Very Fast | ~92% |
| 50 | Fast | ~96% |
| 100 | Medium | ~98% |
| 200 | Slow | ~99% |
Configuration Presets
src/hnsw-presets.ts
Full Configuration Example
src/hnsw-full-config.ts
Related
HNSW Overview
Introduction to HNSW
HNSW Tuning
Tune for your use case
Search Performance
General performance tips