Table of Contents

Class RagBuilder

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

Fluent builder for configuring a RAG pipeline. Follows the same builder pattern as Mythosia.AI's WithFunction, WithSystemMessage, etc.

public class RagBuilder
Inheritance
RagBuilder
Inherited Members

Methods

AddDocument(string)

Adds a single document file to the RAG index. Automatically selects a loader based on file extension (.docx/.xlsx/.pptx/.pdf).

public RagBuilder AddDocument(string filePath)

Parameters

filePath string

Returns

RagBuilder

AddDocuments(IDocumentLoader, string)

Adds documents using a custom IDocumentLoader.

public RagBuilder AddDocuments(IDocumentLoader loader, string source)

Parameters

loader IDocumentLoader
source string

Returns

RagBuilder

AddDocuments(IDocumentLoader, string, ITextSplitter)

Adds documents using a custom IDocumentLoader with a per-source text splitter.

public RagBuilder AddDocuments(IDocumentLoader loader, string source, ITextSplitter textSplitter)

Parameters

loader IDocumentLoader
source string
textSplitter ITextSplitter

Returns

RagBuilder

AddDocuments(string)

Adds all supported text files from a directory (recursive).

public RagBuilder AddDocuments(string directoryPath)

Parameters

directoryPath string

Returns

RagBuilder

AddDocuments(string, Action<DocumentSourceBuilder>)

Adds documents from a directory with per-extension routing (loader/splitter).

public RagBuilder AddDocuments(string directoryPath, Action<DocumentSourceBuilder> configure)

Parameters

directoryPath string
configure Action<DocumentSourceBuilder>

Returns

RagBuilder

AddExcel(string, IDocumentParser?, OfficeParserOptions?)

Adds an Excel document file to the RAG index.

public RagBuilder AddExcel(string filePath, IDocumentParser? parser = null, OfficeParserOptions? options = null)

Parameters

filePath string
parser IDocumentParser
options OfficeParserOptions

Returns

RagBuilder

AddPowerPoint(string, IDocumentParser?, OfficeParserOptions?)

Adds a PowerPoint document file to the RAG index.

public RagBuilder AddPowerPoint(string filePath, IDocumentParser? parser = null, OfficeParserOptions? options = null)

Parameters

filePath string
parser IDocumentParser
options OfficeParserOptions

Returns

RagBuilder

AddText(string, string?)

Adds raw text content directly to the RAG index.

public RagBuilder AddText(string text, string? id = null)

Parameters

text string

The text content.

id string

Optional unique identifier. Auto-generated if null.

Returns

RagBuilder

AddUrl(string)

Adds a document from a URL. Content is fetched via HTTP GET.

public RagBuilder AddUrl(string url)

Parameters

url string

Returns

RagBuilder

AddWord(string, IDocumentParser?, OfficeParserOptions?)

Adds a Word document file to the RAG index.

public RagBuilder AddWord(string filePath, IDocumentParser? parser = null, OfficeParserOptions? options = null)

Parameters

filePath string
parser IDocumentParser
options OfficeParserOptions

Returns

RagBuilder

UseEmbedding(IEmbeddingProvider)

Uses a custom embedding provider.

public RagBuilder UseEmbedding(IEmbeddingProvider provider)

Parameters

provider IEmbeddingProvider

Returns

RagBuilder

UseFileStore(string)

Uses a file-based vector store for persistence across restarts.

public RagBuilder UseFileStore(string directory)

Parameters

directory string

Returns

RagBuilder

UseHybridSearch(float, double?)

Enables hybrid search combining BM25 keyword matching with dense vector similarity. Uses Reciprocal Rank Fusion (RRF) to merge results.

When the underlying store supports IVectorStore.HybridSearchAsync, the query is delegated natively. Otherwise, BM25 is computed at the application level.

public RagBuilder UseHybridSearch(float vectorWeight = 0.5, double? minScore = null)

Parameters

vectorWeight float

Weight for vector similarity vs keyword matching. Range [0, 1]. 0.5 = equal weight (default), 1.0 = pure vector, 0.0 = pure keyword.

minScore double?

Optional minimum score threshold applied after retrieval. When set, results below this score are discarded.

Returns

RagBuilder

UseInMemoryStore()

Uses the in-memory vector store. This is the default. Data is lost when the process exits.

public RagBuilder UseInMemoryStore()

Returns

RagBuilder

UseLocalEmbedding(int)

Uses the local feature-hashing embedding provider (no API key required). This is the default if no embedding provider is specified.

public RagBuilder UseLocalEmbedding(int dimensions = 1024)

Parameters

dimensions int

Returns

RagBuilder

UseOpenAIEmbedding(string, string, int)

Uses OpenAI's embedding API.

public RagBuilder UseOpenAIEmbedding(string apiKey, string model = "text-embedding-3-small", int dimensions = 1536)

Parameters

apiKey string

OpenAI API key.

model string

Embedding model. Default is "text-embedding-3-small".

dimensions int

Vector dimensions. Default is 1536.

Returns

RagBuilder

UseStore(IVectorStore)

Uses a custom vector store implementation (e.g., Qdrant, Chroma, Pinecone).

public RagBuilder UseStore(IVectorStore store)

Parameters

store IVectorStore

Returns

RagBuilder

UseVectorSearch()

Uses the default pure vector search strategy. This is the default.

public RagBuilder UseVectorSearch()

Returns

RagBuilder

WithChunkOverlap(int)

Sets the overlap between consecutive chunks. Default is 30.

public RagBuilder WithChunkOverlap(int overlap)

Parameters

overlap int

Returns

RagBuilder

WithChunkSize(int)

Sets the chunk size in characters. Default is 300.

public RagBuilder WithChunkSize(int chunkSize)

Parameters

chunkSize int

Returns

RagBuilder

WithContextBuilder(IContextBuilder)

Sets a custom context builder implementation.

public RagBuilder WithContextBuilder(IContextBuilder contextBuilder)

Parameters

contextBuilder IContextBuilder

Returns

RagBuilder

WithFinalSelectionPolicy(RagFinalSelectionMode, double)

Configures how final references are selected after optional re-ranking. By default the pipeline preserves the current reranker-only behavior.

public RagBuilder WithFinalSelectionPolicy(RagFinalSelectionMode mode, double retrievalWeight = 0.65)

Parameters

mode RagFinalSelectionMode
retrievalWeight double

Returns

RagBuilder

WithPromptTemplate(string)

Sets a custom prompt template. Use {context} and {question} placeholders.

public RagBuilder WithPromptTemplate(string template)

Parameters

template string

Returns

RagBuilder

Examples

.WithPromptTemplate(@"
    [์ฐธ๊ณ  ๋ฌธ์„œ]
    {context}

    [์งˆ๋ฌธ]
    {question}

    ๋ฐ˜๋“œ์‹œ ๋ฌธ์„œ ๋‚ด์šฉ์„ ๊ทผ๊ฑฐ๋กœ ๋‹ต๋ณ€ํ•˜์„ธ์š”.
")

WithQueryRewriter()

Enables automatic query rewriting for multi-turn conversations. When enabled, follow-up queries like "tell me more about that" are rewritten into retrieval-ready form using the conversation history, and the rewriter may also derive keyword terms for hybrid/text search. The inner AIService is used as the LLM for rewriting.

public RagBuilder WithQueryRewriter()

Returns

RagBuilder

WithQueryRewriter(IQueryRewriter)

Enables query rewriting with a custom IQueryRewriter implementation. Custom rewriters may both rewrite semantic queries and shape retrieval keywords.

public RagBuilder WithQueryRewriter(IQueryRewriter queryRewriter)

Parameters

queryRewriter IQueryRewriter

Returns

RagBuilder

WithQueryRewriter(uint)

Enables query rewriting with a custom max token limit for the LLM response.

public RagBuilder WithQueryRewriter(uint maxTokens)

Parameters

maxTokens uint

Maximum tokens for the rewriter LLM response.

Returns

RagBuilder

WithReranker(IReranker)

Registers a re-ranker to refine search results after initial retrieval. When set, the retrieval results are passed through the re-ranker before context building.

public RagBuilder WithReranker(IReranker reranker)

Parameters

reranker IReranker

Returns

RagBuilder

WithRetrievalMinScore(double)

public RagBuilder WithRetrievalMinScore(double threshold)

Parameters

threshold double

Returns

RagBuilder

WithRetrievalMultiplier(int)

public RagBuilder WithRetrievalMultiplier(int multiplier)

Parameters

multiplier int

Returns

RagBuilder

WithScoreThreshold(double)

Sets the minimum similarity score threshold. Results below this are discarded.

public RagBuilder WithScoreThreshold(double threshold)

Parameters

threshold double

Returns

RagBuilder

WithTextSplitter(ITextSplitter)

Sets a custom text splitter implementation.

public RagBuilder WithTextSplitter(ITextSplitter textSplitter)

Parameters

textSplitter ITextSplitter

Returns

RagBuilder

WithTopK(int)

Sets the number of top results to retrieve. Default is 3.

public RagBuilder WithTopK(int topK)

Parameters

topK int

Returns

RagBuilder