Skip to content
AgenticAIWiki
  1. Learn
  2. Part 4
  3. 26. Evaluating RAG
  4. 26.6

Lesson 26.6 · 6 of 7 · 6 min read · Reviewed 24 Nov 2026

Synthetic test sets

By the end, you can

  • Generate a synthetic RAG test set from your own documents.
  • Filter and review synthetic questions so they don't flatter the system.

Why generate test cases

A good RAGRetrieval-augmented generation (RAG): Retrieving relevant documents at request time and adding them to the prompt so the answer is grounded in them. test set (26.3) takes time to write by hand. Real user questions may be scarce before launch, and people who know the documents are busy. A model can read each chunkChunking: Splitting documents into smaller passages before embedding and indexing them. and write a question it answers, a reference answer and the source id. In an afternoon you have hundreds of cases tied to exact chunks.

The basic loop

for each sampled chunk:
    ask a model: write one question this chunk answers,
                 the answer, and the chunk id
    keep: {question, reference, relevant_chunks: [id], tags}

That works, but the raw output has three known problems.

Problem Why it hurts Fix
Wording copied from the chunk Keyword and vector search find it too easily, so recall looks high Ask for the question a customer would type; paraphrase; reject high word overlap
All single-fact questions Multi-hop, comparison and refusal cases go untested Ask for specific types, and build multi-hop cases from pairs of related chunks
Wrong or vague cases The generator misreads the chunk or writes an unanswerable question by accident Filter with a second model check and have people review a sample

A worked example

Chunk pol-4.3: “Sale items are final sale unless faulty.”

  • Raw question: “Are sale items final sale unless faulty?” It repeats the chunk word for word.
  • Better: “I bought a jacket in the sale and changed my mind. Can I send it back?” Same answer, the phrasing a customer would use.
  • Multi-hop, from pol-4.3 and pol-4.4: “Can I return sale trainers I’ve worn once?” It needs both chunks.
  • Unanswerable, written on purpose: “Do you price-match other shops?” No chunk covers it, so the right answer is a refusal.

A simple overlap filter catches the first kind: count the share of question words that also appear in the chunk, and reject or rewrite anything above a threshold such as 0.6.

Mix synthetic with real

  • Anchor on real questions. Keep a slice from logs (redactedRedaction: Removing or masking sensitive data, such as PII or secrets, before it is stored, logged or sent.) and report it separately. If synthetic and real scores disagree, trust the real slice.
  • Tag the origin. Mark every case synthetic or real so you can split results.
  • Review a sample. People check 10 to 20% of synthetic cases for correctness before the set is used as a gate.
  • Use a different model to generate than to answer, where you can, so the test isn’t written in the system’s own style.

Common mistakes

  • Treating a high synthetic score as proof the system is ready.
  • Generating from every chunk equally, when real questions cluster on a few topics. Weight samplingSampling: Choosing the next token from the model’s probability distribution, rather than always taking the most likely one. by what users ask.
  • Never regenerating. When documents change, regenerate cases for the changed chunks and retire the old ones (26.3).

Key points

  • A model can write questions, reference answers and source ids from your chunks, giving a large test set quickly.
  • Synthetic questions tend to copy the chunk's wording, which makes retrieval look easier than real traffic.
  • Ask for varied types (multi-hop, comparison, unanswerable), paraphrase, then filter and have people review a sample.
  • Use synthetic cases to widen coverage, and keep real user questions as the anchor.
Hands-on labRuns in the Playground

Filter synthetic questions by word overlap

Catch synthetic test questions that copy their source chunk's wording, which make retrieval look easier than real traffic.

You will have: A filter that scores each generated question's overlap with its chunk and prints which cases are kept or rejected.

Steps

  1. Read the generated cases: each has a question and its source chunk.
  2. Compute overlap: the share of the question's content words that also appear in the chunk.
  3. Reject cases above a threshold of 0.6 and keep the rest.
  4. Print kept and rejected cases with their overlap.
  5. Rewrite one rejected question in a customer's words and check that it now passes.

Done when

  • Two of the five generated questions are rejected for copying the chunk.
  • Each printed line shows an overlap between 0 and 1.
  • Your rewritten question scores below 0.6 (the sample rewrite scores 0.17).

Open in the Playground No API key needed.

Starter code (Python)
CASES = [
    ("pol-4.3", "Sale items are final sale unless faulty.", "Are sale items final sale unless faulty?"),
    ("pol-4.3", "Sale items are final sale unless faulty.", "I bought a jacket in the sale and changed my mind. Can I send it back?"),
    ("pol-4.2", "Footwear may be returned within 30 days if unworn.", "May footwear be returned within 30 days if unworn?"),
    ("pol-4.2", "Footwear may be returned within 30 days if unworn.", "How long do I have to send back trainers I haven't worn?"),
    ("pol-2.5", "Gift cards expire 24 months after purchase.", "My aunt gave me a voucher two years ago. Is it still good?"),
]
STOP = {"a", "an", "the", "is", "are", "i", "it", "to", "in", "and", "my", "can", "do", "me", "if"}

def content_words(text):
    return {w.strip(".,?!").lower() for w in text.split()} - STOP

def overlap(question, chunk):
    # TODO: share of the question's content words that also appear in the chunk
    return 0.0

for cid, chunk, q in CASES:
    print(f"{overlap(q, chunk):.2f}  {cid}  {q}")
# TODO: reject cases with overlap above 0.6 and print the counts
Show a solution
CASES = [
    ("pol-4.3", "Sale items are final sale unless faulty.", "Are sale items final sale unless faulty?"),
    ("pol-4.3", "Sale items are final sale unless faulty.", "I bought a jacket in the sale and changed my mind. Can I send it back?"),
    ("pol-4.2", "Footwear may be returned within 30 days if unworn.", "May footwear be returned within 30 days if unworn?"),
    ("pol-4.2", "Footwear may be returned within 30 days if unworn.", "How long do I have to send back trainers I haven't worn?"),
    ("pol-2.5", "Gift cards expire 24 months after purchase.", "My aunt gave me a voucher two years ago. Is it still good?"),
]
STOP = {"a", "an", "the", "is", "are", "i", "it", "to", "in", "and", "my", "can", "do", "me", "if"}

def content_words(text):
    return {w.strip(".,?!").lower() for w in text.split()} - STOP

def overlap(question, chunk):
    q = content_words(question)
    return len(q & content_words(chunk)) / len(q) if q else 0.0

kept, rejected = [], []
for cid, chunk, q in CASES:
    o = overlap(q, chunk)
    (rejected if o > 0.6 else kept).append((o, cid, q))
for o, cid, q in kept:
    print(f"kept      {o:.2f}  {cid}  {q}")
for o, cid, q in rejected:
    print(f"rejected  {o:.2f}  {cid}  {q}")
print(f"{len(kept)} kept, {len(rejected)} rejected")
rewrite = "Can I return a sale top I no longer want?"
print(f"rewrite overlap {overlap(rewrite, CASES[0][1]):.2f}: {rewrite}")
Quick checkRecall@5 is 0.95 on your synthetic test set but 0.70 on real questions from logs. What is the most likely cause?
How sure are you?
Pick an answer and how sure you are