Patchwork: A Unified Framework for RAG Serving

Bodun Hu, Luis Pabon, Saurabh Agarwal, Aditya AkellaarXiv 2025 · DOI

Introduction

Retrieval-Augmented Generation (RAG) has emerged as a critical technique for grounding Large Language Models (LLMs) in external, up-to-date knowledge. However, serving RAG systems at scale presents significant challenges that standard LLM serving infrastructures are not equipped to handle. Unlike linear LLM inference, RAG pipelines are complex "patchworks" of heterogeneous components, including vector databases, query rewriters, and multiple LLM calls with conditional or recursive logic.

Patchwork is a unified serving framework designed to address these complexities. By treating RAG as a distributed system of diverse components and employing a novel max-flow optimization for resource allocation, Patchwork achieves throughput gains of up to 22x and reduces Service Level Objective (SLO) violations by approximately 24% compared to existing solutions.

The Challenges of RAG Serving

Systems engineers face three primary hurdles when deploying RAG at scale:

  1. Heterogeneity: Components have distinct scaling behaviors. For instance, vector databases are often CPU-bound, while LLM generators are GPU-bound.
  2. Fragmented Tooling: The lack of a unified framework often leads to bespoke, monolithic implementations that are difficult to optimize.
  3. Unpredictable Latency: Query-dependent branching—such as "if the retrieved information is irrelevant, try a different search"—results in highly variable execution times, making tight SLO guarantees difficult.

The Patchwork Framework

Patchwork introduces an intent-driven, end-to-end framework built on three core innovations:

Python-Native Specification

To avoid the friction of custom Domain Specific Languages (DSLs), Patchwork utilizes a lightweight client library. It leverages the Python frame evaluation API (PEP 523) to automatically capture the computation graph directly from standard Python code, allowing developers to maintain their existing workflows.

A typical RAG pipeline consists of multiple interconnected components with varying configurations.

Max-Flow Resource Allocation

Patchwork models the RAG pipeline as a compute graph and formulates throughput maximization as a concurrent-flow optimization problem. Using Mixed-Integer Linear Programming (MILP), the offline scheduler jointly determines the optimal batch size and resource allocation for every component in the pipeline.

Proactive Online Scheduling

To manage unpredictable execution, Patchwork employs a "running average estimator" to monitor requests in real-time. If a request is predicted to miss its SLO, the system takes proactive measures, such as prioritizing the request or triggering auto-scaling, to maintain performance targets.

Key Insights

A central finding of the Patchwork research is that traditional metrics for predicting latency are insufficient for complex RAG. In standard LLM serving, input token length is a reliable predictor of latency. However, in multi-stage RAG algorithms like IRCoT or MemoRAG, the relationship between query length and latency is far more volatile.

Query length is a poor predictor of latency in complex RAG algorithms, necessitating dynamic, state-aware estimation.

Furthermore, Patchwork demonstrates that component-level scaling is the key to performance. Different vector databases (e.g., Qdrant vs. ChromaDB) exhibit unique scalability patterns based on document count or the number of nearest neighbors. By optimizing at the component level rather than treating the pipeline as a monolith, Patchwork unlocks significant throughput.

Experimental Results

The framework was evaluated using the LMSYS-Chat-1M dataset for user queries and the C4 dataset for knowledge base population. Benchmarks were conducted across four RAG algorithms: CRAG, MemoRAG, IRCoT, and HippoRAG.

  • Throughput Gains: Patchwork outperformed commercial alternatives like LangGraph by at least 1.48x. For complex algorithms like MemoRAG and HippoRAG, it achieved speedups ranging from 15x to 22x over unoptimized baselines.
  • SLO Improvements: The proactive online scheduler reduced SLO violations by up to 24% under medium load conditions.
  • Optimization Efficiency: The MILP-based optimization routine is highly scalable, finding optimal configurations for clusters of up to 512 heterogeneous nodes in approximately three seconds.

Conclusion and Future Work

Patchwork represents a significant step toward efficient, scalable RAG serving. While it requires a one-time profiling step to understand component scaling, the resulting performance gains are substantial. Future research aims to extend this framework to "compound AI systems" involving multiple interacting agents, where execution logic becomes even more dynamic and unpredictable.

Summary updated

BibTeX
@misc{hu2025patchwork,
  author = {Bodun Hu and Luis Pabon and Saurabh Agarwal and Aditya Akella},
  title = {{Patchwork: A Unified Framework for RAG Serving}},
  year = {2025},
  eprint = {2505.07833},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2505.07833},
}
Figure