DSPy-Opt is designed to be extended. Every dataset lives in its own self-contained subdirectory underDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/avnlp/dspy-opt/llms.txt
Use this file to discover all available pages before exploring further.
src/dspy_opt/ and follows a consistent file naming convention. Adding a new dataset means creating that directory, wiring up the shared utilities from dspy_opt/utils/, and providing YAML config files for each step. The FreshQA pipeline is the canonical reference — when in doubt, open a FreshQA file and adapt it.
Step-by-step Guide
Create the dataset directory
Create a new subdirectory under The directory name becomes the Python package name and the prefix for all file names within it.
src/dspy_opt/ using your dataset name in lowercase with underscores:Create the indexing script and config
Create Create the matching
my_dataset_indexing.py following the FreshQA indexing pattern. The script loads a YAML config, fetches the dataset from HuggingFace, extracts metadata with MetadataExtractor, encodes documents with SentenceTransformer, and inserts them into a Weaviate collection.my_dataset_indexing_config.yml:Create the RAG module
Create What to customise:
my_dataset_rag_module.py. This is the core pipeline class. Subclass dspy.Module, define a dspy.Signature that declares your input and output fields, and compose the shared utilities in forward().- Class names: rename
MyDatasetAnswerSignatureandMyDatasetRAGto match your dataset. - Signature fields: adjust
InputFieldandOutputFielddescriptors to match your task. For multi-hop datasets you may want to exposerewritten_queryandsub_queriesas output fields (seeFreshQAAnswerSignaturefor reference). - Document text extraction: the
doc_textsextraction in the indexing script must match your dataset’s schema (e.g.example["context"]for HotpotQA).
Create optimizer scripts and configs
Create one script and one config file per optimizer. All five scripts follow the same pattern — the only differences are the optimizer class, its constructor arguments, and the output JSON filename.For each optimizer (For GEPA, import
mipro, copro, simba, gepa, bootstrap_few_shot) create:my_dataset_rag_<optimizer>.pymy_dataset_rag_<optimizer>_config.yml
create_gepa_metrics_function instead of create_metrics_function and use dspy.GEPA with the reflection_llm argument. See the Running Optimizers guide for details.Create the evaluation script and config
Create
my_dataset_rag_evaluation.py and my_dataset_rag_evaluation_config.yml. The evaluation script has the same structure as an optimizer script but skips the optimizer.compile() step — it simply instantiates the pipeline and runs dspy.Evaluate directly. This is useful for benchmarking the unoptimized baseline or re-evaluating a previously saved compiled pipeline.The evaluation config has the same structure as an optimizer config but omits the optimizer section.Add a README.md
Create
src/dspy_opt/my_dataset/README.md following the freshqa/README.md template. At a minimum, include:- Dataset name, HuggingFace link, and a one-paragraph description.
- The metadata schema fields and their purpose.
- Commands for indexing, running each optimizer, and evaluation.
- A description of any dataset-specific adaptations made to the standard pipeline.
File Checklist
Once complete, your dataset directory should contain these files:Key Adaptation Points
| File | What to change |
|---|---|
*_rag_module.py | Class names, Signature field descriptors, any dataset-specific output fields |
*_indexing.py | doc_texts extraction logic to match your dataset’s field names |
*_indexing_config.yml | dataset.name, dataset.subset, dataset.split, collection_name, metadata_schema |
*_rag_*_config.yml | dataset.*, weaviate.collection_name, optimizer.* hyperparameters |
| All optimizer scripts | Import path (from dspy_opt.my_dataset.my_dataset_rag_module import MyDatasetRAG) |