Similarity Search and Locality Sensitive Hashing using TCAMs

Rajendra Shinde, Ashish Goel, Pankaj Gupta, Debojyoti DuttaarXiv 2010

TL;DR

This paper introduces Ternary Locality Sensitive Hashing (TLSH), a hardware-accelerated approach to similarity search that leverages Ternary Content Addressable Memories (TCAMs). By using the wildcard capability of TCAMs, the authors achieve $O(1)$ query time and near-linear storage, effectively circumventing theoretical lower bounds for software-based approximate nearest neighbor search.

What Problem Does This Paper Address?

Similarity search—finding the "nearest neighbor" to a query point in a high-dimensional space—is a fundamental kernel for everything from image retrieval to computational biology. However, it faces the notorious "curse of dimensionality": as dimensions increase, exact search methods become no better than a brute-force linear scan.

Existing software solutions like Locality Sensitive Hashing (LSH) offer a trade-off by finding approximate neighbors. While faster than brute force, standard LSH still requires near-quadratic storage space and polynomial query time to be accurate. For high-speed streaming applications (like real-time network traffic analysis or massive-scale web search), even LSH is often too slow or memory-intensive.

Methods

The authors propose moving the problem from general-purpose CPUs to specialized hardware: Ternary Content Addressable Memories (TCAMs). TCAMs are common in high-end networking gear for lightning-fast route lookups. Unlike standard RAM, which returns data given an address, a TCAM returns an address given data. Crucially, TCAMs support a "ternary" state: 0, 1, or * (wildcard).

The core innovation is Ternary Locality Sensitive Hashing (TLSH):

  1. Space Partitioning: Like standard LSH, TLSH uses random hyperplanes to partition the Euclidean space.
  2. Ternary Hashing: While standard LSH hashes regions to 0 or 1, TLSH introduces the wildcard * for regions near the boundaries of these hyperplanes.
  3. Hardware Mapping: Database entries are hashed into ternary vectors and stored in the TCAM. A query is hashed and compared against all entries in parallel in a single hardware clock cycle.
A comparison of LSH and TLSH: LSH hashes regions to 0, 1, 0, 1... while TLSH uses wildcards (*) to "fuzz" the boundaries between regions, improving the probability that nearby points match.

The wildcard * acts as a "fuzzing" mechanism. In standard LSH, two points very close to each other but on opposite sides of a boundary will hash to different values (a false negative). In TLSH, these boundary regions are hashed to *, which matches both 0 and 1, significantly increasing the chance that nearby points are correctly identified as matches.

Datasets

The authors evaluated TLSH using three datasets, each containing one million points in 64-dimensional space:

  • "Random" Data: Points generated uniformly at random from a d-dimensional cube, used as a "benign" baseline.
  • Wikipedia Dataset: Real-world data consisting of "simHash" signatures of English Wikipedia articles (circa 2005).
  • "Threshold" Data: A synthetic dataset specifically designed to be "hard" by placing many points right on the boundaries of similarity, maximizing potential false positives and negatives.

Key Insights and Ideas

  • Beating Theoretical Bounds: The paper notes that TLSH beats the lower bounds of the "cell probe model." In software, a data structure near-linear in size needs $\Omega(\log n / \log \log n)$ probes. Because TCAMs perform massive parallel comparisons in hardware, they achieve $O(1)$ query time.
  • Wildcards as Error Correction: The use of the * state in TCAMs provides a natural way to handle the "boundary problem" in hashing without needing multiple hash tables, which is the standard (and memory-expensive) software workaround.
  • Hardware as a Similarity Engine: The authors demonstrate that enterprise networking hardware (like a Cisco Catalyst switch) can be repurposed as a high-speed similarity search engine.

Key Results

  • Extreme Throughput: Using a Cisco Catalyst 4500 switch, the authors demonstrated 1.5 million queries per second per 1Gb/s port.
  • High Accuracy: On the Wikipedia dataset, a TCAM width of 288 bits achieved an F-score better than 0.95, indicating very high precision and recall.
  • Efficiency: The method requires only a single TCAM lookup and one distance computation to solve the $(1, c)$-Near Neighbor problem with high probability.
  • Scaling: The number of false positives drops rapidly as TCAM width increases, suggesting the method scales well for practical, large-scale datasets.

Limitations and Future Work

  • Hardware Constraints: TCAMs are expensive and consume more power than standard RAM. The width of the TCAM (number of bits per entry) is a physical limit that dictates the maximum dimensionality or number of hash functions one can use.
  • Euclidean Focus: The current TLSH construction is optimized for $L_2$ (Euclidean) space. While the authors suggest it can be adapted, specific constructions for other metrics (like Cosine similarity or Jaccard distance) were not detailed.
  • Database Updates: While lookups are $O(1)$, the paper does not deeply explore the overhead of re-programming the TCAM as the database grows or changes dynamically in a streaming context.

Summary updated

BibTeX
@misc{shinde2010similarity,
  author = {Rajendra Shinde and Ashish Goel and Pankaj Gupta and Debojyoti Dutta},
  title = {{Similarity Search and Locality Sensitive Hashing using TCAMs}},
  year = {2010},
  eprint = {1006.3514},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1006.3514},
}
Figure