SemanticSimilarityExampleSelector<T>
Models & Types ยท AiDotNet.PromptEngineering.FewShot
Selects examples based on semantic similarity to the query.
Inheritance: FewShotExampleSelectorBase<T> โ SemanticSimilarityExampleSelector<T>
For Beginners
Picks examples most similar in meaning to your query.
How it works:
- Convert query and examples to mathematical vectors (embeddings)
- Calculate similarity between query and each example
- Return the most similar examples
Example:
Use this when:
- Query types vary significantly
- Relevant examples improve performance
- You have an embedding model available
How It Works
This selector uses embedding vectors to find examples that are semantically similar to the query. It converts both the query and examples into vector representations and selects those with the highest cosine similarity.
Constructors
| Constructor | Summary |
|---|---|
SemanticSimilarityExampleSelector(Func<string, Vector<T>> embeddingFunction) |
Initializes a new instance of the SemanticSimilarityExampleSelector class. |
SemanticSimilarityExampleSelector(IEmbeddingModel<T> embeddingModel) |
Initializes a new instance of the SemanticSimilarityExampleSelector class. |