MentorAgent Docs
Menu

Questa pagina non è ancora tradotta in italiano: qui la trovi in inglese.

ReferencePackage: Novior.MentorAgent

MentorVectorStoreRagSource<TRecord> class

The MentorVectorStoreRagSource<TRecord> class of Novior.MentorAgent.Rag: An IMentorRagSource over a collection of Microsoft.Extensions.VectorData — pgvector…

On this page

An IMentorRagSource over a collection of Microsoft.Extensions.VectorData — pgvector, Qdrant, Azure AI Search, an in-memory one: any IVectorSearchable. Register it with AddMentorVectorStoreRag, and say in MentorVectorStoreRagOptions<TRecord> what of a record is the document and its citation.

Example
builder.Services.AddMentorVectorStoreRag(
    sp => sp.GetRequiredService<VectorStore>().GetCollection<Guid, Doc>("docs"),
    new MentorVectorStoreRagOptions<Doc>
    {
        Content = d => d.Text,
        Title = d => d.Title,
        SourceUrl = d => d.Url,
        Filter = request => d => d.Tenant == request.TenantId,
    });

The scores are turned into similarities, higher meaning nearer, whatever the collection's distance function: with CosineDistance, the Postgres default, a raw score would keep the farthest documents and drop the nearest. The message is embedded with MentorVectorStoreRagOptions<TRecord>.EmbeddingGenerator, else with MentorOptions.EmbeddingGenerator, once per turn for each model (IMentorQueryEmbedding), else by the collection itself. The source keeps no state of its own.

Namespace: Novior.MentorAgent.Rag. Package: Novior.MentorAgent.

public sealed class MentorVectorStoreRagSource<TRecord> : IMentorRagSource

Implements IMentorRagSource.

Terminal
dotnet add package Novior.MentorAgent

public MentorVectorStoreRagSource(IVectorSearchable<TRecord> collection, MentorVectorStoreRagOptions<TRecord> options, ILogger<MentorVectorStoreRagSource<TRecord>>? logger = null)

A source built by hand. It embeds the message with MentorVectorStoreRagOptions<TRecord>.EmbeddingGenerator, or passes its text to the collection; registered with AddMentorVectorStoreRag, it shares the turn's vector.

Parameters

  • collection: The collection to search.
  • options: What of a record is the document, and what the collection's scores mean.
  • logger: Where its warnings go.

Exceptions

  • InvalidOperationException: The distance function is unknown, or has no fixed scale.

public float? DefaultMinScore { get; }

The relevance threshold suited to this source's scores, used when the host has not set RagMinScore itself. null (the default) leaves the option's default, 2, which suits integer-like keyword scores. A source whose scores are cosine similarity in [0, 1] — a vector store — declares one in that range (0.5 loose to 0.75 strict), or nothing it returns can clear the default. A RagMinScore the host sets, in code or in configuration, wins over it.

public Task<IReadOnlyList<MentorRagResult>> SearchAsync(MentorRagRequest request, CancellationToken ct = default)

Searches for documents relevant to the given query. Called by the coordinator before each user message is sent to the AI, through the MentorRagRequest overload unless the source replaces that one.

Parameters

  • query: The user's message (or a reformulated search query).
  • maxResults: Maximum number of results to return.
  • ct: Cancellation token.

Returns: List of relevant documents ordered by relevance (most relevant first).

public Task<IReadOnlyList<MentorRagResult>> SearchAsync(string query, int maxResults, CancellationToken ct = default)

Searches for documents relevant to the given query. Called by the coordinator before each user message is sent to the AI, through the MentorRagRequest overload unless the source replaces that one.

Parameters

  • query: The user's message (or a reformulated search query).
  • maxResults: Maximum number of results to return.
  • ct: Cancellation token.

Returns: List of relevant documents ordered by relevance (most relevant first).