# MentorVectorStoreRagSource<TRecord> class

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

- URL: https://docs.mentoragent.net/api/novior-mentoragent-rag/mentorvectorstoreragsource-1
- Verified with: MentorAgent 1.4.0
- Last updated: 2026-11-18
- Packages: Novior.MentorAgent

An [`IMentorRagSource`](https://docs.mentoragent.net/api/novior-mentoragent-rag/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>`](https://docs.mentoragent.net/api/novior-mentoragent-rag/mentorvectorstoreragoptions-1) what of a record is the document and its citation.

```text title="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`](https://docs.mentoragent.net/api/novior-mentoragent-rag/mentorvectorstoreragoptions-1#embeddinggenerator), else with `MentorOptions.EmbeddingGenerator`, once per turn for each model ([`IMentorQueryEmbedding`](https://docs.mentoragent.net/api/novior-mentoragent-rag/imentorqueryembedding)), else by the collection itself. The source keeps no state of its own.

## Definition

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

`public sealed class MentorVectorStoreRagSource<TRecord> : IMentorRagSource`

Implements [`IMentorRagSource`](https://docs.mentoragent.net/api/novior-mentoragent-rag/imentorragsource).

```shell
dotnet add package Novior.MentorAgent
```

## Constructors

`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`](https://docs.mentoragent.net/api/novior-mentoragent-rag/mentorvectorstoreragoptions-1#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.

## Properties

### `DefaultMinScore`

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

## Methods

### `SearchAsync`

`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`](https://docs.mentoragent.net/api/novior-mentoragent-rag/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`](https://docs.mentoragent.net/api/novior-mentoragent-rag/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).

---

- Previous: [MentorVectorStoreRagOptions<TRecord>](https://docs.mentoragent.net/api/novior-mentoragent-rag/mentorvectorstoreragoptions-1.md)
- Next: [A2ADetailBar class](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-components/a2adetailbar.md)
