Imagine you have one billion images and you want to find the ten most similar to a new one. Comparing every pair would take years. Yet Google Images, Spotify, and TikTok do something like this in milliseconds. The trick is Locality-Sensitive Hashing (LSH).
Normal hash functions are designed to make similar inputs produce wildly different outputs â a single changed character flips half the bits. LSH deliberately inverts this: it uses hash functions where similar inputs are likely to land in the same bucket, while dissimilar inputs are likely to land in different ones.
The idea sounds modest, but its consequences are enormous. Instead of comparing your query to all one billion items, you hash the query, look up its bucket, and compare only the small number of items that collided there. With the right LSH family the probability of collision is mathematically tied to similarity â nearby things collide often, far-away things almost never.
The technique was formalized by Piotr Indyk and Rajeev Motwani in 1998 in their landmark paper on approximate nearest-neighbor search in high-dimensional spaces. Today every major recommendation engine, duplicate-detection system, and semantic search index uses some descendant of their idea.
Comments
Loading comments...