BeamSearchOptimizer<T>

Models & Types · AiDotNet.PromptEngineering.Optimization

Optimizer that uses beam search to explore multiple promising prompt variations.

Inheritance: PromptOptimizerBase<T> → BeamSearchOptimizer<T>

For Beginners

Explores multiple paths simultaneously.

Example:

How it works:

  • Keep track of top N prompts (the “beam”)
  • Generate variations of all N prompts
  • Score all variations
  • Keep only the top N again
  • Repeat

Benefits:

  • More thorough than greedy search
  • Less likely to get stuck in local optima
  • Faster than exhaustive search

How It Works

Beam search maintains a fixed number of best candidates at each step, exploring variations of all candidates before selecting the top performers.

Constructors

Constructor Summary
BeamSearchOptimizer(int beamWidth, int variationsPerCandidate, int? seed) Initializes a new instance of the BeamSearchOptimizer class.

Methods

Method Summary
void AddVariations(IEnumerable<string> prefixes, IEnumerable<string> suffixes, IEnumerable<string> insertions) Adds custom variations for beam search.