Locality-Sensitive Hashing (LSH) is a probabilistic dimensionality reduction method that uses a family of hash functions to map high-dimensional data points into compact binary codes, or buckets. The core property is that the probability of collision is high for points that are close in the original space and low for points that are far apart. This contrasts with conventional cryptographic hashing, where a tiny input change produces a radically different hash. LSH trades perfect accuracy for dramatic speed gains, reducing the complexity of a nearest neighbor search from linear to sub-linear time.
Glossary
Locality-Sensitive Hashing (LSH)

What is Locality-Sensitive Hashing (LSH)?
Locality-Sensitive Hashing (LSH) is an algorithmic technique that hashes similar input items into the same buckets with high probability, enabling efficient approximate nearest neighbor search in high-dimensional spaces.
Common LSH families are tailored to specific distance metrics. For Jaccard similarity between sets, the MinHash scheme is used. For cosine similarity between vectors, a random hyperplane projection generates a binary bit. For Euclidean distance, projections onto random lines with a fixed bucket width are employed. These generated hashes are typically stored in multiple hash tables to boost recall. LSH is a foundational component in scalable vector database indexing, powering deduplication pipelines, recommendation systems, and the efficient retrieval phase of Retrieval-Augmented Generation (RAG) architectures.
Key Features of LSH
Locality-Sensitive Hashing transforms high-dimensional data into compact signatures where similarity is preserved. These core features define how LSH enables efficient approximate nearest neighbor search at scale.
Hash Collision Probability
The defining property of LSH: similar items collide in the same bucket with high probability, while dissimilar items are mapped to different buckets. This is formalized through a distance-sensitive family of hash functions where the collision probability Pr[h(x) = h(y)] = sim(x, y). For cosine similarity, random hyperplane projections achieve this; for Jaccard similarity, MinHash provides the guarantee. The probability curve creates a sharp threshold—items above a similarity cutoff almost certainly collide, while those below almost never do.
Amplification via AND-OR Construction
LSH controls precision and recall through banding techniques that combine multiple hash functions:
- AND construction (r rows): Concatenating r hash values into a single signature reduces false positives by requiring agreement across all r functions
- OR construction (b bands): Using b independent hash tables reduces false negatives by allowing a match in any band
- The S-curve effect: The AND-OR composition creates a steep sigmoid probability curve, giving near-certain collision above a tunable similarity threshold and near-zero collision below it
Sublinear Query Time
LSH achieves O(n^ρ) query time where ρ < 1, dramatically outperforming brute-force O(n) linear scans. For a dataset of 1 billion vectors, an LSH index with ρ = 0.5 reduces comparisons from 1 billion to approximately 31,600. The parameter ρ is determined by the hash family's sensitivity and the desired similarity threshold. This sublinear scaling is what makes LSH viable for billion-scale nearest neighbor search in production systems like image retrieval and recommendation engines.
Distance Metric Specialization
LSH families are designed for specific distance metrics, each with distinct hash constructions:
- Cosine similarity: Random projection using a random hyperplane; the sign of the dot product determines the hash bit
- Jaccard similarity: MinHash uses the minimum hash value of set elements under random permutations
- Euclidean distance (L2): p-stable distributions (e.g., Gaussian) project points onto random lines, then quantize into buckets
- Hamming distance: Bit sampling directly selects random bit positions
- Earth Mover's Distance: Specialized embeddings for distributional similarity
Locality-Sensitive Families
A hash family H is (d₁, d₂, p₁, p₂)-sensitive if for any two points:
- If d(x, y) ≤ d₁, then Pr[h(x) = h(y)] ≥ p₁
- If d(x, y) ≥ d₂, then Pr[h(x) = h(y)] ≤ p₂ Where p₁ > p₂ and d₁ < d₂. This formal guarantee ensures a gap between the collision probability of close and far points. The amplification gap (p₁ vs p₂) determines how effectively AND-OR construction can separate similar from dissimilar pairs, with larger gaps enabling more efficient indexes.
Candidate Pair Filtering
LSH functions as a pre-filter for exact distance computation, not a replacement. The workflow:
- Hash the query point into all LSH tables
- Retrieve all items that share at least one bucket with the query (candidate pairs)
- Compute exact distances only on candidates, typically reducing comparisons by 99% or more
- Return the k-nearest verified neighbors This two-phase approach guarantees exact results on the filtered set while avoiding the prohibitive cost of exhaustive comparison across the entire dataset.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about locality-sensitive hashing, its mechanisms, and its role in modern approximate nearest neighbor search.
Locality-sensitive hashing (LSH) is an algorithmic technique that hashes similar input items into the same buckets with high probability, enabling efficient approximate nearest neighbor search in high-dimensional spaces. Unlike traditional cryptographic hashes where a single bit change produces a completely different output, LSH functions are designed so that the collision probability between two points increases with their similarity. The core mechanism involves projecting data points through multiple randomized hash functions that partition the space. Points that are close in the original space will likely fall on the same side of each random partition, generating identical hash codes. By using multiple hash tables (an amplification technique), LSH reduces false negatives while maintaining sub-linear query time. Common LSH families include MinHash for Jaccard similarity on sets, SimHash for cosine similarity on vectors, and p-stable distributions for Euclidean distance. This makes LSH a foundational technique for deduplication, near-duplicate detection, and large-scale similarity search in systems like FAISS and content fingerprinting platforms.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Understanding Locality-Sensitive Hashing requires familiarity with the distance metrics, alternative hashing schemes, and search structures that enable efficient approximate nearest neighbor retrieval in high-dimensional spaces.
Hamming Distance
A fundamental metric for comparing binary hash codes generated by LSH. It measures the number of bit positions where two equal-length strings differ.
- Calculation: XOR two binary strings, count the set bits
- LSH Context: Used when LSH outputs compact binary codes; similar items have a small Hamming distance
- Example: The binary strings
101010and101110have a Hamming distance of 1 - Efficiency: Computable in O(1) with hardware-level POPCNT instructions on modern CPUs
Cosine Similarity
The most common similarity measure used in conjunction with LSH for comparing dense vector embeddings from neural networks.
- Definition: Measures the cosine of the angle between two non-zero vectors, ranging from -1 (opposite) to 1 (identical)
- LSH Families: Random hyperplane LSH uses random projections to hash vectors based on which side of a hyperplane they fall on
- Scale Invariance: Unlike Euclidean distance, cosine similarity ignores vector magnitude, focusing purely on directional alignment
- Use Case: Dominant in semantic search systems comparing BERT or GPT embeddings
MinHash
A specific LSH scheme optimized for estimating the Jaccard similarity between sets, widely used for document deduplication.
- Mechanism: Applies multiple hash functions to a set's elements and keeps only the minimum hash value from each function
- Property: The probability that two sets share the same MinHash value equals their Jaccard similarity
- Band Partitioning: MinHash signatures are split into bands to amplify the probability of collision for similar sets
- Application: Powers near-duplicate detection in web crawling and plagiarism checking systems
SimHash
A dimensionality reduction technique that produces a compact fingerprint where similar documents yield hashes with a small Hamming distance.
- Algorithm: Weights each feature of a document by its TF-IDF score, then collapses the weighted vector into a binary fingerprint
- Key Property: Similar documents produce fingerprints differing in only a few bits, enabling efficient near-duplicate detection
- Google's Use: Famously employed in Google's web crawler to detect duplicate pages at scale
- Difference from MinHash: SimHash works on weighted feature vectors, while MinHash operates on sets
Approximate Nearest Neighbor (ANN) Search
The broader problem that LSH is designed to solve, trading a small amount of accuracy for dramatic speed improvements in high-dimensional spaces.
- The Curse of Dimensionality: Exact nearest neighbor search degrades to linear scan in high dimensions
- LSH as an Index: LSH serves as the indexing layer, partitioning the vector space so only a few buckets need to be searched
- Alternative ANN Methods: Graph-based (HNSW), tree-based (Annoy), and quantization-based (IVF) approaches
- Performance Trade-off: LSH offers sub-linear query time with probabilistic guarantees on recall

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us