Q&A-1How do you select, calculate, and trade off retrieval-stage metrics like Hit Rate, Recall@k, MRR, and NDCG against downstream generation quality metrics?
Answer
Retrieval metrics evaluate the candidate set fed into the context window, while generation metrics evaluate whether the reader model extracts, grounds, and states the answer without hallucination. Optimizing retrieval metrics alone does not guarantee downstream generation quality due to distractor interference, context limits, and lost-in-the-middle degradation.
Metric Formulations and Roles
-
Hit Rate@k: Binary indicator whether at least one relevant passage exists in top $k$. $$\text{Hit@}k = \mathbb{I}\left(\sum_{i=1}^k y_i > 0\right)$$ Use for single-evidence lookup tasks (e.g., entity definitions).
-
Recall@k: Fraction of all ground-truth relevant passages captured in top $k$. $$\text{Recall@}k = \frac{\sum_{i=1}^k y_i}{\sum_{j=1}^N y_j}, \quad y_i \in {0, 1}$$ Primary metric for multi-hop or synthesis queries where missing one passage causes generation failure.
-
Mean Reciprocal Rank (MRR@k): Position of the first relevant document. $$\text{MRR@}k = \frac{1}{|Q|} \sum_{q=1}^{|Q|} \frac{1}{\text{rank}_q}, \quad \text{rank}_q \le k$$ Measures initial lookup speed; penalizes relevant evidence buried down the list.
-
Normalized Discounted Cumulative Gain (NDCG@k): $$\text{DCG@}k = \sum_{i=1}^k \frac{2^{r_i} - 1}{\log_2(i + 1)}, \quad \text{NDCG@}k = \frac{\text{DCG@}k}{\text{IDCG@}k}$$ Handles graded relevance ($r_i \in {0, 1, 2, 3}$). Critical when supporting passages vary in evidentiary strength.
The Trade-Off Frontier: Retrieval vs. Generation
Increasing $k$ monotonically increases Recall@k, but downstream generation metrics (Faithfulness, Answer Relevance, Context Precision) exhibit an inverted-U curve:
Metric Value
^
| Recall@k (Monotonic increase)
1.0 -----------------------------------
| * * *
| * * Downstream Generation Quality (Faithfulness)
| * *
| * * Context Pollution & Distractor Risk
0.0 +---------------------------------> k (Context Window Depth)
k=1 k=5 k=10 k=20 k=50- Distractor Noise & Context Saturation: Expanding $k$ from 5 to 25 may raise Recall@k from 0.82 to 0.94, but context noise dilutes attention. Attention weights decay over non-relevant tokens, degrading generation faithfulness.
- Lost in the Middle: Positional bias in reader LLMs means passages located in the middle of long contexts are ignored up to 30% more often than those at the prompt boundaries (Lost in the Middle, Liu et al., 2023).
- Cost and Latency: LLM time-to-first-token scales linearly with prompt token count ($k \times \text{chunk_len}$). Reranking with cross-encoders bounds $k$ to a manageable reading unit.
Production Evaluation Strategy
Run an offline correlation matrix between retrieval cutoffs ($k \in {3, 5, 10, 20}$) and LLM-as-a-judge / human-labeled RAGAS metrics (Faithfulness and Answer Relevance):
| Stage | Metric | Target Floor | Failure Mode Detected | |---|---|---|---| | Retrieval | Recall@5 | $\ge 0.85$ | Systemic index omission or vocabulary mismatch (BEIR benchmarks). | | Reranking | NDCG@5 | $\ge 0.75$ | Critical evidence placed in middle ranks; reranker assigns low weights to dense semantic matches. | | Downstream | Faithfulness | $\ge 0.92$ | Hallucination or ungrounded synthesis caused by irrelevant chunks. | | Downstream | Answer Relevance | $\ge 0.88$ | Retrieval captured tangential context; model answered an altered prompt. |
Optimize by tuning retrieval cutoff $k$ to the knee of the generation curve: maximize NDCG@5 through cross-encoder reranking, compress or deduplicate chunks, and place top-ranked passages adjacent to the query instruction rather than deep within large context windows.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.