Advanced RAG: HyDE, GraphRAG & Agentic Retrieval
Your bar: transform the query before you retrieve, match the retrieval structure to the question shape, and know when to graduate from a static pipeline to a self-correcting agentic loop.
Your bar: transform the raw query before you retrieve, match the retrieval structure to the shape of the question, and know exactly when to graduate from a static pipeline to a self-correcting agentic loop. By the end you can answer:
given a RAG system that retrieves the wrong thing, which lever — pre-retrieval, retrieval structure, or an agentic loop — do you pull, and what does each cost?1Lesson 3 shipped the baseline RAG pipeline. This lesson covers the three changes that turn that baseline into a system. Each chip is one lever:
Query Transformation
The raw user query is often a bad search query: short, vague, full of pronouns, worded nothing like the documents that answer it. Fix it in a pre-retrieval stage, before it touches the index.
A stage that didn’t exist in the baseline
The pre-retrieval techniques, pinned down
| Technique | What problem it solves | Cost |
|---|---|---|
| Query rewriting | Vague / pronoun-laden / misspelled input — clean, expand, disambiguate it. | 1 extra LLM call |
| Multi-query | One phrasing misses; generate N paraphrases, retrieve each, union & dedupe → higher recall. | N retrievals + dedupe |
| HyDE | Questions look nothing like answers; embed a drafted hypothetical answer to bridge the gap. | 1 LLM draft + embed |
| Decomposition | A multi-part question no single chunk answers; split into sub-queries, retrieve each, combine. | 1 split + k retrievals |
| Step-back | Too specific to find grounding; ask a broader question first, then the specific one. | 1 extra retrieval |
| Routing | Wrong datasource entirely; classify the query and send it to docs vs code vs SQL. | 1 classify call |
HyDE — the query/document vocabulary gap
Is Pre-retrieval is any transform applied to the query before it hits the retriever: rewrite, multi-query, HyDE, decomposition, step-back, or routing. The index and model are untouched.
Why it exists Recall lost at retrieval cannot be recovered downstream — no reranker, no bigger model can return a document that was never retrieved. The cheapest place to fix recall is the query.
Like (world) A good librarian doesn’t search your exact words. They restate “why is it slow?” as “checkout latency, connection pool” — the terms the shelves are actually organized by.
Like (code) Query normalization / canonicalization before a DB lookup: lowercasing, expanding synonyms, splitting a compound filter into sub-queries. Same input cleanup, applied to retrieval.
📥 Memory rule: Fix the query before you fix the index. HyDE and multi-query buy recall that no reranker can recover.
Memory check
- Why can't a reranker recover lost recall? → it only reorders the candidates already retrieved; a document never in the set can't be ranked up
- What gap does HyDE bridge? → the query↔document vocabulary gap — questions look unlike answers, so it embeds a drafted hypothetical answer instead
- Multi-query vs decomposition? → multi-query = N paraphrases of the SAME question (recall); decomposition = split a multi-part question into sub-questions (coverage)
M1 — Your RAG recall is poor on multi-part questions like “compare our refund policy in the EU vs the US.” Which pre-retrieval technique, and why?
Hit these points: this is two facts in one query, so a single embedding averages them and matches neither cleanly → decomposition: split into “EU refund policy” and “US refund policy”, retrieve each, then combine the chunks for the answer → optionally add multi-query per sub-question for recall → contrast: HyDE helps the vocabulary gap, not the multi-fact problem; a bigger window doesn’t help if neither fact was retrieved → verify by checking that chunks for both regions appear in the assembled context, not just the answer.
Advanced Retrieval Structures
Lesson 3’s baseline was flat chunk + top-k: one embedding per chunk, return the nearest k. That’s a floor. The shape of the question should pick the structure of the retriever.
Flat vs structured retrieval
Which structure for which question
| Structure | What it’s good at | Cost / complexity | Reach for it when… |
|---|---|---|---|
| Parent-doc / small-to-big | Precision of small chunks + context of the parent. | Low — extra parent lookup | Local facts that need surrounding context. |
| Hierarchical / summary | Retrieve over summaries, then drill into details. | Medium — summary index | Large docs; “which section, then what.” |
| Contextual retrieval | Prepend chunk-situating context + add BM25 → fewer retrieval failures. | Medium — re-embed + dual index | Chunks ambiguous on their own (Lesson 3). |
| Multi-vector / ColBERT | Token-level late interaction → higher precision. | High — many vectors/chunk | Precision-critical, latency-tolerant search. |
| Metadata filtering | Pre-filter by date / type / tenant before vector search. | Low — needs clean metadata | Recency, access control, multi-tenant. |
| GraphRAG | Subgraphs + community summaries for global themes. | High — build & maintain graph | ”Connect-the-dots across the whole corpus.” |
Local fact vs global theme — the GraphRAG line
| Question shape | Flat chunk + top-k | GraphRAG |
|---|---|---|
| ”What is the retry limit?” | ✓ one chunk answers it | ✗ overkill, slower |
| ”What themes recur across all incidents?” | ✗ no single chunk holds it | ✓ community summaries answer it |
Read the diagonal. A local fact lives in one chunk, so flat retrieval finds it and GraphRAG is wasted complexity. A global theme is spread across the whole corpus — no chunk contains it, so only a graph that pre-aggregates relationships can answer.
Is Advanced retrieval structures change what you index and return — parents, summaries, situated chunks, token vectors, filtered candidates, or graph subgraphs — instead of one flat vector per chunk.
Why it exists Different questions have different shapes. Flat top-k optimizes one trade-off (chunk-level similarity); it can’t serve precision-with-context, recency, or corpus-wide synthesis at the same time.
Like (world) A library uses a card catalog (summaries) to find the shelf, the full book (parent) to read context, and a citation graph to answer “what influenced what.” Different tools, different questions.
Like (code) Choosing an index for a query pattern: a B-tree for point lookups, a covering index for range scans, a graph DB for traversals. You match the data structure to the access pattern.
📥 Memory rule: Match the retrieval structure to the question shape — local fact → small-to-big; global theme → GraphRAG.
Memory check
- What does small-to-big decouple? → what you MATCH on (small precise chunk) from what you RETURN (the larger parent for context)
- When does GraphRAG beat flat top-k? → global "connect-the-dots / themes across the whole corpus" questions no single chunk can answer; not for local facts
- What two things does contextual retrieval add? → a short chunk-situating context prepended before embedding, plus a BM25 lexical index alongside the vectors (Anthropic)
M2 — A teammate proposes rebuilding the whole RAG stack on GraphRAG because “it’s the state of the art.” How do you respond as the senior in the room?
Hit these points: first ask what questions users actually ask — pull the distribution → if most are local lookups (“what is the limit for X?”), flat top-k or small-to-big already answers them at a fraction of the cost → GraphRAG earns its keep only on global, theme-spanning questions, and it carries real cost: building the entity graph, generating community summaries, keeping it fresh on every reindex → propose it as an added retriever routed to for global queries, not a rip-and-replace → name the trade-off: complexity and maintenance vs a capability you only need for a slice of traffic.
Agentic & Self-Correcting RAG
Modules 1–2 still ran retrieval once, as a fixed step. The last shift makes retrieval an action inside a loop: the model decides whether to retrieve, grades what it got, and critiques its own draft. This is the read-on-demand pattern from Lesson 3 and the ai-agents track.
The self-correcting loop
Three named patterns
| Pattern | The control loop | What it buys |
|---|---|---|
| Agentic RAG | LLM decides whether / what / when to retrieve; can issue many searches, use tools, iterate. (This is what Claude Code does.) | Handles open-ended, multi-step questions. |
| Self-RAG | Model retrieves on demand, then reflects: critiques its own draft and revises before answering. | Catches ungrounded / unsupported claims. |
| Corrective RAG (CRAG) | Grade retrieved docs; if quality is low, fall back (e.g. web search) or re-retrieve before answering. | Robustness when the index comes up short. |
The trade-off you must name
| Static pipeline | Agentic loop | |
|---|---|---|
| Quality / robustness | Fixed — one shot, no recovery | ✓ checks & corrects itself |
| Latency | ✓ one pass, predictable | ✗ multiple round-trips |
| Cost | ✓ few LLM calls | ✗ grading + re-tries cost more |
| Complexity | ✓ simple to reason about | ✗ loops, budgets, stop conditions |
Read the columns. The agentic loop wins exactly one row — quality — and pays in latency, cost, and complexity for it. Adopt it only where correctness justifies the bill; a static pipeline is the right default for simple, well-covered questions.
Is Agentic / self-correcting RAG turns retrieval from a fixed pipeline step into an action the model invokes in a loop — deciding when to search, grading results, and critiquing its own draft before finalizing.
Why it exists A static pipeline answers once from whatever it retrieved, right or wrong. A loop lets the system detect a bad retrieval and recover — re-search, fall back, or revise — instead of confidently answering from junk.
Like (world) A researcher who checks whether their sources actually support the claim, goes back to the library when they don’t, and proofreads the draft before submitting — rather than writing from the first book they grabbed.
Like (code) A retry-with-validation loop versus a single fire-and-forget call: validate the response, on failure refine the request and retry, with a max-attempts budget so it terminates.
📥 Memory rule: Static RAG answers once; agentic RAG checks its own work — pay the extra calls only when correctness justifies them.
Memory check
- What does CRAG do when retrieved docs grade poorly? → falls back (e.g. web search) or re-retrieves before answering, instead of answering from low-quality docs
- What is the core trade-off of agentic loops? → higher quality / robustness vs more latency, cost, and complexity — only worth it when correctness justifies it
- What does Self-RAG add over plain retrieval? → reflection — the model critiques its own draft for grounding and revises before finalizing
M3 — When would you NOT add an agentic loop to a RAG system, and how do you decide?
Hit these points: when the question distribution is simple and well-covered by the index — a static pipeline already answers correctly, so a loop only adds latency and cost → when latency budget is tight (interactive UX) and the extra round-trips break the SLA → when there’s no reliable grading signal, the loop can’t tell good from bad and just burns calls → decide from eval data: measure static-pipeline accuracy first; add the loop only on the slice where correctness is high-stakes and static accuracy is provably insufficient → always cap attempts and define a stop condition so it terminates.
Retrieval practice — test the three modules
Q1. The core argument for pre-retrieval query transformation is that…
- A larger context window removes the need to ever transform the user's raw query at all
- The reranker can always recover any relevant document the retriever happened to miss
- Recall lost at retrieval is unrecoverable downstream, so fix the query before the index
- The model answers better when it is shown the user's exact wording with no changes
Q2. HyDE (Hypothetical Document Embeddings) works by…
- Drafting a hypothetical answer and embedding that to bridge the query/document gap
- Caching every prior answer and replaying it when a similar question is seen again
- Splitting one compound question into several smaller sub-questions before retrieval
- Ranking candidates with a cross-encoder after the first vector search has finished
Q3. The "small-to-big" (parent-document) retriever gives you…
- A way to store one document across many shards so each query hits every shard
- A graph of entities whose community summaries answer corpus-wide theme questions
- A lexical BM25 index bolted onto the vectors to catch exact keyword and ID matches
- Precision of a small matched chunk plus the surrounding context of its larger parent
Q4. GraphRAG most clearly beats flat chunk + top-k when the question is…
- A single local lookup such as "what is the configured retry limit for the job?"
- A global "connect-the-dots" theme that no single chunk in the corpus contains
- A latency-critical request that must return its answer in well under one second
- A request that must be filtered by tenant and date before any vector search runs
Q5. Corrective RAG (CRAG) differs from a static pipeline because it…
- Embeds the question and returns the nearest k chunks exactly once with no checks
- Fine-tunes the base model on retrieved documents so it memorizes them for later
- Grades the retrieved docs and falls back or re-retrieves when their quality is low
- Prepends a short situating summary to each chunk before it is embedded and indexed
Interview — pick your bar
Answer out loud in ~60s, then reveal. Core = recall · Senior = trade-offs & failure modes · Staff = synthesis under ambiguity · System Design = open design round (a different axis, not a harder level).
What is pre-retrieval query transformation, and name the main techniques.
Explain how HyDE works and what gap it bridges.
What does the small-to-big (parent-document) retriever do?
Define agentic RAG, Self-RAG, and Corrective RAG (CRAG) — what's the control loop in each?
Your RAG recall is poor on multi-part questions like "compare our refund policy in the EU vs the US." Which pre-retrieval technique, and why?
Routing and step-back are both pre-retrieval. Contrast what they do and when each is the right call.
A teammate proposes rebuilding the whole RAG stack on GraphRAG because "it's the state of the art." How do you respond as the senior in the room?
Explain contextual retrieval and when its added cost is worth paying.
Walk through how you match retrieval structure to the shape of the question across a mixed query workload.
When is an agentic / corrective loop worth its latency and cost, and when is a static pipeline the right default?
Make the case that pre-retrieval is the highest-leverage place to spend — then steelman the opposite.
- Characterize the question distribution — local facts vs global themes, single- vs multi-part, recency-sensitive.
- Pre-retrieval — rewrite / multi-query / HyDE / decompose / step-back, and route to the right source.
- Retrieval structure — match it to question shape: small-to-big, hierarchical, contextual, multi-vector, GraphRAG.
- Rerank & assemble within budget — precision first, parents for context, order for primacy/recency.
- Decide static vs loop — add CRAG grade-and-fallback / Self-RAG critique only where correctness justifies the cost.
- Bound the loop — cap attempts, define stop conditions, set a latency/cost budget.
- Observability & failure modes — log assembled context, measure retrieval hit-rate; handle missing / low-quality / stale / conflicting docs.