RAG Retrieves. Agentic RAG Thinks.
A hands-on Python comparison of Traditional RAG and Agentic RAG across 12 engineering documents and 5 query types using `gemini-3.5-flash-lite` and `gemini-embedding-001`. It covers where fixed pipelines break on multi-hop codenames, 3-doc synthesis, and non-retrieval prompts, walks through real parallel tool-calling traces, and breaks down the 3.1x to 9.9x token tradeoff so you know when linear RAG still wins.

Table of Contents4 sections
My first experiment trying to break Traditional RAG backfired. I indexed 5 short engineering documents into ChromaDB with gemini-embedding-001, set k=2, and asked gemini-3.5-flash-lite a two-hop codename question: What is the circuit-breaker cooldown for Project Zephyr?
I wrote my hypothesis before running any code. Because architecture_codenames.md maps Project Zephyr to Async Billing Pipeline, while billing_rate_limits.md lists the 90 seconds cooldown without mentioning Zephyr, single-shot retrieval should miss.
It did not miss. Traditional RAG passed 3/3 in both initial runs (median 4.10s to 5.73s). Checking the retrieved filenames explained why. With only 5 chunks in ChromaDB, k=2 pulled 40% of the corpus on every lookup. Similarity search grabbed incident_runbook.md and billing_rate_limits.md, then guessed 90 seconds without ever fetching architecture_codenames.md to confirm Zephyr mapped to billing.
Where Traditional RAG actually broke was a prompt needing no lookup at all: Convert 90 seconds to minutes as a Python expression. Forced retrieval grabbed two unrelated docs (auth_service.md and deploy_policy.md), and the grounded prompt failed 0/3 with "It is not in the provided context."
Five documents were too few to test multi-hop limits fairly. I expanded the handbook to 12 documents, added a 3-document comparison plus an unanswerable secret lookup, tracked token usage, and added a k=4 ablation on Traditional RAG to check whether pulling more chunks removes the need for an agent loop.
The 12-doc benchmark setup
Everything ran on Ubuntu 24.04.5 LTS (x86_64, 13th Gen Intel Core i3-1315U, 15.2 GiB RAM) with Python 3.14.5, uv 0.11.16, langchain 1.5.2, langgraph 1.2.23, langchain-google-genai 4.5.1, langchain-chroma 1.1.0, and chromadb 1.5.9.
All three pipelines shared identical inputs: 12 engineering documents split with RecursiveCharacterTextSplitter (chunk_size=360, chunk_overlap=40, yielding 12 chunks), embedded into a fresh ChromaDB collection via gemini-embedding-001 (cold index took 2.37s in the 3-trial run), and queried with gemini-3.5-flash-lite. Each query ran 3 trials (n=3) to capture medians, ranges, and token counts.
The handbook covers service codenames (architecture_codenames.md), guardrails for three services (billing_rate_limits.md, webhook_relay_limits.md, auth_service.md), on-call triage (incident_runbook.md), deployment rules (deploy_policy.md), payments SLA (payments_sla.md), Redis caching (cache_policy.md), PostgreSQL failover (database_failover.md), alerting (observability_alerts.md), staging config (staging_config.md), and API versioning (api_versioning.md). At 12 chunks, k=2 covers 16.7% of the store per search instead of 40%.
I ran 5 query types across Traditional RAG (k=2), Traditional RAG (k=4), and Agentic RAG (k=2):
single_hop:What is the default rate limit for the Async Billing Pipeline?(Expected:120 req/min.)multi_hop:What is the circuit-breaker cooldown for Project Zephyr?(Expected:90 secondsvia 2 docs.)cross_doc_compare:Which service has a longer circuit-breaker cooldown: Project Zephyr or Project Meridian, and by how many seconds?(Expected:Project Meridianby60 secondsacross 3 docs: codenames, billing90 seconds, webhook relay150 seconds.)no_retrieval:Convert 90 seconds to minutes as a Python expression.(Expected:90 / 60, ideally 0 retrievals.)abstention:What is the PostgreSQL primary password for Project Zephyr?(Expected: refusal;database_failover.mdnotes credentials live only in Vault.)
Three practical snags appeared along the way. First, bash source failed on .env (GOOGLE_API_KEY: command not found) because of spaces around =, so I loaded credentials via python-dotenv. Second, langchain-google-genai 4.5.1 emitted a UserWarning that gemini-3.5-flash-lite uses fixed sampling defaults and ignores temperature, so I dropped temperature=0. Third, my first 12-doc 3-trial run hit the 600s timeout (exit=124) with buffered stdout hiding progress. Switching to line-buffered stdout (python -u) plus timeout=45, max_retries=3 on ChatGoogleGenerativeAI fixed it; a 1-trial check finished in 110.57s and the 3-trial benchmark completed in 421.11s.
Where fixed pipelines break, even at k=4
Traditional RAG runs as a straight line in src/traditional_rag.py:
hits = store.similarity_search_with_score(question, k=k)
context = "\n\n".join(
f"[{doc.metadata.get('source', 'unknown')}]\n{doc.page_content}"
for doc, _ in hits
)
messages = [
(
"system",
"Answer concisely using only the provided context for internal service facts. "
"If the context does not contain the answer, state that it is not in the provided context.",
),
("human", f"Context:\n{context}\n\nQuestion: {question}"),
]
response = chat.invoke(messages)
That design buys predictability. It always makes 1 retrieval and 1 LLM call, keeping token usage flat (163 to 198 median tokens at k=2). On single_hop, k=2 answered 120 req/min. across 3/3 trials in 4.59s median using 189 tokens. On abstention, it fetched database_failover.md and architecture_codenames.md and refused cleanly 3/3 in 2.67s median using 191 tokens.
Then the linear flow hit three walls. On multi_hop, k=2 dropped to 0/3 (median 3.47s, 193 tokens). Similarity search pulled incident_runbook.md and billing_rate_limits.md without architecture_codenames.md, and this time the model answered "It is not in the provided context." On cross_doc_compare, k=2 failed 0/3 (median 5.01s, 198 tokens): two chunks cannot carry facts split across three files. On no_retrieval, k=2 passed only 1/3 (median 9.61s, 163 tokens) because unconditional search pulled auth_service.md and deploy_policy.md.
What if you just double k from 2 to 4? I tested that ablation in the same run.
Bumping to k=4 fixed multi_hop, jumping from 0/3 to 3/3 (median 3.52s, 305 tokens) because architecture_codenames.md landed in slot 4. Elsewhere, k=4 hit the ceiling of one-shot retrieval. On cross_doc_compare, it still failed 0/3 (median 9.68s, 321 tokens): auth_service.md took slot 3 and pushed webhook_relay_limits.md out. On no_retrieval, k=4 dropped to 0/3 (median 4.72s, 275 tokens) after stuffing four unrelated docs into the prompt.
One reporting caveat on Traditional (k=4) for single_hop: the script printed pass=2/3, pulling its summary down to Traditional(k=4)=2/5. Inspecting E024.log showed trial 1 returned 12\n0 req/min because Gemini emitted split content blocks that extract_text joined with "\n". Factually, k=4 solved 3/5 cases (single_hop, multi_hop, abstention), yet still failed 3-doc synthesis and non-retrieval routing.
Turning retrieval into an agent loop
Agentic RAG changes one assumption: retrieval stops being a mandatory pre-step and becomes a tool the LLM calls zero, one, or many times. In src/agentic_rag.py, I attached two tools over the same ChromaDB store (k=2) to LangChain's create_agent with DEFAULT_RECURSION_LIMIT = 10:
@tool
def list_doc_sources() -> str:
"""List all document filenames available in the internal engineering knowledge base."""
meta = store._collection.get(include=["metadatas"]).get("metadatas") or []
sources = sorted({str(m.get("source", "unknown")) for m in meta if isinstance(m, dict)})
return ", ".join(sources)
@tool
def search_docs(query: str) -> str:
"""Search internal engineering docs for a service name, codename, rate limit, or policy."""
hits = store.similarity_search_with_score(query, k=k)
lines = []
for doc, distance in hits:
src = doc.metadata.get("source", "unknown")
lines.append(f"[source={src} distance={distance:.4f}]\n{doc.page_content}")
return "\n---\n".join(lines)
Invocation guards against runaway loops:
try:
output = agent.invoke(
{"messages": [("user", question)]},
config={"recursion_limit": recursion_limit},
)
except GraphRecursionError:
Four behavioral shifts follow. First is routing: on general Python questions, the model answers with 0 vector lookups. Second is query rewriting: instead of embedding the raw prompt, the model issues focused keywords ('Zephyr', 'Async Billing Pipeline', 'Webhook Relay Worker'). Third is iterative chaining: after reading returned chunks, the model decides whether context is complete or requires another search. Fourth is loop safety: config={"recursion_limit": recursion_limit} plus GraphRecursionError prevents unbounded API spend.
One surprise appeared across both live runs (E023 and E024): gemini-3.5-flash-lite never called list_doc_sources once (tool_calls equaled retrieval_calls on every trial). Yet its schema still shipped in every prompt turn, adding input tokens for zero calls.
The E024 traces show how the loop behaves. On multi_hop, Agentic RAG passed 3/3 using 2 searches and 3 LLM calls every time (median 15.35s, 1,147 tokens):
trial1 step 1: search_docs({'query': 'Zephyr'}) | sources=['architecture_codenames.md', 'incident_runbook.md']
trial1 step 2: search_docs({'query': 'Async Billing Pipeline'}) | sources=['billing_rate_limits.md', 'architecture_codenames.md']
Querying 'Zephyr' ranked architecture_codenames.md first (distance 0.5812). Reading the alias let step 2 fetch billing_rate_limits.md (distance 0.4075) and return 90 seconds.
On cross_doc_compare, Agentic RAG passed 3/3 with retrievals=[4, 4, 4] inside just llm_calls=[3, 3, 3] (median 11.48s, 1,777 tokens):
trial1 step 1: search_docs({'query': 'Project Zephyr'}) | sources=['architecture_codenames.md', 'incident_runbook.md']
trial1 step 2: search_docs({'query': 'Project Meridian'}) | sources=['architecture_codenames.md', 'incident_runbook.md']
trial1 step 3: search_docs({'query': 'Async Billing Pipeline'}) | sources=['billing_rate_limits.md', 'architecture_codenames.md']
trial1 step 4: search_docs({'query': 'Webhook Relay Worker'}) | sources=['webhook_relay_limits.md', 'architecture_codenames.md']
Because gemini-3.5-flash-lite batched tool calls in parallel, turn 1 resolved both codenames, turn 2 fetched both guardrail docs, and turn 3 compared 150 seconds against 90 seconds to answer Project Meridian by 60 seconds. Parallel batching is why 4-search cross_doc_compare (11.48s median) beat 2-search multi_hop (15.35s median).
On no_retrieval, Agentic RAG made 0 tool calls and 1 LLM call across all 3 trials, answering 90 / 60 in 3.69s median with 186 tokens. On abstention, thoroughness had a price: it passed 3/3 across 2 to 3 searches (3 to 4 LLM calls), citing Vault from database_failover.md instead of a generic refusal, at 1,884 median tokens and 15.37s median.
Traditional vs. agentic RAG: the numbers
Full 3-trial results from E024 (gemini-3.5-flash-lite, gemini-embedding-001, 12 docs, n=3):
| Query case | Traditional k=2 (pass · tokens · median / range) |
Traditional k=4 (pass · tokens · median / range) |
Agentic k=2 (pass · retrievals · LLM calls · tokens · median / range) |
|---|---|---|---|
single_hop |
3/3 · 189 tok · 4.59s (4.52s-5.36s) | 2/3* · 305 tok · 5.74s (5.32s-8.10s) | 3/3 · 1 ret · 2 LLM · 593 tok · 9.02s (8.41s-9.04s) |
multi_hop |
0/3 · 193 tok · 3.47s (2.06s-4.32s) | 3/3 · 305 tok · 3.52s (1.83s-4.13s) | 3/3 · 2 ret · 3 LLM · 1,147 tok · 15.35s (11.85s-17.58s) |
cross_doc_compare |
0/3 · 198 tok · 5.01s (4.31s-6.96s) | 0/3 · 321 tok · 9.68s (6.15s-25.61s) | 3/3 · 4 ret · 3 LLM · 1,777 tok · 11.48s (8.38s-20.52s) |
no_retrieval |
1/3 · 163 tok · 9.61s (4.50s-9.83s) | 0/3 · 275 tok · 4.72s (2.04s-5.13s) | 3/3 · 0 ret · 1 LLM · 186 tok · 3.69s (3.48s-3.69s) |
abstention |
3/3 · 191 tok · 2.67s (2.24s-37.57s) | 3/3 · 321 tok · 9.63s (8.60s-33.50s) | 3/3 · 2-3 ret · 3-4 LLM · 1,884 tok · 15.37s (14.33s-23.93s) |
*Trial 1 printed 12\n0 req/min from a newline join in extract_text; factually Traditional (k=4) solved 3/5 cases, Traditional (k=2) passed 2/5, and Agentic (k=2) passed 5/5.
Hosted API latency fluctuates sharply (note the 37.57s and 33.50s spikes on single-call abstention), making token usage and LLM calls steadier cost signals. Between E023 (n=1) and E024 (n=3), Agentic RAG median tokens stayed within 2% on every case. Against Traditional k=2, Agentic RAG burned 3.1x tokens on single_hop (593 vs. 189), 5.9x on multi_hop (1,147 vs. 193), 9.0x on cross_doc_compare (1,777 vs. 198), and 9.9x on abstention (1,884 vs. 191). Only no_retrieval inverted the bill: Agentic RAG spent 186 tokens (32% fewer than k=4's 275) and ran 2.6x faster than k=2 (3.69s vs. 9.61s).
| Dimension | Traditional RAG | Agentic RAG |
|---|---|---|
| Control flow | Fixed 1-shot sequence | Dynamic tool-calling loop |
| Retrieval trigger | Always 1 lookup | Adaptive (0, 1, or 2-4 lookups) |
| Query handling | Raw user prompt | Rewritten per step |
| Multi-doc synthesis | Bound by top-k window | Sequential and parallel searches |
| Cost profile | Flat (163-321 tok, 1 LLM call) | Variable (186-1,884 tok, 1-4 LLM calls) |
On this 12-document handbook with gemini-3.5-flash-lite, Agentic RAG was the only setup that solved all 5 query types. Even so, linear RAG still wins on direct lookups: k=2 matched Agentic accuracy on single_hop at 3.1x fewer tokens, half the LLM calls, and roughly half the latency (4.59s vs. 9.02s). Move to Agentic RAG when queries cross documents, resolve codenames, or mix general questions with internal search. When you switch, drop unused tools like list_doc_sources, enforce recursion_limit, and budget 3.1x to 9.9x more tokens for multi-step queries and abstentions.
Full benchmark source code, tests, and
reproduce.sh: github.com/agenticbd/agentic-rag-vs-naive-rag

