Skip to content
FS Fábio Silva
← All ideas
· 11 min read · ai· rag· architecture· engineering

Agentic RAG: why your retrieval pipeline needs a brain

A retrieval pipeline that fetches but never reasons fails silently — a confidently wrong answer with no error thrown. Agentic RAG hands the LLM real agency over how grounding happens, and the engineering discipline that demands.


There’s a quiet crisis in enterprise AI that nobody talks about at conferences.

Teams spend months building RAG systems — careful chunking strategies, tuned embedding models, optimized vector stores — and the demos look great. Then production happens. A user asks something that spans two documents and a database table. Another query needs three reasoning steps to resolve. A third requires the system to notice that the first retrieval came back empty and try again with different terms.

The pipeline breaks. Silently. No error thrown. Just a confidently wrong answer.

This is the RAG paradox: the retrieval works, but the system doesn’t think. And thinking, it turns out, is exactly what was missing.

From pipeline to agent: the paradigm shift

Standard RAG — what researchers now call Naive RAG — follows a rigid three-step sequence:

Query → Embed → kNN Retrieval → Concatenate → LLM → Response

It’s elegant in its simplicity and brittle in practice. Fixed chunk sizes ignore document structure. A single retrieval pass cannot resolve multi-hop questions. There’s no mechanism to detect when retrieved context is irrelevant or incomplete. And sparse lexical signals — product codes, proper nouns, rare technical terms — often vanish inside dense embeddings.

Advanced RAG improved this with query rewriting, hybrid retrieval (dense + BM25), cross-encoder reranking, and contextual compression. Real gains. But still a fixed pipeline: the LLM received whatever retrieval produced and had no say in the matter.

Agentic RAG removes that constraint entirely.

The LLM is no longer a passive generator waiting for context to be handed to it. It becomes an active orchestrator that:

  • Plans a retrieval strategy given the query’s structure and complexity
  • Routes sub-queries to the right knowledge source — vector stores, SQL databases, graph DBs, external APIs
  • Evaluates whether retrieved evidence is sufficient to answer the question
  • Iterates — re-queries with refined terms, broadens scope, or narrows to specifics as needed
  • Reflects on its own draft answers to catch unsupported claims before they reach the user

This is not smarter retrieval. It’s agentic reasoning applied to your entire knowledge landscape.

The architecture under the hood

An Agentic RAG system has five core components that work in concert. Understanding their boundaries is essential to building one that doesn’t collapse under production load.

User query Orchestrator (LLM agent) Query planner Tool selector Response synthesizer Memory system Working (context) Episodic (session) Semantic (entity KG) Procedural (prompts) TOOL CALLS TOOL REGISTRY Vector DB Dense retrieval SQL / NL-to-SQL Relational data Web / API Live sources Code exec Sandbox interpreter Graph traversal Knowledge graph POST-RETRIEVAL Context assembly + re-ranking Dedup · cross-encoder fusion · position-aware ordering AGENTIC REASONING ReAct loop Reason + act iteratively Plan + execute DAG parallel steps Multi-agent Hierarchical collab Reflection + self-critique SELF-RAG tokens · CRAG evaluator · Critic-actor pattern Insufficient → re-query orchestrator SUFFICIENT Response synthesis Aggregate evidence · grounded citations Final answer
The agentic loop: the orchestrator plans and routes to a registry of retrieval tools, assembles and re-ranks the returned context, reasons and self-critiques — looping back when the evidence is thin, and only then synthesising a grounded answer.

The orchestrator

The orchestrator is the LLM itself — prompted or fine-tuned to decompose queries into atomic sub-questions, generate retrieval plans, dispatch tool calls, evaluate returned evidence, and synthesize a final response. In practice this is implemented either via native function calling (Anthropic tool use, OpenAI function calling) or via structured output parsing from a capable frontier model.

The key design choices here — which model to use, whether to use system prompts or fine-tuning, how to cap iteration depth — have enormous downstream consequences for cost, latency, and answer quality.

The retrieval fabric

Behind the orchestrator lies a heterogeneous retrieval layer abstracting over multiple backends:

  • Dense vector stores (Pinecone, Qdrant, pgvector, Weaviate) for semantic similarity
  • Sparse lexical engines (Elasticsearch BM25, OpenSearch) for exact term matching
  • Graph databases (Neo4j, Amazon Neptune) for relationship traversal
  • Relational databases via natural-language-to-SQL for structured enterprise data
  • External APIs for live data — search engines, internal REST services, third-party feeds

The fabric exposes a uniform interface to the orchestrator. A well-designed retrieval fabric lets the orchestrator call retrieve(query, source_id, top_k, filters) without knowing anything about what’s happening underneath.

The tool registry

Every callable retrieval tool is registered with metadata that the orchestrator uses to make routing decisions:

{
  "tool_id": "vector_search_product_docs",
  "description": "Retrieve relevant sections from internal product documentation. Use for product feature questions, API reference, and release notes. Do NOT use for billing queries.",
  "latency_p99_ms": 250,
  "cost_per_call_usd": 0.0001
}

Tool description quality is the single most underestimated engineering concern in Agentic RAG. A vague description causes mis-routing; a mis-routed query retrieves nothing useful and forces an expensive retry. The discriminative power of your tool descriptions directly determines your system’s routing accuracy.

Memory systems

Agentic RAG needs multiple memory layers, and conflating them is a common mistake:

Memory typeScopeImplementation
Working memorySingle agent turnLLM context window
Episodic memorySession-levelRedis / in-process store
Semantic memoryCross-sessionVector DB
Procedural memoryAgent definitionSystem prompt / fine-tune

Storing everything in the context window exhausts your token budget fast and degrades performance in ways that are genuinely hard to debug.

Retrieval strategies worth knowing

Query decomposition

Complex queries rarely map to a single retrieval operation. Take: “What were the main causes of the 2008 financial crisis, and how do they compare to the conditions preceding the dot-com bubble?”

That’s at minimum two retrievals plus a synthesis step. An Agentic RAG system decomposes this before touching the vector store, retrieving each piece independently, then synthesizing. The overhead is one additional LLM call — worth it for query types where single-shot retrieval reliably fails.

HyDE: hypothetical document embeddings

One of the cleverer techniques in the modern retrieval toolkit. Instead of embedding the user’s question for retrieval, you prompt the LLM to generate a hypothetical ideal document that would answer the query, then embed that.

Why it works: the hypothetical document uses the same declarative, full-sentence prose as your actual indexed documents, closing the vocabulary gap between how users ask questions and how knowledge is written down. The trade-off is one additional generation step and the risk that the hypothetical document introduces hallucinations that bias retrieval — validate that returned chunks stay grounded in real corpus content.

RAPTOR: hierarchical index structure

RAPTOR (Recursive Abstractive Processing for Tree-Organized Retrieval) builds a multi-level index by recursively clustering and summarizing chunks, creating progressively higher-level “summary nodes.” At query time, retrieval spans all tree levels simultaneously.

This matters for questions that need both fine-grained detail and high-level conceptual context — the kind of question that breaks flat vector stores because the answer lives at two different granularities. The downside: tree construction is expensive and must run offline, with rebuild pipelines triggered on corpus updates.

Hybrid retrieval + RRF

Dense retrieval captures semantic similarity and handles paraphrase. Sparse BM25 retrieval captures exact terms — product codes, API names, rare tokens that get washed out during embedding. The two signals are complementary, and combining them with Reciprocal Rank Fusion (RRF) consistently outperforms either alone:

RRF_score(d) = Σ_r 1 / (60 + rank_r(d))

Simple, parameter-free, and empirically robust. Start here before investing in learned fusion.

Reasoning patterns that matter in production

ReAct: reason + act

The foundational pattern. The agent alternates between explicit reasoning steps and tool invocations, producing a transparent trace:

Thought: I need the company's FY2023 revenue figure.
Action: vector_search(query="Company X 2023 annual revenue", top_k=5)
Observation: [chunk: "Company X reported $4.2B in FY2023..."]
Thought: Now I need FY2022 for the YoY comparison.
Action: vector_search(query="Company X 2022 annual revenue", top_k=3)
Observation: [chunk: "FY2022 revenue was $3.8B..."]
Thought: Revenue grew 10.5% YoY. Sufficient context.
Final Answer: ...

The reasoning trace is the key debugging asset. When the system gives a wrong answer, you read the trace and find exactly where it went off the rails. That’s a qualitative advantage over black-box pipelines.

Plan-and-execute

Separates planning from execution to unlock parallelism. A planner LLM generates a DAG of retrieval steps; independent steps execute concurrently via asyncio.gather(); dependent steps wait. For multi-hop queries, this can yield 2–4× latency reduction over sequential ReAct.

The implementation overhead is real — you need a DAG executor and careful dependency tracking — but for latency-sensitive production workloads it pays for itself.

Self-reflection: SELF-RAG and CRAG

Two patterns address the core hallucination problem:

SELF-RAG trains the model to generate special reflection tokens inline: [Retrieve], [Relevant]/[Irrelevant], [Grounded]/[Ungrounded], and [Utility]. The model decides while generating whether to retrieve, whether what it retrieved is relevant, and whether its claims are supported.

CRAG (Corrective RAG) uses a lightweight evaluator to grade each retrieved document. Documents graded Incorrect trigger a web search fallback; Ambiguous documents trigger query refinement. The key innovation is that retrieval failure has an explicit corrective path rather than silently polluting the context.

Both add latency. Both materially reduce hallucination rates. In legal, medical, and financial domains, they’re not optional.

The production engineering reality

Latency compounds

This is the uncomfortable truth about Agentic RAG: every agent step adds latency, and the math compounds quickly.

For a 3-iteration agent with LLM calls at 300ms each, vector retrieval at 50ms, and reranking at 150ms:

3 × 300ms (LLM) + 3 × 50ms (retrieval) + 3 × 150ms (rerank) = 1,500ms
+ 1 × 300ms (final synthesis) ≈ 1.8s P50

And P99 can be 3–5× P50 due to LLM tail latency. If your use case requires sub-second responses, Agentic RAG needs aggressive optimization: speculative retrieval, parallel tool execution, model cascading (use Claude Haiku or GPT-4o-mini for routing and evaluation, a frontier model only for synthesis), and streaming final responses while the last retrieval is still completing.

Cost management

Cost drivers multiply with agent depth. The levers:

  • Compress context — don’t feed the full retrieved corpus to every LLM call; distill it
  • Model cascading — route sub-tasks to cheaper models whenever quality allows
  • Semantic caching — cache retrieval results not just on exact query match but on embedding similarity above a threshold; hit rates for enterprise use cases can be substantial
  • Early termination — if the first retrieval yields a high-confidence sufficient context, exit the loop

Set an explicit per-session cost cap and a step budget. Token overruns are a frequent silent performance bug.

Observability is non-negotiable

Unlike traditional APIs, Agentic RAG failures manifest as quality degradation rather than errors. Nothing throws an exception when the agent retrieves irrelevant context and generates a confident wrong answer.

Minimum instrumentation: a structured trace per agent run capturing every step — step type, input/output tokens, latency, tool called, cache hit, retrieval scores, and a faithfulness score on the final answer. Tools like LangSmith, LangFuse, and Arize Phoenix can handle this. What matters is that you have dashboards for:

  • Mean retrieval rounds per query
  • Tool selection accuracy by query type
  • Faithfulness score distribution over time
  • P50/P95/P99 latency per step type
  • Cost per successful query

Failure modes to design against

FailureSymptomMitigation
Plan loopingAgent repeats the same tool callMax iteration cap + step deduplication
Context poisoningAdversarial corpus content alters behaviorInput sanitization + prompt injection defenses
Overconfident synthesisHigh-confidence answer from low-quality retrievalConfidence calibration; explicit “I don’t know” path
Runaway costMany tool calls per queryPer-session cost cap + step budget
Stale retrievalOutdated documents dominateTTL metadata filtering + corpus refresh pipelines

When Agentic RAG is — and isn’t — worth it

The cost and complexity are real. Before committing, the honest question is whether your use case actually needs it.

Agentic RAG is worth the investment when:

  • Queries are multi-hop — answering requires synthesizing information from multiple documents or sources
  • Knowledge lives in heterogeneous stores — SQL, vectors, graph DBs, APIs — that require intelligent routing
  • Accuracy is high-stakes — hallucinations have legal, financial, or medical consequences
  • You need compliance-ready reasoning traces

Stick with Advanced RAG (or less) when:

  • Queries are simple, single-hop lookups
  • Your corpus is homogeneous and lives in one vector store
  • Latency requirements are strict and your use case doesn’t justify the overhead
  • You’re building a chatbot, not a decision system

Put bluntly: Agentic RAG is becoming table stakes for teams building decision systems. It’s overkill for everything else — and pretending otherwise is how you end up paying frontier-model prices to answer “what are your office hours?”

Ecosystem and tooling

FrameworkBest for
LlamaIndexRetrieval-heavy workflows; best-in-class indexing abstractions, RAPTOR, GraphRAG
LangGraphComplex agentic state machines with human-in-the-loop requirements
LangChainGeneral-purpose agent/RAG; large ecosystem
HaystackProduction RAG pipelines; strong evaluation tooling
DSPyProgrammatic prompt optimization; compiles prompts from data
Raw SDKsMaximum control and minimal abstraction overhead

For new systems: LlamaIndex for retrieval-heavy work, LangGraph when you need durable stateful agents, raw Anthropic/OpenAI SDKs when abstraction cost exceeds benefit.

What’s coming next

The field is moving fast enough that anything written today risks being outdated by the time you read it. The research directions worth tracking:

RAFT (Retrieval-Augmented Fine-Tuning): training models to use retrieved context more faithfully — including learning to ignore irrelevant retrieved content rather than incorporating it.

Long-context vs. RAG trade-offs: as context windows expand toward 1M+ tokens, when does feeding the entire corpus beat retrieval? Emerging evidence suggests retrieval remains necessary at corpus sizes beyond a few hundred documents — but this boundary is shifting.

Agentic retrieval safety: formal bounds on agent tool use to prevent self-modification of retrieval configurations or data exfiltration through chains of seemingly benign calls.

Multi-modal RAG: unified retrieval over images, audio, video, tables, and code — the full enterprise knowledge landscape, not just text.

The core insight

Retrieval-Augmented Generation was always about grounding LLM outputs in real knowledge. Agentic RAG is about giving the LLM genuine agency over how that grounding happens.

The engineering discipline required is substantial. Latency compounds. Costs scale with reasoning depth. Failures are silent and quality-oriented rather than loud and error-oriented. None of that goes away.

But for the use cases that demand it — multi-source reasoning, high-stakes accuracy, transparent decision trails — there’s no credible alternative architecture on the table. The question isn’t whether to build Agentic RAG. It’s whether you build it with the operational discipline it requires.