AI GLOSSARY · AI CONCEPTS
Hierarchical Navigable Small World (HNSW)
Definition
HNSW (Hierarchical Navigable Small World) is a graph-based method for approximate nearest neighbor search: it finds vectors close to a query without comparing against all of them, by searching through layered graphs from sparse to dense.
Also called: HNSW, HNSW index, HNSW algorithm, HNSW graph, hierarchical navigable small world graphs.
In plain language
Imagine finding a street in an unfamiliar country. You do not check every house: you look at a country map, then a regional map, then a city map, then the street. HNSW does the same for lists of numbers that stand for the meaning of text or images. It builds several maps of the data, from coarse to detailed, and starts at the coarse one. This lets a search system return items very similar to your query quickly. The catch is that the result is approximate, so the true closest item can be missed, and the graph is held in memory, which costs more as the data grows.
Technical definition
HNSW, proposed by Malkov and Yashunin (arXiv 1603.09320, first submitted 30 March 2016), builds a multi-layer set of proximity graphs over nested subsets of the data. Each element's top layer is drawn at random with an exponentially decaying probability, so upper layers are sparse. A query enters at the top layer, moves greedily to the neighbour closest to the query until no neighbour is closer, then drops a layer and repeats down to layer 0, which holds all vectors. Build and query behaviour is tuned by parameters such as M (links per vertex), efConstruction and efSearch, which trade recall against build and search time; only M affects index memory, per Pinecone.
Worked examples in this catalogue
Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.
Skill by Skill Almanac · Illustrative, not executed
rag-chunking-planner 56/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- Your documents chunked by three strategies, with defects and offline recall measured for each, so chunk settings are chosen with numbers.
- Why it exercises the concept
- An index such as HNSW can only return the chunks you stored. This skill measures the chunking step that decides what is available to find.
Skill by Skill Almanac · Illustrative, not executed
library-docs-lookup 52/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- An answer to a library question drawn from the installed package's own files, with file and line cited.
- Why it exercises the concept
- It is retrieval for a coding agent by reading files. It shows the lookup problem that vector indexes solve at larger scale, without using one.
Guide · Illustrative, not executed
What Is RAG? Retrieval-Augmented Generation Explained
- What you see
- The guide walks through indexing and querying, then a worked chunking example.
- Why it exercises the concept
- The query phase of RAG is where a nearest neighbor index such as HNSW is usually used.
How it shows up when you use agents
If you build an agent or a RAG pipeline, your documents are turned into embeddings, lists of numbers whose closeness reflects similarity of meaning. A vector database then has to find the stored vectors nearest to a question's vector. Comparing against all of them gets slow as the collection grows, so many systems build an approximate index. HNSW is one such index. IBM lists it as an index type that vector databases use, and Weaviate documents it as its default index type.
You usually do not call HNSW yourself. You meet it as settings in a vector store: a link count (often called M), a build-time candidate list size (efConstruction) and a query-time one (efSearch). Pinecone's write-up says a higher M improves recall but raises memory and search time, and that efSearch can be changed after the index is built.
What breaks when it is misunderstood: people treat the top result as exact, then blame the language model when a relevant passage was simply missed by the approximate search. The next action is to test recall on a small set of questions with known answers, and raise the query-time setting before changing prompts. Also plan memory, because the graph must be stored alongside the vectors. This matters for semantic search too: measure retrieval first.
Common confusions
- HNSW versus a vector database. HNSW is an algorithm and index structure. A vector database is a system that stores vectors and may use HNSW, among other index types.
- Approximate versus exact search. HNSW returns neighbours that are very likely close, not a guarantee of the closest. Exact search compares against all vectors and gets slower as data grows.
- HNSW versus embeddings. Embeddings are the vectors. HNSW is how you search among them.
- Myth. Higher recall settings are free. In Pinecone's tests, raising M costs memory and raising efSearch costs search time.
Related terms
Terms that mention Hierarchical Navigable Small World (HNSW)
6 terms mention this one
More in AI concepts
Sources
- Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs, arXiv (Malkov and Yashunin) (accessed 2026-11-24)
- Hierarchical Navigable Small Worlds (HNSW), Pinecone (accessed 2026-11-24)
- What is a vector database?, IBM (accessed 2026-11-24)
- Vector Indexing, Weaviate (accessed 2026-11-24)
Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-24. Wikipedia is never the only source.
Review record
Last verified
Drafted by claude-sonnet-5-5; sources and example targets checked by claude-haiku-5-5 source check; claude-sonnet-5-5 editor pass on 2026-11-24. Last verified .
This entry is still in review, so it is not listed in search engines yet.
Change log (2)
- : First version.
- : Verifier pass: applied verifier corrections to sourcing and wording.