Zenaique

Match each DSPy optimizer to its core search strategy

Match pairs·Hard·4.0 · 0·~2 min·Asked atBraintrustRedisServicenow
Attempt it

Drag each answer to line up with its matching prompt

Bootstraps few-shot examples from a stronger teacher model and selects the ones that pass the metric

MIPROv2

Jointly optimises instructions and demonstrations via Bayesian search over a candidate space

BootstrapFinetune

Refines instructions through coordinate ascent, perturbing one prompt component at a time and keeping winners

COPRO

Bootstraps demonstrations with random search over a finite candidate set, the cheap baseline

BootstrapFewShotWithRandomSearch

Fine-tunes the underlying LM weights against the metric instead of editing the prompt

BootstrapFewShot

TL;DR

DSPy optimizers vary by what they edit (demos vs instructions vs weights) and how they search (greedy bootstrap, random, Bayesian, coordinate ascent, gradient).

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Picture a chef trying to nail a dish for a critic. BootstrapFewShot watches a master chef make it five times and copies the bites the critic liked. RandomSearch tries random combinations of plates and keeps the best. COPRO tweaks one ingredient at a time, keeping the change if the critic smiles. MIPROv2 is the data-driven chef who runs a smart trial and error plan over both the recipe and the plating. BootstrapFinetune sends the apprentice back to culinary school to actually learn new techniques.

Key concepts

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

DSPy frames prompt engineering as a compilation problem. You write a program declaratively (signatures, modules), supply a metric, and let an optimizer search over the tunable parts to maximize that metric. Each optimizer is a search strategy with its own assumptions about what to perturb and how to evaluate. Knowing the menu, and the cost versus power trade for each item, is the senior-level skill the question is testing.

This section walks the five optimizers in the question along the two axes that organize them (what they edit, how they search), then connects the strategy to the operational decision: when to use which, in what order, and what failure mode to watch for at each step.

The two axes that organize the menu

Every DSPy optimizer perturbs something and runs some search procedure over the perturbations. Those two axes, the what and the how, let you map any optimizer in the library to a slot in the design space.

The what axis has three positions: few-shot demonstrations (the examples shown to the model), the instruction string (the task description), or the model weights themselves. Demonstrations are the cheapest thing to edit because you can generate them with a teacher LM. Instructions are mid-cost because each edit needs evaluation but the candidate space is small. Weights are expensive because gradient updates need a full fine-tuning loop.

The how axis ranges from greedy bootstrap (collect candidates from a teacher, keep what scores) through random search (sample candidates uniformly), coordinate ascent (change one component at a time, keep wins), Bayesian optimization (model the response surface and propose promising candidates), to gradient descent (the fine-tune end of the spectrum). Each strategy trades sample efficiency for compute per round.

The two bootstrap optimizers. Demonstrations from a teacher
COPRO and MIPROv2. Instruction-aware optimizers
BootstrapFinetune. The outlier
Practical escalation order and failure modes to watch
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
python
import dspy
from dspy.teleprompt import BootstrapFewShot, BootstrapFewShotWithRandomSearch, COPRO, MIPROv2

class QA(dspy.Signature):
    """Answer the question concisely."""
    question: str = dspy.InputField()
    answer: str = dspy.OutputField()

program = dspy.ChainOfThought(QA)

def metric(example, pred, trace=None):
    return example.answer.lower() in pred.answer.lower()

# Cheap baseline: bootstrap a few demos from a teacher
compiled = BootstrapFewShot(metric=metric, max_bootstrapped_demos=4).compile(
    program, trainset=trainset
)

# Broader sweep: random search over candidate demo sets
compiled = BootstrapFewShotWithRandomSearch(metric=metric, num_candidate_programs=10).compile(
    program, trainset=trainset, valset=valset
)

# Instruction tuning: coordinate ascent
compiled = COPRO(metric=metric).compile(program, trainset=trainset, eval_kwargs={})

# Joint search: Bayesian over instructions and demos
compiled = MIPROv2(metric=metric, auto='medium').compile(
    program, trainset=trainset, valset=valset
)
OptimizerWhat it editsSearch strategyCost
BootstrapFewShotFew-shot demosGreedy bootstrap from teacherLow
BootstrapFewShotWithRandomSearchFew-shot demosRandom search over candidate setsLow to medium
COPROInstruction stringCoordinate ascentMedium
MIPROv2Instructions plus demosBayesian optimizationMedium to high
BootstrapFinetuneModel weightsGradient updates on bootstrapped tracesHigh plus GPU time

Real products, models, and research that use this idea.

  • Stanford's STORM Wikipedia-generation system uses DSPy with MIPROv2 to tune its multi-stage pipeline
  • The DSPy documentation's benchmark notebooks consistently rank MIPROv2 above plain BootstrapFewShot on HotpotQA and MATH
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhen does using a stronger teacher than student matter most in BootstrapFewShot?
A

Whenever the student lacks a capability the teacher has. Multi-hop reasoning, structured output discipline, domain knowledge. The demos demonstrate the capability and the student learns the pattern. A weaker teacher caps what bootstrap can teach.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Conflating 'optimizer' in DSPy with 'optimizer' in deep learning. DSPy optimizers search over prompts and demos, not gradient updates (except BootstrapFinetune).

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • The two axes that distinguish DSPy optimizers: what they edit and how they search

  • BootstrapFewShot mechanism and its dependence on a teacher LM

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Defend the call to…
Short answer·Hard