I’ve been exploring Retrieval-Augmented Generation (RAG) in .NET and noticed that most approaches I tried either came bundled with more features than I needed or required setting up external services like vector databases or cloud APIs.
So I built RAGSharp - a small C# library that focuses on the basics:
load → chunk → embed → search
What it includes
- Document loading (files, directories, web, Wikipedia; custom loaders supported)
- Token-aware text chunking (SharpToken for GPT-style tokenization)
- Embeddings (works with OpenAI-compatible endpoints, so LM Studio, Ollama, vLLM, or custom providers)
- Vector stores (in-memory/file-backed, no DB required; extensible to Postgres/Qdrant)
- A simple retriever to tie it all together
Quick example
var docs = await new FileLoader().LoadAsync("sample.txt");
var retriever = new RagRetriever(
new OpenAIEmbeddingClient("http://localhost:1234/v1", "lmstudio", "bge-large"),
new InMemoryVectorStore()
);
await retriever.AddDocumentsAsync(docs);
var results = await retriever.Search("quantum mechanics", topK: 3);
If you’re experimenting with RAG in .NET, I’d love to hear your feedback or ideas for making it more useful in real projects.
Top comments (0)