Command Palette

Search for a command to run...

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

Is the extra call worth it?

The hit rates, latencies and tokens are made up to show the calculation. The price is an example: use your provider's. Measure your own numbers.

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?

Is the extra call worth it?
Sign in to run this example in your browser.

Expected output

rewrite with a model    +9 points, +450 ms, 0.024 dollars per 1000 queries -> keep
standalone question     +33 points, +450 ms, 0.040 dollars per 1000 queries -> keep
three phrasings fused   +1 points, +900 ms, 0.080 dollars per 1000 queries -> drop