Notes
Two halves
Retrieval can miss the right section, rank it low, or crowd it with irrelevant ones. Generation can ignore the text, misread it, add facts that are not in it, or cite the wrong source. If you only score final answers, you cannot tell which half to fix. So measure retrieval on its own, then generation given the retrieved text.
- retrieval: the right section is missing noise sections crowd it out wrong ranking
- generation: ignores or misreads the text adds facts not in the text cites the wrong source
- measure each half on its own
Retrieval metrics
Three retrieval metrics. Recall at k: how often the right section is somewhere in the top k results. Mean reciprocal rank: one divided by the rank of the right section, averaged, so rank one scores one and rank two scores a half. Precision at k: the share of returned sections that are relevant. All three need the expected section for each golden question, which you added in the last episode.
- recall@k: how often the right section is in the top k
- MRR: 1 / rank of the right section, averaged (rank 1 = 1, rank 2 = 0.5, missing = 0)
- precision@k: share of returned sections that are relevant
- needs: the expected section for each golden question
Measured
We measured ShopRung's retriever on eleven golden questions. Recall at three: ten of eleven. Mean reciprocal rank: zero point nine one. But precision was only zero point three eight: most returned sections were not needed, often the shoppers' saving money tips. The one miss was twelve mugs: the question never says quantity, so the keyword retriever matched mugs in gift ideas instead of the rule. Retrieval is deterministic, so these numbers are the same every run.
recall@3 10/11 MRR 0.91 precision@k 0.38 miss: "Can I buy 12 mugs?" got: Gift ideas, Searching needed: Quantities and stock noise: "Saving money" often retrieved, rarely needed
A measured fix
Customers and documents use different words. Customers say discount; the help pages say coupon. Without a small synonym map, the discount question ranked shipping first and coupons second. With discount mapped to coupon, coupons rank first: mean reciprocal rank rose from zero point eight six to zero point nine one, while recall stayed the same. Real systems use embeddings or hybrid search for this; either way, measure before and after.
help pages say "coupon" without synonyms: "Do you have a discount code?" 1. Shipping costs 2. Coupon codes with discount → coupon: 1. Coupon codes MRR 0.86 → 0.91, recall same
Faithfulness
For generation, the key check is faithfulness, also called groundedness: is every claim in the answer supported by the retrieved text? The correct cancel answer quotes the cancel section almost word for word. The bad one invented a customer service team, and an answer under the prompt regression bug invented a review and approval step. Neither appears anywhere in the help pages. A judge with the retrieved text, or a human, checks this claim by claim.
faithful: "a SHIPPED or DELIVERED order can no longer be cancelled" (in Cancel an order) not faithful: "...or call our customer service team" (no such text) "We'll review your request ... if approved" (no such step)
Faithful but wrong
A trap: an answer can be faithful and still wrong. With ShopRung's injection bug on, a shopper written tips page claims a code called free one hundred gives one hundred percent off. The model repeated it faithfully. Faithfulness only says the answer matches its context; when the context is poisoned, you also need correctness checks against trusted facts, and control over which sources are retrieved. The injection episode goes deeper.
retrieved: a shopper tips page "...the code FREE100 now gives 100% off every order" answer: "Yes, the code FREE100 now gives 100% off every order." faithful to its context: yes correct: no. FREE100 is fake
More checks
A few more checks. Citations: the sources listed should be the ones the answer used. No answer: when retrieval finds nothing useful, saying I don't know beats guessing. And context size: with ShopRung's long context bug, every help section goes into the prompt, eight hundred and eighteen tokens instead of two hundred and seventy seven. The answers stayed right in three runs, so the extra context bought nothing but triple the cost.
- citations: listed sources are the ones actually used
- no answer: "I don't know" when retrieval finds nothing useful
- context size: all 12 sections (bug chat-long-context): 818 prompt tokens vs 277, answers still right 3/3 → 3x cost for nothing
Common mistakes
RAG mistakes. Scoring only final answers, so you cannot tell retrieval from generation problems. Measuring recall per page, which hid ShopRung's twelve mugs miss, because the right page appeared with the wrong section. No expected source per golden question. Trusting faithfulness alone. Stuffing more context in to be safe, which costs money and can bury the right text. And indexing untrusted pages without care.
- scoring only final answers
- page-level recall (hides the wrong section)
- no expected source per question
- trusting faithfulness alone
- stuffing more context "to be safe"
- untrusted pages in the index
Say it like this
In the interview: I test RAG in two halves. Retrieval gets an expected section for every golden question and is measured with recall at k, mean reciprocal rank and precision, before and after each change. Generation is checked for faithfulness claim by claim, for correctness against trusted facts, for citations, and for saying I don't know when nothing relevant was found. I also watch context size, because it drives cost.
- "Two halves. Retrieval: an expected section per golden
- question, recall@k, MRR, precision, measured before and after changes. Generation: faithfulness claim by claim, correctness against trusted
- facts, citations, and "I don't
- know" when nothing is found.
- Plus context size and cost."