Building a RAG evaluation set from your own documents means converting a folder of files into a set of question–answer pairs, each anchored to the passage that supports the answer, and then using that set to measure your retrieval and generation pipeline. You do not need a hand-labelled dataset to begin: the Ragas test set generation guide and Hugging Face’s RAG evaluation cookbook both describe generating candidate questions with one LLM and filtering or judging them with another.
This guide is for practitioners who already have a document collection and a working retrieval-augmented generation pipeline, and who now want a repeatable way to tell whether changes to chunking, embeddings, or prompts actually help. It covers the structure of an evaluation set, the two documented generation workflows, the filtering step that keeps low-quality questions out, and the limitations you should accept before trusting the scores.
What an evaluation set actually contains
An evaluation set for RAG is not just a list of questions. Hugging Face’s cookbook describes the core unit as a question–answer couple — a question, its expected answer, and the context that should support it. In practice, a useful record has four parts:
- Question — phrased the way a user would ask it.
- Reference answer — the answer a correct system should produce.
- Ground-truth context — the chunk or passage from your documents that contains the evidence.
- Metadata — source file, section, or document ID, so you can trace failures back to a specific part of the corpus.
The ground-truth context is what separates a RAG evaluation set from a general QA benchmark. It lets you score retrieval separately from generation: did the retriever surface the right passage, and did the generator use it faithfully?
Prerequisites
Before generating anything, confirm you have:
- A document collection in a loadable format. The Ragas quickstart uses Markdown files in a directory; the Hugging Face cookbook loads a documentation dataset. Any format your loader supports will work.
- A Python environment with the loader and generation libraries installed. The Ragas example installs
langchain-communityandlangchain-openai; the Hugging Face cookbook installstorch,transformers,langchain,sentence-transformers,datasets, andragatouille, among others. - Access to at least one LLM for generation and one embedding model. Ragas documents OpenAI, AWS, Google Cloud, and Azure paths, so a hosted OpenAI key is convenient but not the only option.
- A decision about where your documents may be sent. Generating questions means an LLM reads your corpus. If the corpus is private, that is a data-handling decision to make before you start, not after.
Step 1 — Load your own documents
Replace the sample corpus with your own files. The Ragas quickstart uses LangChain’s DirectoryLoader with a glob pattern:
from langchain_community.document_loaders import DirectoryLoader
path = "Sample_Docs_Markdown/"
loader = DirectoryLoader(path, glob="**/*.md")
docs = loader.load()
Swap path for your own directory and adjust the glob for your file types — for example **/*.txt or **/*.html. The loader returns a list of document objects, and that list is the input to the generation step.
Check: print the number of loaded documents and the first few hundred characters of one of them. If the count is zero, the glob or the path is wrong; if the text is empty, the loader is not parsing that format.
Step 2 — Choose the generator LLM and embeddings
Ragas wraps LangChain components so they can be used inside its pipeline. The quickstart sets an API key, then wraps a chat model and an embedding model:
import os
os.environ["OPENAI_API_KEY"] = "your-openai-key"
from ragas.llms import LangchainLLMWrapper
from langchain_openai import ChatOpenAI
from ragas.embeddings import OpenAIEmbeddings
import openai
generator_llm = LangchainLLMWrapper(ChatOpenAI(model="gpt-4o"))
openai_client = openai.OpenAI()
generator_embeddings = OpenAIEmbeddings(client=openai_client)
The wrapper is the important idea: generation and embedding are pluggable, and the Ragas documentation lists OpenAI, AWS, Google Cloud, Azure, and other provider setups. Because the wrapper takes a LangChain LLM, a locally served model that exposes a LangChain-compatible interface is a plausible substitute — but question quality depends heavily on the generator, so a small local model may produce shallow or repetitive questions. Treat local generation as something to measure, not something to assume.
Step 3 — Generate the test set
With documents loaded and a generator configured, the Ragas pipeline builds a test set from your documents. The quickstart continues from the snippets above into a test set generator that consumes docs and produces question–context–answer records. The exact class and method names have changed across Ragas releases, so follow the current quickstart rather than copying an older signature from a blog post.
The Hugging Face cookbook takes a different but compatible route: it loads a knowledge base with datasets.load_dataset("m-ric/huggingface_doc", split="train") and then builds a synthetic dataset for evaluation. The two approaches share the same assumption — the LLM can read your documents and invent plausible questions grounded in them.
Two knobs matter at this stage. First, how many questions you generate: more questions give a more stable estimate, but each one costs tokens and review time. Second, how the corpus is chunked before generation: if the generator only sees fragments, the questions will be fragment-level, and your evaluation will not test multi-passage reasoning.
Step 4 — Filter and validate the generated questions
Raw generated questions are not automatically good. The Hugging Face cookbook is explicit that questions are filtered out by other LLMs before the dataset is used. Filtering catches several recurring failure modes:
- Ungrounded questions — the answer is not actually in the cited passage.
- Trivial or ambiguous questions — answerable from the question alone, or with several equally valid answers.
- Duplicates — the same fact asked five different ways, which inflates the apparent score.
- Unanswerable questions — useful as a separate negative set, but misleading if mixed into the positive set.
A practical filter is a second LLM pass that scores each question for groundedness and clarity against its source chunk, plus a cheap string or embedding similarity check for near-duplicates. Keep the rejected items — they are useful evidence that your filter is doing something rather than just shrinking the file.
Step 5 — Score your pipeline
The cookbook’s second component is an evaluator that computes accuracy on the generated dataset using an LLM-as-a-judge agent. In a RAG setting, that means running each question through your actual pipeline, then judging the result against the reference answer and ground-truth context.
Split the measurement in two:
- Retrieval quality — did the retriever return the chunk that contains the answer? This is a ranking question and can be scored without an LLM.
- Generation quality — given the retrieved context, is the answer correct and faithful, or does it add claims the context does not support?
Separating these two is the main practical payoff of building your own set. A pipeline that fails retrieval and a pipeline that hallucinates on good context need different fixes, and a single accuracy number hides the difference.
An illustrative walkthrough
Suppose you maintain a plugin handbook as a folder of Markdown files. You point DirectoryLoader at that folder, generate roughly a hundred questions, and filter them down to the ones a support reader would plausibly ask. You then run each surviving question through your RAG pipeline twice: once with the current chunk size and once with a smaller one. Because every question is tied to a specific source file, you can see whether the smaller chunks helped on the sections that were previously split mid-procedure. This scenario is illustrative — the outcome depends entirely on your corpus and configuration, and no measured results are claimed here.
Limitations and tradeoffs
- Synthetic questions are not real questions. A generator tends to ask about the text that is easiest to ask about. Your users may ask about things your documents cover badly, and the synthetic set will not reveal that.
- LLM judges have biases. Using a model to grade a model introduces systematic preferences — for length, for confident phrasing, or for its own style. Spot-check a sample by hand.
- Cost and privacy. Every generation and judging pass sends document text to a model. For private corpora, that is a real constraint rather than a footnote.
- Drift. An evaluation set built from last quarter’s documents silently becomes wrong when the documents change. Regenerate or audit after major edits.
Common failure modes
- Everything scores well. Usually means the questions are too easy or too similar. Check the duplicate rate and the distribution of question lengths.
- Nothing scores well. Usually a retrieval problem, not a generation problem. Inspect whether the ground-truth chunk is even in the index.
- Answers look right but are judged wrong. The reference answer and the judge disagree on formatting or scope. Tighten the reference answers before blaming the judge.
- Generation is slow or expensive. Reduce the number of questions first; a smaller, well-filtered set is more useful than a large noisy one.
Next action
Start with one folder, one generator, and twenty questions. Run them through your pipeline, split the results into retrieval and generation failures, and only then scale up. If you hit a specific error while wiring the generator or the judge, share your environment, the library versions, and the exact message in the community — that detail is what makes a failure reproducible for everyone else.
FAQ
Do I need an OpenAI key to generate a test set?
Not necessarily. The Ragas quickstart uses OpenAI as its example, but the documentation lists AWS, Google Cloud, Azure, and other provider setups, and the LangchainLLMWrapper is designed to accept LangChain-compatible models.
How many questions should the evaluation set contain?
The cited sources do not prescribe a fixed number. The practical constraint is token cost and human review time; a smaller, carefully filtered set is more informative than a large set full of duplicates and ambiguous items.
Can I generate the test set with a local model?
The Ragas wrapper takes a LangChain LLM, so a LangChain-compatible local model is a plausible substitute. Question quality depends heavily on the generator, so measure the output rather than assuming a small local model will match a larger hosted one.
Why filter the generated questions at all?
The Hugging Face cookbook filters questions with additional LLMs before using the dataset. Filtering removes ungrounded, ambiguous, and duplicate items that would otherwise inflate or distort your evaluation scores.