MEMORY-VQ: Compression for Tractable Internet-Scale Memory

Yury Zemlyanskiy, Michiel de Jong, Luke Vilnis, Santiago Ontañón, William W. Cohen, Sumit Sanghai, Joshua Ainslie

Abstract

Retrieval augmentation is a powerful but expensive method to make language models more knowledgeable about the world. Memory-based methods like LUMEN (de Jong et al., 2023a) pre-compute token representations for retrieved passages to drastically speed up inference. However, memory also leads to much greater storage requirements from storing pre-computed representations. We propose MEMORY-VQ, a new method to reduce storage requirements of memory-augmented models without sacrificing performance. Our method uses a vector quantization variational autoencoder (VQ-VAE) to compress token representations. We apply MEMORY-VQ to the LUMEN model to obtain LUMEN-VQ, a memory model that achieves a 16x compression rate with comparable performance on the KILT benchmark. LUMEN-VQ enables practical retrieval augmentation even for extremely large retrieval corpora.

Introduction

Retrieval-augmented generation (RAG) allows Large Language Models (LLMs) to look up facts from external corpora, but it is computationally expensive because the model must process retrieved text on-the-fly. To solve this, "memory-based" models like LUMEN pre-compute and store embeddings for every token in a corpus (e.g., Wikipedia). While this speeds up inference by 3x, it creates a massive storage bottleneck. For a standard T5-XXL model, LUMEN requires 8KB of storage per token. Storing embeddings for a 1-trillion-token corpus would require approximately 7 Petabytes, which is economically and technically impractical. MEMORY-VQ aims to shrink this "memory" footprint without sacrificing the model's ability to answer complex questions.

Methodology

The authors propose MEMORY-VQ, which applies Vector Quantization (VQ) techniques to the intermediate representations of the language model.

  1. Product Quantization (PQ): Instead of quantizing a massive 4096-dimensional vector as one unit, it is split into $g$ smaller subspaces (e.g., 256 subspaces). Each subspace is quantized independently.
  2. VQ-VAE Integration: A Vector Quantized Variational Autoencoder (VQ-VAE) approach allows the compression layer to be trained jointly with the rest of the language model. Using a "straight-through estimator," gradients can flow through the discrete compression step during training.
  3. LUMEN-VQ Architecture: Applied to the LUMEN model, an offline "memory encoder" processes the corpus and compresses the output into discrete integer codes. During inference, these codes are retrieved and decompressed via a simple codebook lookup before being fed into the "live" part of the LLM.
  4. Initialization: Using kmeans++ initialization and a "codebook reset" strategy (re-initializing infrequently used codes) was vital for maintaining high representational quality.

Experimental Setup

Evaluation was conducted using the KILT Benchmark, which includes tasks such as Question Answering (NaturalQuestions, TriviaQA, HotpotQA), Fact Verification (FEVER), and Relation Extraction (TREX, ZeroShot RE). The retrieval corpus consisted of a Wikipedia dump containing approximately 4 billion tokens, segmented into 200-word chunks.

Results and Discussion

Joint training of compression codes alongside the model proved essential, allowing the LLM to become robust to the approximation errors introduced by lossy compression. By reducing the cost per token from 8KB to 0.5KB (using int16 codes), an internet-scale corpus of 1 trillion tokens drops from 7PB to a manageable 500TB. Interestingly, the resulting integer codes are almost entirely incompressible by standard tools like gzip, suggesting the VQ-VAE already maximizes information density.

Comparison of inference cost, storage cost, and KILT performance across models.

As shown in the table above, LUMEN-VQ (L-VQ) achieves near-parity performance with the uncompressed LUMEN and the standard Fusion-in-Decoder (FiD) baseline while significantly reducing storage requirements.

KILT performance vs. compression rate for LUMEN-VQ and baselines.

MEMORY-VQ achieves a 16x compression rate with negligible loss in accuracy. Compared to "naive" compression methods like scaling down the model or keeping fewer tokens, MEMORY-VQ shows a much more graceful decline in performance as the compression ratio increases. Furthermore, because decompression is a simple table lookup, LUMEN-VQ retains the 3x inference speedup of the original LUMEN over standard RAG methods.

Conclusion

MEMORY-VQ makes internet-scale AI memory practical by achieving a 16x reduction in storage with minimal performance impact. While the model performs excellently on KILT, future work could explore task-specific domain generalization and efficient updates for dynamic corpora.

Summary updated

BibTeX
@inproceedings{zemlyanskiy2024memory,
  author = {Yury Zemlyanskiy and Michiel de Jong and Luke Vilnis and Santiago Ontañón and William W. Cohen and Sumit Sanghai and Joshua Ainslie},
  title = {{MEMORY-VQ: Compression for Tractable Internet-Scale Memory}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  url = {https://openreview.net/forum?id=JunAGW76vz},
}
Figure