ClassDefaultSimilarityCalculator
Provides a default implementation of the ISimilarityCalculator interface for finding the most similar text fragments to a given question using embeddings.
Definition
Namespace:Telerik.Documents.AI.RAG
Assembly:Telerik.Documents.AI.RAG.dll
Syntax:
public class DefaultSimilarityCalculator : ISimilarityCalculator
Inheritance: objectDefaultSimilarityCalculator
Implements:
Constructors
DefaultSimilarityCalculator(IEmbedder)
Initializes a new instance of the DefaultSimilarityCalculator class using the specified embedder.
Declaration
public DefaultSimilarityCalculator(IEmbedder embedder)
Parameters
embedder
The embedder used to generate vector representations for similarity calculations. Cannot be null.
Methods
CalculateScores(string, IList<Embedding>)
Finds the most similar text fragments to the specified question and returns their similarity scores.
Declaration
public Task<IList<SimilarityScore<IFragment>>> CalculateScores(string prompt, IList<Embedding> embeddings)
Parameters
prompt
The input question to compare against the provided fragments. Cannot be null, empty, or whitespace.
embeddings
An array of embeddings representing the text fragments to search. Cannot be null or empty.
Returns
Task<IList<SimilarityScore<IFragment>>>
An array of similarity scores, each containing a fragment and its similarity to the question. Returns an empty array on error conditions.
Implements
Remarks
The method uses the current embedding model to compute similarity between the question and each fragment. If the specified limit exceeds the number of fragments, all fragments are considered. The results are ordered by descending similarity score.