Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

These exercises practice retrieving what the Module 10 reading explained. They aren’t graded. Work each one on paper first, then check your answer, and only then confirm it with code from Lab 10 if you like. The section IDs are the handbook’s, H01–H10, and prices are in US dollars per million tokens, from the reading. The answers are in the collapsed blocks; open one only after you have an answer of your own.

Worked example: laying out a grounded prompt

A staff member asks, “When does the stock count run?” Retrieval returned H08 (stock requests) and H10 (closing). Lay out the prompt:

  1. Documents first: a <documents> block with <doc id="H08"> and <doc id="H10">, each holding the section’s exact text, escaped.

  2. Instructions next: answer from the documents only, quote the exact sentence that supports the answer with its section ID, and reply “I don’t know” if no section answers.

  3. The question last: <question>When does the stock count run?</question>.

The IDs let the answer name its source, and the fixed order keeps the documents at the start, where they can be cached.

Exercise P10.1 (LO-10.1, ★, about 10 minutes)

Draft the shape of a prompt from H03 and H09 about returns.

Hint 1

Follow the worked example’s three steps, in order.

Hint 2

Give each section its own tag with its ID, so a quote can name the section it came from.

Answer
  1. A <documents> block with <doc id="H03"> and <doc id="H09">, each holding its section’s exact text.

  2. <instructions> that ask for an exact quote and its section ID, or “I don’t know” if neither section answers.

  3. <question> with the return-window question, last.

H09 holds the answer (“within 14 days with a receipt”), and H03 is there because returns need a receipt. A common mistake is to put the question first, or to merge both sections into one block with no IDs, which leaves the answer no way to say which section it quotes.

Worked example: recall for one and two sections

A question needs one section, H05, and retrieval ranks H07, H05, H02. Recall at 1 is 0/1 = 0, because H05 isn’t first. Recall at 2 and at 3 are 1/1 = 1.

Another question needs H01 and H10, and retrieval ranks H01, H04, H10. Recall at 1 is 1/2 = 0.5, at 2 still 0.5, and at 3 it is 2/2 = 1. Full coverage fails at k=1k = 1 and k=2k = 2, and passes at k=3k = 3.

Exercise P10.2 (LO-10.2, ★★, about 15 minutes)

The relevant IDs are A and C. The ranked IDs are D, C, A. Find recall at 1, 2, and 3.

Hint 1

The denominator is the number of relevant sections, two, at every depth.

Hint 2

At each depth, count how many of A and C appear among the first k results.

Answer
  • k = 1: the first result is D, which isn’t relevant, so recall is 0/2 = 0.

  • k = 2: D and C hold one relevant section, so recall is 1/2 = 0.5.

  • k = 3: D, C, and A hold both, so recall is 2/2 = 1.

Full coverage passes only at k = 3. A common mistake is to divide by k instead of by the number of relevant sections, which gives 1/2 at k = 2 by luck, but 2/3 at k = 3. That measures precision, the share of results that are relevant, not recall.

Worked example: a real quote that doesn’t support

The question is “What must I wear when cutting a cable?” An answer says “Nothing special” and quotes H06: “Keep the workbench clear of bags.”

  1. Provenance: the quote occurs exactly in H06, so the exact-match check passes.

  2. Support: the sentence is about bags, not clothing, so it doesn’t support the answer. Worse, H06 also says “Wear safety glasses when cutting a cable.”, so the answer is wrong.

Score the two checks separately: provenance passes, and support fails.

Exercise P10.3 (LO-10.3, ★★, about 15 minutes)

A response cites a real H04 sentence about when a loan bicycle is due back, for a question about how many loan bicycles are available. How do you score it?

Hint 1

Check exact match and support separately, as in the worked example.

Hint 2

Find the H04 sentence that would support an answer about the number.

Answer

The quote, “A loan bicycle is due back by 17:00 the same day.”, occurs in H04, so it passes the exact-match check. It says nothing about how many bicycles there are, so it neither states nor supports a number, and the answer fails the support criterion. The supporting sentence is “The shop has two loan bicycles.” A common mistake is to pass the response because its quote is real and from the right section: exact match proves only where the text came from.

Worked example: when a 1-hour cache pays

A 10,000-token prefix on Opus 5.5 costs $4 per million as ordinary input, $8 per million for a 1-hour cache write, and $0.20 per million to read. Ignoring the suffix, assume one write and a hit on every later request:

RequestsUncachedCached
1$0.04$0.08 (the write)
2$0.08$0.08 + $0.002 = $0.082
3$0.12$0.08 + 2 × $0.002 = $0.084

With a 1-hour cache, caching is cheaper from the third request on. Each read saves $0.038 against ordinary input, and the write’s extra $0.04 takes two reads to recover.

Exercise P10.4 (LO-10.4, ★★★, about 25 minutes)

A 10,000-token prefix costs $4 per million tokens as ordinary input, $5 per million to write to the cache, and $0.20 per million to read. Assume one write and a hit on every later request. Ignoring the suffix, how many requests make caching cheaper?

Hint 1

Compare one request, and then two.

Hint 2

Work out how much the write costs beyond ordinary input, and how much each read saves.

Answer

One request costs $0.04 uncached, or $0.05 for the cache write. Two cost $0.08 uncached, or $0.052 for a write and a hit. Caching is cheaper starting with the second request. The write costs $0.01 more than ordinary input, and the first read saves $0.038, so one hit is enough.

Two mistakes are common. One is to charge the write on every request, which makes caching look more expensive than it is. The other is to forget that the first request costs more cached than uncached, which matters for a prefix used only once.