09. Advanced Concepts
RAG and Agentic RAG
RAG (Retrieval-Augmented Generation) retrieves evidence from your corpus and grounds the LLM answer. Agentic RAG goes further: the agent plans sub-queries, calls search as a tool, grades evidence, hops again under budgets, and cites sources — classic RAG when one retrieve is enough; agentic loops when questions need multi-hop or critique.
What you will learn
- Define classic RAG vs Agentic RAG clearly
- Sketch a budgeted plan-retrieve-grade-answer loop
- Choose tool RAG, multi-hop, critique, or router patterns
- List evals and failure modes for grounded agents
- Answer interview questions with short, solid answers
Definition
Classic RAG is a mostly fixed pipeline: embed/query → retrieve top-k → stuff context → generate (ideally with citations). Agentic RAG makes retrieval part of the agent’s tool loop: it may rewrite queries, search multiple sources, read chunks, critique sufficiency, and only then answer — or refuse.
Both rest on Module 08 foundations (embeddings, vector stores, ACL filters). Agentic RAG adds planning, tool use, and stop conditions so loops do not burn unbounded tokens.
Introduction
This lesson (#1 in Advanced Concepts) opens Module 09 after Logging/Tracing. You can observe runs; now deepen how agents ground knowledge under harder questions.
Next: Advanced Memory Management.
Why move beyond classic RAG
- Multi-hop questions need facts from several documents
- First retrieve often misses; rewrite improves recall
- Agents must choose KB vs SQL vs web tools
- Critique reduces hallucinations when evidence is weak
- Still start classic — agentic only when evals demand it
Classic RAG recap
- Offline: chunk, embed, index with metadata/ACL
- Online: retrieve → (re-rank) → generate with citations
- Hybrid search for IDs + meaning
- Cap context size; measure recall@k
- Best for single-hop FAQ and policy lookup
Agentic RAG loop
Treat retrieval as a controllable subroutine with an exit condition.
- Plan - decompose into sub-queries
- Retrieve - hybrid search with tenant filters
- Grade - enough evidence? conflicting?
- Act - answer with citations, refuse, or rewrite/hop
- Budget - max hops, tokens, wall-clock
- Trace every hop (observability lesson)
Patterns
Use the smallest pattern that passes your eval set.
- Tool RAG - model calls search_docs when needed
- Multi-hop - new query from intermediate findings
- Critique / self-RAG style - grade then retrieve again
- Router - pick corpus, SQL, or web per question type
- Ensemble - parallel retrieves then merge/re-rank
Design rules
- Allowlisted search tools — not free-form crawl everything
- Return compact cited snippets, not whole PDFs
- Separate retrieval quality evals from answer style
- Prefer refuse over invent when grade fails
- Keep SQL system of record for authoritative fields
- Pin embedding + chat models; version the index
Evaluation
- Classic: recall@k / hit rate on gold docs
- Agentic: hops used, success under hop budget
- Faithfulness: answer supported by cited chunks
- End-to-end correctness on multi-hop question sets
- Cost: tokens and latency per successful answer
- Compare classic vs agentic on the same suite before shipping loops
Map to earlier modules
- Embeddings/vector DB lessons supply the retrieve substrate
- Tool-use / Agents SDK handoffs power tool RAG
- LangGraph/CrewAI/ADK can encode the plan-grade graph
- Observability spans should mark each retrieve hop
- Next: memory beyond one-shot RAG chunks
Failure modes
- Unbounded hops → cost explosions
- Agentic complexity without better eval scores
- Critique that always “needs more search” (no stop rule)
- Missing ACL filters on every hop
- Citations pointing to unused or wrong chunks
Program / implementation notes
Ship classic RAG with citations and recall@k dashboards first. Add a search_docs tool and a max-hop critique loop only for question types classic RAG fails.
- Log query rewrites and retrieved ids per hop
- Next: Advanced Memory Management
Advantages and limitations
- Advantage: grounds answers in private knowledge
- Advantage: agentic loops handle multi-hop and weak first retrieves
- Advantage: routers unify KB, SQL, and web tools
- Limitation: more moving parts and failure modes
- Limitation: higher latency and token cost
- Limitation: still only as good as the corpus and chunking
Key points
- Classic RAG: retrieve once (or fixed pipeline) then generate.
- Agentic RAG: plan, retrieve, grade, hop — under budgets.
- Start classic; add agentic patterns when evals require them.
- Citations, ACL filters, and stop rules are mandatory.
- Eval retrieval and faithfulness separately from hop count.
- Trace every hop for cost and debugging.
FAQs
Is Agentic RAG always better?
No. It costs more. Use it when classic RAG fails multi-hop or evidence-quality evals — not by default.
How is this different from fine-tuning?
RAG/Agentic RAG pulls fresh documents at runtime. Fine-tuning changes model weights/behavior. Many systems use both for different goals.
What stop conditions should I use?
Max hops, max tokens/time, “evidence graded sufficient,” or user abort — never rely on the model alone to stop searching.
Tool RAG vs always-on retrieve?
Always-on is simpler and predictable. Tool RAG lets the model skip retrieval for chitchat — with risk it skips when it should not; constrain with policies.
Interview questions
- What is RAG?
Answer Retrieval-Augmented Generation: retrieve relevant evidence from a knowledge store, insert it into context, then generate an answer grounded in that evidence.
- What is Agentic RAG?
Answer An agent-controlled retrieval loop that can plan queries, call search tools, critique evidence, and hop again under budgets before answering with citations.
- When prefer classic RAG?
Answer Single-hop questions over a well-indexed corpus where one retrieve-and-generate path already hits recall and faithfulness targets.
- Name three Agentic RAG patterns.
Answer Tool RAG (search_docs on demand), multi-hop retrieval, and critique-then-retrieve-again; routers to pick sources are also common.
- How do you keep Agentic RAG safe and cheap?
Answer ACL on every retrieve, max hops/tokens, compact cited snippets, refuse when evidence is weak, and trace cost per hop.
- How do you evaluate Agentic RAG?
Answer Measure gold-doc hit rate, answer faithfulness to citations, multi-hop task success under hop budget, plus latency and token cost versus classic RAG.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- Write one-sentence definitions of classic RAG and Agentic RAG.
- Design a max-3-hop loop with an explicit “enough evidence” grade checklist.
- List 5 multi-hop questions classic RAG would likely fail on your domain.
- Specify stop conditions and what you log on each hop.
- Answer interview questions 1, 2, and 5 in two sentences each.