Skip to content
Bots
Articles

AI engineering field guide

How to evaluate a RAG system before deploying it to production

An expense assistant cites the reimbursement policy and still gives the wrong deadline. Use this case to test retrieval, answer quality and the evidence you need for a release decision.

Bots5 min read

An employee asks how long they have to submit a receipt. The assistant replies “30 calendar days” and cites a paragraph that says exactly that. A reviewer who checks only the citation approves the answer. A reviewer who checks the expense date sees that the company had already shortened the deadline to ten days.

A retrieval-augmented generation (RAG) system retrieves passages from documents and supplies them to a model to compose an answer. In this example, retrieval and generation can fail independently. We can test each stage with a fictional policy that fits in two rows.

Set up two versions of the same rule

Source Date the expense was incurred Policy text
D-1, §2 January 1 through September 30, 2026 Submit your receipt within 30 calendar days of incurring the expense.
D-2, §2 From October 1, 2026 Submit your receipt within 10 calendar days of incurring the expense.

How long do I have to submit the receipt for an expense incurred on October 15, 2026? Before running the system, record 10 calendar days, under D-2, §2, as the reference answer. The expense date determines which rule applies. An employee asking in November about a September expense still needs the September rule.

Read one run in three stages

In this worked example, the retriever passes a single passage to the model. Record the index, prompt and model versions alongside the trace.

What to check Evidence from the illustrative run Result
Did the model receive the applicable source? The context contained D-1, §2. The reference calls for D-2, §2. Retrieval failed
Does the passage support the claim? D-1 says “30 calendar days”. The answer says “30 calendar days” and cites D-1, §2. The passage supports the claim
Did the employee get the right advice? The rule in effect for the October 15 expense allows 10 days. Incorrect answer for this case

A test that measures only faithfulness to the context may pass this run. To isolate the failure, repeat the same question and supply D-2, §2 directly to the model. If the answer changes to ten days and cites D-2, investigate document selection and effective-date filtering. If it still says thirty, inspect the context actually sent, the prompt and the generation step.

Reproduce the check in Python

Copy this snippet to a file and run it with Python 3. D-1 and D-2 identify §2 of their respective revisions. Each answer that gives a deadline contains the number of days, the unit and the cited source. The code checks values already extracted from an answer, so you can exercise the acceptance rule without making a model call.

def evaluate(expected, passages, answer):
    if expected == "abstain":
        return answer == "abstain"
    days, unit, source = expected
    return source in passages and answer == (days, unit, source)

september = (30, "calendar", "D-1")
october = (10, "calendar", "D-2")

# October 15 expense. Only the expired revision was retrieved.
assert not evaluate(october, ["D-1"], september)
# Even with the right deadline, the cited source must have been retrieved.
assert not evaluate(october, ["D-1"], october)
# The model saw the right passage but got the deadline or unit wrong.
assert not evaluate(october, ["D-2"], (30, "calendar", "D-2"))
assert not evaluate(october, ["D-2"], (10, "business", "D-2"))
# Check both sides of the effective date.
assert evaluate(october, ["D-2"], october)
assert evaluate(september, ["D-1"], september)
# The records start in 2026. Ask for the policy for a 2025 expense.
assert evaluate("abstain", [], "abstain")
assert not evaluate("abstain", [], september)

In the last case, the employee might see “The available policies start in January 2026. I need the policy covering your 2025 expense to confirm the deadline.” The value "abstain" records this explicit request for information. An empty or unparseable answer should fail the check. To use the check with your RAG system, capture the IDs of the passages sent to the model and extract the deadline, unit and citation from its output. Treat “ten business days” as a different value from “ten calendar days”.

Build an evaluation you can reuse after a change

  1. Choose cases by the consequences of an error. Include frequent questions, the day before a revision takes effect, its first day in force, questions without an expense date and dates outside the available records. A missing date calls for a clarifying question. Include a case where the document exists but the user lacks permission to read it.
  2. Measure each stage. Among questions with a known source, count how often that source appears in the first k passages passed to the model. Among questions the system answers, count how often the deadline, unit and citation are all correct. For cases without coverage, count how often it asks for information or abstains appropriately. Report the numerator and denominator for each group.
  3. Compare two versions on the same cases. Reserve a set of questions for the release decision and tune on a separate set. Record newly failing cases, 95th-percentile latency and cost per query under the same load. If a model grades answers, have someone familiar with the policy check a sample of its judgments.
  4. Define what blocks a release. For this example, one possible rule is to block a version that gives the wrong deadline at a policy boundary or exposes restricted content. Agree on quality, latency and cost limits with the people who operate the service. Record the decision, the reviewer and the version to restore if monitoring uncovers a regression.

Choose tools for the questions you need to answer

Ragas helps measure whether retrieved passages support the claims in an answer. For the expense case, pair that measurement with an effective-date check. Radar #011 on Ragas · Faithfulness metric documentation

DeepEval lets you include evaluation cases in your test workflow. Keep the question and reference answer fixed when comparing releases. Its contextual recall metric assesses how much of the expected answer is supported by the retrieved context. Radar #022 on DeepEval · Contextual recall documentation

Langfuse helps you reconstruct what happened during a request. Link retrieval, the IDs and versions of passages passed to the model, and generation in one trace. Decide what data the trace may contain and who can view it. Radar #001 on Langfuse · Observability documentation

To document a release decision, link each check to its test result and owner. Bots provides architecture decision record templates and an audit checklist in PDF and Markdown. Teams can also practice evaluation with their own documents and questions in a technical training session. Open the audit readiness checklist · Technical training at Bots

Want to discuss this in your context?

A technical discussion with your architecture team. We walk through the structure, guardrails and evaluation strategy and identify what would make a difference in your context.