The easiest way to test a retrieval-augmented chatbot is to talk to it. You ask a few questions, the answers look right, and you ship. I did that for a while. Then I wrote a small evaluation set and ran it on every change, and it started catching problems that would otherwise have been reported by customers.
This post covers what goes into that set, how it runs, and the kinds of bugs it caught. None of it needs a framework, though frameworks exist if you want one.
What a RAG system can get wrong
There are three separate places to fail, and a single "is the answer good?" score hides which one broke:
- Retrieval: the right chunk never reaches the model.
- Grounding: the right chunk arrives, but the model answers from its own general knowledge or invents details.
- Refusal: the question is out of scope, and the bot answers anyway instead of saying it doesn't know.
For a multi-tenant product there is a fourth, and it is the one that matters most: isolation. One customer's question must never be answered from another customer's documents.
Building the set
I keep it small enough to read: somewhere between fifty and a hundred cases per test tenant. Each case is a question plus what a correct system should do.
{
"q": "How long is the refund window?",
"tenant": "demo-coffee",
"expect_source": "refund-policy.pdf",
"must_contain": ["30 days"],
"kind": "answer"
}The cases come from four places:
- Questions real users asked, with personal details removed.
- Paraphrases of those questions, because users rarely use the document's wording.
- Out-of-scope questions with
"kind": "refuse", such as asking a coffee shop's bot about tax law. - Cross-tenant traps: asking tenant A something only tenant B's documents can answer.
Scoring without a judge model
You can use an LLM to grade answers, and for nuanced cases it helps. But most of my checks are plain code, because plain code is cheap, fast and never has a bad day.
def score(case, result):
out = {}
srcs = [c.source for c in result.chunks]
if case["kind"] == "answer":
out["hit@k"] = case["expect_source"] in srcs
out["contains"] = all(s.lower() in result.text.lower() for s in case["must_contain"])
out["cited"] = case["expect_source"] in result.citations
elif case["kind"] == "refuse":
out["refused"] = result.refused
elif case["kind"] == "isolation":
out["no_leak"] = all(c.tenant == case["tenant"] for c in result.chunks)
return outThe run prints a table of pass rates per kind and lists every failure with the retrieved chunks next to it. Reading those failures is where the value is.
The bugs it caught
A chunker that cut tables in half
Pricing questions started failing after a change to the chunk size. The new chunker split a pricing table between two chunks, so the row with the price and the row header naming the plan were never retrieved together. The fix was to treat tables as a single unit.
Stale answers after a document update
A customer edits their FAQ and expects the bot to follow. One eval re-uploads a changed document and asks about the new value. It caught a path where old vectors were never deleted, so the bot quoted both versions.
A prompt change that made the bot helpful in the wrong way
Softening the system prompt made answers friendlier, and the refusal pass rate dropped sharply. The bot had started answering general questions from its own knowledge. Without the refusal cases, that would have looked like an improvement.
Isolation, the one that must never fail
The isolation cases are a hard gate: a single failure blocks the release. The strongest protection is architectural, with a separate vector collection per tenant so a query physically cannot reach another tenant's data. The evals exist to prove that stays true as the code changes.
If a failure would be embarrassing, make it a hard gate. If it is a quality trend, track it and look at it weekly.
Running it
| Check | When it runs | Gate |
|---|---|---|
| Isolation | Every pull request | Must be 100% |
| Refusal | Every pull request | No drop from the last release |
| Retrieval hit@k, grounding | Every pull request | Reported, reviewed by a person |
| LLM-judged answer quality | Nightly | Trend only |
Changes to the chunker, the embedding model, the prompt or the LLM provider all trigger the full set. Those are exactly the changes that feel safe and are not.
What I would tell someone starting
- Start with twenty cases you wrote by hand this afternoon. A small set you run is worth more than a large one you plan.
- Separate retrieval from generation in your scores, or you will fix the wrong half.
- Write refusal and isolation cases first. They are the failures users remember.
- Read the failures, not just the percentages.
Chatting with your bot tells you it can be right. An eval set tells you when it stopped being right.
