MentorAgent Docs
Menu

ReferencePackage: Novior.MentorAgent

IMentorRagSource interface

The IMentorRagSource interface of Novior.MentorAgent.Rag: Contract for RAG (Retrieval-Augmented Generation) sources in MentorAgent. Implement this interface…

View as Markdown
On this page

Contract for RAG (Retrieval-Augmented Generation) sources in MentorAgent. Implement this interface to connect any vector store or search backend (Azure AI Search, Qdrant, Pinecone, Weaviate, custom, etc.) to the AI coordinator. Basic custom implementation:

Example
public class MyRagSource : IMentorRagSource
{
    public async Task<IReadOnlyList<MentorRagResult>> SearchAsync(
        string query, int maxResults, CancellationToken ct = default)
    {
        var hits = await _myStore.SearchAsync(query, maxResults, ct);
        return hits.Select(h => new MentorRagResult(h.Text, h.Url, h.Title, h.Score)).ToList();
    }
}

// Register in Program.cs BEFORE AddMentorAgent():
builder.Services.AddSingleton<IMentorRagSource, MyRagSource>();
builder.Services.AddMentorAgent(options => { options.UseRag = true; });

An ITextSearch is not wrapped for you (TextSearchRagSource is a placeholder): call your search client from your own implementation, as above. Who is asking, and from where: implement the MentorRagRequest overload as well. MentorAgent calls that one; its default implementation calls the text-only overload, so a source written for that keeps working unchanged. A source with cosine scores in [0, 1] declares its own threshold with IMentorRagSource.DefaultMinScore:

Example
public class MyVectorSource : IMentorRagSource
{
    public float? DefaultMinScore => 0.6f;   // cosine similarity: 0.5 loose … 0.75 strict

    public Task<IReadOnlyList<MentorRagResult>> SearchAsync(
        MentorRagRequest request, CancellationToken ct = default)
        => SearchCoreAsync(request.Query, request.MaxResults, request.User, ct);

    // Still required by the interface; MentorAgent itself calls the overload above.
    public Task<IReadOnlyList<MentorRagResult>> SearchAsync(
        string query, int maxResults, CancellationToken ct = default)
        => SearchCoreAsync(query, maxResults, user: null, ct);
}

Do not make each overload call the other: with both delegating, a search never returns.

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

public interface IMentorRagSource

Terminal
dotnet add package Novior.MentorAgent

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.

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

Searches with the whole request: the message, the recent conversation, the user and the current page. This is the overload MentorAgent calls. The default implementation calls IMentorRagSource.SearchAsync with MentorRagRequest.Query and MentorRagRequest.MaxResults.

Parameters

  • request: What is searched for, and the context it was asked in.
  • ct: Cancellation token.

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

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).