Advanced RAG Patterns
- Decompose multi-hop questions into dependent sub-queries and execute them sequentially
- Sketch when graph-RAG, RAPTOR-style summary trees, and agentic retrieval each earn their complexity
- Route between structured (SQL) and unstructured (vector) sources for a mixed question
- Assemble the week into a failure-mode taxonomy and a debugging flowchart you will use on the capstone
| Spaced-rep: due cards + bi- vs cross-encoder from memory (D117) | 10 min |
| ELI5 + tech read | 25 min |
| Guided: multi-hop + routing labs | 40 min |
| Practice: prescription drill | 18 min |
| Project: debugging flowchart | 22 min |
| Quiz + flashcards | 5 min |
Builds on: Day 117 β Reranking & query transforms Β· Day 113 β RAG architecture Β· Day 111 β Tool use & function calling
Some questions can't be answered from one shelf. "Did the author of our expense policy also write the security policy?" needs three trips: find who wrote the expense policy, find who wrote the security policy, compare. A single search for the whole question retrieves a muddle β no one page contains the answer, because the answer doesn't LIVE anywhere; it has to be assembled.
The advanced patterns are all ways of making multiple, smarter trips. Multi-hop decomposition breaks the question into steps where each search uses the previous answer. A summary tree (RAPTOR) adds "shelf summaries" and "floor summaries" to the library so zoomed-out questions ("what are the big themes?") have something zoomed-out to retrieve. Graph-RAG draws a map of which people, teams, and documents connect to each other, so "everything related to X" follows edges instead of similarity. And agentic retrieval hires the intern from next week early: let the model itself decide what to search next, look at what came back, and search again β an open-book exam where the student may return to the shelves as often as needed.
One-shot retrieval tops out fast on real corpora: enterprise users ask comparison questions, aggregate questions ("how many customers mentioned pricing?"), and questions whose answers span three systems β the exact queries that make naive RAG look broken in a pilot. Knowing which pattern fixes which failure β and that each adds latency, cost, and failure surface β is the difference between an engineer and a framework-user. The debugging flowchart you build today is a genuine FDE artifact: when a customer says "it answered wrong," you'll walk the flowchart live instead of shrugging. It also completes the mental model your capstone and Day 136's evals depend on.
Guided practice
Multi-hop over a corpus where one-shot fails
25 min- Create
multihop_lab.pywith the starter code: a corpus with document authorship facts and a hand-written two-hop plan for the question "Did the author of the expense policy also write the security policy?" - Run the one-shot baseline: the full question retrieves a muddle (verify: no single chunk contains the answer).
- Run the multi-hop version: hop 1 retrieves the expense policy's author chunk; a tiny extractor pulls the name; hop 2's query is BUILT from that name; the synthesizer compares. Note the dependency β hop 2 could not have been written in advance.
- Poison hop 1: change the extractor to return the wrong name and watch hop 2 confidently retrieve irrelevant evidence. Write one sentence on why intermediate verification matters.
- In production the plan comes from an LLM ("split this question into sequential sub-queries; later queries may reference earlier answers as β¨answer1β©") β the printed PLAN_PROMPT shows exactly that prompt.
Route the question: SQL, vectors, or both
15 min- Append the starter code: a mini "warehouse" (a list of ticket dicts), the vector corpus from exercise 1, and a keyword-based router standing in for an LLM classification call (the real router prompt is printed).
- Run the three test questions: an aggregate ("how many tickets mention refunds"), a policy lookup ("what needs pre-approval"), and a mixed one ("are refund complaints against our stated policy?").
- Verify the aggregate goes to the SQL-ish path and returns an exact count β then force it through vector retrieval instead and see why that's malpractice (it returns 2 example tickets, not a count).
- For the mixed question, confirm both paths run and note what the synthesis step would need to cite: a number from one source, a quote from the other.
On your own
Pattern-matching drill: prescribe, don't implement
18 minFor each symptom below, prescribe the cheapest adequate fix from this week's toolbox (chunking / hybrid / rerank / rewrite / HyDE / decomposition / RAPTOR / graph-RAG / routing / freshness), plus one sentence of reasoning. Then rank your prescriptions by implementation cost.
- "Summarize our Q2 customer themes" retrieves five random specific tickets.
- "Compare the old and new expense policies" answers from only one of them.
- Follow-up questions in chat retrieve nonsense.
- "Who has worked with vendor Acme across any team?" misses connections spread over many docs.
- Answers cite a policy retired two months ago.
- "SKU-9981 warranty length" returns unrelated warranty prose.
No peeking until done. Reasonable answers: 1 RAPTOR-style summaries (no zoomed-out chunks exist); 2 decomposition (two targeted retrievals + compare); 3 query rewriting; 4 graph-RAG (relationship question); 5 freshness/incremental indexing + tombstones; 6 hybrid (exact identifier).
The RAG debugging flowchart
Create rag_debugging.md β the artifact you will physically use during the capstone and can show in interviews. Part 1: the failure taxonomy as a table (symptom β stage β root cause β fix β which day taught it) covering at least 9 failures from this week. Part 2: a flowchart (Mermaid or ASCII) starting from "answer is wrong" that branches on OBSERVABLE checks in debugging order: was the doc ingested? β is the fact intact in one chunk? β is that chunk in stage-one top-20? β in reranked top-3? β did the prompt contain it? β did the model use it faithfully? Each leaf names the fix. Part 3: three symptoms where the fix is an ADVANCED pattern (decomposition, routing, summaries), so you don't over-prescribe them for stage-level bugs. Commit it.
Common mistakes & misconceptions
- Prescribing agentic/multi-hop retrieval for stage-level bugs. If the chunk was torn or the identifier unsmellable, fix chunking or add BM25 β advanced patterns multiply cost and failure surface.
- Letting hop-2 run on an unverified hop-1 answer. Dependent hops compound errors; verify intermediate extractions (or at least carry confidence forward) when hops chain.
- Answering aggregate questions from a vector index. "How manyβ¦" needs SQL over records; similarity search returns examples, not counts β route, don't retrieve.
- Building RAPTOR trees or knowledge graphs before query logs demand them. Both are heavy at ingest and painful on updates; earn them with observed thematic/relationship queries.
- Forgetting deletions. Removing a doc from the source without tombstoning its chunks means the retired policy keeps answering β freshness includes forgetting.
- Treating the debugging flowchart as documentation. It is a runbook: walk it top-down on every capstone failure, and update it when a new failure class appears.
Q1. "Which of our policies were written by the same person?" fails with one-shot retrieval becauseβ¦
Q2. A user asks "how many tickets mentioned refunds last quarter?" The correct architecture move isβ¦
Q3. What problem do RAPTOR-style summary trees solve?
Go deeper β curated resources
- GraphRAG (Microsoft) β community summaries β Combines both structure patterns: build an entity graph, detect communities, summarize each community β graph structure plus RAPTOR-style altitude in one system.
- Multi-hop lab run, including the poisoned-hop experiment
- Router demonstrated on all three question types, with the malpractice case shown
- All six prescriptions reasoned and cost-ranked
- rag_debugging.md committed with taxonomy + flowchart
- Quiz β₯ 2/3
β Back: This day is Week 17's synthesis: Day 113's stages became Day 114β117's fixes, and today's taxonomy files every one of them. The router is Day 111's tool-choice pattern pointed at data sources.
Forward β: Tomorrow (Day 119) the capstone kicks off and your flowchart becomes a living runbook. Agentic retrieval gets its full treatment as the agent loop on Days 120β122, and Day 136 turns each taxonomy row into a metric.