Table of Contents

Class RagStore

Namespace
Mythosia.AI.Rag
Assembly
Mythosia.AI.Rag.dll

A pre-built, shareable RAG index. Build once, share across multiple AIService instances.

public class RagStore
Inheritance
RagStore
Inherited Members
Extension Methods

Methods

BuildAsync(Action<RagBuilder>, Func<IReadOnlyList<VectorRecord>, Task>?, CancellationToken)

Builds a RagStore by loading, splitting, embedding, and indexing all configured documents. The resulting store can be shared across multiple AIService instances.

public static Task<RagStore> BuildAsync(Action<RagBuilder> configure, Func<IReadOnlyList<VectorRecord>, Task>? onDocumentEmbedded = null, CancellationToken cancellationToken = default)

Parameters

configure Action<RagBuilder>

Configuration delegate for the RAG builder.

onDocumentEmbedded Func<IReadOnlyList<VectorRecord>, Task>

Optional callback invoked after each document's embedding is complete. When provided, replaces the default UpsertBatchAsync call โ€” the callback receives the generated VectorRecord list and decides how to persist them. When omitted, records are saved to the configured store automatically.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<RagStore>

Examples

// Default: embed and save to store automatically
var ragStore = await RagStore.BuildAsync(config => config
    .AddDocuments("./knowledge-base/")
    .UseOpenAIEmbedding(apiKey)
);

// With callback: replace vectors atomically per document
var ragStore = await RagStore.BuildAsync(config => config
    .AddDocuments(loader, filePath)
    .UseEmbedding(embeddingProvider)
    .UseStore(vectorStore),
    onDocumentEmbedded: records =>
        vectorStore.ReplaceByFilterAsync(
            VectorFilter.ByMetadata("full_path", filePath), records),
);

QueryAsync(string, RagQueryOptions?, CancellationToken)

Processes a query through the RAG pipeline with per-request query overrides.

public Task<RagProcessedQuery> QueryAsync(string query, RagQueryOptions? options, CancellationToken cancellationToken = default)

Parameters

query string
options RagQueryOptions
cancellationToken CancellationToken

Returns

Task<RagProcessedQuery>

QueryAsync(string, IReadOnlyList<ConversationTurn>?, RagQueryOptions?, CancellationToken)

Processes a query through the RAG pipeline with automatic query rewriting and per-request query overrides.

public Task<RagProcessedQuery> QueryAsync(string query, IReadOnlyList<ConversationTurn>? conversationHistory, RagQueryOptions? options, CancellationToken cancellationToken = default)

Parameters

query string
conversationHistory IReadOnlyList<ConversationTurn>
options RagQueryOptions
cancellationToken CancellationToken

Returns

Task<RagProcessedQuery>

QueryAsync(string, IReadOnlyList<ConversationTurn>?, CancellationToken)

Processes a query through the RAG pipeline with automatic query rewriting for multi-turn conversations. If a Mythosia.AI.Rag.RagStore.QueryRewriter is configured and conversation history is provided, the query is rewritten into retrieval-ready form before search, and retrieval-oriented keywords may also be derived.

public Task<RagProcessedQuery> QueryAsync(string query, IReadOnlyList<ConversationTurn>? conversationHistory, CancellationToken cancellationToken = default)

Parameters

query string

The current user query.

conversationHistory IReadOnlyList<ConversationTurn>

Previous conversation turns for context, or null to skip rewriting.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<RagProcessedQuery>

QueryAsync(string, CancellationToken)

Processes a query through the RAG pipeline: embed โ†’ search โ†’ build context. Returns the request message content and references without calling an LLM.

public Task<RagProcessedQuery> QueryAsync(string query, CancellationToken cancellationToken = default)

Parameters

query string
cancellationToken CancellationToken

Returns

Task<RagProcessedQuery>

SetQueryRewriter(IQueryRewriter?)

Sets or clears the query rewriter at runtime. Pass null to disable query rewriting and retrieval keyword derivation.

public void SetQueryRewriter(IQueryRewriter? queryRewriter)

Parameters

queryRewriter IQueryRewriter

UpdateOptions(Action<RagPipelineOptions>)

Updates pipeline options at runtime without rebuilding the index.

public bool UpdateOptions(Action<RagPipelineOptions> configure)

Parameters

configure Action<RagPipelineOptions>

Returns

bool

Examples

store.UpdateOptions(opt =>
{
    opt.TopK = 8;
    opt.MinScore = 0.4;
    opt.RetrievalMultiplier = 3;
    opt.PromptTemplate = "Based on:\n{context}\n\nQuestion: {question}";
});

UpdateRetrievalStrategy(bool, float)

Switches the retrieval strategy at runtime between vector-only and hybrid search without rebuilding the entire pipeline or re-indexing documents. Returns false if the underlying pipeline does not support runtime updates.

public bool UpdateRetrievalStrategy(bool useHybridSearch, float vectorWeight = 0.5)

Parameters

useHybridSearch bool

True to enable hybrid (vector + BM25) search, false for vector-only.

vectorWeight float

Weight for vector similarity [0, 1] when hybrid is enabled. 0.5 = equal weight.

Returns

bool