Source: https://dspy.ai/api/optimizers/MIPROv2/ · Fetched: 2026-09-05
Note: body below is original English documentation text. Do not treat this file as a translation.
MIPROv2 (Multiprompt Instruction PRoposal Optimizer Version 2) is a prompt optimizer capable of optimizing both instructions and few-shot examples jointly. It does this by bootstrapping few-shot example candidates, proposing instructions grounded in different dynamics of the task, and finding an optimized combination of these options using Bayesian Optimization. It can be used for optimizing few-shot examples & instructions jointly, or just instructions for 0-shot optimization.
How MIPROv2 works
At a high level, MIPROv2 works by creating both few-shot examples and new instructions for each predictor in your LM program, and then searching over these using Bayesian Optimization to find the best combination of these variables for your program.
These steps are broken down in more detail below:
Bootstrap Few-Shot Examples: Randomly samples examples from your training set, and run them through your LM program. If the output from the program is correct for this example, it is kept as a valid few-shot example candidate. Otherwise, we try another example until we've curated the specified amount of few-shot example candidates. This step creates
num_candidatessets ofmax_bootstrapped_demosbootstrapped examples andmax_labeled_demosbasic examples sampled from the training set.Propose Instruction Candidates. The instruction proposer includes (1) a generated summary of properties of the training dataset, (2) a generated summary of your LM program's code and the specific predictor that an instruction is being generated for, (3) the previously bootstrapped few-shot examples to show reference inputs / outputs for a given predictor and (4) a randomly sampled tip for generation (i.e. "be creative", "be concise", etc.) to help explore the feature space of potential instructions. This context is provided to a
prompt_modelwhich writes high quality instruction candidates.Find an Optimized Combination of Few-Shot Examples & Instructions. Finally, we use Bayesian Optimization to choose which combinations of instructions and demonstrations work best for each predictor in our program. This works by running a series of
num_trialstrials, where a new set of prompts are evaluated over our validation set at each trial. The new set of prompts are only evaluated on a minibatch of sizeminibatch_sizeat each trial (whenminibatch=True). The best averaging set of prompts is then evaluated on the full validation set everyminibatch_full_eval_steps. At the end of the optimization process, the LM program with the set of prompts that performed best on the full validation set is returned.
Isolation note (for KB indexing)
Candidate = instructions and few-shot demos of the student LM program (not the optimizer itself). Optimizer = MIPROv2 (bootstrap + instruction proposer + Optuna/TPE Bayesian search). Eval & control = user metric + valset; minibatch exploration with periodic full-valset promotion of the best combination.