We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Locality-Sensitive Hashing

Checking every single vector in our dataset for every query is really slow. Locality Sensitive Hashing (LSH) offers a clever solution: pre-group similar vectors into "buckets" using a special hash function. Then, when we search for similar vectors, we check only those in the same bucket.

LSH is a tradeoff: it speeds up searches but can miss some similar vectors. In ML terms, you get lower recall. Use LSH when speed matters more than perfect accuracy.

For example, assume we have an LSH hash function called lsh_hash. It might group the following movies like this:

lsh_hash(jungle_book_vec)  # bucket A
lsh_hash(indiana_jones_vec)  # bucket A
lsh_hash(tarzan_vec)  # bucket A
lsh_hash(holy_grail_vec)  # bucket B
lsh_hash(life_of_brian_vec)  # bucket B