Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 13.5 — Trade-off Questions
RAG and Vector Search · Example 2 of 2

Choosing k: quality gain against cost

The hit rates are example numbers. Measure your own with the harness of Topic 9.9. Prices are examples: check your provider.

How to argue a choice instead of reciting a preference: chunk size, k, hybrid or not, re-rank or not, which store, RAG or long context. Each is a table of costs and a measurement.

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

Option A scores precision 5, cost 2. Option B scores precision 3, cost 5. With weights precision 2 and cost 1, print the weighted total of each and the pick.

02

A team sends 5 passages of 300 tokens per question and considers 3. For 20,000 questions a day at an input price of 0.50 dollars per million tokens, print the dollars saved per day.

Explain it without notes

01

Give the four-part structure of a trade-off answer.

02

How would you choose a chunk size and defend it?

03

How do you decide between hybrid search and vectors only?

04

When is long context a better answer than RAG?

Choosing k: quality gain against cost
Sign in to run this example in your browser.

Expected output

k=1  hit 55%  tokens  500  $0.64 per 1000  gain +55
k=2  hit 72%  tokens  800  $0.79 per 1000  gain +17
k=3  hit 81%  tokens 1100  $0.94 per 1000  gain +9
k=4  hit 85%  tokens 1400  $1.09 per 1000  gain +4
k=5  hit 86%  tokens 1700  $1.24 per 1000  gain +1
k=6  hit 86%  tokens 2000  $1.39 per 1000  gain +0
pick: k=3 (the next passage adds under 5 points)