HNSW stands for Hierarchical Navigable Small World. It searches a stack of proximity graphs: sparse upper layers guide the route, then the base layer searches among all indexed vectors. Choose a query and press Play to follow each expansion and descent.
Search breadth (efSearch) controls how many promising candidates the base-layer search retains. It is not a cap on distance calculations. A wider search can find better neighbours at the cost of more work, but cannot guarantee perfect recall. At the end, compare the three returned neighbours with exact search and see how many unique vectors were scored. The separate exact comparison is excluded from that work count.
This example uses 36 fixed four-dimensional vectors, a sparse index with M = 2 and entry point N01. Distances use all four dimensions. The plot uses two coordinates plus organisational height for layers, so screen proximity can be misleading. Repeated nodes across layers represent the same vector. Fixed levels and simple neighbour selection make this a teaching model, not a production benchmark.
The maths
- How many true neighbours did we find?
A is the returned set and E is the exact nearest-neighbour set. Finding two of the exact top three gives about 67% recall for this query. The final comparison shows both sets; exact search scores all 36 vectors separately.
Sources and model assumptions
Follow the original mechanism behind this explainer. The interactive examples identify their toy data and simplifying assumptions above.
Related terms
- Vector databaseA vector database stores embeddings and finds the nearest ones to a query vector quickly. It is an index for meaning, and for small corpora you very often do not need one.
- EmbeddingsAn embedding turns a piece of text into a list of numbers that captures its meaning, so that similar ideas land near each other. Embeddings are what let you search by meaning instead of by exact keyword.