Skip to content
RAG · Evaluation · LLMOps

How to evaluate a RAG assistant before you ship it

A lightweight evaluation for RAG systems: a golden question set, retrieval hit rate, and a grounded-answer check you can run on every change.

By · · 5 min read

TL;DR

Before launching a RAG assistant, build a golden set of real questions with the passage that should answer each, then measure two numbers on every change: retrieval hit rate (is the right passage in the top k?) and groundedness (does the answer stay inside the retrieved text?). Fix retrieval first; prompts second.

1. Build a golden set

Collect 30–100 questions real users asked — including dialect and typos — and record the document chunk that contains the answer. This file is the most valuable asset of the project.

[
  {"q": "ممكن ارجع الاوردر بعد كام يوم؟", "expected_chunk_id": "returns-policy-02"},
  {"q": "do you ship to Alexandria?",       "expected_chunk_id": "shipping-areas-01"}
]

2. Measure retrieval hit rate

def hit_rate(golden, retriever, k=5):
    hits = 0
    for row in golden:
        docs = retriever.invoke(row["q"])[:k]
        ids = {d.metadata["chunk_id"] for d in docs}
        hits += row["expected_chunk_id"] in ids
    return hits / len(golden)

print(f"hit@5 = {hit_rate(golden, retriever):.0%}")

If hit rate is low, no prompt will save the answers. Improve normalization, chunking, the embedding model or metadata filters first.

3. Check that answers stay grounded

JUDGE = """Context:\n{ctx}\n\nAnswer:\n{ans}\n
Is every claim in the answer supported by the context? Reply YES or NO."""

def grounded(ctx: str, ans: str) -> bool:
    out = llm.invoke(JUDGE.format(ctx=ctx, ans=ans)).content
    return out.strip().upper().startswith("YES")

4. Run it on every change

  • Re-run the set whenever you change chunking, the model or the prompt.
  • Track both numbers over time; a prompt that raises groundedness but drops hit rate is a regression.
  • Add every real failure from production to the golden set.

Need this built for your business?

Start a Project