All Projects
AI & MLadvanced View on GitHub

.NET RAG Chat

Retrieval-Augmented Generation pipeline in C# with Azure OpenAI and Azure AI Search

2–4 hours to set up (requires Azure subscription)10 technologies5 guided steps

About This Project

Build a production RAG (Retrieval-Augmented Generation) system entirely in .NET using Azure OpenAI for LLM completions, Azure AI Search for vector retrieval, and Semantic Kernel for orchestration. Upload documents, index them with embeddings, and chat with your data — with source citations on every answer.

What You'll Learn

Build a complete RAG pipeline in .NET with Semantic Kernel
Chunk and embed documents with Azure OpenAI embeddings
Implement vector search with Azure AI Search hybrid mode
Stream LLM completions to the browser via Server-Sent Events
Design multi-tenant document isolation for RAG systems

Key Features

Document ingestion: PDF, Word, Markdown → chunked → embedded → indexed
Vector search with Azure AI Search (HNSW index)
Hybrid search: semantic + keyword for better retrieval accuracy
Semantic Kernel orchestrates retrieval + LLM completion
Source citations: every answer links back to the source document + page
Conversation memory: multi-turn chat with context window management
Streaming responses via Server-Sent Events
Multiple knowledge bases — each user/tenant has isolated document sets
Hallucination guard: answers grounded only on retrieved context
React chat UI with streaming message display

Setup Guide

1

Clone and configure Azure credentials

Clone the repo and set Azure keys in user secrets.

bash
git clone https://github.com/asmanasir/dotnet-rag.git
cd dotnet-rag

dotnet user-secrets set "AzureOpenAI:Endpoint" "https://your-instance.openai.azure.com/"
dotnet user-secrets set "AzureOpenAI:ApiKey" "your-key"
dotnet user-secrets set "AzureOpenAI:DeploymentName" "gpt-4o"
dotnet user-secrets set "AzureOpenAI:EmbeddingDeployment" "text-embedding-3-small"
dotnet user-secrets set "AzureSearch:Endpoint" "https://your-search.search.windows.net"
dotnet user-secrets set "AzureSearch:ApiKey" "your-key"
2

Start PostgreSQL with Docker

PostgreSQL stores conversation history and document metadata.

bash
docker-compose up -d db
dotnet ef database update
3

Install frontend dependencies

The React chat UI is in the /frontend directory.

bash
cd frontend && npm install && cd ..

Running the Project

1

Start the API and frontend

Run both in separate terminals.

bash
# Terminal 1 — API
dotnet run --project src/RagChat.Api

# Terminal 2 — React UI
cd frontend && npm run dev
2

Upload a document and chat

Upload a PDF, wait for indexing, then ask questions about it.

bash
# Upload a document
curl -X POST http://localhost:5000/api/documents \
  -F "file=@./sample.pdf"

# Wait for indexing (~10 seconds), then open the chat UI
# http://localhost:3000

Project Info

CategoryAI & ML
Difficultyadvanced
Setup time2–4 hours to set up (requires Azure subscription)
Technologies10 tools

Tech Stack

ASP.NET Core (.NET 8)Semantic KernelAzure OpenAIAzure AI Search (vector index)Azure Blob StorageEF Core 8PostgreSQLDockerReactTypeScript

Prerequisites

  • .NET 8 SDK installed
  • Azure subscription with Azure OpenAI access approved
  • Azure AI Search instance (free tier works)
  • Docker Desktop installed
  • Node.js 18+ for the React frontend
View Source on GitHub
L

Learnixo

Project Author

RAG is the most requested AI pattern in enterprise .NET shops right now. This project shows the full pipeline — document ingestion, embedding, vector search, and grounded generation — using the Semantic Kernel stack that .NET teams are adopting.