HNSW
HNSW is a graph-based approximate nearest-neighbor indexing and search method that organizes data points in a hierarchy of navigable proximity graphs.
Just Use Postgres!
An HNSW index is a graph-based approximate nearest-neighbor index using a hierarchical navigable small-world graph.
- How it is used
- Optimizes vector similarity search for generative-AI applications such as movie recommendations.
- How deep it goes
- Explains graph layers, traversal, index creation, execution plans, recall, and ef_search, without deeper implementation theory.
- Examples
- Demonstrates movie-embedding searches, PostgreSQL index definitions, execution plans, returned movie rows, and ef_search tuning.
- What you can do after
- Operate/configure HNSW in PostgreSQL, inspect its query plan, and adjust search accuracy with ef_search.
Generative AI in Action
HNSW is a graph-based approximate nearest-neighbor indexing algorithm that organizes vectors in navigable hierarchical layers.
- How it is used
- Speeds similarity search over embeddings for retrieval and matching workflows.
- How deep it goes
- Defines graph organization, contrasts HNSW with brute-force FLAT, and specifies metrics and schema settings without deriving graph internals.
- Examples
- Uses a Redis blog-post index with FLOAT32 embeddings, 1536 dimensions, and COSINE distance.
- What you can do after
- Operate/configure Redis vector search by selecting HNSW and setting vector type, dimensions, and distance metric.
AI-Powered Search
HNSW is a graph-based approximate nearest neighbor indexing and search algorithm that builds a multilayer hierarchy of proximity graphs.
- How it is used
- Supports dense-vector retrieval and semantic autocomplete when full-corpus similarity comparison is too expensive.
- How deep it goes
- Explains multilayer graph construction and gives an implementation workflow, while deferring detailed algorithm internals.
- Examples
- Demonstrates concept autocomplete for “bag,” “mountain hike,” and “dehyd” using nearest-neighbor result lists.
- What you can do after
- Apply HNSW via NMSLIB by indexing normalized embeddings and querying filtered nearest neighbors.
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.
- How it is used
- Balances semantic-search speed, memory use, and recall when choosing a vector database index.
- 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 you can do after
- Operate HNSW through Faiss and Haystack while evaluating speed, RAM requirements, and recall for semantic retrieval.
Read how Natural Language Processing in Action, Second Edition explains HNSW →
MongoDB 8.0 in Action, Third Edition
HNSW is a graph-based approximate nearest-neighbor search algorithm that organizes data points into multiple navigable layers.
- How it is used
- Accelerates approximate similarity search for large-scale, real-time applications.
- How deep it goes
- Explains layered graph construction and greedy descent, but does not specify index-tuning parameters or implementation code.
- Examples
- Uses layered vector graphs and Atlas $vectorSearch queries with exact set to false as concrete examples.
- What you can do after
- Apply HNSW through Atlas Vector Search indexes and $vectorSearch for fast approximate retrieval of semantically similar documents.
Read how MongoDB 8.0 in Action, Third Edition explains HNSW →
Outlier Detection in Python
HNSW is a graph-based approximate nearest-neighbor data structure that organizes navigable connections between data points.
- How it is used
- Accelerates approximate nearest-neighbor searches in large-scale numeric outlier-detection workflows.
- How deep it goes
- Demonstrates index construction and querying, but stops short of explaining internal navigation mechanics or accuracy trade-offs.
- Examples
- Uses 1,000 random ten-feature rows, a NumPy Euclidean distance function, sequential insertion, and a ten-neighbor query.
- What you can do after
- Apply it via datasketch to build an index and query approximate nearest neighbors for numeric vectors.
Building Reliable AI Systems
Hierarchical Navigable Small World is an approximate nearest-neighbor search algorithm that organizes vectors in a multilayer graph.
- How it is used
- Accelerates approximate nearest-neighbor search across vector collections without scanning every vector.
- How deep it goes
- Explains graph navigation, complexity, tuning parameters, and trade-offs, then demonstrates FAISS configuration without deriving the algorithm.
- Examples
- Shows a FAISS index for 10,000 128-dimensional vectors and policy retrieval through Pinecone.
- What you can do after
- Apply HNSW through FAISS to index vectors and retrieve nearest neighbors, then benchmark against alternatives for the workload.
Related concepts
- approximate nearest neighbor algorithmimplements · An approximate nearest neighbor algorithm efficiently finds items close to a query under a distance or similarity measure without guaranteeing the exact nearest items.
- flatalternative to · A flat index is a vector-search structure that compares each query directly with every stored vector without partitioning or compression.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.






