Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 12.10 — Playbook: Choosing an Advanced Pattern
RAG and Vector Search · Example 1 of 2

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.

01

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.

02

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

01

How would you choose between parent-child retrieval and summaries?

02

What do you do before adding any advanced pattern?

03

Why keep a baseline after adding a pattern?

04

Which guards belong in any model-driven search loop?

Recipe: expand hits to parents within a budget
Sign in to run this example in your browser.

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