Building and Evaluating RAG Context
Measure retrieval separately from answer grounding and end-to-end usefulness.
generative ai, rag, retrieval evaluation, groundingConstruct a context
After retrieving permitted passages, choose relevant text and source identifiers within the model's token budget. Preserve enough surrounding context to avoid misleading fragments. Place task instructions separately from retrieved content; passages are untrusted data, not authority to call tools or reveal secrets.
Measure one retrieval
Suppose four passages in an evaluation collection are relevant. The retriever returns three passages, of which two are relevant.
- Precision is
2 / 3: two of the three retrieved are relevant. - Recall is
2 / 4 = 1 / 2: two of the four relevant passages were found. - Then inspect whether the generated answer uses those passages correctly and cites the right source. Retrieval success alone is not answer success.
See the reasoning
Count relevant passages
Separate precision and recall for one labelled query. This is a prepared demonstration, not live code execution.
Inspect results
- Retrieved3 passagesCurrent focus
- Relevant retrieved2 passages
- All relevant4 passages
The labelled evaluation set identifies four relevant passages.
Evaluate the pipeline
Use labelled queries and relevant passages, including no-answer cases. Report retrieval precision or recall at a specified cutoff and evaluate answer correctness, grounding, citation accuracy, latency and permissions. Relevant-set labels can be incomplete, and an automatic judge can be wrong; use human review and report uncertainty. A model may ignore or misread a correct passage, and a cited source can be stale.
Reflect on the concept
Four fixed questions to reinforce the reasoning. Answers are not saved or scored.
