A Comparative Study of HNSW Implementations for Scalable Approximate Nearest Neighbor Search

Harshit Shah · 2025

Hierarchical Navigable Small World (HNSW) graphs are among the most widely adopted algorithms for an approximate nearest neighbor (ANN) search in high-dimensional data, supporting applications across machine learning, recommendation, and computer vision. Multiple open source libraries including FAISS-HNSW, HNSWlib, and NMSLIB-HNSW implement HNSW with different design choices and performance characteristics, yet comprehensive comparisons between them remain limited. This paper presents an empirical benchmarking study of these three libraries, systematically varying the size of the data set, the vector dimension, and key HNSW parameters (ef_construction and M). We evaluated each library on four critical metrics: indexing time, memory usage, query latency, and recall. Our results reveal distinct trade-offs: NMSLIB-HNSW provides the fastest index construction and highest recall, but suffers from significantly slower query times at scale. FAISS-HNSW offers the most balanced overall performance, while HNSWlib excels in smaller-scale settings. All benchmarks were conducted on CPU-based synthetic in-memory datasets. The findings offer actionable guidance for practitioners selecting and tuning HNSW libraries for varied deployment scenarios.

Read the paper · More papers on PaperTik