Intermediate project
RAG with an eval harness
Builds on 3 lessonsabout 1 h 30 min of reading first
In this project
What you need first
- Completed:RAG architecture and chunkingRetrieval-augmented generation
- Completed:Better retrievalRetrieval-augmented generation
- Completed:RAG evaluation in depthRetrieval-augmented generation
Skills you will practise
- Document processing
- Retrieval
- Retrieval-augmented generation
- RAG evaluation
Problem
Build a RAG system you can measure, and use the measurements to decide what to change.
Requirements
- A corpus of 50–200 documents.
- Hybrid retrieval plus a reranker.
- Citations and an abstain path.
- A golden set of at least 40 queries, including unanswerable ones.
- A report of recall@k, MRR and faithfulness.
Prerequisites
Tasks
- To do: Design first: write the one-page lane diagram (ingest and query) and name one metric for each stage before you write any code.
- To do: Assemble the corpus and ingest it.
- To do: Implement hybrid retrieval and a reranker.
- To do: Add citations and an abstain path.
- To do: Write the golden set (at least 40 queries).
- To do: Run the metrics and write the report.
- To do: Ablate chunk size and reranking, and record the effect of each.
- To do: Change one thing per run, on the same golden set, and write your keep-or-drop rule before you look at the results.
- To do: Write the diagnosis: for each query that failed, name the failing stage and the evidence (retrieved ids, scores, prompt).
- To do: Stretch: put an access filter inside retrieval, as in RAG with per-user permissions, and check that recall does not silently fall.
- To do: Stretch: calibrate your faithfulness judge against about 20 answers you label by hand, and report how often it agrees with you.
- To do: Stretch: turn the golden set into a regression gate that fails when recall@k drops on any slice.
Evaluation
Record real measurements and never invent numbers. The finished project should give you: retrieval-vs-generation diagnosis, a trade-off table and a regression gate.
| Criterion | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| Retrieval metrics correct | Not measured | Hit rate only | recall@k and MRR computed per query and checked by hand on three queries, on a 50 to 200 document corpus, with hybrid retrieval plus a reranker in the measured system | As level 2, sliced by query type, with the sample size stated |
| Generation measured separately | One “answer quality” score | Faithfulness judged by eye | Faithfulness scored on the answered queries, apart from retrieval, and every answer cites chunk ids | As level 2, with the judge’s agreement with your own labels reported |
| Abstain tested on unanswerable queries | No unanswerable queries | A few, not scored | Correct refusals and wrong refusals both counted | As level 2, with the abstain threshold set on the golden set and the trade-off shown |
| One-change-at-a-time ablation | Several changes at once | One change, no comparison | Each change run alone on the same set, with quality, latency and cost, and a keep-or-drop rule written before the runs and applied | As level 2, plus a dense-only against hybrid ablation |
| Written diagnosis names the failing stage | No diagnosis | “The model got it wrong” | Each failure assigned to a stage with logged evidence (retrieved ids, scores, prompt), and the lane diagram and a metric per stage written before coding | As level 2, plus one fix tried and re-measured |
Pass mark: at least 2 on every criterion (so the lowest passing total is 10 of 15).
Architecture
Why these choices, and what each one costs:
| Decision | Alternative rejected | Why |
|---|---|---|
| Hybrid retrieval (dense plus BM25, fused with RRF) | Dense search alone | Dense search can miss exact tokens such as IDs and error codes, and BM25 can miss paraphrases. Choose your 50 to 200 documents so both kinds of query exist. On a corpus this small dense alone may already do well; the ablation tells you, and “no gain here” is a valid result. |
| A reranker on a wide shortlist | Pass the fused top-k straight to the prompt | A cross-encoder reads query and chunk together, so it is more precise, but it adds latency and cost. Keep it only if the ablation shows a gain worth that price. |
| Abstain gate after the rerank, before generation | Rely on the prompt’s “say I don’t know” alone | A gate on the best score stops a guess before it is written. It sits after the rerank because cross-encoder scores separate relevant from irrelevant chunks more sharply than first-stage scores (the lesson shows an earlier gate before reranking; test both if you like). Similarity scores do not transfer between models, so set the threshold on your own golden set and count wrong refusals as well as wrong answers. |
| Separate retrieval and generation metrics | One end-to-end answer score | One score cannot tell a wrong page from a misread page, so it cannot say which stage to fix. |
| Log per stage on every request | Log only the final answer | Without retrieved chunk ids and scores you can only guess which stage failed. |
What to log at each stage:
| Stage | Log |
|---|---|
| Ingest | Document id, chunk ids, chunk size and overlap, embedding model and version, index version |
| Retrieve | Query, dense and BM25 candidate ids with scores, fused ranks |
| Rerank | Reranked ids with scores, the chunks cut |
| Abstain | Top score, threshold, decision |
| Generate | Final prompt, answer, cited chunk ids, tokens, latency per stage |
Interview questions
Provenance: Generated practice. Not reported from any company.
- Design an evaluation that tells a retrieval regression from a generation regression. Practise with A7 in the Advanced bank.
- Why add hybrid search, and what does a reranker cost you? Practise with I11 and I12 in the Intermediate bank.
- How do you test that the system refuses when the corpus cannot answer? Practise with question 55 in the Top 100 priority questions.
- A user gets a wrong answer although the right document is in the corpus. What do you check, in order? Practise with question 35 in the Top 100 priority questions.
Portfolio checklist
- To do: The repository has a README with the lane diagram and the metric for each stage.
- To do: The golden set is committed, with unanswerable queries marked, and was written before the ablations.
- To do: The report has the metric table and plots, the sample size, and the keep-or-drop rule.
- To do: If you did the stretch: one run of the regression gate is shown, passing or failing, with what it checked.