Evaluating RAG pipelines with promptfoo: when a regression starts in retrieval
When answers from a retrieval-augmented application get worse, the first question is where the failure started. A retrieval regression and a generation regression look the same to a user: a wrong or thin answer. But they call for different fixes. A changed chunking setting, a new embedding model or a stale index points at retrieval. A new prompt, a different model version or a context window that is now stuffed with noise points at generation. promptfoo documents RAG evaluation as two steps for this reason: it checks document retrieval accuracy and LLM output quality separately, using factuality and context adherence metrics. Teams need this split as soon as more than one component can change between releases, which is nearly every production RAG system.
The work starts by writing test cases that capture the retrieved context, not only the question and the expected answer. Each case needs the passages your retriever returned for that query, or a fixed set of known-relevant documents, so that the context-relevance, context-recall and context-faithfulness checks have something to grade. Decide which of these you need. Context relevance asks whether the retrieved material is on topic, context recall asks whether the material needed for the answer was found, and context faithfulness asks whether the answer stays within that material. End-to-end factuality compares the final answer with a reference answer. Confirm the exact assertion names and their options against the promptfoo RAG evaluation guide for the version you run, since these settings change between releases.
Wiring retrieved context into tests is the step most teams skip, and it determines whether a failing test is useful. If the retrieval step is not re-run or recorded, a faithfulness failure cannot tell you whether the model ignored good context or whether the context was never there. Plan who owns the fixture set, how often it is refreshed when documents change, and which failures block a release versus which trigger investigation. This page covers the two-step evaluation design, the metric choices, how to supply retrieved context to promptfoo tests and how to read results when retrieval and generation scores move in different directions.
Which RAG check fits which failure
This table compares the four RAG checks by what each one measures, the inputs it needs and the symptom it helps diagnose. Read it by starting from the failure you see in production, then choosing the check that isolates the stage that caused it. For exact assertion names, follow the promptfoo RAG evaluation guide.
| Check | What it measures | Inputs it needs | Symptom it helps diagnose |
|---|---|---|---|
| Context relevance | Whether the retrieved chunks relate to the user query at all | Query and retrieved chunks | Answers drift off topic or pull in unrelated documents |
| Context recall | Whether the retrieved chunks contain the information needed for the reference answer | Query, retrieved chunks and reference answer | Correct facts exist in the corpus but the retriever misses them |
| Context faithfulness | Whether the generated answer sticks to what the retrieved context says | Retrieved chunks and generated answer | The model adds details that the supplied documents do not contain |
| Factuality | Whether the generated answer agrees with a trusted reference answer end to end | Query, generated answer and reference answer | The final answer is wrong, whether or not retrieval looked healthy |
| Retrieval fine, answer wrong | Context relevance and recall pass while faithfulness or factuality fails | All four inputs for the failing case | The generator ignores or misreads good context, often a prompt or model issue |
| Answer right, context weak | Factuality passes while context recall fails | Reference answer and retrieved chunks | The answer is right by luck or from model memory, so the pipeline is fragile |
| Reference answers missing | Recall and factuality cannot run without a gold answer for each query | Curated question and answer pairs | Coverage gaps in the eval set, so regressions go unnoticed |
How retrieved context flows into a promptfoo test
The test case starts with a query and a reference answer. The retriever returns chunks, and those chunks are passed both into the prompt sent to the application's model and into the grader's context, so the grader can judge whether the answer is supported by what was retrieved. The retrieval assertions and the answer assertions then produce separate results. The promptfoo run itself executes on your machine and calls the model directly, so check that the retriever and the model endpoints it reaches are the ones you intend to test.
Retrieved chunks feed both the model prompt and the grader, producing two separate result sets.
Wiring retrieved context into promptfoo tests
This sequence turns a RAG application into repeatable promptfoo tests by capturing the context the retriever actually returns, then grading retrieval and answers against that same context. The output is a local eval suite that the team has reviewed before it becomes a CI gate.
Select a representative query set
The application owner and a domain expert choose the queries the system must answer well, drawn from real user questions, support tickets and known hard cases such as multi-document questions and queries with no answer in the corpus. Keep a mix of answerable and unanswerable questions so the suite can catch both missed retrieval and fabricated answers. The step is done when the query list is versioned in the repository and each query has a short note on why it is included. Check that the set spans the document types and topics your users actually ask about, not only the ones the team tested during development.
Capture retrieved context for each query
Run each query through the same retriever, chunking, embedding model and top-k settings that production uses, and save the returned chunks, their source identifiers and scores to a file next to the test config. Engineers who own the retrieval pipeline should perform this step, since they know which index version and filters apply. Before relying on the captured data, confirm that a sample of captured context matches what production returns for the same queries, including the index version and any access filters for the requesting user. The step is complete when the captured context reproduces production results for that sample.
Write retrieval-side checks
Write assertions that judge whether the retriever returned the right material, separate from the final answer. Promptfoo's RAG evaluation guide describes retrieval accuracy as one of two steps, and the context relevance, context recall and context faithfulness metrics in this topic map onto that split. Start with checks that compare returned source identifiers against the documents a reference answer depends on, then add model-graded checks where wording varies. The step is done when each query has at least one retrieval check and a deliberately broken retrieval run fails the suite.
Write answer-side checks against captured context
Write assertions that grade the generated answer using the captured chunks as the source of truth. Use factuality assertions against reference answers for end-to-end correctness, and context-faithfulness style checks to confirm each claim is supported by the supplied chunks. Inline the relevant context in the grader prompt so the grader does not rely on its own knowledge. The step is finished when a test with an answer that contradicts its context fails, and an answer that is correct but phrased differently passes.
Run the suite locally
The engineer running the suite executes promptfoo on a workstation, where evals run locally and call the model directly, and reviews the results view for each query. Because the context is captured in files, the run does not depend on the live index, so results should be repeatable when the model and settings are unchanged. Confirm that the same run twice gives the same retrieval results and that grader outputs are stable enough to trust. The step is done when two local runs agree on the retrieval checks and the team accepts the grader behavior on a sample.
Review failures before enforcing thresholds
The application owner and the retrieval engineer go through every failing test and label the cause: retriever miss, chunking problem, grader error, reference answer error or genuine answer defect. Fix the cause in the right place, update reference answers where they were wrong, and rerun the suite. Record which failures were grader noise so that the same noise does not block a release later. The step is complete when each failure has a recorded cause and the remaining failures reflect real problems in the application.
Add the suite as a CI gate
After the local review is stable, move the same config and captured context into the delivery pipeline and set a pass-rate threshold for the retrieval and answer checks. Confirm that the pipeline uses the same model settings and that the captured context is refreshed on a schedule the team has agreed, since stale context will hide retrieval changes. Pipeline setup, secrets for the model provider and caching choices should be checked against the CI guidance in the promptfoo integrations documentation. The step is done when a deliberate regression in the retriever fails the pipeline job and the failure report points to the affected queries.
Running the evals locally, in CI or on a shared server
The CLI on a developer machine is the fastest place to build and debug a RAG eval. promptfoo documents that it runs completely locally: evals run on your machine and talk directly with the LLM, so the retriever, the embedding service and the judge model are called from your workstation. Engineers use this loop to tune chunking, retrieval depth and prompts before anything is shared.
- Fast iteration: Edit the config, rerun the eval and inspect failing cases in the local web viewer before committing.
- Credentials stay local: Provider keys live in the developer's environment, so confirm your policy allows API keys on laptops and how they are rotated.
- Retrieved context in view: Check that the context passed to each test matches what the retriever returned for that query.
- Results are personal: Output stays on the machine unless someone exports it, so it cannot serve as a team baseline by default.
- Model cost falls on the individual: Each run calls the judge and target models, so agree on which models developers should use for routine runs.
Before relying on a local result, confirm that the same configuration, model versions and retrieval index are used in the pipeline run that gates a release.
A CI pipeline runs the same RAG suite on every change to prompts, retrievers, chunking or the model, and fails the build when quality drops. promptfoo can be used in CI/CD pipelines, and its documented integrations cover running evals inside delivery systems. The pipeline needs the retrieval index, the embedding model and the judge model to be reachable from the runner, which is often the hardest part to arrange.
- Pinned inputs: Pin the index snapshot, embedding model and judge model version so a score change can be traced to a code change.
- Gate on thresholds: Set pass-rate thresholds per assertion type, such as retrieval relevance separate from faithfulness, so a failing stage is easy to read.
- Secrets in the runner: Store provider keys in the CI secret store and limit which branches can read them.
- Cost per commit: Judge-based assertions call a model on every case, so consider caching and a smaller suite for pull requests.
- Artifacts: Save result files as build artifacts so reviewers can open failing cases without rerunning the eval.
Confirm with your CI platform team where runners can reach internal retrieval services and whether self-hosted runners are required.
The self-hosted promptfoo app is an Express server that serves the web UI and API, and it can be deployed with Docker, Docker Compose or Kubernetes with Helm. It gives a team one place to view eval results, but its data model has limits that matter for RAG evaluation. Self-hosted promptfoo stores data in a local SQLite database that cannot be shared across replicas, has no RBAC, horizontal scaling, built-in authentication or SSO, and is not recommended for production use.
- Single instance only: Run one replica with persistent storage for the SQLite file, and plan for restore if that volume fails.
- No built-in access control: Anyone who can reach the server can view results, so restrict it at the network or reverse proxy layer.
- Authentication is external: Put the server behind your identity-aware proxy or VPN, and confirm how your security team will review that setup.
- Shared results need a plan: If several teams must share results with access control, SSO and custom roles, confirm the Enterprise options and their On-Premise deployment with promptfoo.
- Evidence trail: Keep exported result files under your own retention rules, since the server does not replace them.
Ask your security team to review the access path and data location before any retrieved documents or customer text reach this server.
Security risks in RAG test data and retrieved documents
A RAG evaluation suite handles three kinds of sensitive material: the fixtures and captured chunks it stores, the documents it retrieves and feeds to the model, and the credentials that let it reach the model. Each one creates a risk that the eval itself can introduce, so the suite needs the same controls as the application it tests.
Sensitive data in fixtures and chunks
Test cases, expected answers and captured retrieval results often contain real customer records, contract text or patient details copied from production documents. Promptfoo writes results to local files and reports, so those artifacts can outlive the test run. Before you commit fixtures or share result files, remove or mask personal and regulated data and confirm where reports are stored, who can open them and how long they are kept.
RAG evaluation guideIndirect prompt injection through documents
Retrieved documents are untrusted input. A file in your knowledge base can carry instructions that try to override the system prompt or exfiltrate context, which maps to OWASP LLM01 Prompt Injection. Add test cases where a retrieved chunk contains an instruction, then check that the answer ignores it. Also check whether the model repeats hidden system or retrieval content, which falls under LLM08 Hidden Context Exposure.
OWASP LLM Top 10 2026Vector and embedding weaknesses
Embedding stores can leak content through similarity search, and poorly scoped collections let one user's documents surface for another. This is OWASP LLM09 Vector and Embedding Weaknesses. In your eval suite, include queries from one tenant or role and confirm that chunks from other access scopes are never retrieved. Ask your platform team how the retriever enforces document-level permissions before results reach the prompt.
Model API key handling
Promptfoo calls the model provider with your API keys, usually read from environment variables or config files. Keys placed in promptfooconfig.yaml or committed with test data become a credential exposure. Store keys in your secrets manager or CI secret store, scope them to the evaluation project, and rotate them when people with access change roles.
Confirm where prompts and data go
Promptfoo documentation states that evals run on your machine and talk directly with the LLM, so test prompts and retrieved chunks go to the model endpoint you configure, not to promptfoo. Confirm that the provider, gateway or region used for judge and target calls is approved for the data class in your suite. Judge models also receive outputs and context, so treat them as data processors in the same review.
Document access controls on test data
Eval data often sits outside the permission model that protects the production corpus. A test set built from an HR or finance knowledge base may be readable by anyone with repository access. Apply the same access rules to eval fixtures, limit who can run evals against production indexes, and record which dataset version produced each result so an audit can trace it.
Questions teams ask before evaluating RAG with promptfoo
What does it cost to evaluate a RAG pipeline with promptfoo?
The promptfoo software is MIT licensed, and the Community edition is free and includes all LLM evaluation features, so the main costs are the people and the model calls. Effort rises with the corpus size, the number of retrievers you compare, how many reference answers must be written and reviewed, and which grader you choose, since model-graded metrics add judge calls on every run. Ask any quote to separate one-time work (test design, reference sets, retrieval snapshots) from recurring work (re-running suites, maintaining references after document changes, and paying your model providers). Ask for the number of queries and retrievers in the written scope so the price follows from the work.
How long does a first RAG evaluation suite take to build?
Duration depends mostly on how fast your team can produce trustworthy queries and expected answers, not on the promptfoo configuration itself. Other drivers are the number of retrieval pipelines under test, whether retrieved context can be captured from your existing stack or must be rebuilt, and how many review rounds the reference answers need from domain experts. A useful first milestone is one retriever, one corpus, and a small query set that covers your main document types. Ask for the planned milestones and the dependencies on your team in the written scope before agreeing on dates.
What must our team supply before the work starts?
Plan to provide four inputs: representative user queries, expected answers written or approved by people who know the content, snapshots of the retrieved context for each query, and a model key for the grader and the application under test. Queries should reflect real usage, including awkward phrasing and questions the corpus cannot answer. Context snapshots matter because they let you separate retrieval failures from generation failures on repeatable runs. Keys should be scoped to the evaluation and stored in your secrets manager, not in the repository.
Can an in-house team evaluate RAG with promptfoo alone?
Yes, a team with engineers who know the application can build a suite using the documentation, and promptfoo can run from the CLI, as a library, or in CI/CD pipelines. The hard parts are less about tooling and more about judgment: deciding what counts as a correct answer, choosing when a model grader is trustworthy, and keeping references current as documents change. Teams usually struggle when no one owns the reference data or when the same people build the application and grade it. Confirm internally who will own the query set, the reference answers and the thresholds before you start.
When does a partner help with RAG evaluation, and what does DeployOpen cover?
A partner is most useful when the evaluation must be reviewed by people outside the build team, when several retrievers and models must be compared on a fixed schedule, or when the suite has to run inside your own infrastructure with controlled data handling. DeployOpen plans, implements and documents self-hosted platforms in your own environment and runs security testing, including AI and agent security review. Most engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts. DeployOpen does not publish a price list, so ask for a quote based on the written scope.
How do we know whether faithfulness failures come from retrieval or generation?
Measure the two stages separately. Retrieval is judged by whether the context fetched for a query contains what is needed to answer it, while answer quality is judged by whether the output is factual and stays within the supplied context. promptfoo documents RAG evaluation as these two steps, using factuality and context adherence metrics. If an answer is wrong while the retrieved context was missing the needed passage, fix retrieval first. If the context was correct and the answer still drifted, the generation prompt or model is the problem. Capturing context snapshots makes this split repeatable.
What ongoing work follows the first RAG suite?
Expect recurring work for as long as the corpus, retriever, or model changes. Each change can shift retrieval results, so reference answers and context snapshots need refreshing, and thresholds may need adjusting after a model upgrade. Grader model calls and provider usage recur on every run, and CI pipelines need maintenance when runners or keys change. Ask any quote whether ongoing support, upgrades and continuous testing are included as a retainer, and who is responsible for updating references after content changes.
How DeployOpen scopes and delivers RAG evaluation work
DeployOpen plans, builds, documents and supports promptfoo RAG evaluation inside the infrastructure you control, so retrieval and answer tests run where your documents and models already live. Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
How we scope
- Inventory the RAG application, retriever, embedding model, generator and the document sources they read from
- Agree which metrics apply: context relevance, context recall, context faithfulness and end-to-end factuality
- Write down the data handling rules for test documents, queries and judge model calls before any work starts
How we build
- Build a golden set of questions with reference answers and the source passages each should retrieve
- Wire retrieved context into promptfoo test cases so retrieval and generation are graded separately
- Configure judge models and thresholds, then run the suite against your staging endpoint to confirm results are stable
How we hand over
- Deliver the promptfoo configuration, test datasets and CI job definitions in your version control
- Document how each failing metric points to retrieval or generation, with a triage guide for your team
- Walk through the self-hosted or local run setup and confirm which results your team can review and keep
How we support
- Plan upgrades of promptfoo and its Node.js runtime, and retest the suite after each planned change
- Extend the golden set as documents change, and review metric drift after reindexing or model swaps
- Offer ongoing support and continuous testing as a retainer, sized to the written scope

