Name the stage that broke
K = 3 passages may be sent and the prompt may spend 40 tokens on sources (toy numbers). The token counts per passage are example values, not measured with a real tokenizer.
A wrong answer can come from five different stages. A triage walks the stages in order and names the first one that broke, so each failure goes to the right fix instead of to guesswork.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write stage_counts(verdicts) taking a list of verdict strings and returning a dict of counts. Print it for a list of six verdicts of your choice.
Write packed(ranking, tokens, k, budget) that returns the ids that fit, taking passages in rank order from the top k and stopping at the first that does not fit. Print the result for a ranking of three passages with token counts 31, 27 and 18 and a budget of 40.
Explain it without notes
List the five stages in order and say what each means.
Why is the order of the checks important?
A question has the right passage at rank 5 with k = 3. Which stage is it, and name two fixes.
How would you decide where to spend a month of work on a failing RAG product?
Expected output
case 1: ok: D8 was sent and used
case 2: not indexed: D12 is not in the index
case 3: not retrieved: D3 is not in the 5 results
case 4: ranked too low: D1 is rank 5, only the top 3 are sent
case 5: cut by budget: sent D10 (31 of 40 tokens)
case 6: ignored by the model: D9 was sent but the answer lacks '14 days'
stages: ok 1, not indexed 1, not retrieved 1, ranked too low 1, cut by budget 1, ignored by the model 1