Skip to main content
Learn how to tune HNSW parameters for different scenarios.

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:
  1. Increase efSearch for search-time improvement
  2. Increase M and efConstruction, then rebuild index
If search is too slow:
  1. Decrease efSearch
  2. Consider lower M if memory allows

Slow Indexing

If bulk indexing is too slow:
  1. Decrease efConstruction
  2. Consider building without HNSW, then enabling it

HNSW Overview

Introduction to HNSW

HNSW Configuration

Parameter reference

Search Performance

General performance tips