Mythosia.AI.Rag
1.2.0
dotnet add package Mythosia.AI.Rag --version 1.2.0
NuGet\Install-Package Mythosia.AI.Rag -Version 1.2.0
<PackageReference Include="Mythosia.AI.Rag" Version="1.2.0" />
<PackageVersion Include="Mythosia.AI.Rag" Version="1.2.0" />
<PackageReference Include="Mythosia.AI.Rag" />
paket add Mythosia.AI.Rag --version 1.2.0
#r "nuget: Mythosia.AI.Rag, 1.2.0"
#:package Mythosia.AI.Rag@1.2.0
#addin nuget:?package=Mythosia.AI.Rag&version=1.2.0
#tool nuget:?package=Mythosia.AI.Rag&version=1.2.0
Mythosia.AI.Rag
Package Summary
Mythosia.AI.Rag provides RAG (Retrieval-Augmented Generation) as an optional extension for Mythosia.AI.
Install this package to add .WithRag() to any AIService — no changes to the AI core required.
Installation
dotnet add package Mythosia.AI.Rag
Quick Start
using Mythosia.AI.Rag;
var service = new ClaudeService(apiKey, httpClient)
.WithRag(rag => rag
.AddDocument("manual.txt")
.AddDocument("policy.txt")
);
var response = await service.GetCompletionAsync("What is the refund policy?");
That's it. Documents are automatically loaded, chunked, embedded, and indexed on the first query (lazy initialization).
Document Sources
.WithRag(rag => rag
// Single file
.AddDocument("docs/manual.txt")
// All files in a directory (recursive)
.AddDocuments("./knowledge-base/")
// Per-extension routing in a directory
.AddDocuments("./knowledge-base/", src => src
.WithExtension(".pdf")
.WithLoader(new PdfDocumentLoader())
.WithTextSplitter(new CharacterTextSplitter(800, 80))
)
.AddDocuments("./knowledge-base/", src => src
.WithExtension(".docx")
.WithLoader(new WordDocumentLoader())
.WithTextSplitter(new TokenTextSplitter(600, 60))
)
// Inline text
.AddText("Product price is $99.", id: "price-info")
// URL (fetched via HTTP GET)
.AddUrl("https://example.com/faq.txt")
// Custom loader
.AddDocuments(new MyPdfLoader(), "docs/manual.pdf")
)
Search Settings
.WithRag(rag => rag
.AddDocument("docs.txt")
.WithTopK(5) // Number of results to retrieve (default: 3)
.WithChunkSize(500) // Characters per chunk (default: 300)
.WithChunkOverlap(50) // Overlap between chunks (default: 30)
.WithScoreThreshold(0.5) // Minimum similarity score (default: none)
)
Embedding Providers
// Local feature-hashing (default, no API key required)
.UseLocalEmbedding(dimensions: 1024)
// OpenAI embedding API
.UseOpenAIEmbedding(apiKey, model: "text-embedding-3-small", dimensions: 1536)
// Custom provider
.UseEmbedding(new MyCustomEmbeddingProvider())
Vector Stores
// In-memory (default, data lost on process exit)
.UseInMemoryStore()
// Custom store (e.g., Qdrant, Chroma, Pinecone)
.UseStore(new MyQdrantVectorStore())
Prompt Templates
.WithPromptTemplate(@"
[Reference Documents]
{context}
[Question]
{question}
Answer based only on the provided documents.
")
Use {context} and {question} placeholders. If no template is specified, a default numbered-reference format is used.
Streaming
var ragService = new ChatGptService(apiKey, httpClient)
.WithRag(rag => rag.AddDocument("manual.txt"));
await foreach (var chunk in ragService.StreamAsync("How do I use this product?"))
{
Console.Write(chunk);
}
Shared RagStore (Multiple Services)
Build the index once, share across multiple AI services:
var ragStore = await RagStore.BuildAsync(config => config
.AddDocuments("./knowledge-base/")
.UseOpenAIEmbedding(embeddingApiKey)
.WithTopK(5)
);
var claude = new ClaudeService(claudeKey, http).WithRag(ragStore);
var gpt = new ChatGptService(gptKey, http).WithRag(ragStore);
// Both use the same pre-built index
var resp1 = await claude.GetCompletionAsync("What is the refund policy?");
var resp2 = await gpt.GetCompletionAsync("How long does shipping take?");
Disable RAG Per-Request
var ragService = service.WithRag(rag => rag.AddDocument("doc.txt"));
// Use RAG
var withRag = await ragService.GetCompletionAsync("question with context");
// Temporarily bypass RAG
var withoutRag = await ragService.WithoutRag().GetCompletionAsync("general question");
Retrieve Without LLM Call
Inspect the augmented prompt and references before sending to the LLM:
var result = await ragService.RetrieveAsync("What is the refund policy?");
Console.WriteLine(result.AugmentedPrompt); // Context + query
Console.WriteLine(result.References.Count); // Number of matched chunks
foreach (var r in result.References)
{
Console.WriteLine($"Score: {r.Score:F4} | {r.Record.Content}");
}
Architecture
Mythosia.AI (core) <- unchanged
|
Mythosia.AI.Rag.Abstractions <- interfaces (IRagPipeline, IVectorStore, etc.)
|
Mythosia.AI.Rag <- fluent API, pipeline, builders, extensions
Mythosia.AI.VectorDB <- InMemoryVectorStore
Mythosia.AI.Loaders.Abstractions <- IDocumentLoader, RagDocument
The AI core has zero knowledge of RAG. Everything is wired through the IRagPipeline interface and C# extension methods.
Custom Implementations
Custom Embedding Provider
public class MyEmbeddingProvider : IEmbeddingProvider
{
public int Dimensions => 768;
public Task<float[]> GetEmbeddingAsync(string text, CancellationToken ct = default)
{
// Your embedding logic
}
public Task<IReadOnlyList<float[]>> GetEmbeddingsAsync(IEnumerable<string> texts, CancellationToken ct = default)
{
// Batch embedding logic
}
}
Custom Vector Store
public class MyVectorStore : IVectorStore
{
// Implement: CreateCollectionAsync, UpsertAsync, SearchAsync, DeleteAsync, etc.
}
Custom Document Loader
public class MyPdfLoader : IDocumentLoader
{
public Task<IReadOnlyList<RagDocument>> LoadAsync(string source, CancellationToken ct = default)
{
// Parse PDF and return documents
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Mythosia.AI (>= 4.6.2)
- Mythosia.AI.Loaders.Office (>= 1.1.0)
- Mythosia.AI.Loaders.Pdf (>= 1.1.0)
- Mythosia.AI.Rag.Abstractions (>= 1.0.0)
- Mythosia.AI.VectorDB (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.2.0: DocumentSourceBuilder for per-extension routing, MarkdownTextSplitter, RecursiveTextSplitter, CharacterTextSplitter overlap fix, removed semantic splitter.