Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 7.9 — Playbook: Query Recipes
RAG and Vector Search · Example 1 of 2

Three query recipes

Recipe 1 (prompt and guard), recipe 2 (fuser), recipe 3 (router). The prompt keeps only the last four messages, each cut to 40 characters.

Recipes to copy: a standalone-question prompt with a reply guard, a multi-query fuser, a router with a safe default, and a checklist with numbers for deciding whether an extra model call earns its place.

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 6 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 decide(gain, ms, min_gain, max_ms) returning keep or drop by the rule in the example. Print the decision for (9, 450), (33, 450) and (1, 900) with min_gain = 5 and max_ms = 600.

02

Write fuse_top(rankings, n) returning the top n ids by reciprocal rank fusion, joined with commas. Print it for [["a", "b"], ["c", "a"]] with n = 2.

Explain it without notes

01

What does the guard on a rewrite do, and which checks does it make?

02

How do you decide whether a multi-query step is worth it?

03

What belongs in the log of a query layer?

04

Why should a router have a default, and what should it be?

Three query recipes
Sign in to run this example in your browser.

Expected output

Rewrite the last message as a standalone question. Reply with the question only. Conversation: User: And helmets? | Assistant: A helmet is included free with every ren | User: Can I cancel? | Assistant: Yes, up to 2 hours before the start. | Last message: and later?
Can I cancel less than 2 hours before the start?
and later?
and later?
D5 0.0328, D10 0.0164
Where is my booking receipt?  orders
thanks!                       none
Do shops open on holidays?    docs