The Hierarchical navigable small world (HNSW) algorithm is a
graph-based
approximate nearest neighbor search technique used in many
vector databases.[1][2] Nearest neighbor search without an index involves computing the distance from the query to each point in the database, which for large datasets is computationally prohibitive. For high-dimensional data, tree-based exact vector search techniques such as the
k-d tree and
R-tree do not perform well enough because of the
curse of dimensionality. To remedy this, approximate k-nearest neighbor searches have been proposed, such as
locality-sensitive hashing (LSH) and product quantization (PQ) that trade performance for accuracy.[2] The HNSW graph offers an approximate k-nearest neighbor search which scales logarithmically even in high-dimensional data.
It is an extension of the earlier work on navigable
small world graphs presented at the Similarity Search and Applications (SISAP) conference in 2012 with an additional hierarchical navigation to find entry points to the main graph faster.[3] HNSW-based libraries are among the best performers in the approximate nearest neighbors benchmark.[4][5][6]
Use in vector databases
HNSW is a key method for approximate nearest neighbor search in high-dimensional vector databases, for example in the context of embeddings from neural networks in large language models. Databases that use HNSW as search index include:
Several of these use the hnswlib library[7] provided by the original authors.
References
^Malkov, Yu A.; Yashunin, D. A. (2016). "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs".
arXiv:1603.09320 [
cs.DS].
^
abMalkov, Yury A; Yashunin, Dmitry A (1 April 2020). "Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs". IEEE Transactions on Pattern Analysis and Machine Intelligence. 42 (4): 824–836.
arXiv:1603.09320.
doi:
10.1109/TPAMI.2018.2889473.
PMID30602420.