When retrieval needs more than one search
Agentic RAG lets an agent decide when, where, and how to retrieve, reformulate weak queries, use multiple sources, and verify whether evidence is sufficient.
What You Will Learn
- Decide when adaptive retrieval is worth more than one fixed search.
- Transform queries and choose sources from observed evidence gaps.
- Grade relevance, authority, provenance, and conflicting evidence.
- Stop retrieval using evidence and resource budgets.
What makes retrieval agentic?
Baseline RAG follows one designed retrieval path: transform the question, retrieve passages, and generate from them. Agentic RAG adds decisions around that path. The agent may decide retrieval is unnecessary, choose a source, reformulate a weak query, follow a cited document, compare evidence, or stop because the available sources cannot support an answer.
The agent should not merely ask whether passages look similar to the question. It should check relevance, authority, publication or effective date, provenance, and whether the evidence actually covers the claims the answer must make. When trusted sources conflict, the conflict is itself an outcome to report or escalate—not an invitation to average them together.
Baseline RAG versus Agentic RAG
Instructional figure
Baseline RAG and Agentic RAG take different paths
Where does an adaptive retrieval system make extra decisions?
Baseline RAG
Agentic RAG
Retrieve, judge the evidence and choose the next search
Classify whether retrieval is needed.
Plan one or more searches with filters.
Grade retrieved evidence and reformulate if weak.
Synthesize with citations, verify support, and stop within a retrieval budget.
Bound the corrective retrieval loop
A weak result can trigger a more specific query, a different approved collection, or a request for clarification. Each retry must have a reason tied to an evidence gap. Stop after the configured attempt, latency, or cost limit, and return the best supported partial result or abstain.
Agentic RAG is not worthwhile when one well-tuned retrieval query already solves the task, when low latency is critical, or when the source space is too weak to benefit from adaptation. Extra searches add cost and increase exposure to irrelevant or hostile content.
Instructional figure
The corrective retrieval loop
What should happen when evidence is weak or conflicting?
Worked Example: Comparing the latency of one retrieval with an adaptive loop
The times below are illustrative measured components for one question, not universal performance claims.
- Baseline RAG uses one retrieval taking 0.25 s and one answer generation taking 1.10 s.
- Baseline total = 0.25 + 1.10 = 1.35 s.
- Agentic RAG uses a 0.35 s decision, two retrievals at 0.25 s each, a 0.30 s evidence check, and a 1.10 s answer generation.
- Agentic total = 0.35 + (2 × 0.25) + 0.30 + 1.10 = 2.25 s.
- Extra latency = 2.25 − 1.35 = 0.90 s.
What the result means: Adaptive retrieval must earn its extra 0.90 seconds by improving evidence quality on the task; otherwise baseline RAG is the better design.
A Realistic Example: Researching a policy change
The agent searches the latest policy, follows a referenced amendment, compares effective dates, and refuses to answer if authoritative documents conflict.
Read the Mechanism in Code
Use the label and note to understand what this block represents before reading each line.
for attempt in range(3):
docs = retrieve(query, filters={"approved": True})
grade = relevance_and_authority(docs, question)
if grade.sufficient:
return grounded_answer(question, docs)
query = rewrite_query(question, docs, grade)
return escalate("Insufficient evidence")Hands-On Runnable Python Lab: Reject an Old Policy and Fill a Missing Refund Claim
The first fixture returns a current price and an outdated refund rule. Only the current price is accepted. A second targeted search returns the current 30-day policy. Two searches are allowed.
- Accept D1’s $40 price and reject OLD because current=False.
- Compute the missing field: refund_days. Use that gap to select a policy lookup.
- Accept D2’s 30-day rule, retaining D2 as its source.
- Produce a supported answer only when both fields are present; test a second run without D2 to demonstrate a partial answer.
One missing claim drives one targeted retrieval
A rejected 90-day policy never enters the answer. D1 supports the price and D2 supports the refund period; without D2 the answer remains partial.
batches = [
[{"id": "D1", "current": True, "facts": {"price_usd": 40}},
{"id": "OLD", "current": False, "facts": {"refund_days": 90}}],
[{"id": "D2", "current": True, "facts": {"refund_days": 30}}],
]
required = {"price_usd", "refund_days"}
def retrieve_and_check(search_results):
evidence, sources = {}, {}
for attempt, docs in enumerate(search_results[:2], start=1):
print("search", attempt, "for", sorted(required - evidence.keys()))
for doc in docs:
if not doc["current"]:
print(" rejected:", doc["id"], "(outdated)")
continue
for field, value in doc["facts"].items():
if field in required:
evidence[field] = value
sources[field] = doc["id"]
print(f" coverage: {len(evidence)}/{len(required)}")
if required <= evidence.keys():
break
if required <= evidence.keys():
print(f"Answer: USD {evidence['price_usd']} [{sources['price_usd']}]; "
f"{evidence['refund_days']}-day refunds [{sources['refund_days']}]")
else:
print("Partial evidence:", evidence)
print("Cannot verify:", ", ".join(sorted(required - evidence.keys())))
print("Complete run")
retrieve_and_check(batches)
print("Missing-policy run")
retrieve_and_check(batches[:1])
Complete run
search 1 for ['price_usd', 'refund_days']
rejected: OLD (outdated)
coverage: 1/2
search 2 for ['refund_days']
coverage: 2/2
Answer: USD 40 [D1]; 30-day refunds [D2]
Missing-policy run
search 1 for ['price_usd', 'refund_days']
rejected: OLD (outdated)
coverage: 1/2
Partial evidence: {'price_usd': 40}
Cannot verify: refund_daysWhat This Run Shows
- The outdated 90-day rule never enters accepted evidence despite matching the topic.
- The second search has a visible purpose: fill one missing field.
- When D2 is unavailable, the controller names the missing claim instead of borrowing the rejected rule.
Compare adaptation with a well-tuned fixed pipeline on the same test set. Extra retrieval is justified only when its gain in supported answers outweighs latency, cost and exposure to untrusted material.
From the Exercise to an Application
Experiment: Mark the old policy as current=True.
The fixture is accepted and could prematurely produce a 90-day answer. Metadata quality and authority checks are part of retrieval correctness, not decoration.
Summary / Key Takeaways
- Baseline RAG usually retrieves once; Agentic RAG lets the system decide whether, when, where, and how to retrieve.
- An Agentic RAG loop can rewrite queries, change sources, grade evidence, and retrieve again when the first attempt is weak.
- Evidence sufficiency and authority should be checked before generation, not assumed because retrieval returned documents.
- Conflicting authoritative sources may require abstention or escalation rather than another blind retrieval loop.
- Every additional retrieval and grading step adds latency, cost, and exposure to irrelevant or malicious content.
- Retrieval attempts, source permissions, query rewrites, and tool authority should therefore be bounded.
- Agentic RAG is justified when adaptive retrieval measurably improves difficult questions; simple RAG remains preferable for straightforward cases.
Verified Further Reading
These primary research papers and current official specifications support the concepts and implementation guidance in this lesson. The explanations, analogies, exercises, and code above remain original teaching material.
Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection
Research on adaptive retrieval and self-critique instead of always adding a fixed number of passages.
Corrective Retrieval Augmented Generation
Research on evaluating retrieval quality and triggering corrective retrieval actions when evidence is weak.