Generate Rag Generation Eval Dataset
π¨ NeMo Data Designer: Generate Diverse RAG Evaluations
π What you'll learn
This tutorial demonstrates how to generate comprehensive evaluation datasets for Retrieval-Augmented Generation (RAG) systems, customized to your content and use cases.
π IMPORTANT βΒ Environment Setup
If you haven't already, follow the instructions in the README to install the necessary dependencies.
You may need to restart your notebook's kernel after setting up the environment.
In this notebook, we assume you have a self-hosted instance of Data Designer up and running.
For deployment instructions, see the Installation Options section of the NeMo Data Designer documentation.
π¦ Import the essentials
-
The
data_designermodule ofnemo_microservicesexposes Data Designer's high-level SDK. -
The
essentialsmodule provides quick access to the most commonly used objects.
βοΈ Initialize the NeMo Data Designer Client
NeMoDataDesignerClientis responsible for submitting generation requests to the microservice.
ποΈ Define model configurations
-
Each
ModelConfigdefines a model that can be used during the generation process. -
The "model alias" is used to reference the model in the Data Designer config (as we will see below).
-
The "model provider" is the external service that hosts the model (see the model config docs for more details).
-
By default, the microservice uses build.nvidia.com as the model provider.
ποΈ Initialize the Data Designer Config Builder
-
The Data Designer config defines the dataset schema and generation process.
-
The config builder provides an intuitive interface for building this configuration.
-
The list of model configs is provided to the builder at initialization.
π± Loading Seed Data
-
We'll use the symptom-to-diagnosis dataset as our seed data.
-
This dataset contains patient symptoms and corresponding diagnoses which will help generate realistic medical scenarios.
π± Why use a seed dataset?
Seed datasets let you steer the generation process by providing context that is specific to your use case.
Seed datasets are also an excellent way to inject real-world diversity into your synthetic data.
During generation, prompt templates can reference any of the seed dataset fields.
π‘ About datastores
You can use seed datasets from either the Hugging Face Hub or a locally deployed datastore.
By default, we use the local datastore deployed with the Data Designer microservice.
The datastore endpoint is specified in the deployment configuration.
π Note: At this time, we only support using a single file as the seed. If you have multiple files you would like to use as
seeds, it is recommended you consolidated these into a single file.
βοΈ Document Processing
Now we'll create a Document Processor class that handles loading and chunking the source documents.
This class uses langchain's RecursiveCharacterTextSplitter and unstructured.io for robust document parsing.
ποΈ Data Models
-
Let's define Pydantic models for structured output generation.
-
These schemas will ensure our generated data has consistent structure and validation.
π² Adding Categorical Columns for Controlled Diversity
Now we'll add categorical columns to control the diversity of our RAG evaluation pairs. We'll define:
-
Difficulty levels: easy, medium, hard
-
Reasoning types: factual recall, inferential reasoning, etc.
-
Question types: answerable vs. unanswerable (with weighting)
π¦ Adding LLM-Structured Column for Q&A Pair Generation
Now let's set up the core of our data generation: the Q&A pair column that will produce structured question-answer
pairs based on our document context and control parameters.
π Quality Assessment: LLM-as-a-Judge
When generating our synthetic dataset, we need to determine the quality of the generated data
We use the LLM-as-a-Judge strategy to do this.
To do so, we need to define the rubric that the LLM should use to assess generation quality along with a prompt that provides relavant instructions.
π Iteration is key βΒ preview the dataset!
-
Use the
previewmethod to generate a sample of records quickly. -
Inspect the results for quality and format issues.
-
Adjust column configurations, prompts, or parameters as needed.
-
Re-run the preview until satisfied.
π Analyze the generated data
-
Data Designer automatically generates a basic statistical analysis of the generated data.
-
This analysis is available via the
analysisproperty of generation result objects.
π Scale up!
-
Happy with your preview data?
-
Use the
createmethod to submit larger Data Designer generation jobs.