Unit 10 of 11 · about 5 hours · derive, measure
Retrieval, citation and groundedness metrics
A ranking metric, a citation metric and answer correctness test different contracts. Explicit units and denominators prevent an attractive aggregate from concealing unsupported or unanswered questions.
You'll be able to
- Derive precision, recall, reciprocal rank and linear-gain nDCG on a graded ranking and check them against a pinned implementation.
- Compute citation recall and precision from hand-labeled joint, individual and leave-one-out support decisions.
- Report paired retrieval and answer results with explicit denominators, query coverage and evaluator limitations.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Ranking metric definitions and oracleir-measures: Measure Definitions
Measures entries P, R, RR, nDCG and Success; nDCG parameters dcg and gains (page read 2026-10-18)
Use ir-measures 0.4.3 with the
pytrec_evalprovider and linear log2-discount nDCG. The live reference documents multiple provider conventions; record the actual one used. - Citation quality arithmetic and limitsEnabling Large Language Models to Generate Text with Citations (ALCE)
Section 3.3 and Figure 3; Section 2, footnote 4, citation cap; Appendix C, NLI model; Appendix E, partial-support limitation
Reproduce support logic with hand labels, not the 11B model. Section 2 allows at most three citations per statement; declare any different cap and do not claim exact benchmark replication.
- Separate ranking, evidence and answer evaluationAI Engineering Handbook - Retrieval
Chapter 6.7: Recall@k tells you if the answer is in the room; MRR tells you how high it landed; Faithfulness checks the answer against the context, not the world (page read 2026-10-18)
Correct the prose: binary nDCG is not redundant with recall and MRR, and mean recall is not the fraction of fully supported questions. Deduplicate IDs before scoring; the example recall code can double-count duplicate hits. Skip synthetic labels without review and benchmark performance claims.
Focus on
- For unique document IDs, precision divides relevant top-cutoff hits by the cutoff, recall divides them by all judged relevant documents, and reciprocal rank uses only the first relevant rank. Use a positive-grade relevance threshold of 1. Success measures any hit, not fractional recall.
- For the selected convention, derive and divide by the DCG of the ideal graded order. Here is the nonnegative relevance grade. Exponential gain is another convention, not this default; explicitly handle zero ideal gain.
- ALCE recall averages fully supported cited sentences. Citation precision averages reference-level decisions: joint support is required, and a reference passes if it supports alone or removing it destroys joint support. Redundant individually sufficient references can pass. Atomic-claim coverage is useful too, but is a separately named metric.
- Use the fixed 300 SciFact test queries, original document IDs, deterministic ties and unjudged documents treated as nonrelevant for scoring. Include empty runs, macro-average over the declared query set and retain per-query values. On the separate two-tenant corpus, report pointer validity, support, correctness, abstention, freshness and permissions independently. Audit any optional local judge against hand labels and reuse paired uncertainty from the existing harness.
Common mistakes · 3
- Using exponential-gain nDCG in hand calculations but linear gain in the oracle. Both are meaningful, but their graded results differ.
- Counting a short list's precision denominator as its returned length. Precision at a fixed cutoff still divides by that cutoff.
- Dropping failed or abstained queries and reporting only successful responses. Report all-item correctness and response coverage alongside conditional support scores.
Try it yourself
Closed-book, before checking anything
a, b, c, d grades 3, 2, 1, 0 and rank ['d', 'b', 'a']. At cutoff 3, precision and recall are both , reciprocal rank is , and linear-gain nDCG is . Check your code against ir-measures 0.4.3. Then reconstruct ALCE Figure 3 from a hand-labeled support table: two of three sentences pass joint support and four of six references pass precision, giving recall and precision .Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Can binary rankings share recall and reciprocal rank but differ in nDCG?Answer
Yes. Move a later relevant hit while preserving the first hit and total hits. Its discounted contribution changes, while recall and reciprocal rank do not.
2.Does citation precision require a minimal evidence set?Answer
No. ALCE allows redundant individually sufficient citations. Its rule rejects a citation that is insufficient alone and unnecessary to the supporting set.
3.Why can perfect citation recall accompany an incomplete answer?Answer
It measures support for produced sentences, not coverage of every requested fact. A short supported answer can omit required information.
4.How should zero-support and zero-denominator cases be reported?Answer
Use the pinned ranking provider's declared behavior. For claim-free or citation-free answer metrics, state undefined or an explicit convention and report counts; do not quietly award a perfect score.
You're done when
The ranking and citation fixtures match their independent oracles, empty and short runs have explicit policies, and every aggregate can be regenerated from retained per-query judgments and stage records.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 17 more in the section
- AI Engineering Handbook - RetrievalHandbook Academy · primary
Complete Part 6 Retrieval: parsing and chunking, embeddings and vector search, hybrid search and reranking, query understanding, citations, advanced retrieval, retrieval evaluation and production RAG. Implement each stage on one controlled corpus before adding abstractions.
- ir-measures: Measure Definitionsir-measures · required
Read the R, P, RR and nDCG entries and use the library as an oracle for your own metric code. Default nDCG uses linear gain with a
log2(rank + 1)discount, not2**rel - 1; precision@k divides by k. State the query set, unjudged-document handling and averaging. - Enabling Large Language Models to Generate Text with Citations (ALCE)Gao et al. · required
Read Section 3.3 Citation Quality with the Figure 3 examples and the Appendix E limitation. Citation recall is statement-support coverage and citation precision uses a leave-one-out rule; implement both with stable claim and chunk IDs and a hand-labeled entailment check instead of the 11B scorer.
Also in this section
- AI Agents in Depth - Knowledge BaseBojie Li · required
Read Chapter 3 sections 3.2.1 to 3.2.4 (chunking, dense, sparse and hybrid retrieval), 3.3.1, 3.3.3 (incremental updates, retiring obsolete content, multi-user permissions and tenant isolation), 3.3.4 (agentic retrieval and the security boundaries of RAG) and 3.3.5 contextual retrieval. Keep 3.1 memory for AI-5. The companion
chapter3/retrieval-pipeline/evaluate.py --no-dense --no-rerankruns offline. - Evidence-Grounded Retrieval SystemRoadmap-Final · required
Build the bounded slice first: Milestone A (no-retrieval and oracle-evidence baselines), the architecture constraint that authorization filters apply before exposure and are rechecked before context, citation and cache reuse, and Milestones D and E. Use a small hand-written two-tenant corpus with stable source, version and chunk IDs, deleted and conflicting facts, near-miss unanswerables and poisoned documents. The full project (80 to 130 hours) continues in AI-8.
- AlgoMaster - Evaluating RAG SystemsAlgoMaster · support
The owned premium lesson is a short pass on retrieval and generation metrics, fixed evaluation sets, automated judges and regression workflows. Recompute every metric it uses in your own harness and keep item-level evidence.
- The Hitchhiker's Guide to Agentic AI - Chapter 16Haggai Roitman · support
Use v3 Chapter 16 selectively: 16.3 (BM25, DPR, RRF), 16.4 chunking, 16.7 agentic RAG, 16.8 metrics and failure modes, 16.9.4 incremental indexing. Its Equation 16.28 divides context precision by K where the Ragas docs divide by the relevant items, and its
upsert_documentlisting deletes before adding with no transaction, so a query in between sees neither version: test that gap. - Sentence Transformers Retrieve and Re-RankSentence Transformers · required
Implement the documented bi-encoder retrieval plus cross-encoder reranking pattern on SciFact or your own corpus. Reranking only reorders the candidates, so measure recall before it and ranking quality, latency and cost after it. The MiniLM cross-encoder outputs raw logits, not 0 to 1 probabilities. Pin model revisions.
- The Probabilistic Relevance Framework: BM25 and BeyondStephen Robertson and Hugo Zaragoza · required
Read Sections 3.4.4 to 3.5 (term-frequency saturation, length normalization
(1 - b) + b * dl / avdl, variants). Library BM25 implementations differ in IDF handling, so record k1, b, tokenization and the implementation with every result. - Reciprocal Rank Fusion Outperforms Condorcet and Individual Rank Learning MethodsCormack, Clarke and Buettcher · required
Read the Section 1 equation: score each document by the sum of
1 / (k + rank)over the rankings, with ranks from 1 and k = 60 fixed in a pilot. Fusion cannot recover a document missing from every candidate list; record candidate depths and tie handling. - Know What You Don't Know: Unanswerable Questions for SQuADRajpurkar, Jia and Liang · required
Read Section 2 (plausible, relevant negatives) and the threshold paragraph in Section 5.1 (tuned on development data). Build answerable and unanswerable pairs from your corpus and report coverage, risk on answered items and errors on unanswerable items separately.
- Lost in the Middle: How Language Models Use Long ContextsLiu et al. · required
Read Section 2.1, Table 1 (closed-book and oracle controls) and Figure 11 (retriever recall versus answer accuracy). Run an evidence-position sweep with the query, distractors, model and token budget fixed.
- Not What You've Signed Up For: Compromising Real-World LLM-Integrated Applications with Indirect Prompt InjectionGreshake et al. · required
Read Sections 3.1 (injection delivery), 4.1.1 (the synthetic setup) and 5.2 (limits). Add a local document that carries an instruction beside benign facts, mock every tool, and test instruction-following separately from retrieval. Permission filters do not stop an authorized document from injecting.
- Ragas Metrics: Faithfulness, Context Precision and Context RecallRagas · support
Read the faithfulness, context precision (an AP-like quantity, not precision@K) and context recall pages and the local-model adapter guide. The legacy API was removed in 1.0, so pin a version. Calibrate any LLM-based metric against your hand labels before trusting it.
- FActScore: Fine-grained Atomic Evaluation of Factual Precision in Long Form Text GenerationMin et al. · support
Read the Section 3.1 definition and Figure 1. FActScore is precision conditional on responding, so report it with the response rate; a system can raise it by saying less.
- Poisoning Retrieval Corpora by Injecting Adversarial PassagesZhong et al. · support
Read Section 3 (threat model) and Section 4.1 with Figure 2: success means one adversarial passage reaches the top k, and attacks transfer poorly across retrievers. Measure poison exposure at k separately from answer corruption.
- PoisonedRAG: Knowledge Corruption Attacks to Retrieval-Augmented Generation of Large Language ModelsZou et al. · support
Read Section 3.1 (attacker capabilities) and the retrieval and effectiveness conditions in Section 4.1, then Tables 2 and 4 (v1 numbering). Its attack success rate is target-substring matching, so check matches by hand.
- Contextual RetrievalAnthropic · support
Read "Introducing Contextual Retrieval", "Methodology" and the reranking section. The reported 5.7% to 2.9% retrieval failure is a 49% relative reduction in 1 - recall@20, not 49 points. Test one context-prefix ablation only after plain BM25, dense and hybrid retrieval pass, and keep the source text apart from generated context.
- Enterprise RAG and Perplexity AI Search Case StudiesEngineering Handbook · support
Read the Enterprise RAG case study as the main architecture review and compare it with the Perplexity AI Search case. Identify where tenant policy, freshness, citation, latency and evaluation belong, then defend what your bounded project deliberately omits.
- BEIR: A Heterogeneous Benchmark for Zero-shot Evaluation of Information Retrieval ModelsBEIR Team · support
Read Section 3 and Table 1 (SciFact: 5,183 documents, 300 test queries) and the qrels workflow in the repository README, then run one small dataset as a relevance oracle. Dataset terms differ from the code license (SciFact annotations are CC BY 4.0, abstracts ODC-By). Full benchmark reproduction stays depth.