QUITO: Accelerating Long-Context Reasoning Through Query-Guided Context Compression

Wenshan Wang, Yihang Wang, Yixing Fan, Huaming Liao, Jiafeng Guo

Abstract

As Large Language Models (LLMs) are increasingly deployed in Retrieval-Augmented Generation (RAG) and long-context scenarios, the computational overhead and performance degradation associated with massive input prompts have become significant bottlenecks. This paper introduces QUITO (Query-gUIded aTtention cOmpression), a novel framework designed to reduce inference costs and mitigate the "lost in the middle" phenomenon. Unlike traditional methods that rely on perplexity-based pruning, QUITO leverages the attention mechanism of a lightweight 0.5B parameter model to identify and preserve query-relevant information. Our results demonstrate that QUITO significantly outperforms larger compression models across complex reasoning tasks while maintaining high accuracy and efficiency.

Introduction

The expansion of context windows in modern LLMs has enabled the processing of extensive documents and multi-document retrieval. However, this capability comes with three primary challenges: escalating inference costs (latency and token usage), physical context limits, and the "lost in the middle" effect, where models struggle to retrieve information buried in the center of a long prompt.

Context compression has emerged as a strategy to prune irrelevant tokens before they reach the primary LLM. However, many existing solutions utilize perplexity (PPL) as a proxy for importance. PPL measures how "surprising" a token is to a model, which does not necessarily correlate with its relevance to a specific user query. Furthermore, many PPL-based methods are query-agnostic, failing to prioritize the specific information needed to answer a given question. QUITO addresses these gaps by shifting the focus from probabilistic uncertainty to query-guided attention.

The QUITO Framework

QUITO (Query-gUIded aTtention cOmpression) operates on the principle that attention weights provide a more direct map of information relevance than perplexity. The framework utilizes a small model (e.g., Qwen2-0.5B) to evaluate the context in the presence of the query.

Query-Guided Self-Attention

QUITO places the context and the user query into a conversational template. It identifies a "trigger token"—the final token that signals the model to begin generating a response. The attention weights from this trigger token back to the context tokens are extracted. These weights represent the model's internal prioritization of which context segments are most critical for addressing the query.

Context Reformulating and Normalization

To ensure fair scoring across different segments, QUITO applies a softmax normalization specifically across the context tokens. This prevents the scores from being diluted by the conversational template or the query itself, ensuring that the relative importance of context segments is accurately captured.

Filtering Strategies

QUITO implements three distinct strategies for pruning text based on the calculated attention scores:

  1. Phrase Level: This strategy employs a Gaussian filter to ensure that tokens adjacent to high-attention "target" words are preserved, maintaining the local semantic integrity of the text.
  2. Sentence Level: Entire sentences are scored based on the maximum attention score of their constituent tokens, allowing for the preservation of complete thoughts.
  3. Dynamic Sentence Level: A hybrid approach that prioritizes sentence-level filtering but fills the remaining token budget with high-value phrases to maximize information density.

Experimental Evaluation

The researchers evaluated QUITO using two primary benchmarks: NaturalQuestions (NQ), which requires identifying a single answer within 20 documents, and ASQA, which involves synthesizing information from multiple Wikipedia snippets to answer ambiguous questions.

Crucially, while previous state-of-the-art compression methods often required 7B or 13B parameter models, QUITO was tested using a tiny Qwen2-0.5B model to determine if smaller models could effectively guide larger ones.

Key Results and Insights

Superior Accuracy and Efficiency

QUITO demonstrated substantial improvements over established baselines such as Selective-Context and LongLLMLingua. On the NaturalQuestions dataset with a 2x compression ratio, QUITO (Phrase Level) achieved 58.9% accuracy, compared to 41.2% for LongLLMLingua and 53.2% for Selective-Context. Even at a 4x compression ratio (removing 75% of the text), QUITO maintained a performance lead of nearly 15 percentage points over the next best baseline.

Attention as a Better Proxy

The core insight of this research is that attention weights are superior to perplexity for context pruning. While perplexity measures how well a model predicts the next token, attention measures which specific tokens the model "looks at" to formulate a response. This query-aware approach allows a 0.5B parameter model to outperform much larger models that rely on query-agnostic metrics.

Resilience to Positioning

While all Transformer-based models exhibit some performance decline when relevant information is located in the middle of a prompt, QUITO showed significantly more resilience than its competitors. By filtering out the "noise" of irrelevant text, QUITO helps the downstream model focus on the relevant signal, regardless of its original position in the document.

Conclusion and Future Work

QUITO represents a significant step forward in making long-context LLM reasoning more efficient and accurate. By utilizing query-guided attention in a small model, it provides a high-performance, low-cost solution for context compression.

Future research will focus on integrating QUITO with dedicated re-ranking modules in RAG pipelines. While QUITO effectively filters irrelevant content, combining it with a model that re-orders the remaining snippets (placing the most relevant information at the beginning or end of the prompt) could further mitigate the architectural biases of the Transformer and solve the "lost in the middle" problem entirely.

Summary updated

Abstract

In-context learning (ICL) capabilities are foundational to the success of large language models (LLMs). Recently, context compression has attracted growing interest since it can largely reduce reasoning complexities and computation costs of LLMs. In this paper, we introduce a novel Query-gUIded aTtention cOmpression (QUITO) method, which leverages attention of the question over the contexts to filter useless information. Specifically, we take a trigger token to calculate the attention distribution of the context in response to the question. Based on the distribution, we propose three different filtering methods to satisfy the budget constraints of the context length. We evaluate the QUITO using two widely-used datasets, namely, NaturalQuestions and ASQA. Experimental results demonstrate that QUITO significantly outperforms established baselines across various datasets and downstream LLMs, underscoring its effectiveness. Our code is available at https://github.com/Wenshansilvia/attention_compressor.
BibTeX
@inproceedings{wang2024quito,
  author = {Wenshan Wang and Yihang Wang and Yixing Fan and Huaming Liao and Jiafeng Guo},
  title = {{QUITO: Accelerating Long-Context Reasoning Through Query-Guided Context Compression}},
  booktitle = {CCIR},
  year = {2024},
  url = {https://openreview.net/forum?id=oAMaBqnuq5},
}
Figure