Recipe: expand hits to parents within a budget
Sizes are in words to keep the example simple. In production count tokens (Topic 8.2).
A table that maps a measured symptom to a pattern, with recipes to copy for parent expansion within a budget, a stuck-loop guard, and where a real tool-calling search loop plugs in.
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 pick_pattern(symptom) that looks the symptom up in a dictionary and returns the pattern, or "measure first" for an unknown symptom. Include three symptoms of your own. Print the result for one known and one unknown symptom.
Write unique_in_order(items) that removes repeats and keeps the first occurrence of each item. Print it for ["D52", "D50", "D52", "D51", "D50"].
Explain it without notes
How would you choose between parent-child retrieval and summaries?
What do you do before adding any advanced pattern?
Why keep a baseline after adding a pattern?
Which guards belong in any model-driven search loop?
Expected output
budget 500: D52, D50, D51 | 400 words
budget 350: D52, D50, D51.2 (chunk only) | 329 words
budget 150: D52.4 (chunk only), D50, D51.2 (chunk only) | 140 words