Evaluate RAG Systems with Promptfoo
A promptfoo example scoring a corporate RAG chatbot with factuality, relevance, recall, and faithfulness metrics.
Why it matters
Automate the evaluation of Retrieval Augmented Generation (RAG) systems. This asset helps ensure your RAG pipelines are performing optimally by providing a framework for testing and analysis.
Outcomes
What it gets done
Index data for RAG systems.
Summarize evaluation results.
Query and analyze RAG performance metrics.
Integrate with promptfoo for comprehensive testing.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/pfoo-rag-eval | bash Overview
Rag Eval
This promptfoo example evaluates a corporate RAG chatbot on HR-policy questions, scoring responses with factuality, answer-relevance, context-recall, context-relevance, and context-faithfulness metrics. Use it as a template for evaluating a full RAG pipeline (retrieval plus generation) rather than just final-answer correctness.
What it does
This promptfoo example evaluates a corporate internal chatbot (openai:gpt-4.1-mini) that answers HR-policy questions using retrieved document context, scoring each response across five distinct RAG quality dimensions: factuality (does the answer match a known fact), answer-relevance (does it address the query), context-recall (did the answer use the relevant facts present in the context), context-relevance (was the retrieved context itself relevant), and context-faithfulness (does the answer stick to what the context actually says).
When to use - and when NOT to
Use this example when you need to evaluate a retrieval-augmented generation pipeline holistically - not just whether the final answer is correct, but whether the retrieved context was relevant and whether the answer stayed faithful to it. It is a strong template when you have separate context and query variables per test, as a typical RAG setup does; it is not applicable to prompts without a distinct retrieved-context input.
Inputs and outputs
The shared prompt injects both query and context (loaded from files like file://docs/reimbursement.md) into a corporate-chatbot persona. Each test combines a contains or factuality check on the answer with four threshold-based RAG metrics:
- vars:
query: What is the max purchase that doesn't require approval?
context: file://docs/reimbursement.md
assert:
- type: contains
value: '$500'
- type: factuality
value: the employee's manager is responsible for approvals
- type: answer-relevance
threshold: 0.9
- type: context-recall
threshold: 0.9
value: max purchase price without approval is $500. Talk to Fred before submitting anything.
- type: context-relevance
threshold: 0.9
- type: context-faithfulness
threshold: 0.9
A second test on maternity leave uses a deliberately absurd context-recall reference value ("4 months of maternity leave, unless you are an elephant, in which case you get 22 months") to illustrate how the recall metric compares the answer against a specific expected-facts string.
Integrations
Runs against openai:gpt-4.1-mini with file-loaded context documents, and uses promptfoo's contains, factuality, answer-relevance, context-recall, context-relevance, and context-faithfulness assertion types, several with a 0.9 pass threshold.
Who it's for
Teams building RAG-based internal tools (HR bots, support assistants, knowledge-base chatbots) who want a template covering the full set of promptfoo's RAG-specific quality metrics rather than just final-answer correctness.
Source README
yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
description: Evaluating RAG responses using multiple quality metrics
| prompts: |
|---|
You are an internal corporate chatbot.
Respond to this query: {{query}}
Here is some context that you can use to write your response: {{context}}
providers:
- openai:gpt-4.1-mini
tests: - vars:
query: What is the max purchase that doesn't require approval?
context: file://docs/reimbursement.md
assert:- type: contains
value: '$500' - type: factuality
value: the employee's manager is responsible for approvals - type: answer-relevance
threshold: 0.9 - type: context-recall
threshold: 0.9
value: max purchase price without approval is $500. Talk to Fred before submitting anything. - type: context-relevance
threshold: 0.9 - type: context-faithfulness
threshold: 0.9
- type: contains
- vars:
query: How many weeks is maternity leave?
context: file://docs/maternity.md
assert:- type: factuality
value: maternity leave is 4 months - type: answer-relevance
threshold: 0.9 - type: context-recall
threshold: 0.9
value: The company offers 4 months of maternity leave, unless you are an elephant, in which case you get 22 months of maternity leave. - type: context-relevance
threshold: 0.9 - type: context-faithfulness
threshold: 0.9
- type: factuality
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.