TLDR: HA-RAG is a new optimization system for Retrieval-Augmented Generation (RAG) that significantly speeds up LLM inference by addressing KV chunk loading and memory access bottlenecks. It uses a ‘hotness-aware’ strategy, combining mixed-precision compression for KV chunks based on their access frequency and intelligent data placement in memory hierarchies. This approach reduces memory footprint and I/O overhead, achieving an average 2.10x and maximum 10.49x speedup in Time-To-First-Token (TTFT) compared to TurboRAG, with minimal impact on accuracy.
Large Language Models (LLMs) have transformed many fields with their impressive capabilities in tasks like text generation and translation. However, they often struggle with a problem known as “hallucination,” where they generate information that isn’t factually accurate. They also face delays in integrating the latest knowledge due to their training data not being updated frequently enough.
To tackle these issues, Retrieval-Augmented Generation (RAG) systems have emerged as a powerful solution. RAG works by connecting LLMs to external knowledge bases. When a user provides input, RAG retrieves relevant documents from this knowledge base and adds them as context to the LLM’s input. This process significantly improves the quality and factual reliability of the generated text, helping to reduce hallucinations and keep the model’s knowledge up-to-date.
While RAG offers significant advantages, it introduces its own set of challenges. Appending external documents to the input dramatically increases the input length. This leads to substantial computational overhead, especially during the “prefill” stage of inference, where the LLM processes the entire input sequence to generate the first output token. The computational complexity grows quadratically with input length, severely impacting efficiency.
Previous efforts, like TurboRAG, tried to address this by precomputing the Key and Value (KV) pairs of retrieved documents and storing them on disk. These precomputed KV chunks are then loaded on demand during inference, avoiding redundant computation and speeding up the RAG system.
The Remaining Challenges for RAG
Despite these advancements, RAG still faces two critical hurdles. First, there’s a significant data loading overhead. For instance, a LLaMA2-7B model might require approximately 128 GB of KV data. Transferring such a large volume of data from disk to GPU memory is time-consuming. Studies show that KV chunk loading can account for about 70% of the total inference latency when generating short sequences.
Second, existing approaches haven’t fully optimized KV chunk scheduling for memory access efficiency. KV chunks are typically large, and moving them between host and device memory incurs considerable latency. If the same chunk is accessed multiple times, reloading it from disk each time creates substantial I/O and memory access overhead. A statistical analysis revealed that only about 1% of documents are frequently retrieved, indicating a highly skewed access frequency distribution.
Introducing HA-RAG: A Hotness-Aware Solution
To overcome these challenges, researchers have proposed HA-RAG (Hotness-Aware RAG), an inference optimization system that leverages the access frequency of different KV chunks. HA-RAG focuses on two main components: hotness-aware mixed-precision compression and loading, and hotness-aware data placement.
Smart Compression and Loading
HA-RAG first analyzes the numerical characteristics of KV chunks, observing that their values are concentrated within narrow ranges and their exponent distributions are also concentrated. This suggests that traditional BF16 format (16-bit) wastes significant bitwidth. This insight led to the adoption of lower-precision data representations like INT8, FP8 (E4M3 and E5M2 formats), and a novel 8-bit grouped shared exponent representation (GSE-8).
The core idea here is to categorize KV chunks into “hot” (frequently accessed) and “cold” (infrequently accessed) blocks. For hot chunks, HA-RAG prioritizes compression schemes that minimize accuracy loss, such as INT8, E4M3, and E5M2. This ensures that the most critical data maintains high quality. For cold chunks, where speed is paramount, it uses compression formats like GSE-8 that offer faster decompression times, improving runtime efficiency without significant online overhead.
Intelligent Data Placement
The second key innovation is a hotness-aware data placement strategy. In heterogeneous computing systems, data moves through various memory hierarchies: from disk to CPU pageable memory, then potentially to CPU pinned memory, and finally to GPU memory. Each stage has different access speeds.
HA-RAG intelligently allocates KV chunks across these memory tiers based on their access frequency. Frequently accessed “hot” chunks are prioritized for placement in high-speed storage like GPU memory and CPU pinned memory. This minimizes the need to fetch them from slower storage. Conversely, “cold” chunks are stored in slower memory, such as CPU pageable memory or disk, and loaded only when needed. This strategy prevents frequent evictions of hot chunks and significantly improves overall memory access efficiency.
Impressive Performance Gains
Experimental evaluations comparing HA-RAG with TurboRAG, using the LLaMA2-7B model and MS MARCO dataset, demonstrated significant improvements. HA-RAG achieved an average speedup of 2.10x and a maximum speedup of 10.49x in Time-To-First-Token (TTFT), which measures the latency to generate the first output token. This speedup was particularly noticeable with larger test set sizes, as the system optimized KV chunk placement over time, leading to higher hit rates in faster memory.
Crucially, these performance gains came with negligible accuracy loss. For approximately 60% of inputs, HA-RAG generated results identical to TurboRAG (ROUGE-1 F1 score of 1). For over 80% of inputs, it maintained a ROUGE-1 F1 score greater than 0.5, indicating high text generation quality.
An ablation study further highlighted the impact of each component. The mixed-precision compression and loading method alone (MP-only) delivered a substantial 1.75x speedup, primarily by reducing KV chunk size and thus loading overhead. While data placement optimization also contributed, its gains were somewhat limited by the operating system’s natural caching behavior and the likelihood of frequently accessed chunks already residing in GPU memory.
Also Read:
- Boosting LLM Efficiency: How Token Permutation Makes Attention Sparser
- New Quantization Method Makes Large Language Models More Efficient
Conclusion
HA-RAG represents a significant step forward in optimizing Retrieval-Augmented Generation systems. By intelligently combining hotness-aware mixed-precision compression and strategic data placement, it effectively addresses the critical bottlenecks of KV chunk loading and memory access. This novel framework strikes an excellent balance between inference performance and accuracy, making RAG systems more efficient and practical for real-world deployment. You can read the full research paper here.


