Modular RAG

On this page 7

Modular RAG is a retrieval-augmented generation architecture that decomposes the pipeline into independent, interchangeable modules, such as query rewriting, routing, retrieval, reranking, memory and generation, and connects them through configurable flows rather than one fixed sequence. In the field of Retrieval & knowledge within artificial intelligence, it represents the third stage of RAG design after naive RAG and advanced RAG.

The core idea is composition over hard-wiring. Each module has a defined input and output, so teams can replace a retriever, insert a reranker or add a verification loop without rebuilding the system. This makes Modular RAG the reference frame for most production systems, including agentic and graph-based variants.

How Modular RAG organizes the pipeline

Modular RAG organizes a system into modules and operators. A module is a functional stage, for example indexing or post-retrieval processing, while operators are the concrete techniques inside it, such as semantic chunking, HyDE or cross-encoder reranking. The orchestration layer decides which modules run, in what order and how many times.

This separation turns the pipeline into a graph of components instead of a straight line. A query may pass through rewriting, be routed to one of several indexes, return candidates for reranking and only then reach the language model. The table below lists the modules that most Modular RAG designs share.

ModulePurposeExample operators
IndexingPrepare and store source contentChunking, embeddings, metadata extraction
Pre-retrievalImprove the query before searchQuery rewriting, expansion, decomposition
RoutingChoose a source or pathQuery routing, intent classification
RetrievalFind candidate passagesDense, sparse or hybrid search
Post-retrievalFilter and order evidenceReranking, compression, deduplication
GenerationProduce the grounded answerPrompting, citation generation
OrchestrationControl the flow between modulesConditional branches, loops, scheduling
Typical modules in a Modular RAG system

Some designs add further modules, such as a memory module that stores earlier answers for reuse, a fusion module that merges evidence from parallel searches, or a verification module that checks the draft answer against retrieved passages before it is returned. The exact list varies by system, but the principle stays constant: every capability lives in a separately testable unit with a clear responsibility and a documented interface.

Flow patterns that connect the modules

The distinctive contribution of Modular RAG is a vocabulary of flow patterns. A pattern describes how modules interact, and choosing the right one matters as much as choosing good components. Simple questions need a linear flow, while research questions may need several retrieval rounds.

PatternHow it runsBest suited for
LinearModules execute once in a fixed orderStable, well-defined lookups
ConditionalA router selects one branch per queryMixed query types and sources
BranchingParallel retrievals are fused afterwardAmbiguous queries, RAG-Fusion
IterativeRetrieve and generate repeat a set number of timesMulti-hop retrieval
AdaptiveThe model decides when to retrieve againSelf-RAG and Corrective RAG designs
Main Modular RAG flow patterns

Branching flows commonly merge their result lists with reciprocal rank fusion, while adaptive flows rely on reflection signals or confidence scores to stop. Each added loop raises cost, so production designs usually cap iterations at two to four rounds.

How Modular RAG differs from earlier paradigms

Modular RAG is best understood as an evolution. Naive RAG follows a rigid index, retrieve and generate chain, and advanced RAG adds optimizations before and after retrieval while keeping the chain linear. Modular RAG generalizes both into reconfigurable building blocks.

AspectNaive RAGAdvanced RAGModular RAG
StructureFixed three stepsFixed chain with extra stagesGraph of swappable modules
Query handlingQuery used as writtenRewriting and expansionAny operator, chosen per query
Retrieval roundsOneUsually oneOne or many
AdaptabilityLowModerateHigh
Engineering effortLowModerateHigher, needs orchestration
Naive, advanced and Modular RAG compared

The boundary with agentic RAG is gradual. When a language model itself chooses modules and loops through tool calls, the system is usually called agentic; Modular RAG describes the architectural framework that makes such behavior possible, whether the control logic is coded or model-driven.

Designing and evaluating a modular system

Good modular design starts with clear module contracts: each component should accept and return well-defined objects, such as a query, a list of scored passages or a final answer with citations. Stable contracts allow teams to benchmark each module in isolation and replace weak ones.

  • Measure retrieval modules with Recall@k and mean reciprocal rank before tuning generation.
  • Evaluate generation for faithfulness and answer relevance using a RAG evaluation set.
  • Log every module’s inputs and outputs so failures can be traced to a single stage.
  • Add a module only when evaluation shows a measurable gain that justifies its latency.

Component-level evaluation is the practical payoff of modularity. If answers degrade, the team can check whether the router misclassified the query, the retriever missed the passage or the generator ignored good evidence.

Trade-offs and common pitfalls

Flexibility has a price. Each extra module adds latency, cost and failure points, and loosely specified flows can behave unpredictably. The table below lists frequent problems in modular deployments.

SymptomLikely causeRemedy
High response latencyToo many sequential modules or loopsParallelize branches and cap iterations
Wrong source consultedWeak query routerTrain or test routing on labeled queries
Irrelevant context in answersNo post-retrieval filteringAdd reranking or context compression
Hard-to-reproduce errorsMissing per-module loggingTrace every step with identifiers
Common Modular RAG problems

A common mistake is adopting complexity before evidence. Many workloads perform well with a linear flow plus hybrid search and reranking, and a full modular graph is justified only when query diversity or multi-hop needs demonstrably exceed what a simpler design achieves.

Another pitfall is inconsistent data between modules. If the indexing module changes its chunking strategy while the reranker was tuned on the old chunk sizes, quality can drop silently. Versioning indexes, prompts and models together, and rerunning the evaluation suite after every change, keeps a modular system reliable over time.

The short version

Think of a kitchen with separate stations. One cook chops, one grills and one plates the food. If the grill is slow, you replace only the grill. The rest of the kitchen keeps working.

Modular RAG builds AI answer systems the same way. One part improves the question. Another part finds documents. A third part sorts them, and a fourth writes the answer. Each part can be swapped or rearranged without starting over.

Where it makes a difference

A large insurance company runs an internal assistant for claims staff. Questions range from simple policy lookups to complex cases that combine contract terms, regulations and past rulings. A single linear pipeline handled lookups well but failed on multi-part questions.

The team rebuilt it as Modular RAG. A router sends simple lookups to a fast keyword index, while complex questions go through query decomposition, two retrieval rounds across contract and regulation indexes, and cross-encoder reranking. Because each module is logged separately, engineers discovered that most remaining errors came from the router and retrained it on 2,000 labeled queries. Answer accuracy on complex cases improved noticeably, while simple lookups kept their sub-second response time.