The HNSW algorithm (from the English Hierarchical Navigable Small World) finds, in a large set of vectors, those closest to a given one without comparing the query against every one of them: instead of brute-force search, it walks a graph that has layers of short and long links [1]. It was proposed by Yury Malkov and Dmitry Yashunin, who posted a preprint on March 30, 2016 [1]; in the journal version of the paper, Yashunin's address is given as Nizhny Novgorod, and Malkov was by then already the author of the Nizhny Novgorod NSW algorithm, from which HNSW grew [2][3]. Approximate vector search today is almost everywhere built on HNSW: it powers the pgvector extension for PostgreSQL, the Apache Lucene library and the Elasticsearch search engine, and the Qdrant and Weaviate databases [4][5][6][7][8].

The nearest-neighbor problem

Text, an image, or a sound can be converted into a set of numbers — a vector — and then similar objects end up close together in the space of those numbers. To answer a query, it is enough to find the vectors closest to it. An exact answer requires comparing the query against every object in the store; with millions and billions of objects this becomes too expensive, and approximate methods come into play: the Elasticsearch documentation directly describes HNSW as an approximate method that sacrifices some accuracy of the result for speed [8].

The price of this trade-off is measured by recall — the share of true nearest neighbors among those found. Exact brute-force search gives a recall of one, while an approximate index gives slightly less but responds tens and hundreds of times faster; index settings can raise recall at the expense of speed and memory [4].

How it works

The basis is a proximity graph that is searched greedily: from the current point we move to whichever neighbor is closer to the query, and keep going until there is nowhere closer to move. A graph in which a short chain of such moves leads from any object to any other is called a navigable small world; the predecessor, the NSW algorithm, was built on it [3].

HNSW builds a hierarchy on top of this. The algorithm constructs several layers of proximity graphs for subsets of objects nested within one another: the upper layers are sparse and hold long-range links, while the lower ones are dense and hold short-range links. The maximum layer an object reaches is chosen at random, with exponentially decreasing probability. Search begins at the top layer and descends, and it is this separation of links by characteristic distance scales that gives costs growing logarithmically with the number of objects [1].

The second difference from NSW is the rule by which a new object is linked to its neighbors. Instead of simply taking the nearest ones, the algorithm applies a selection heuristic that noticeably improves quality where high recall is required, and on data gathered into dense clusters [1].

The authors also pointed to the kinship of their structure with the skip list — hence, in their words, a simple distributed implementation. The algorithm requires no additional structures at all: it is entirely graph-based, whereas in most earlier methods the graph search was preceded by a separate coarse stage [1].

The index has three settings: how many links an object keeps per layer, how many candidates to consider during construction, and how many during search. In pgvector they default to 16, 64, and 40 [4].

The Nizhny Novgorod line: from MERA Labs to the hierarchy

HNSW continues work that was carried out in the early 2010s at the Nizhny Novgorod company MERA Labs — in publications it appears as MERA Labs LLC, with an address at 13 Delovaya Street. In 2012, Yury Malkov, Alexander Ponomarenko, Andrey Logvinov, and Vladimir Krylov presented at the international Similarity Search and Applications conference (SISAP) an algorithm for distributed approximate search in general metric spaces; the company's Nizhny Novgorod address appears in the publication details of all four [9].

In November 2013, the same four published in the journal Information Systems the NSW algorithm — search on navigable small world graphs; it appeared in the print issue in 2014, volume 45, pages 61–68. Malkov's second affiliation is listed as the Gaponov-Grekhov Institute of Applied Physics of the Russian Academy of Sciences; Ponomarenko's is the Laboratory of Algorithms and Technologies for Network Structure Analysis at the Nizhny Novgorod "Vyshka" (the Higher School of Economics); Krylov's is the Polytech [3].

The hierarchy was added to this graph by Malkov and Yashunin. They revised the preprint for four years — the last of its four versions is dated August 14, 2018 [1] — and the finished work appeared in the journal IEEE Transactions on Pattern Analysis and Machine Intelligence (volume 42, issue 4, pages 824–836; online December 28, 2018) [2].

According to the open bibliographic database OpenAlex, as of November 2026 this work had been cited 3,831 times, which puts it in the top percent of publications in its field by citation count; the 2013 paper on NSW has about six hundred citations [10][11]. The count depends on the database: in an interview from the Nizhny Novgorod Higher School of Economics about the NEYMARK prize awarded to laureate Dmitry Malyshev, a figure of over 4,500 citations was given [12].

Where it is used

The pgvector extension adds vector handling to PostgreSQL. By default it searches exactly, and it has two approximate indexes, the first of which is HNSW: the documentation describes it as a multilayer graph that, at the same recall, responds faster than the alternative, IVFFlat, but takes longer to build and requires more memory. The 2016 paper appears in the extension's list of references [4].

The Apache Lucene library has a package with a telling name, org.apache.lucene.util.hnsw; its description calls the structure a navigable small world graph, "nominally hierarchical," although in that version there was only one layer [5]. Elasticsearch runs on top of Lucene, and its documentation states outright: to search for the k nearest neighbors, the system uses the HNSW algorithm [8].

In the Faiss library, developed by Meta, HNSW is represented by the IndexHNSWFlat class and its variants, and besides serving as a standalone index, it also acts as a quantizer for indexes of the IVF family [6].

In specialized vector databases it takes the place of the main mechanism: in Weaviate, HNSW is the default index type [7], and Qdrant, according to its own documentation, uses nothing else for dense vectors [13]. The authors also have their own implementation: the hnswlib library in C++ with Python bindings, released under the Apache 2.0 license [14].

The semantic search of this encyclopedia runs on the same pgvector, but without an HNSW index: with a few thousand pages, it is cheaper to compare a query against all of them than to build a graph and keep it in memory. The advantage of approximate search begins where there are millions of objects.

Sources

  1. arxiv.org — Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs (preprint, versions 2016–2018)
  2. doi.org — IEEE Transactions on Pattern Analysis and Machine Intelligence — Efficient and Robust Approximate Nearest Neighbor Search Using Hierarchical Navigable Small World Graphs
  3. doi.org — Information Systems — Approximate nearest neighbor algorithm based on navigable small world graphs
  4. github.com — pgvector — vector types and indexes for PostgreSQL: the Indexing and HNSW sections
  5. lucene.apache.org — description of the org.apache.lucene.util.hnsw package
  6. github.com — Faiss — overview of indexes, the IndexHNSW variants section
  7. docs.weaviate.io — Vector indexes: HNSW as the default index
  8. elastic.co — Elasticsearch — the dense_vector type and k-nearest-neighbor search
  9. doi.org — SISAP 2012 — Scalable Distributed Algorithm for Approximate Nearest Neighbor Search Problem in High Dimensional General Metric Spaces
  10. openalex.org — record of the HNSW paper: citation count and citation ranking
  11. api.openalex.org — record of the NSW paper: citation count
  12. nnov.hse.ru — "The Development of AI Has Turned Search into a Dialogue": Professor at the Nizhny Novgorod HSE Campus Becomes Laureate of the NEYMARK — 2026 Prize
  13. qdrant.tech — Indexing: HNSW as the only index for dense vectors
  14. github.com — hnswlib — an HNSW implementation in C++ with Python bindings