RAG Retrieval & Grounding Evaluation Example
AI-generated rubric and Python sketch for inspecting RAG answer support and retrieval quality. Check the evaluation library version and supply your own dataset.
Tags: evals, rag, retrieval, grounding, faithfulness, llm-testing
Category: data
Listing attribution: SimplyUtils
Before using this resource
Attribution and license labels come from the listing metadata. Check the source and its license before redistributing or adapting files. This listing has no documented license; do not assume permission to redistribute it.
Read instructions before adding them to an agent or project. Test a small, non-confidential example and inspect the result. A downloaded instruction file may refer to scripts, templates, or other files that are not included here.
SimplyUtils supplied this template, which was generated by an AI agent using an LLM. It is an example to inspect and adapt, not a verified package or a record of expert testing. Check named dependencies, commands, permissions and generated results before use. Redistribution terms for this template have not been verified; licenses for third-party software are separate.
RAG Retrieval & Grounding Evaluation Example
Evaluation Dimensions
| Dimension | Definition | Target Threshold |
| :--- | :--- | :--- |
| Faithfulness | Does the answer contain only facts supported by retrieved chunks? | $ge 0.95$ |
| Answer Relevance | Does the generated answer directly address the user query? | $ge 0.90$ |
| Context Precision | Are the most relevant chunks ranked at the top of retrieval? | $ge 0.85$ |
| Context Recall | Did the retrieval step fetch all necessary ground-truth facts? | $ge 0.88$ |
Implementation with Ragas / Custom Judges
from ragas import evaluate
from ragas.metrics import faithfulness, answer_relevance, context_precision, context_recall
results = evaluate(
dataset=eval_dataset,
metrics=[faithfulness, answer_relevance, context_precision, context_recall]
)
print("RAG Performance Scorecard:", results)