Evaluating the RAG answer quality
Walks through deploying an evaluation model, generating ground truth, and running bulk evaluations on RAG answer quality.
What this file does
Walks through deploying an evaluation model, generating ground truth, and running bulk evaluations on RAG answer quality.
When to use it
- You need to measure RAG answer quality with automated metrics
- You want to compare answer quality across different RAG configurations
- You need to generate ground truth data for evaluating your RAG system
- You want to run evaluations automatically on pull requests
Assumes this stack
Evaluating the RAG answer quality
📺 Watch: (RAG Deep Dive series) Evaluating RAG answer quality
Follow these steps to evaluate the quality of the answers generated by the RAG flow.
- Deploy an evaluation model
- Setup the evaluation environment
- Generate ground truth data
- Run bulk evaluation
- Review the evaluation results
- Run bulk evaluation on a PR
Deploy an evaluation model
-
Run this command to tell
azdto deploy a GPT-4 level model for evaluation:azd env set USE_EVAL true -
Set the capacity to the highest possible value to ensure that the evaluation runs relatively quickly. Even with a high capacity, it can take a long time to generate ground truth data and run bulk evaluations.
azd env set AZURE_OPENAI_EVAL_DEPLOYMENT_CAPACITY 100By default, that will provision a
gpt-4omodel, version2024-08-06. To change those settings, set the azd environment variablesAZURE_OPENAI_EVAL_MODELandAZURE_OPENAI_EVAL_MODEL_VERSIONto the desired values. -
Then, run the following command to provision the model:
azd provision
Setup the evaluation environment
Make a new Python virtual environment and activate it. This is currently required due to incompatibilities between the dependencies of the evaluation script and the main project.
python -m venv .evalenv
source .evalenv/bin/activate
Install all the dependencies for the evaluation script by running the following command:
pip install -r evals/requirements.txt
Generate ground truth data
Generate ground truth data by running the following command:
python evals/generate_ground_truth.py --numquestions=200 --numsearchdocs=1000
The options are:
numquestions: The number of questions to generate. We suggest at least 200.numsearchdocs: The number of documents (chunks) to retrieve from your search index. You can leave off the option to fetch all documents, but that will significantly increase time it takes to generate ground truth data. You may want to at least start with a subset.kgfile: An existing RAGAS knowledge base JSON file, which is usuallyground_truth_kg.json. You may want to specify this if you already created a knowledge base and just want to tweak the question generation steps.groundtruthfile: The file to write the generated ground truth answwers. By default, this isevals/ground_truth.jsonl.
🕰️ This may take a long time, possibly several hours, depending on the size of the search index.
Review the generated data in evals/ground_truth.jsonl after running that script, removing any question/answer pairs that don't seem like realistic user input.
Run bulk evaluation
Review the configuration in evals/evaluate_config.json to ensure that everything is correctly setup. You may want to adjust the metrics used. See the ai-rag-chat-evaluator README for more information on the available metrics.
By default, the evaluation script will evaluate every question in the ground truth data. Run the evaluation script by running the following command:
python evals/evaluate.py
The options are:
numquestions: The number of questions to evaluate. By default, this is all questions in the ground truth data.resultsdir: The directory to write the evaluation results. By default, this is a timestamped folder inevals/results. This option can also be specified inevaluate_config.json.targeturl: The URL of the running application to evaluate. By default, this ishttp://localhost:50505. This option can also be specified inevaluate_config.json.
🕰️ This may take a long time, possibly several hours, depending on the number of ground truth questions, the TPM capacity of the evaluation model, and the number of LLM-based metrics requested.
Review the evaluation results
The evaluation script will output a summary of the evaluation results, inside the evals/results directory.
You can see a summary of results across all evaluation runs by running the following command:
python -m evaltools summary evals/results
Compare answers to the ground truth by running the following command:
python -m evaltools diff evals/results/baseline/
Compare answers across two runs by running the following command:
python -m evaltools diff evals/results/baseline/ evals/results/SECONDRUNHERE
Run bulk evaluation on a PR
This repository includes a GitHub Action workflow evaluate.yaml that can be used to run the evaluation on the changes in a PR.
In order for the workflow to run successfully, you must first set up continuous integration for the repository.
To run the evaluation on the changes in a PR, a repository member can post a /evaluate comment to the PR. This will trigger the evaluation workflow to run the evaluation on the PR changes and will post the results to the PR.
Evaluate multimodal RAG answers
The repository also includes an evaluate_config_multimodal.json file specifically for evaluating multimodal RAG answers. This configuration uses a different ground truth file, ground_truth_multimodal.jsonl, which includes questions based off the sample data that require both text and image sources to answer.
Note that the "groundedness" evaluator is not reliable for multimodal RAG, since it does not currently incorporate the image sources. We still include it in the metrics, but the more reliable metrics are "relevance" and "citations matched".
Evaluate PBSG Golden Set triage behavior
For the Pro Bono SG workflow, use the per-id JSON files under data/pbsg_golden_set_by_id/ (default) or pass --dataset to a directory or legacy single-array JSON file. Run the endpoint-based evaluator:
python evals/pbsg_golden_set_eval.py --targeturl http://localhost:50505
This evaluator checks:
- Phase 1 entry selection: whether the answer picks the expected
Selected EntryID - Part B completeness: whether all expected triage questions for that entry are present
- Phase 2 route validity: whether returned route labels (
Route A,Route B, etc.) are valid for that entry
Useful options:
--max-entries: run only a subset of entries for quick iteration--per-entry-variations: limit number of variations per entry--output: customize where the JSON report is written (defaultevals/results/pbsg_golden_set_eval.json)
What's inside
6 sections with 6 shell commands, 3 Python scripts, 2 config files, and 1 GitHub Action workflow
Change this for your project
- Replace
evals/ground_truth.jsonlwith your own ground truth file path - Replace
evals/evaluate_config.jsonwith your own evaluation configuration - Replace
http://localhost:50505with your application's URL - Replace
bhavesh-chainani/rag-chatbot-azurewith your repository name
Where it goes
Keep alongside your test suite. Used to define and score model evaluations.
Worth borrowing
- Separating evaluation environment from main project to avoid dependency conflicts
- Using a
/evaluatecomment on PRs to trigger evaluation workflows - Providing diff commands to compare evaluation runs across baselines
Related Documents
AI Tools for Developers
Curates a personal reference of AI coding tools, models, and setup instructions for VS Code, Xcode, and Cursor.
Voice AI Leaderboards, Benchmarks, and Evaluation Gaps (Jan 2025 -- Feb 2026)
Surveys 20+ voice AI benchmarks from Jan 2025, Feb 2026, identifies evaluation gaps, and provides leaderboard data for STT, TTS, and end-to-end voice agents.
Evaluating AI Agent Systems: Metrics, Benchmarks, and Quality Assurance (2024-2026)
Surveys 2024-2026 metrics, benchmarks, and monitoring tools for evaluating AI agent systems, with recommendations for a self-improving coding agent.
IATA BCBP Standard Compliance
Documents which IATA BCBP fields and barcode formats a Swift library implements, including Version 8 gender code support.