Overview
Top-K is a straightforward search algorithm that always selects the best program as the parent and uses the next best programs as context. It’s the simplest effective baseline in SkyDiscover.Greedy Selection
Always picks the highest-scoring program to evolve
Elite Context
Provides top programs as examples in the prompt
No Stagnation
Continues refining even if improvement is slow
Minimal Overhead
Fast and simple with no complex bookkeeping
How It Works
Sampling Strategy
On each iteration, Top-K:- Parent Selection: Choose the program with the highest
combined_score - Context Selection: Select the next K programs (ranks 2 to K+1) as context
- Prompt Generation: Include context programs as examples of good solutions
- Evolution: Generate a mutation of the best program
If only one program exists, it’s used as both parent and context.
Pure Exploitation
Top-K is a pure exploitation strategy:- No exploration of diverse solutions
- No randomness in selection
- Focuses entirely on refining the current best
Configuration
Basic Usage
Python API
Configuration File
Configuration Options
Number of top programs (after the best) to include as context
Directory to save programs and checkpoints
Whether to save prompts and responses
When to Use Top-K
Best For
Best For
- Quick experiments and baselines
- Problems where greedy refinement works well
- Short discovery runs (< 50 iterations)
- When you want simple, predictable behavior
- As a starting point before trying more complex algorithms
Avoid When
Avoid When
- Problems with many local optima requiring exploration
- Need for diverse solution approaches
- Risk of getting stuck in local optima
Comparison with Other Algorithms
| Algorithm | Exploration | Exploitation | Complexity |
|---|---|---|---|
| Top-K | None | High | Low |
| Best-of-N | None | High | Low |
| Beam Search | Medium | Medium | Medium |
| AdaEvolve | Adaptive | Adaptive | High |
Example
Simple Optimization
Output Structure
Tips for Best Results
Start Simple
Start Simple
Top-K is an excellent starting point. Run it first to establish a baseline before trying more complex algorithms.
Monitor for Stagnation
Monitor for Stagnation
If the score stops improving after several iterations, consider switching to an algorithm with exploration (like AdaEvolve or Beam Search).
Use Good Context
Use Good Context
Increase
num_context_programs (e.g., to 8) to give the LLM more examples of successful solutions.Iterate Quickly
Iterate Quickly
Top-K’s simplicity makes it fast. Use it for rapid iteration during development.
Variants
You can easily modify Top-K behavior:Random Top-K
Sample randomly from top-K instead of always using #1:Top-K with Temperature
Weight selection by score:Related Algorithms
- Best-of-N - Similar greedy approach with N attempts per parent
- Beam Search - Maintains multiple candidates instead of just one
- AdaEvolve - Adaptive version with exploration