Nearest Neighbor Search with Compact Codes: A Decoder Perspective

Kenza Amara, Matthijs Douze, Alexandre Sablayrolles, Hervé Jégou

TL;DR

This paper demonstrates that we can significantly improve the accuracy of approximate nearest neighbor (ANN) search by upgrading the decoder while keeping the existing encoder fixed. By replacing standard linear decoders with a small neural network, the authors achieve better vector reconstruction and search recall on billion-scale datasets without requiring users to re-index their data.

What Problem Does This Paper Address?

In large-scale vector search (like finding similar images or documents), we often use "compact codes" to represent high-dimensional vectors. Techniques like Product Quantization (PQ) or Binary Hashing compress vectors into a few bytes to save memory and speed up search.

Traditionally, these methods are viewed as a pair: an encoder that turns a vector into a code, and a decoder that turns that code back into an approximation of the original vector. Most research focuses on making better encoders. However, changing an encoder is expensive—it requires re-processing and re-storing billions of vectors.

The authors identify a "decoder gap": standard decoders make simplistic assumptions (like assuming different parts of the code are independent). They ask: If we are stuck with a specific encoding (for backward compatibility or speed), can we build a smarter decoder to get more "juice" out of those same bits?

Methods

The authors re-interpret quantization and hashing through the lens of auto-encoders. They propose two main upgrades to the decoding process:

  1. Linear Upgrade (AQ Decoder): Instead of the standard PQ decoder (which reconstructs sub-vectors independently), they use an Additive Quantization (AQ) style decoder. This treats the entire code as a set of look-up table (LUT) entries that are summed together, allowing the decoder to account for some correlations between different parts of the code.
  2. Non-linear Upgrade (Neural Decoder): They introduce a small neural network (an MLP) as the decoder.
  3. Architecture: The first layer is a structured Look-Up Table (LUT) that maps code indices to embeddings. This is followed by a few fully connected layers with ReLU activations and Batch Normalization.
  4. Loss Function: The network is trained to minimize Mean Squared Error (MSE) between the original and reconstructed vectors. Optionally, they add a Triplet Loss to ensure that the reconstructed space preserves the original ranking of neighbors.

The beauty of this approach is that it is backward-compatible. You can apply this neural decoder to a database that was indexed years ago using standard PQ or binary hashing.

Datasets

The authors evaluate their approach on two standard large-scale benchmarks for vector search:

  • BigANN1M: 1 million 128-dimensional SIFT descriptors.
  • Deep1M: 1 million 96-dimensional deep learning image features.

These datasets represent the "gold standard" for testing how well compression techniques preserve the semantic similarity of vectors.

Key Insights and Ideas

  • Exploiting Suboptimality: Existing decoders (like those in PQ) implicitly assume that the bits in a code carry no mutual information. In reality, encoders are rarely perfect, and residual information exists between sub-indices. A neural decoder can "learn" these correlations to provide a much more accurate reconstruction.
  • The Re-ranking Use Case: While a neural network is slower than a simple table lookup, it is still very fast. The authors propose a two-stage pipeline: use the fast, "naive" decoder to get a short-list of candidates, then use the Neural Decoder to re-rank that short-list. This provides high accuracy with negligible impact on total search time.
  • Decoupling is Powerful: By disentangling the encoder from the decoder, practitioners can choose an extremely fast, hardware-optimized encoder (like binary hashing or PQ16x4) and still achieve high-quality results by using a sophisticated decoder at query time.

Key Results

  • PQ Improvements: On BigANN1M, using a neural decoder with a standard PQ16x4 encoder improved the Recall@1 from 0.168 to 0.202.
  • Beating the "Topline": In data-starved regimes (small training sets), the Neural Decoder actually outperformed the theoretically "optimal" linear decoder (the topline) because the neural network was better at generalizing with fewer parameters.
  • Binary Hashing: For binary codes (ITQ), the neural decoder provided a significant boost, raising Recall@1 on BigANN1M from 0.103 to 0.118.
  • Efficiency: In the re-ranking scenario, most of the accuracy gains were achieved by re-ranking just the top 10 results, meaning the computational overhead was nearly zero compared to the initial search.

Limitations and Future Work

  • Training Requirement: Unlike standard PQ, which can be used out-of-the-box or with simple k-means, the neural decoder requires a representative training set of vectors and their corresponding codes to learn the reconstruction mapping.
  • Memory Overhead: Storing the weights of the neural decoder (and the associated LUTs) requires more memory than a standard PQ table, though the authors note this is usually a constant cost that doesn't scale with the database size.
  • Future Directions: The authors suggest exploring even more complex architectures or integrating the decoder training more tightly with the specific hardware constraints of modern CPUs and GPUs (e.g., SIMD instructions).

Summary updated

BibTeX
@inproceedings{amara2022nearest,
  author = {Kenza Amara and Matthijs Douze and Alexandre Sablayrolles and Hervé Jégou},
  title = {{Nearest Neighbor Search with Compact Codes: A Decoder Perspective}},
  booktitle = {ICMR},
  year = {2022},
  url = {https://openreview.net/forum?id=-y0VymgMJpp},
}

Loading related content...

Figure