Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs

Yu. A. Malkov, D. A. Yashunin
3/30/2016
cs.DScs.CVcs.IR

Official code: nmslib/hnswlib (5,353 stars, Apache-2.0, last commit 2026-09-15).

Abstract

We present a new approach for the approximate K-nearest neighbor search based on navigable small world graphs with controllable hierarchy (Hierarchical NSW, HNSW). The proposed solution is fully graph-based, without any need for additional search structures, which are typically used at the coarse search stage of the most proximity graph techniques. Hierarchical NSW incrementally builds a multi-layer structure consisting from hierarchical set of proximity graphs (layers) for nested subsets of the stored elements. The maximum layer in which an element is present is selected randomly with an exponentially decaying probability distribution. This allows producing graphs similar to the previously studied Navigable Small World (NSW) structures while additionally having the links separated by their characteristic distance scales. Starting search from the upper layer together with utilizing the scale separation boosts the performance compared to NSW and allows a logarithmic complexity scaling. Additional employment of a heuristic for selecting proximity graph neighbors significantly increases performance at high recall and in case of highly clustered data. Performance evaluation has demonstrated that the proposed general metric space search index is able to strongly outperform previous opensource state-of-the-art vector-only approaches. Similarity of the algorithm to the skip list structure allows straightforward balanced distributed implementation.

View on arXivView PDF

Code Implementations(1)

nmslib/hnswlibOfficial100%
Apache-2.0

Header-only C++/python library for fast approximate nearest neighbors

5,353857C++, CMakeJul 6, 20171 months agoApache-2.0

Cite this paper

@article{malkov2016efficient,
  title  = {Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs},
  author = {Yu. A. Malkov and D. A. Yashunin},
  year   = {2016},
  eprint = {1603.09320},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1603.09320}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/1603.09320.svg)](https://codeofpaper.com/paper/1603.09320)

Discussion