AI Glossary / Graphs and symbolic AI / Intermediate

Locality-sensitive hash

Definition

A locality-sensitive hash is a hash designed so that similar items are more likely than dissimilar items to receive the same value. Similarity must be defined through an appropriate distance or similarity measure. Locality-sensitive hashing, commonly abbreviated LSH, uses such hashes to generate promising candidates for similarity search without comparing every possible pair directly.

What it means

An ordinary lookup hash supports finding exact keys efficiently. Locality-sensitive hashing addresses a different question: which stored items are close to this item under a chosen representation? Sharing a bucket is useful evidence for further comparison, but it is not proof that the items are equivalent.

The idea is probabilistic. Nearby items can fail to collide, and distant items can collide. A complete search design combines hashes and checks candidate similarities to manage these errors. The selected representation remains crucial: similarity between text token sets, for example, is not the same as similarity of meaning between documents.

How it works

Choose a representation and similarity measure, then choose a hash family with the appropriate collision behavior. MinHash is associated with Jaccard similarity between sets. Random-hyperplane hashing relates collision probability to the angle between nonzero vectors. These methods are not interchangeable without considering the intended geometry.

Build signatures or bucket keys for stored items and for a query. Items sharing selected keys become candidates. Compare candidates with the intended similarity measure or another validated verification step.

Combining several hash matches within one table can reduce accidental collisions. Using multiple tables or bands can recover more nearby items. These choices trade memory, computation, candidate counts, and missed matches. A threshold applied after retrieval does not recover similar items that were never retrieved as candidates.

Three practical examples

1. A document-processing team uses word-shingle sets and MinHash-based candidate generation to locate near-duplicate text for subsequent comparison.

2. An image-search prototype hashes suitable feature vectors to retrieve a smaller set of visually similar candidates. The quality of those features affects what “similar” means.

3. A data-cleaning workflow groups potentially related records for detailed matching. A bucket collision is a screening signal, while record-merging decisions require additional evidence and explicit rules.

Think of it this way

Think of sorting library cards into several rough indexes so that related cards have a good chance of appearing together in at least one drawer. You inspect the resulting shortlist instead of reading the whole catalog every time.

The analogy has limits: the actual grouping follows a mathematical hash construction and a defined similarity measure. A shared drawer can contain unrelated cards, and a relevant card may be missed. The index helps decide where to look; it does not establish the final relationship between items.

Worked example

Take sets A = {a,b,c,d} and B = {a,b,c,e}. Their intersection has three elements and their union has five, so Jaccard similarity is 3/5 = 0.6. Under ideal MinHash using a uniformly random ordering, one hash matches with probability 0.6.

Suppose an illustrative scheme uses two independent hashes per band and three independent bands. A band matches only when both hashes match, giving probability 0.6 squared = 0.36. A pair becomes a candidate when at least one band matches.

The probability of no band matching is (1 - 0.36) cubed = 0.64 cubed = 0.262144. Candidate probability is therefore 1 - 0.262144 = 0.737856, or about 73.8%.

For a pair with Jaccard similarity 0.2, the same calculation gives 1 - 0.96 cubed = 0.115264, about 11.5%. The scheme favors the more similar pair but neither guarantees retrieval nor eliminates accidental candidates. These are idealized probability calculations assuming independence, not measured software performance.

Illustrative case study

Fictional case: Pine Archive wants to review near-duplicate manuals before consolidating its catalog. Analysts build shingle sets and an LSH index, then compute detailed similarities for retrieved candidates.

They retain a separately checked sample of similar and dissimilar pairs to assess missed candidates and review workload. A shared copyright notice creates some misleading similarities, so the team examines preprocessing rather than merely increasing the number of hash tables. Final consolidation decisions remain separate from candidate retrieval. This fictional workflow reports no real storage reduction or duplicate-detection accuracy.

Common misconceptions and mistakes

Do not assume a hash match proves duplicate content. Even high similarity under a chosen representation may leave meaningful differences, such as a changed instruction or version number.

Do not confuse locality sensitivity with cryptographic security or anonymization. A similarity-preserving signature is not, merely by being a hash, a guarantee that underlying information is hidden.

Also distinguish approximate candidate generation from exact nearest-neighbor certification. Standard LSH configurations can miss relevant neighbors. Any stronger guarantee must come from the particular construction and assumptions, not from the general term “hash.”

Business use

For business applications, define the cost of a missed match and the cost of reviewing a false candidate before tuning parameters. Measure recall on representative known matches, alongside latency, index size, and candidate volume.

Keep preprocessing and hash settings consistent between indexed items and queries. When the representation changes, determine whether the index must be rebuilt. Evaluate the final workflow separately from the retrieval stage: a fast shortlist is useful only if it retains enough relevant items and the subsequent decision process interprets them correctly.

People also ask

Does LSH guarantee that similar items share a hash?

Standard constructions provide probability-based behavior, not an unconditional guarantee for every nearby pair. Exact guarantees depend on the chosen variant.

Is one locality-sensitive hash enough for reliable retrieval?

Usually a practical design combines several hashes and verifies candidates. The right configuration depends on the desired error and resource trade-offs.

Can the same hash family be used for every similarity measure?

No. The collision behavior must match the chosen geometry, such as Jaccard similarity or angular distance.

Check your understanding

In the worked example, does a 73.8% candidate probability mean the documents are 73.8% similar?

Answer: No. Their Jaccard similarity is 60%. The 73.8% value is the retrieval probability produced by the specified combination of independent hashes and bands.

Related terms

  • Random projection
  • Similarity Search
  • Recall
  • Approximate nearest neighbor
  • MinHash
  • Jaccard similarity
  • hash collision

Learn next

Study MinHash's collision probability, then vary the number of rows per band and number of bands. Track candidate probability separately from true similarity and from the final decision threshold.

More in Graphs and symbolic AI

  • Local consistency - Local consistency is a family of conditions used in constraint satisfaction to check whether assignments to small groups of variables can be extended...
  • Local search - Local search is a family of methods that looks for useful solutions by modifying current candidate solutions and evaluating nearby alternatives.
  • Localist representation - A localist representation assigns a particular concept or item to a dedicated representational unit.
  • Locking - In historical automated theorem proving, locking is a restriction on resolution that uses labels on literal occurrences to control which inferences are...
  • Logic - Logic provides formal ways to express statements and determine what follows from them.
  • Logical connectives - Logical connectives are operators that combine or modify statements to form more complex statements.

Sources

Stanford CS246, locality-sensitive hash families and amplification: https://snap.stanford.edu/class/cs246-2015/slides/04-lsh_theory.pdf

Stanford CS168, MinHash and Jaccard probability: https://theory.stanford.edu/~tim/s16/l/l4.pdf

The set example and fictional archive case are original teaching illustrations.

Previous: Localist representation Next: Localization

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer