Repository navigation
RAG 2 · Query rewriting, reranking and hybrid search — measured, not assumed #24
akash-coded
started this conversation in
Exercises
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Exercise · RAG · Interim 2
Language: Python · Topics: query rewriting, reranking, hybrid search, CRAG, Self-RAG · Level: Intermediate
Scenario
Naive RAG shipped. Two problems surfaced: vague passenger questions retrieve the wrong chunk, and questions about topics missing from the corpus (pet-in-cabin rules) get confidently wrong answers. You will add corrective loops and trace how they route.
CRAG grades retrieval, then corrects:
flowchart TB Q[Question] --> RET[Retrieve] --> GRADE{Relevant docs?} GRADE -->|yes| GEN[Generate] GRADE -->|no| COR[Rewrite + search elsewhere] COR --> GEN GEN --> A[Answer]Self-RAG decides IF to retrieve, then self-checks:
flowchart TB Q[Question] --> DEC{Retrieve needed?} DEC -->|no| DIR[Answer directly] DEC -->|yes| RET[Retrieve] --> FIL[Keep relevant] --> GEN[Generate] GEN --> REF{Answer supported?} REF -->|no| RW[Rewrite + retry] --> RET REF -->|yes| DONE[Final answer]Reference nodes:
Part A · What each lever fixes (MCQ)
Q1. Reranking fixes which failure?
Q2. Hybrid search fuses semantic and keyword search to rescue:
JX48Q2that a vector may smearQ3. Query rewriting is applied:
Part B · Trace the CRAG graph
Q4. Passenger asks "What is the refund window for a cancelled flight?" and the corpus has a refund chunk. Which branch does
crag_graderoute to, and what is inrelevant?Q5. Passenger asks "How many kilograms can a cabin pet weigh?" and the corpus has no pet rules. Which branch, and what does the correction step do here?
Part C · Read the grade node (MCQ)
Q6. In
crag_grade, what single value decidesroute?Part D · Trace Self-RAG
Q7. For "What is 2 + 2?", which path does Self-RAG take, and why?
Q8. For "How do I change my seat after booking?", list the nodes visited in order, assuming the answer is supported on the first try.
Part E · Match CRAG grades to action
Q9. Match the classic CRAG grade to its action. One is a distractor.
Part F · Spot the wrong arrow, pick the fix
Q10. This CRAG diagram has one wrong edge. Which fix is correct?
flowchart TB RET[Retrieve] --> GRADE{Relevant?} GRADE -->|yes| GRADE GRADE -->|no| COR[Correct] COR --> GEN[Generate]yesedge must go toGenerate, not loop back toGRADEPart G · Multi-select
Q11. Which are Self-RAG's self-checks? (choose all)
Part H · Debug the loop (free fix)
Q12. This reflection router can loop forever on a hard question. Identify the missing guard and write the corrected line.
Part I · Rectify the wrong suggestion
Q13. A teammate says: "Retrieval is flaky, so let us add query rewriting, reranking, hybrid search, contextual compression, and small-to-big all at once." Explain why this is the wrong move and state the correct principle in one line.
Part J · Trace the state table
Q14. A CRAG run on a gap question. Fill the
routeandattemptscolumns after each node.Part K · Pick the correct diagram
Q15. Which diagram correctly represents Self-RAG?
Diagram X:
flowchart LR Q[Question] --> RET[Always retrieve] --> GEN[Generate]Diagram Y:
flowchart LR Q[Question] --> DEC{Retrieve needed?} DEC -->|no| DIR[Answer directly] DEC -->|yes| RET[Retrieve] --> GEN[Generate]Part L · Skeptic check
Q16. Self-RAG and CRAG both add extra model or retrieval calls per question. Name one situation where that overhead is NOT justified.
All reactions