Similarity Join Size Estimation using Locality Sensitive Hashing

Hongrae Lee, Raymond T. Ng, Kyuseok Shim

TL;DR

Estimating the size of a similarity join—finding how many pairs in a dataset are "close" to each other—is notoriously difficult when the similarity threshold is high. This paper introduces LSH-SS, a stratified sampling algorithm that leverages Locality Sensitive Hashing to concentrate "true" pairs into manageable buckets, providing accurate size estimates even when only 0.00001% of pairs qualify.

What Problem Does This Paper Address?

In database systems, a similarity join finds all pairs of objects (like documents or images) whose similarity exceeds a certain threshold $\tau$. For a query optimizer to work effectively, it needs to know the size of this join before actually performing it.

The challenge is the "high threshold" problem. At low thresholds, many pairs qualify, and simple random sampling works fine. But at high thresholds (e.g., $\tau = 0.9$), the number of qualifying pairs might be tiny—literally a few thousand out of billions of possibilities. In these cases, a standard random sampler will likely find zero matches, leading to a massive underestimation, or it might find one and wildly overestimate the total. This high variance makes query optimization a nightmare.

Methods

The authors propose a stratified sampling approach called LSH-SS (Locality Sensitive Hashing - Stratified Sampling). The core idea is to use an LSH index to partition the space of all possible pairs into two "strata":

  1. Stratum H (High Probability): Pairs that fall into the same LSH bucket. These are much more likely to be similar.
  2. Stratum L (Low Probability): Pairs that fall into different buckets. These are unlikely to be similar but are far more numerous.

Key Innovations:

  • Stratified Sampling: Instead of sampling the whole dataset uniformly, LSH-SS samples heavily from Stratum H (where the "needles" are concentrated) and uses a different strategy for Stratum L.
  • Adaptive Sampling for Stratum L: To handle the sparse Stratum L, the authors use an adaptive technique that keeps sampling until it either finds enough "true" pairs to be statistically significant or hits a maximum sample limit.
  • Safe Lower Bound: If the sampler doesn't find enough pairs in Stratum L to provide a confident estimate, it returns a "safe lower bound" rather than a high-variance guess. This prevents the catastrophic overestimations that plague standard sampling.

Datasets

The authors evaluated their approach on three large-scale, real-world datasets:

  • DBLP: ~800,000 vectors representing research publications (authors and titles).
  • NYT (New York Times): ~150,000 vectors of news articles using TF-IDF weights.
  • PUBMED: ~400,000 vectors of medical abstracts.

These datasets are representative of the sparse, high-dimensional data common in modern search and recommendation engines.

Key Insights and Ideas

  • LSH as a Statistical Tool: Traditionally, LSH is used for finding similar items. This paper brilliantly repurposes it as a partitioning tool to reduce the variance of statistical estimators.
  • Concentration of Measure: The "aha moment" is realizing that while true pairs are rare in the global space, they are relatively common within LSH buckets. By focusing sampling there, you get a much clearer picture of the "tail" of the similarity distribution.
  • Handling the "Grey Area": The authors acknowledge that there is a middle ground where thresholds aren't quite "high" or "low." Their adaptive sampling naturally adjusts to these cases without requiring the user to manually tune parameters for different thresholds.

Key Results

  • Accuracy at the Edge: On the DBLP dataset with a threshold of 0.9 (selectivity of 0.00001%), standard random sampling failed completely, while LSH-SS provided estimates with very low relative error.
  • Stability: LSH-SS showed significantly lower variance (Standard Deviation) across 100 experiments compared to random sampling and the previous state-of-the-art, Lattice Counting (LC).
  • Efficiency: The estimation process is extremely fast. For the DBLP dataset, LSH-SS took less than 750 milliseconds, making it practical for real-time query optimization.
  • Robustness: The algorithm proved insensitive to the choice of $k$ (the number of hash functions), meaning it works well with any reasonably configured LSH index already present in the system.

Limitations and Future Work

  • Index Dependency: LSH-SS assumes an LSH index is already available or can be built cheaply. While common in similarity search systems, it adds overhead if an index doesn't already exist.
  • Underestimation at Low Thresholds: The paper notes a slight tendency to underestimate at very low thresholds ($\tau \le 0.5$) because the "safe lower bound" logic in Stratum L is conservative. However, the authors argue that users are rarely interested in joins at such low similarities.
  • Parameter Tuning: While robust, the performance still depends on the "dampening factor" ($c_s$) used for the safe lower bound, which might require some domain-specific knowledge to optimize perfectly.

Summary updated

BibTeX
@article{lee2011similarity,
  author = {Hongrae Lee and Raymond T. Ng and Kyuseok Shim},
  title = {{Similarity Join Size Estimation using Locality Sensitive Hashing}},
  journal = {PVLDB},
  year = {2011},
  doi = {10.14778/1978665.1978666},
}
Figure