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

Skills you will practise

  • Document processing
  • Retrieval
  • Retrieval-augmented generation
  • RAG evaluation
Skip to the tasks

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.

Criterion0123
Retrieval metrics correctNot measuredHit rate onlyrecall@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 systemAs level 2, sliced by query type, with the sample size stated
Generation measured separatelyOne “answer quality” scoreFaithfulness judged by eyeFaithfulness scored on the answered queries, apart from retrieval, and every answer cites chunk idsAs level 2, with the judge’s agreement with your own labels reported
Abstain tested on unanswerable queriesNo unanswerable queriesA few, not scoredCorrect refusals and wrong refusals both countedAs level 2, with the abstain threshold set on the golden set and the trade-off shown
One-change-at-a-time ablationSeveral changes at onceOne change, no comparisonEach change run alone on the same set, with quality, latency and cost, and a keep-or-drop rule written before the runs and appliedAs level 2, plus a dense-only against hybrid ablation
Written diagnosis names the failing stageNo 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 codingAs 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

Diagram: The ingest lane turns documents into chunks and fills two indexes.

Query lane (every question)

Ingest lane (runs ahead of time)

no

yes

Documents and metadata

Chunk

Embed

Dense index and BM25 index

Query

Hybrid retrieve and RRF

Rerank to top few

Top score above threshold?

Abstain: say the corpus does not answer

Generate with citations

Per-request log

Diagram summary: The ingest lane turns documents into chunks and fills two indexes. The query lane retrieves from both, fuses and reranks, then abstains when the best score is too low or generates a cited answer, and every query stage writes to a per-request log so a bad answer can be traced to a stage.

Why these choices, and what each one costs:

DecisionAlternative rejectedWhy
Hybrid retrieval (dense plus BM25, fused with RRF)Dense search aloneDense 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 shortlistPass the fused top-k straight to the promptA 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 generationRely on the prompt’s “say I don’t know” aloneA 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 metricsOne end-to-end answer scoreOne score cannot tell a wrong page from a misread page, so it cannot say which stage to fix.
Log per stage on every requestLog only the final answerWithout retrieved chunk ids and scores you can only guess which stage failed.

What to log at each stage:

StageLog
IngestDocument id, chunk ids, chunk size and overlap, embedding model and version, index version
RetrieveQuery, dense and BM25 candidate ids with scores, fused ranks
RerankReranked ids with scores, the chunks cut
AbstainTop score, threshold, decision
GenerateFinal 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.