Skip to content

Add MIPROv2 optimizer implementation - #18

Merged
krypticmouse merged 2 commits into
krypticmouse:mainfrom
conikeec:prompt_optimizer
Oct 6, 2025
Merged

Add MIPROv2 optimizer implementation#18
krypticmouse merged 2 commits into
krypticmouse:mainfrom
conikeec:prompt_optimizer

Conversation

@conikeec

@conikeec conikeec commented Oct 5, 2025

Copy link
Copy Markdown
Contributor

Summary

Implements MIPROv2 (Multi-prompt Instruction Proposal Optimizer v2) as an alternative to COPRO for prompt optimization. MIPROv2 uses LLMs to generate program descriptions and candidate prompts based on execution traces and prompting best practices.

Key Changes

  • Core optimizer (mipro.rs): 3-stage process
    • Stage 1: Generate execution traces from training data
    • Stage 2: LLM generates program description + candidate prompts using prompting tips
    • Stage 3: Evaluate candidates and select best
  • 29 comprehensive test cases covering traces, selection, configuration, edge cases
  • Example (08-optimize-mipro.rs): Full working example with HotpotQA
  • Prompting tips library: 15+ best practices built-in
  • Documentation: Implementation guide and usage examples
  • README updates: Optimizer comparison and configuration details

Implementation Details

  • Follows Rust best practices (no unsafe, proper error handling, async throughout)
  • Strong typing with Trace, PromptCandidate, PromptingTips
  • Builder pattern for flexible configuration
  • All tests passing

Trade-offs

MIPROv2 trades speed for quality - makes more LLM calls but produces better prompts by leveraging prompting techniques.

Use MIPROv2 when:

  • Complex reasoning tasks
  • Have decent training data (15+ examples)
  • Quality matters more than speed

Use COPRO when:

  • Need fast iteration
  • Limited compute budget
  • Straightforward tasks

Testing

cargo test optimizer::mipro::tests
cargo run --example 08-optimize-mipro --features parquet

Implements MIPROv2 (Multi-prompt Instruction Proposal Optimizer v2) as an
alternative to COPRO for prompt optimization. MIPROv2 uses LLMs to generate
program descriptions and candidate prompts based on execution traces and
prompting best practices.

Key additions:
- mipro.rs: Core optimizer with 3-stage process (trace generation, candidate
  generation via LLM, evaluation/selection)
- 29 test cases covering trace handling, candidate selection, configuration,
  and edge cases
- Example (08-optimize-mipro.rs) demonstrating optimization on HotpotQA
- Prompting tips library with 15+ best practices
- Updated README with optimizer comparison and usage

MIPROv2 trades speed for quality - it makes more LLM calls but produces
better prompts by leveraging prompting techniques. Recommended for complex
tasks with decent training data (15+ examples).

@krypticmouse krypticmouse left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I'll suggest to store all tests in the test folder and docs in the suitable group as well! But now worries if you can't I can take care of it!

@krypticmouse

Copy link
Copy Markdown
Owner

Thank you so much for the contribution!

@krypticmouse

krypticmouse commented Oct 6, 2025

Copy link
Copy Markdown
Owner

As another suggestion we can also use Prompting tips as output from Signature but it's mostly an implementation choice.

@krypticmouse
krypticmouse merged commit d64c60a into krypticmouse:main Oct 6, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants