Table of Contents

Class RagServiceExtensions

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

Extension methods for AIService to enable RAG functionality. Follows the same Fluent API style as Mythosia.AI's WithFunction, WithSystemMessage, etc.

public static class RagServiceExtensions
Inheritance
RagServiceExtensions
Inherited Members

Methods

WithRag(IAIService, RagStore)

Enables RAG on this AIService using a pre-built RagStore. Use this to share a single index across multiple AIService instances.

public static RagEnabledService WithRag(this IAIService service, RagStore ragStore)

Parameters

service IAIService
ragStore RagStore

Returns

RagEnabledService

Examples

var ragStore = await RagStore.BuildAsync(config => config
    .AddDocuments("./knowledge-base/")
    .UseOpenAIEmbedding(apiKey)
);

var claude = new AnthropicService(claudeKey, http).WithRag(ragStore);
var gpt = new OpenAIService(gptKey, http).WithRag(ragStore);

WithRag(IAIService, Action<RagBuilder>)

Enables RAG on this AIService with the specified configuration. Documents are loaded and indexed lazily on the first query.

public static RagEnabledService WithRag(this IAIService service, Action<RagBuilder> configure)

Parameters

service IAIService
configure Action<RagBuilder>

Returns

RagEnabledService

Examples

var service = new AnthropicService(apiKey, httpClient)
    .WithRag(rag => rag
        .AddDocument("manual.pdf")
        .AddDocument("policy.txt")
    );

var response = await service.GetCompletionAsync("ํ™˜๋ถˆ ์ •์ฑ…์ด ์–ด๋–ป๊ฒŒ ๋˜๋‚˜์š”?");