Class
DefaultContextRetriever

Provides a default implementation for retrieving relevant context fragments based on semantic similarity to a given question.

Definition

Namespace:Telerik.Documents.AI.RAG

Assembly:Telerik.Documents.AI.RAG.dll

Syntax:

cs-api-definition
public class DefaultContextRetriever : IContextRetriever

Inheritance: objectDefaultContextRetriever

Implements: IContextRetriever

Constructors

DefaultContextRetriever(IContextFragmentsManager, IEmbedder, ISimilarityCalculator, ITokensCounter, IEmbeddingSettings)

Initializes a new instance of the DefaultContextRetriever class with the specified context fragments manager, embedder, similarity calculator, tokens counter, and embedding settings.

Declaration

cs-api-definition
public DefaultContextRetriever(IContextFragmentsManager contextFragmentsManager, IEmbedder embedder, ISimilarityCalculator similarityCalculator, ITokensCounter tokensCounter, IEmbeddingSettings settings)

Parameters

contextFragmentsManager

IContextFragmentsManager

The manager responsible for handling context fragments used in retrieval operations. Cannot be null.

embedder

IEmbedder

The component used to generate embeddings for context fragments. Cannot be null.

similarityCalculator

ISimilarityCalculator

The calculator used to determine similarity between embeddings. Cannot be null.

tokensCounter

ITokensCounter

The service used to count tokens in context fragments and embeddings. Cannot be null.

settings

IEmbeddingSettings

The settings that configure embedding parameters, such as the maximum number of embeddings, embedding token size, and model input token limit. Cannot be null.

Properties

ContextFragmentsManager

Gets the manager responsible for handling context fragments within the current instance.

Declaration

cs-api-definition
protected IContextFragmentsManager ContextFragmentsManager { get; }

Property Value

IContextFragmentsManager

Methods

GetContextAsync(string)

Gets the text representation of the relevant embeddings for the provided question.

Declaration

cs-api-definition
public Task<string> GetContextAsync(string question)

Parameters

question

string

The question text to find relevant context for. Cannot be null.

Returns

Task<string>

The text representation of the relevant embeddings.

Implements IContextRetriever.GetContextAsync(string)

SetContextAsync(string, int)

Asynchronously splits the specified text into fragments based on the provided embedding token size.

Declaration

cs-api-definition
public Task SetContextAsync(string text, int embeddingTokenSize)

Parameters

text

string

The text to be divided into fragments. Cannot be null.

embeddingTokenSize

int

The maximum number of tokens allowed in each fragment. Must be a positive integer.

Returns

Task

A task that represents the asynchronous operation of fragmenting the text.

Implements IContextRetriever.SetContextAsync(string, int)