liveBook · Manning

HNSW

As explained in Natural Language Processing in Action, Second Edition

Hierarchical Navigable Small World is a graph-based approximate nearest-neighbor algorithm that organizes navigable proximity graphs into progressively sparser layers.

Hierarchical Navigable Small World (HNSW) is a graph-based approximate nearest-neighbor index. It connects vectors to nearby neighbors, then organizes those connections into progressively sparser layers for fast navigation. section 10.3.5

HNSW searches from coarse navigation to local precision:

  • Builds a navigable small-world graph in which each vector connects to close neighbors. section 10.3.5
  • Places fewer, more widely separated points in higher layers. section 10.3.5
  • Traverses downward through the layers, trading retrieval speed and throughput against nearest-neighbor precision and recall. section 10.3.5 section 10.3.9

Semantic QA under resource constraints

A Haystack question-answering application used the HNSW option in Faiss to fit within a free-tier Hugging Face server. Its vector index retrieves relevant documents before a reader extracts an answer, requiring a balance among speed, RAM, and recall. section 10.3.9

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains neighbor graphs, sparse layers, and traversal intuition, but defers detailed index tuning.
Examples
Uses social-network degrees of separation, international travel, and a Haystack QA application backed by Faiss.
What it assumes
Assumes familiarity with vectors and semantic search while introducing graph navigation through accessible analogies.
What you can do after
Operate HNSW through Faiss and Haystack while evaluating speed, RAM requirements, and recall for semantic retrieval.
How it connects
Connects approximate nearest-neighbor search with embeddings, semantic search, vector databases, recall, and throughput.

Also explained in

Compare how 7 books explain HNSW →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.