Documentation Index
Fetch the complete documentation index at: https://mintlify.com/skydiscover-ai/skydiscover/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Best-of-N is a simple yet effective algorithm that reuses the same parent program for N consecutive iterations, generating N different variants and keeping the best. This allows thorough exploration of variations from a single starting point.Focused Exploration
Generates multiple variants from the same parent
Automatic Reset
Switches to a new parent after N iterations
Simple Logic
Easy to understand and configure
Efficient Sampling
No complex selection or archive management
How It Works
Iteration Cycle
- Parent Selection: Select the best program as parent (if starting fresh or after N iterations)
- Variant Generation: Generate a variant of the parent
- Evaluation: Score the variant
- Counter Increment: Increment iteration counter
- Check Reset: If counter reaches N, reset and select new parent
- Repeat: Continue with same or new parent
Context Programs
While the parent stays fixed for N iterations, context programs are sampled fresh each time from the current top programs, providing updated examples.Configuration
Basic Usage
Configuration File
Python API
Configuration Options
Number of consecutive iterations to reuse the same parent before selecting a new one.Recommended values:
- 3-5: Quick iteration, frequent parent updates
- 5-10: Balanced exploration/update
- 10-20: Deep exploration of each parent
Number of top programs to include as context (updated each iteration)
When to Use Best-of-N
Best For
Best For
- Problems where each parent has many possible improvements
- Stochastic or creative generation (gives LLM multiple tries)
- When you want to thoroughly explore variations
- Limited iteration budgets where you want multiple attempts
Avoid When
Avoid When
- Deterministic generation (LLM produces same output each time)
- Problems requiring diverse exploration of solution space
- Very short runs where N > total iterations
Example
Creative Text Generation
Best-of-N works well for creative tasks with high LLM variance:Choosing N
The optimal value of N depends on several factors:LLM Variance
- High Variance
- Low Variance
If the LLM produces very different outputs each time (creative tasks, underspecified problems):More attempts = higher chance of finding a good variant
Iteration Budget
- Total iterations = 30:
best_of_n: 3(10 parent updates) - Total iterations = 100:
best_of_n: 5-10(10-20 parent updates) - Total iterations = 500:
best_of_n: 10-25(20-50 parent updates)
Monitoring Progress
Track Parent Switches
Analyze Variants
After a run, analyze which variants were best:Comparison with Other Algorithms
| Algorithm | Parent Reuse | Exploration | Use Case |
|---|---|---|---|
| Best-of-N | Fixed for N iterations | Limited to variants | Creative/stochastic tasks |
| Top-K | Changes each iteration | None | Deterministic refinement |
| Beam Search | Multiple in parallel | Controlled breadth | Multiple solution paths |
| AdaEvolve | Island-based | Adaptive | Complex landscapes |
Advanced Strategies
Adaptive N
Adjust N based on improvement:Diversity Sampling
Vary the context programs more:Tips for Best Results
Use Temperature
Enable LLM temperature > 0 to get diverse variants from the same parent
Monitor Variance
Track score variance of variants. Low variance = reduce N
Balance N and Budget
Ensure at least 5-10 parent updates in your iteration budget
Combine with Restarts
Periodically reset to explore from different starting points
Related Algorithms
- Top-K - Similar but updates parent every iteration
- Beam Search - Maintains multiple parents simultaneously
- GEPA Native - Uses acceptance gating for variant selection