Block-Attention for Efficient RAG

East Sun, Yan Wang, Lan Tian · DOI

Abstract

Retrieval-Augmented Generation (RAG) is essential for grounding Large Language Models (LLMs) in external knowledge, yet it suffers from high latency during the prefilling stage. This is primarily due to the auto-regressive nature of standard attention, which requires re-calculating Key-Value (KV) states for the entire context whenever a query changes. We present Block-attention, a modular attention mechanism that segments input into independent blocks. This allows for the pre-computation and reuse of KV caches for retrieved documents. Our results demonstrate a 98.7% reduction in Time to First Token (TTFT) for 32K sequences with negligible impact on accuracy.

1. Introduction

Standard RAG systems often prepend numerous external documents to a user query to provide context. However, the quadratic complexity of self-attention and the auto-regressive dependency of tokens make this "prefilling" phase computationally expensive. Every new query or document reordering necessitates a full re-computation of the context's KV states. This "efficiency tax" makes real-time applications with long contexts sluggish and expensive.

The Block-attention framework segments documents into independent blocks, allowing for modular KV cache reuse while the query attends to all preceding blocks.

2. Methodology

Block-attention introduces a fundamental shift in how LLMs process long contexts by enforcing independence between segments.

2.1 Block Segmentation and Independent Encoding

The input sequence is divided into discrete blocks, typically corresponding to individual retrieved documents. During encoding, each block calculates its KV states independently. This means tokens within a block only attend to other tokens in the same block, effectively creating a block-diagonal attention mask for the context. Only the final block, containing the user query, is permitted to attend to all preceding blocks.

2.2 Position Re-encoding and KV Caching

To handle varying document positions across different prompts, the system utilizes Rotary Positional Embeddings (RoPE). Blocks are cached with internal positions reset to zero. During inference, these cached states are "rotated" to their correct global positions, ensuring the model maintains spatial awareness without re-encoding the entire sequence.

Architectural flow of Block-attention, highlighting the interaction between the KV Cache, position re-encoding, and the final output generation.

2.3 Block Fine-Tuning

Standard LLMs exhibit performance degradation when first exposed to blocked attention masks. To mitigate this, a brief "block fine-tuning" phase (approximately 500–1000 steps) is employed using a mix of general instruction data (Tulu3-SFT) and RAG-specific samples from TriviaQA and 2WikiMultiHopQA. This allows the model to become "bilingual," maintaining full-attention accuracy while gaining block-attention efficiency.

3. Experimental Results

The researchers evaluated the proposed method across 11 benchmarks, including RAG tasks (Natural Questions, HotpotQA), In-Context Learning (GSM8K, BBH), and general capabilities (MMLU, IFEval).

3.1 Efficiency Gains

The most significant impact of Block-attention is observed in latency reduction. For a 32K token sequence, the TTFT was reduced from 3,638ms to just 45ms—a 98.7% speedup. Furthermore, prefilling floating-point operations (FLOPs) saw a 99.8% reduction at the same scale.

3.2 Accuracy Maintenance

The fine-tuned model, Tulu3-block-ft, maintains performance comparable to full-attention baselines. On the 2WikiMultiHopQA benchmark, it achieved 72.2% accuracy compared to the baseline's 73.2%, demonstrating that the efficiency gains do not come at the cost of reasoning capability.

4. Conclusion

Block-attention addresses the "efficiency tax" of RAG by enabling modular, reusable KV caches. By treating documents as independent units, the computational burden of long-context processing is drastically reduced. Beyond RAG, this method holds potential for dynamic environments like gaming, where massive game states can be updated incrementally rather than re-encoded in full.

Summary updated

BibTeX
@inproceedings{sun2025block,
  author = {East Sun and Yan Wang and Lan Tian},
  title = {{Block-Attention for Efficient RAG}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=7zNYY1E2fq},
}
Figure