dspy-miprov2-optimizer

Jointly tune DSPy instructions and demonstrations via Bayesian optimization.

120|13|Updated Dec 21, 2025
One-click install
npx skills add https://github.com/OmidZamani/dspy-skills --skill dspy-miprov2-optimizer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dspy-miprov2-optimizer
Source: https://github.com/OmidZamani/dspy-skills/tree/main/skills/dspy-miprov2-optimizer
Command: npx skills add https://github.com/OmidZamani/dspy-skills --skill dspy-miprov2-optimizer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill performs state-of-the-art Bayesian optimization to jointly tune DSPy instructions and few-shot demonstrations, delivering higher-performing programs with fewer manual trials.

Core Features & Use Cases

  • Phase-driven workflow (Bootstrap, Propose, Search) to generate candidates, ground instructions, and explore space.
  • Supports large training sets (200+ examples) and configurable trial counts.
  • Production-grade example shows improved performance with MIPROv2.

Quick Start

  1. Set up the environment: dspy.configure(lm=dspy.LM("openai/gpt-4o-mini"))
  2. Define a RAG-based DSPy agent and run the optimizer: optimizer = dspy.MIPROv2(..., auto="medium", num_threads=24) compiled = optimizer.compile(RAGAgent(), trainset=trainset)

Frequently Asked Questions about dspy-miprov2-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize DSPy instructions and demonstrations together?

Bayesian optimization jointly tunes both instructions and few-shot demonstrations for DSPy programs, exploring the instruction-demo space systematically to find higher-performing combinations. MIPROv2 uses a three-stage Bootstrap-Propose-Search workflow to ground candidates in training data and converge on state-of-the-art results.

When should I use Bayesian optimization for DSPy instead of manual tuning?

Bayesian optimization is essential for large datasets (200+ training examples) and extended optimization runs (40+ trials) where both instructions and demos require tuning. Manual approaches become inefficient at this scale; Bayesian methods achieve better performance with fewer manual iterations.

Can I use MIPROv2 with my RAG-based DSPy program?

Yes. MIPROv2 supports RAG workflows and any DSPy program with sufficient training data. Configure your language model, define your agent, and pass it to the optimizer with your trainset and metric. It outputs a fully compiled, optimized DSPy module ready for deployment.

What training data do I need to run this optimizer?

The optimizer requires a training dataset (200+ examples recommended), a DSPy program, and a metric function to evaluate performance. Larger datasets and longer trial counts (40+) enable better exploration of the instruction-demo space and higher-quality results.

How does the Bootstrap-Propose-Search workflow improve optimization?

Bootstrap generates diverse candidate instructions and demonstrations from training data. Propose grounds them in examples. Search explores the combined space efficiently using Bayesian optimization, converging faster than random search or greedy approaches while maintaining exploration breadth.

What's the difference between tuning instructions alone versus instructions and demos together?

Tuning only instructions limits expressiveness; jointly optimizing instructions and demonstrations allows the system to adapt both the guidance and the examples shown to the model. This combined approach yields state-of-the-art performance impossible to achieve by tuning either component in isolation.