Practice with Graph-based ANN Algorithms on Sparse Data: Chi-square Two-tower model, HNSW, Sign Cauchy Projections

Ping Li, Weijie Zhao, Chao Wang, Qi Xia, Alice Wu, Lijun PengarXiv 2023 · OpenReview

Abstract

Sparse data are common in industrial applications, where handcrafted features and ReLU-activated embeddings often exhibit high sparsity. This paper explores efficient search in sparse data using graph-based Approximate Nearest Neighbor (ANN) algorithms like HNSW and its GPU variant, SONG. We introduce a "chi-square two-tower" model that, when integrated with ReLU, produces highly sparse embeddings. To further optimize performance, we incorporate Sign Cauchy Random Projections (SignCRP) to hash vectors into bits, reducing memory costs and accelerating search. Our results on proprietary LinkedIn Ads data and public benchmarks demonstrate significant improvements in retrieval efficiency and memory usage.

Introduction

In modern recommendation and advertising systems, Embedding-Based Retrieval (EBR) is essential for matching queries with billions of potential items. Standard two-tower models typically use cosine similarity, but these often fail to fully exploit the sparsity inherent in modern neural networks. As the scale of data grows, the computational and memory overhead of ANN search becomes a critical bottleneck. We address this by designing a retrieval pipeline that intentionally maximizes sparsity and leverages specialized algorithms to accelerate search.

Methodology

The proposed framework consists of three integrated components: the Chi-square Two-tower model, graph-based ANN search, and SignCRP hashing.

Chi-square Two-tower Model

Unlike traditional models that rely on dot product or cosine similarity, our model utilizes the chi-square similarity kernel. By combining this kernel with ReLU activation and sum-to-one normalization, we generate embedding vectors that are significantly sparser than those produced by cosine-based architectures. This architecture is specifically designed to handle member-side and campaign-side features through shared embedding and interaction layers.

Detailed architecture of the Chi-square two-tower model for pCTR.

Efficient Search with HNSW and SignCRP

For serving, we employ Hierarchical Navigable Small World (HNSW) graphs, optimized to skip zero-value entries in sparse vectors during distance calculations. To further compress the embeddings, Sign Cauchy Random Projections (SignCRP) hash high-dimensional chi-square vectors into compact bitstrings. This allows for extremely fast Hamming distance computations on modern hardware.

Experimental Results

We evaluated our approach using LinkedIn's Ads Targeting dataset (4.5 billion records) and several public benchmarks including Webspam, News20, RCV1, and MNIST.

Sparsity and Scaling

A key finding is that increasing embedding dimensionality enhances sparsity in the chi-square model more effectively than in the cosine model. At a dimension of 2048, the chi-square model achieved a sparsity of 0.6%, compared to 3.6% for the cosine model. This extreme sparsity allows for faster search even at higher dimensions.

Sparsity vs. Embedding Dimension for Chi-square and Cosine models.

Retrieval Performance

The extreme sparsity of the chi-square embeddings directly translates to search efficiency. In HNSW, distance computation is the primary bottleneck; our sparse format reduced this cost by approximately 3x. Furthermore, using SignCRP to hash vectors into 1024 bits yielded a 12x to 18x speedup in similarity computations on the Webspam dataset while maintaining 90% recall. On public datasets like News20 and RCV1, chi-square similarity actually outperformed cosine similarity in classification accuracy.

Discussion and Conclusion

Our exploration demonstrates that chi-square similarity is a robust, "search-friendly" alternative to cosine similarity for deep learning-based retrieval. While two-tower models are primarily retrieval-focused and may not capture the complex interactions of cross-encoders, the efficiency gains from sparsity and hashing are substantial for large-scale industrial applications. Future work will investigate the limits of sparsity at even higher dimensions and further optimize the overhead of SignCRP projections.

Summary updated

Abstract

Sparse data are common. The traditional ``handcrafted'' features are often sparse. Embedding vectors from trained models can also be very sparse, for example, embeddings trained via the ``ReLu'' activation function. In this paper, we report our exploration of efficient search in sparse data with graph-based ANN algorithms (e.g., HNSW, or SONG which is the GPU version of HNSW), which are popular in industrial practice, e.g., search and ads (advertising). We experiment with the proprietary ads targeting application, as well as benchmark public datasets. For ads targeting, we train embeddings with the standard ``cosine two-tower'' model and we also develop the ``chi-square two-tower'' model. Both models produce (highly) sparse embeddings when they are integrated with the ``ReLu'' activation function. In EBR (embedding-based retrieval) applications, after we the embeddings are trained, the next crucial task is the approximate near neighbor (ANN) search for serving. While there are many ANN algorithms we can choose from, in this study, we focus on the graph-based ANN algorithm (e.g., HNSW-type). Sparse embeddings should help improve the efficiency of EBR. One benefit is the reduced memory cost for the embeddings. The other obvious benefit is the reduced computational time for evaluating similarities, because, for graph-based ANN algorithms such as HNSW, computing similarities is often the dominating cost. In addition to the effort on leveraging data sparsity for storage and computation, we also integrate ``sign cauchy random projections'' (SignCRP) to hash vectors to bits, to further reduce the memory cost and speed up the ANN search. In NIPS'13, SignCRP was proposed to hash the chi-square similarity, which is a well-adopted nonlinear kernel in NLP and computer vision. Therefore, the chi-square two-tower model, SignCRP, and HNSW are now tightly integrated.
BibTeX
@misc{li2023practice,
  author = {Ping Li and Weijie Zhao and Chao Wang and Qi Xia and Alice Wu and Lijun Peng},
  title = {{Practice with Graph-based ANN Algorithms on Sparse Data: Chi-square Two-tower model, HNSW, Sign Cauchy Projections}},
  year = {2023},
  eprint = {2306.07607},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.07607},
}
Figure