Locality-Sensitive Hashing (LSH) finds similar items without comparing every pair of them, which is extremely slow for large datasets. It puts items into buckets so that similar ones are likely to land together, and we compare only those.
Here we apply LSH to MinHash signatures, short columns of numbers that summarise documents.
The setup: bands and rows
We write the signatures as the columns of a matrix, one column per document. Then we cut the matrix into \(b\) bands of \(r\) rows each, so a signature has length \(n = br\).
Each band is hashed separately. Two documents become a candidate pair if they share a bucket in at least one band. We assume there are enough buckets that, in practice, only identical bands share one.
We need just four quantities:
- \(s\): the Jaccard similarity of two documents
- \(r\): the number of rows in a band
- \(b\): the number of bands
- \(P\): the probability that the two documents become a candidate pair
Deriving the formula

We build the formula from the inside out. By the MinHash property, two signatures agree in any one row with probability \(s\). Treating the rows as independent:
- All rows of a band are equal: \(s^r\)
- Some row of a band is unequal: \(1 - s^r\)
- None of the \(b\) bands is identical: \((1 - s^r)^b\)
- At least one band is identical: the complement of step 3
Therefore:
\[ P = 1 - (1 - s^r)^b \]
The S-curve and its threshold
Plotted against \(s\), this probability forms an S-curve:
- When \(s\) is low, \(P\) is close to 0, so the pair is usually filtered out.
- When \(s\) is high, \(P\) is close to 1, so the pair is usually kept.
- In between, \(P\) rises steeply around a threshold \(t\):
\[ t \approx \left(\frac{1}{b}\right)^{1/r} \]
The picture above is idealised: it draws the rise as almost vertical. With realistic values of \(b\) and \(r\), the curve climbs more gradually.
The formula for \(t\) is only an approximation. With \(b = 20\) and \(r = 5\) it gives 0.55, while \(P\) reaches 0.5 at a similarity of about 0.51.
Example: 20 bands of 5 rows
Let \(b = 20\) and \(r = 5\), so each signature holds \(20 \times 5 = 100\) hash values. The threshold is:
\[ t \approx \left(\frac{1}{20}\right)^{1/5} \approx 0.55 \]

Reading the table:
- \(s = 0.2\): only 0.6% of such pairs become candidates, so we almost never waste time on them.
- \(s = 0.4\): 18.6% get through. Most are filtered out, but not all.
- \(s = 0.6\): just above the threshold, the chance jumps to 80.2%.
- \(s = 0.8\): the chance is 99.96%, so only about 1 pair in 2,800 is missed.
Two kinds of error
No choice of \(b\) and \(r\) gives a perfect step, so LSH makes two kinds of mistakes:
- False positives: dissimilar pairs that become candidates. We remove them by checking each candidate pair afterwards, at the cost of extra work.
- False negatives: similar pairs that never share a bucket. We never compare them, so they are lost.
Tuning the filter
Changing \(b\) and \(r\) moves the curve:
| \(b\) | \(r\) | \(n = br\) | \(t\) | \(P\) at \(s = 0.4\) | \(P\) at \(s = 0.8\) |
|---|---|---|---|---|---|
| 20 | 5 | 100 | 0.55 | 0.186 | 0.9996 |
| 50 | 5 | 250 | 0.46 | 0.402 | > 0.9999 |
| 10 | 5 | 50 | 0.63 | 0.098 | 0.981 |
| 20 | 8 | 160 | 0.69 | 0.013 | 0.975 |
- More bands (\(b\)) shift the curve to the left. We miss fewer similar pairs but check more dissimilar ones.
- More rows (\(r\)) shift it to the right. We check fewer dissimilar pairs but miss more similar ones.
- Increasing both can make the curve steeper while keeping the threshold in place, but needs longer signatures.
First decide how similar two documents must be to interest us. Then choose \(b\) and \(r\) so that \(t\) is near that value, a little lower if missing a pair is costly, or a little higher if checking pairs is costly.
Key takeaways
- LSH replaces a brute-force comparison of all pairs with a check of candidate pairs only.
- A pair with similarity \(s\) becomes a candidate with probability \(1 - (1 - s^r)^b\).
- The threshold \((1/b)^{1/r}\) tells us roughly where the filter switches from rejecting to accepting.
- With \(b = 20\) and \(r = 5\), most pairs below 0.4 similarity are removed, and nearly all pairs at 0.8 or above are kept.
References
- Leskovec, J., Rajaraman, A. and Ullman, J. D. (2020). Mining of Massive Datasets (3rd ed.). Cambridge University Press. doi:10.1017/9781108684163. Chapter 3, Finding Similar Items (archived copy): Section 3.4, LSH for documents and the analysis of banding.
- Broder, A. Z. (1997). On the resemblance and containment of documents. Proceedings of Compression and Complexity of SEQUENCES, 21–29.
- MinHash LSH, documentation of the
datasketchPython library.