Introduction
Retrieval-Augmented Generation (RAG) has emerged as the standard for grounding Large Language Models (LLMs) in external knowledge. However, deploying RAG systems in production reveals a fundamental tension: the "tug-of-war" between generation quality and system performance. High-quality retrieval often requires complex rerankers and deep search depths that introduce unacceptable latency, while high-performance systems may sacrifice accuracy through aggressive quantization or shallow retrieval.
The RAG Configuration Challenge
Building a RAG pipeline involves navigating a multi-dimensional "knob" space. On the algorithmic side, developers must select chunking strategies, embedding models, retrieval depths (Top-K), and auxiliary components like query rewriters. On the systems side, decisions regarding hardware (CPU vs. GPU), software frameworks (e.g., vLLM, SGLang), and indexing structures (e.g., HNSW, IVF) significantly impact throughput and cost.
Currently, these dimensions are optimized in isolation. A system might achieve state-of-the-art accuracy on a benchmark but prove too expensive for real-time applications. Conversely, a fast system might suffer from "hallucinations" due to suboptimal retrieval. There is no unified framework to co-optimize these factors, especially as new models and hardware are released.
The RAG-Stack Framework
To address this, we propose RAG-Stack, an architectural blueprint designed to find the optimal balance—the Pareto frontier—between quality and performance.
The framework consists of three core components:
- RAG-IR (Intermediate Representation): A workload abstraction layer that represents a RAG pipeline as a dataflow graph. It captures performance-critical attributes (e.g., model size, sequence length, data transfer) while abstracting away quality-specific details like model weights.
- RAG-CM (Cost Model): This component uses the RAG-IR and hardware profiles to predict metrics such as Time-To-First-Token (TTFT), throughput, and cost-efficiency.
- RAG-PE (Plan Exploration): An iterative algorithm that navigates the configuration space. It evaluates quality using standard metrics and performance via RAG-CM to identify configurations where quality cannot be improved without sacrificing performance.
Handling Heterogeneous and Agentic Workloads
Modern RAG is evolving from linear pipelines into "agentic" systems where different queries trigger different execution paths. A simple query might only require a direct vector search, while a complex one might trigger query rewriting, multiple retrievals, and a final reranking step.
RAG-IR is specifically designed to handle this heterogeneity by defining dataflow graphs on a per-request basis. This decoupling allows ML engineers to swap model versions or retrieval strategies while the system automatically recalculates the performance impact without requiring a full end-to-end re-test.
Key Insights and Research Gaps
A critical insight of the RAG-Stack approach is the cost of re-indexing. While adjusting a Top-K value is computationally cheap, changing an embedding model or chunking strategy requires rebuilding the entire vector database. Consequently, the RAG-PE exploration algorithm must be "cost-aware" to minimize unnecessary database rebuilds.
As a vision paper, RAG-Stack identifies several research gaps for the community:
- Index Abstraction: Determining whether specific index configurations (like HNSW parameters) should be part of the high-level abstraction or managed by the underlying system.
- Retrieval Cost Modeling: Developing mature cost models for vector retrieval, which currently lag behind the well-understood models for LLM inference.
- Efficient Exploration: Creating smarter algorithms to predict which database configurations are worth testing to avoid the high overhead of re-indexing.
Conclusion
RAG-Stack provides the necessary formalization to treat RAG optimization as a joint search for quality and performance. By bridging the gap between algorithmic design and system execution, it paves the way for the next generation of efficient, high-fidelity AI systems.
Summary updated