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 2 of 2

Recipe: guard a search loop

The three guards in order: a final answer, a repeated query, the step limit.

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: guard a search loop
Sign in to run this example in your browser.

Expected output

script A: answered at step 2 after 1 search(es)
script B: stopped at step 2: repeated query
script C: stopped: step limit 3