Abstract
Retrieval-Augmented Generation (RAG) significantly enhances the knowledge capacity of Large Language Models (LLMs) but introduces a substantial "latency tax" due to sequential dependencies between inference and retrieval. We present PipeRAG, a novel algorithm-system co-design framework that eliminates the "stop-and-wait" bottleneck. By utilizing stale queries for prefetching and a performance-driven model to overlap retrieval with inference, PipeRAG achieves up to a 2.6× speedup while simultaneously improving generation quality.
Introduction
Advanced RAG systems, such as RETRO, perform periodic retrievals to provide fresh context during text generation. However, this creates a massive efficiency problem: the GPU (inference) sits idle while the database (retrieval) searches for data, and vice versa. As generated sequences grow, the LLM's attention mechanism slows down, further complicating the balance between fixed-time search costs and variable inference latency. PipeRAG addresses these challenges by breaking the rigid dependencies of traditional RAG pipelines.
Methodology
PipeRAG introduces three core strategies to optimize hardware utilization and generation speed:
- Pipeline Parallelism (S1): Instead of waiting for the most recent tokens to form a query, PipeRAG uses a "stale" query window (tokens generated in previous steps) to prefetch content. This allows the retrieval system to work on the next chunk of data while the LLM processes the current one.
- Flexible Retrieval Intervals (S2): Standard models often retrieve at fixed intervals (e.g., every 64 tokens). PipeRAG modifies the attention mechanism to support flexible intervals, allowing the system to tune retrieval frequency to align with hardware processing speeds.
- Performance-Model-Driven Retrieval (S3): A performance model predicts the duration of the next LLM inference step. The retrieval system then dynamically expands its search space (increasing
nprobein vector search) to maximize quality without exceeding the predicted inference time, effectively "hiding" retrieval latency.
Experimental Setup
The researchers evaluated PipeRAG using a 3-billion-token database constructed from the C4 corpus. Language modeling quality was tested on Wikipedia, the RealNews subset of C4, and a general C4 English document subset. Results were compared against the state-of-the-art RETRO baseline (582M parameters).
Key Results and Insights
Speed and Efficiency
PipeRAG successfully eliminated hardware idle time, maintaining high utilization for both the GPU and the CPU-based retrieval server. This resulted in an end-to-end generation speedup of up to 2.6× over RETRO.
Generation Quality
Counter-intuitively, using "stale" queries did not degrade performance. Because language context shifts gradually, tokens from 16 or 32 steps ago remain highly effective for retrieval. Furthermore, PipeRAG actually improved generation quality, reducing perplexity by as much as 0.93 points. This improvement stems from the system using "saved" time to perform deeper, more accurate database searches within the inference time budget.
Conclusion
PipeRAG demonstrates that algorithm-system co-design can effectively mitigate the latency overhead of RAG. By treating retrieval staleness as a manageable trade-off and dynamically scaling search depth to fit inference windows, PipeRAG provides a path toward highly efficient, knowledge-rich LLM applications. Future work includes extending these principles to modern decoder-only architectures and integrating more complex reranking stages into the parallel pipeline.
Summary updated