MMRExampleSelector<T>
Models & Types · AiDotNet.PromptEngineering.FewShot
Selects examples using Maximum Marginal Relevance (MMR) to balance relevance and diversity.
Inheritance: FewShotExampleSelectorBase<T> → MMRExampleSelector<T>
For Beginners
Picks examples that are both relevant AND different from each other.
Think of it like building a playlist:
- Pure relevance: All songs sound almost identical (boring!)
- Pure diversity: Random songs that don’t fit together (confusing!)
- MMR: Similar style, but each song brings something different (perfect!)
Example:
The lambda parameter controls the balance:
- lambda = 1.0: Pure relevance (like SemanticSimilarity)
- lambda = 0.5: Equal balance
- lambda = 0.0: Pure diversity (like Diversity)
How It Works
MMR combines relevance (similarity to query) and diversity (difference from already-selected examples). It iteratively selects examples that maximize: lambda * relevance - (1 - lambda) * max_similarity_to_selected
Constructors
| Constructor | Summary |
|---|---|
MMRExampleSelector(Func<string, Vector<T>> embeddingFunction) |
Initializes a new instance of the MMRExampleSelector class. |
MMRExampleSelector(Func<string, Vector<T>> embeddingFunction, T lambda) |
Initializes a new instance of the MMRExampleSelector class. |
MMRExampleSelector(IEmbeddingModel<T> embeddingModel) |
Initializes a new instance of the MMRExampleSelector class. |
MMRExampleSelector(IEmbeddingModel<T> embeddingModel, T lambda) |
Initializes a new instance of the MMRExampleSelector class. |
Properties
| Property | Summary |
|---|---|
T Lambda { get; } |
Gets the lambda value used for MMR scoring. |