liveBook · Manning

Locality-sensitive hashing

As explained in Natural Language Processing in Action, Second Edition

Locality-sensitive hashing is a hashing technique designed to map similar high-dimensional objects to the same or nearby hash buckets with relatively high probability.

Locality-sensitive hashing (LSH) is an approximate indexing technique for high-dimensional vectors. It assigns hashes to regions of hyperspace, making nearby embeddings easier to retrieve without comparing a query against every document. The trade-off is deliberate: retrieval becomes faster, while precision may decline. section 4.8.1 section 10.3.4

Use LSH with these practical expectations:

  • Treat it as an approximate k-nearest-neighbors method that performs both vector indexing and neighbor retrieval. section 10.3.4
  • Prefer it when exhaustive search would require one similarity comparison for every document, especially at large collection sizes. section 4.8.1 section 10.3.4
  • Measure quality rather than assuming exact matches: accuracy deteriorates around 12 dimensions in the illustrated semantic-search setting, and results become especially poor beyond 16 dimensions. section 4.8.1

Semantic search at scale

A semantic-search system can convert a query and documents into topic or embedding vectors, use LSH to index the vectors, and retrieve approximate neighbors instead of calculating dot products against millions of articles. For production deployments, LSH is one indexing choice alongside tree-based and graph-based methods; hosted vector databases can manage scaling. section 10.3.4 section 10.3.5

Figure 4.5 Semantic search accuracy deteriorates at around 12 dimensions
figure

Inspect the dimensionality comparison showing how semantic-search accuracy deteriorates as vector dimensions increase. section 4.8.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains hyperspace regions, exhaustive-search costs, accuracy limits, and production alternatives, but defers implementation details.
Examples
Uses semantic vectors, millions of articles, dimensionality comparisons, and production systems such as Faiss and hosted vector databases.
What it assumes
Assumes familiarity with vectors, embeddings, similarity comparison, and semantic search; motivates why exhaustive search does not scale.
What you can do after
Apply it via an ANN indexing pipeline while evaluating retrieval-speed gains against reduced precision.
How it connects
Connects locality-sensitive hashing with semantic search, embeddings, cosine similarity, approximate nearest neighbors, and vector databases.

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.