Retaining Key Information under High Compression Ratios: Query-Guided Compressor for LLMs

Zhiwei Cao, Qian Cao, Yu Lu, Ningxin Peng, Luyang Huang, Shanbo Cheng, Jinsong Su

Introduction

Large Language Models (LLMs) have revolutionized tasks requiring the processing of extensive context, such as multi-document question answering (QA) and retrieval-augmented generation (RAG). However, the inclusion of long contexts introduces significant challenges: increased inference costs, higher latency, and the "lost in the middle" phenomenon, where models struggle to extract information from the center of a long prompt.

Existing context compression methods generally fall into two categories: discrete compression, which deletes "unimportant" tokens, and continuous compression, which summarizes documents into fixed-length vectors. However, both approaches often fail at high compression ratios because they lack awareness of the user's specific query. Without this context, compressors cannot distinguish between irrelevant noise and the specific "needle" required to answer a question. To address this, we present the Query-Guided Compressor (QGC), a framework that leverages the user's query to guide the compression process, achieving high efficiency without sacrificing accuracy.

The Query-Guided Compressor (QGC) Framework

QGC is a "white-box" compressor that transforms long documents into "soft prompt" vectors. Unlike methods that prune text, QGC produces continuous representations that are semantically aligned with the target LLM's embedding space. The architecture is composed of four primary layers:

  1. Query-Guided Context Encoder: This layer processes the query and the document simultaneously. By feeding them together into Transformer layers, the document representations become "query-aware" from the initial stage of encoding.
  2. Query-Guided Pooling Layer: The document is partitioned into n-grams. QGC calculates the relevance of each token relative to the query, using weighted pooling to compress each n-gram into a single representative vector.
  3. Query-Document Reviewing Layer: To mitigate information loss during pooling, this module "reviews" the compressed vectors against the original query and document, refining the representations to ensure key details are preserved.
  4. Semantic Alignment Layer: Finally, the refined vectors are projected into the specific embedding space of the target LLM (e.g., Llama-2 or LongChat), allowing the model to process them as if they were standard input embeddings.

A critical innovation in QGC is the Dynamic Compressing Strategy. Rather than applying a uniform compression ratio to all documents, QGC uses a reranker score to allocate the "compression budget." Highly relevant documents are compressed less (preserving more detail), while irrelevant documents are compressed aggressively or discarded entirely.

Experimental Evaluation

The researchers evaluated QGC across several multi-document QA benchmarks, including NaturalQuestions, TriviaQA, and HotpotQA, as well as In-Context Learning (ICL) tasks like SST-2 and GSM8K.

Performance and Efficiency

QGC demonstrates a significant leap in both compression capability and task performance:

  • High Compression Ratios: On the NaturalQuestions dataset, QGC achieved a 15.2x compression ratio, significantly higher than the 4.1x achieved by LongLLMLingua.
  • Improved Accuracy: Despite the drastic reduction in input size, QGC improved accuracy by an average of 5 percentage points over state-of-the-art baselines.
  • Increased Throughput: By reducing the sequence length processed by the target LLM, QGC achieved 2.42x higher throughput compared to discrete compression methods.
  • Robustness: In scenarios with high noise (numerous irrelevant documents), QGC maintained performance with only a 10% drop, whereas competing methods saw performance declines of nearly 47%.

Discussion and Insights

The success of QGC highlights that "importance" is a relative metric. In long-context tasks, a detail's value is defined by its relevance to the user's intent. By using the query as a "north star," QGC retains the essential information even when the total context is shrunk by over 90%. Furthermore, the use of continuous "soft prompts" preserves semantic nuances that are often lost when words are simply deleted.

Efficiency is another key advantage. QGC does not require fine-tuning the massive target LLM. Instead, it utilizes a smaller compressor model (based on Llama-2-7B with only 3.5% trainable parameters), making it a cost-effective solution for deployment.

Limitations and Future Work

While QGC offers substantial improvements, it currently requires "white-box" access to the target LLM's internal embeddings. This limits its immediate applicability to closed-source, API-only models like GPT-4. Additionally, while the framework excels in QA and ICL, its performance on generative tasks like creative writing or open-ended summarization remains to be explored. Future research will focus on extending QGC to a broader range of LLMs and integrating it with advanced retrieval-augmentation techniques.

Conclusion

The Query-Guided Compressor represents a significant advancement in managing long-context LLM inputs. By prioritizing query-relevance and utilizing continuous vector compression, QGC provides a scalable, efficient, and accurate solution for processing vast amounts of information in real-time applications.

Summary updated

BibTeX
@inproceedings{cao2024retaining,
  author = {Zhiwei Cao and Qian Cao and Yu Lu and Ningxin Peng and Luyang Huang and Shanbo Cheng and Jinsong Su},
  title = {{Retaining Key Information under High Compression Ratios: Query-Guided Compressor for LLMs}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.acl-long.685},
}
Figure