liveBook · Manning

Approximate nearest neighbor search

Also called ANN, approximate nearest neighbor algorithm

Approximate nearest neighbor search efficiently finds items close to a query under a distance or similarity measure without guaranteeing the exact nearest items.

How 7 Manning books explain it

AI-Powered Search

Approximate nearest neighbor search is a retrieval technique that finds vectors likely to be nearest to a query vector while reducing the computations required for exact nearest-neighbor search.

How it is used
Speeds up dense vector retrieval for semantic autocomplete and document search.
How deep it goes
Explains HNSW’s layered proximity graphs and demonstrates index creation and querying, while relying on a library for algorithm implementation.
Examples
Indexes 12,375 autocomplete embeddings and retrieves related terms for “bag,” then searches question titles for “mountain hike.”
What you can do after
Apply it via NMSLIB to build an HNSW index, encode queries, and retrieve nearest-neighbor candidates.

Read how AI-Powered Search explains approximate nearest neighbor search →

Natural Language Processing in Action, Second Edition

An approximate nearest neighbor algorithm finds items near a query vector with lower computational cost than exhaustive exact search while allowing some accuracy loss.

How it is used
Accelerates semantic search over dense embedding vectors when exhaustive exact search cannot meet scale or latency needs.
How deep it goes
Defines the speed–precision tradeoff, explains LSH and ANN families, and connects indexing choices to production vector databases.
Examples
Uses Wikipedia-scale document retrieval, job-title similarity, LSH, Annoy, pgvector, and hosted vector databases as concrete examples.
What you can do after
Apply it via an ANN index or vector database to build faster semantic retrieval while evaluating acceptable precision loss.

Read how Natural Language Processing in Action, Second Edition explains approximate nearest neighbor search →

MongoDB 8.0 in Action, Third Edition

Approximate nearest neighbor search retrieves vectors near a query vector using an efficient approximation rather than exhaustive comparison.

How it is used
Finds similar embedded documents efficiently through Atlas Vector Search, particularly for semantic search and recommendations.
How deep it goes
Explains HNSW’s layered graph traversal and walks through query parameters, but does not implement the algorithm from scratch.
Examples
Uses a movie-plot embedding query for “village life” and a local index configured with 1,536 dimensions and Euclidean similarity.
What you can do after
Apply it via Atlas Vector Search by configuring an ANN query and choosing when its speed warrants a precision trade-off.

Read how MongoDB 8.0 in Action, Third Edition explains approximate nearest neighbor search →

Building Reliable AI Systems

A search method that efficiently finds vectors close to a query vector while allowing approximate rather than exact nearest neighbors.

How it is used
Uses ANN to retrieve semantically similar listings before filtering and final ranking.
How deep it goes
Explains HNSW graph traversal and index-building parameters, including accuracy, memory, and indexing trade-offs.
Examples
Illustrates retrieval with listing embeddings and a real-time user query.
What you can do after
Evaluate and understand ANN retrieval and HNSW tuning in a production search pipeline.

Read how Building Reliable AI Systems explains approximate nearest neighbor search →

Outlier Detection in Python

A search technique that finds points near a query point with lower computational cost than exact nearest-neighbor search by allowing limited approximation.

How it is used
Supports fast nearest-neighbor searches for large-scale outlier detection and related data-processing tasks.
How deep it goes
Explains the performance motivation, numeric-data limitation, HNSW workflow, and query example without deriving approximation guarantees.
Examples
Demonstrates a datasketch HNSW index over 1,000 ten-feature records and a ten-neighbor query.
What you can do after
Apply it via datasketch HNSW to index numeric records and query approximate nearest neighbors.

Read how Outlier Detection in Python explains approximate nearest neighbor search →

Retrieval Augmented Generation, The Foundational Ideas

Approximate nearest-neighbor search efficiently finds vectors close to a query vector without exhaustively comparing every stored vector.

How it is used
Makes semantic search and RAG retrieval responsive across millions or billions of vectors.
How deep it goes
Contrasts brute-force and approximate search, then emphasizes recall, latency, memory, and monitoring without detailing index internals.
Examples
Uses movie embeddings, Amazon's 200-million-item catalog, and billion-document web search as scale comparisons.
What you can do after
Evaluate ANN deployments by balancing recall, query latency, memory use, and index-growth behavior.

Read how Retrieval Augmented Generation, The Foundational Ideas explains approximate nearest neighbor search →

LLM Customization and Fine-Tuning

An indexing/search approach that trades a small amount of recall for much faster nearest-neighbor retrieval.

How it is used
Speeds up top-k similarity search in vector indexes when exhaustive search becomes too slow.
How deep it goes
Defines the recall-speed tradeoff and names HNSW and IVF, but does not detail their internals.
Examples
Compares NumPy, FAISS, and vector databases across corpus sizes and names HNSW and IVF deployment contexts.
What you can do after
Apply the scale-based guidance to choose an index library or vector database for retrieval.

Read how LLM Customization and Fine-Tuning explains approximate nearest neighbor search →

Also covered in

What to know first

Related concepts

Questions about approximate nearest neighbor search

What is approximate nearest neighbor search?

Approximate nearest neighbor search efficiently finds items close to a query under a distance or similarity measure without guaranteeing the exact nearest items.

Which Manning books explain approximate nearest neighbor search?

AI-Powered Search, Natural Language Processing in Action, Second Edition, MongoDB 8.0 in Action, Third Edition, Building Reliable AI Systems, Outlier Detection in Python, Retrieval Augmented Generation, The Foundational Ideas and LLM Customization and Fine-Tuning.

What should I know before learning approximate nearest neighbor search?

Manning books that teach approximate nearest neighbor search usually introduce embedding, similarity search, vector database and Euclidean distance first.

What is the difference between approximate nearest neighbor search and similarity search?

Approximate nearest neighbor search efficiently finds items close to a query under a distance or similarity measure without guaranteeing the exact nearest items. Similarity search is a retrieval technique that finds or ranks items by their similarity to a query, often by comparing feature or vector representations under a similarity or distance measure.

What is approximate nearest neighbor search also called?

Approximate nearest neighbor search is also called ANN or approximate nearest neighbor algorithm.

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.