Test data generation
A useful test set has high-quality samples, covers the scenarios users actually produce, is large enough for a conclusion, and keeps being updated so it does not drift. Writing that by hand is slow. Ragas synthesizes it, with a full pipeline for RAG and an early one for agents.
Query types in RAG Hop × specificity
A single-hop question is answered from one source. A multi-hop question joins two or more. Specific asks for a fact; abstract asks for an interpretation.
Specific queries push retrieval toward precise passages. Abstract queries need passages that explain, compare, or interpret. Each type needs a different bundle of chunks, which is why generation walks a knowledge graph instead of sampling chunks at random.
Knowledge graph Split, extract, relate
Documents become nodes. Extractors add properties. Relationship builders connect nodes that share those properties. A transform runs the steps in order.
Document splitter
Chunks become hierarchical Nodes. A financial splitter can cut on Income Statement, Balance Sheet, and Cash Flow. Domain splitters are custom.
Extractors
LLMBasedExtractor or rule-based Extractor. NERExtractor writes an entities property onto each node.
Relationship builder
JaccardSimilarityBuilder links nodes that share entities. The edge type and score are stored on the relationship.
sample_nodes = [
Node(properties={"page_content": "Einstein's theory of relativity ..."}),
Node(properties={"page_content": "Time dilation occurs when an object moves ..."}),
]extractor = NERExtractor()
output = [await extractor.extract(node) for node in sample_nodes]
# ('entities', ['Einstein', 'theory of relativity', 'space', 'time', ...])
for (key, val), node in zip(output, sample_nodes):
node.properties.update({key: val})kg = KnowledgeGraph(nodes=sample_nodes)
rel_builder = JaccardSimilarityBuilder(
property_name="entities",
key_name="PER",
new_property_name="entity_jaccard_similarity",
)
relationships = await rel_builder.transform(kg)transforms = [
Parallel(KeyphraseExtractor(), NERExtractor()),
rel_builder,
]
apply_transforms(kg, transforms)Once the graph exists, a query such as “compare revenue growth of Company X and Company Y from FY2020 through FY2023” is a traversal to the nodes that hold those figures.
Scenarios and synthesizers Persona, length, style
The same pair of nodes can yield many questions. A scenario fixes the nodes plus query length, query style, and persona.
| Scenario field | Examples |
|---|---|
| Nodes | The chunks the question and the reference answer are built from |
| Query length | Short, medium, long |
| Query style | Web search, chat |
| Persona | Senior engineer, junior engineer (planned) |
A QuerySynthesizer implements two steps. _generate_scenariosqueries the graph and combines nodes, style, length, and persona until it has the requested count. _generate_sample turns one scenario into an eval sample: user input, reference contexts, and a reference answer, as a single-turn or multi-turn sample.
Agents and tool use
Agentic workflows are harder to cover because each task is a sequence of tool calls and edge cases. Ragas documents this generator as work in progress and points teams to collaborate on the upcoming releases. The RAG pipeline above is the one that is specified end to end.
Key takeaways
- Generate across single-hop and multi-hop, and across specific and abstract, or the test set only measures fact lookup.
- The knowledge graph is how Ragas picks the right chunks before an LLM writes the question.
- A scenario is nodes plus length, style, and persona. The synthesizer turns that into query, context, and reference.