Skip to content

George-Sakellariou/rag-chatbot-poc

Repository files navigation

RAG Chatbot - Intelligent Document Assistant

.NET React TypeScript Azure OpenAI Qdrant

A production-ready Retrieval-Augmented Generation (RAG) chatbot system that enables intelligent conversations with your documents. Upload PDFs, Word documents, or text files and ask questions about their content using advanced AI capabilities.

πŸš€ Features

Core Capabilities

  • Multi-format Document Processing: PDF, DOCX, DOC, and TXT files
  • Intelligent Document Chunking: Semantic chunking with overlap for context preservation
  • Real-time Chat Interface: Live streaming responses with SignalR
  • Vector Semantic Search: Powered by Qdrant for accurate document retrieval
  • Citation Support: Automatic source document citations in responses
  • Background Processing: Async document processing with real-time status updates

Technical Features

  • Real-time Updates: Live document processing status via SignalR hubs
  • Multi-layer Caching: Redis caching for optimal performance
  • Health Monitoring: Comprehensive health checks for all services
  • Clean Architecture: Modular design with clear separation of concerns
  • Production Ready: Full error handling, logging, and monitoring

πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   React Web    β”‚    β”‚   .NET Core     β”‚    β”‚   Azure OpenAI  β”‚
β”‚   Frontend      │◄──►│   API           │◄──►│   GPT-4o        β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚ SignalR               β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Document      β”‚    β”‚   SQL Server    β”‚    β”‚   Qdrant        β”‚
β”‚   Processing    β”‚    β”‚   Metadata      β”‚    β”‚   Vector DB     β”‚
β”‚   Worker        β”‚    β”‚                 β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Azure Blob    β”‚    β”‚   Redis Cache   β”‚    β”‚   Background    β”‚
β”‚   Storage       β”‚    β”‚                 β”‚    β”‚   Services      β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Project Structure

RagChatbot/
β”œβ”€β”€ RagChatbot.API/              # Web API & SignalR Hubs
β”‚   β”œβ”€β”€ Controllers/             # REST API endpoints
β”‚   β”œβ”€β”€ Hubs/                   # SignalR real-time communication
β”‚   └── frontend/               # React TypeScript frontend
β”œβ”€β”€ RagChatbot.Core/            # Domain entities & interfaces
β”œβ”€β”€ RagChatbot.Application/     # Business logic & services
β”œβ”€β”€ RagChatbot.Infrastructure/  # External service implementations
β”‚   β”œβ”€β”€ Data/                  # EF Core & database
β”‚   β”œβ”€β”€ Services/              # Azure OpenAI, Qdrant, Redis
β”‚   └── Workers/               # Background processing
└── Tests/                     # Unit & integration tests

πŸ›  Technology Stack

Backend

  • .NET 8 - Modern C# web framework
  • ASP.NET Core - REST API with OpenAPI/Swagger
  • SignalR - Real-time bidirectional communication
  • Entity Framework Core - ORM with SQL Server
  • Serilog - Structured logging

Frontend

  • React 18 - Modern component-based UI
  • TypeScript - Type-safe JavaScript
  • Tailwind CSS - Utility-first styling
  • Zustand - Lightweight state management
  • Microsoft SignalR Client - Real-time updates
  • Axios - HTTP client with interceptors

AI & Data

  • Azure OpenAI - GPT-4o for chat, text-embedding-ada-002 for embeddings
  • Qdrant - Vector database for semantic search
  • Redis - Multi-layer caching strategy
  • Azure Blob Storage - Scalable file storage

Document Processing

  • iText7 - PDF text extraction
  • DocumentFormat.OpenXml - Word document processing
  • Semantic Chunking - Intelligent text segmentation

πŸš€ Quick Start

Prerequisites

  • .NET 8 SDK
  • Node.js 18+
  • Docker & Docker Compose
  • Azure OpenAI API access
  • SQL Server (or LocalDB)

1. Clone & Setup

git clone https://github.com/yourusername/rag-chatbot-poc.git
cd rag-chatbot-poc

2. Start Infrastructure Services

# Start Qdrant and Redis
docker-compose up -d qdrant redis

3. Configure Backend

cd RagChatbot.API
cp appsettings.json appsettings.Development.json

Edit appsettings.Development.json:

{
  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=RagChatbotDB;Trusted_Connection=true;",
    "Redis": "localhost:6379"
  },
  "AzureOpenAI": {
    "Endpoint": "https://your-resource.openai.azure.com/",
    "ApiKey": "your-api-key",
    "ChatDeploymentName": "gpt-4o",
    "EmbeddingDeploymentName": "text-embedding-ada-002",
    "ApiVersion": "2024-02-15-preview"
  },
  "Qdrant": {
    "Host": "localhost",
    "Port": 6333,
    "CollectionName": "documents"
  }
}

4. Initialize Database

dotnet ef database update

5. Start Backend

dotnet run

API available at: https://localhost:7262

6. Start Frontend

cd frontend
npm install
npm run dev

Frontend available at: http://localhost:3000

πŸ“– Usage Guide

1. Document Upload

  • Navigate to the Documents page
  • Drag & drop or select files (PDF, DOCX, DOC, TXT)
  • Monitor real-time processing status
  • View processing statistics and chunk counts

2. Chat with Documents

  • Go to the Chat page
  • Create a new chat session
  • Ask questions about your uploaded documents
  • View source citations for all responses

3. Direct Queries

  • Use the Query page for one-off questions
  • Search documents without creating a chat session
  • View similarity scores and source chunks

πŸ”§ Configuration

Environment Variables

# Database
ConnectionStrings__DefaultConnection="Server=localhost;Database=RagChatbot;..."
ConnectionStrings__Redis="localhost:6379"

# Azure OpenAI
AzureOpenAI__Endpoint="https://your-resource.openai.azure.com/"
AzureOpenAI__ApiKey="your-api-key"
AzureOpenAI__ChatDeploymentName="gpt-4o"
AzureOpenAI__EmbeddingDeploymentName="text-embedding-ada-002"

# Qdrant
Qdrant__Host="localhost"
Qdrant__Port="6333"
Qdrant__CollectionName="documents"

# Azure Storage
AzureStorage__ConnectionString="DefaultEndpointsProtocol=https;..."
AzureStorage__ContainerName="documents"

RAG Settings

{
  "RagSettings": {
    "ChunkSize": 500,
    "ChunkOverlap": 50,
    "MaxRetrievedChunks": 5,
    "SimilarityThreshold": 0.7
  }
}

🐳 Docker Deployment

Development

docker-compose up -d

Production

# Build and deploy
docker-compose -f docker-compose.prod.yml up -d

πŸ“Š Monitoring & Health Checks

Health Endpoints

  • /health - Overall application health
  • /health/ready - Readiness probe (DB/Cache)
  • /health/live - Liveness probe
  • /health/external - External service status

Metrics & Logging

  • Serilog structured logging to console and files
  • Application Insights integration ready
  • Health check dashboard for monitoring dependencies

πŸ§ͺ Testing

Backend Tests

# Unit tests
dotnet test RagChatbot.Tests.Unit

# Integration tests
dotnet test RagChatbot.Tests.Integration

# All tests with coverage
dotnet test --collect:"XPlat Code Coverage"

Frontend Tests

cd frontend
npm test
npm run test:coverage

πŸ”’ Security

  • API Authentication ready for JWT integration
  • CORS configured for frontend origins
  • Input validation on all endpoints
  • SQL injection protection via EF Core
  • XSS protection via React's built-in sanitization
  • Secrets management via Azure Key Vault (configurable)

πŸš€ Performance

Optimizations

  • Redis caching for frequently accessed data
  • Connection pooling for database and Redis
  • Lazy loading for large document collections
  • Streaming responses for real-time user experience
  • Background processing for CPU-intensive tasks

Scalability

  • Horizontal scaling ready with stateless design
  • Load balancing compatible
  • Container orchestration ready (Kubernetes)
  • CDN integration for static assets

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Follow SOLID principles and clean architecture
  • Write unit tests for new functionality
  • Update documentation for API changes
  • Use conventional commits for clear history

πŸ“ API Documentation

REST Endpoints

  • Chat Sessions: /api/chat/sessions
  • Documents: /api/documents
  • Queries: /api/query
  • Health: /health

SignalR Hubs

  • Chat Hub: /hubs/chat - Real-time messaging
  • Document Hub: /hubs/documents - Processing updates

Full API documentation available at /swagger when running in development mode.

πŸ›Ÿ Support

Common Issues

  1. Azure OpenAI Connection: Verify endpoint and API key
  2. Qdrant Connection: Ensure Docker container is running
  3. Database Issues: Check connection string and run migrations
  4. Frontend CORS: Verify API URL in frontend configuration

Getting Help

  • Create an issue for bugs or feature requests
  • Check existing issues for solutions
  • Review logs for detailed error information

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🎯 Roadmap

  • Multi-tenant Support - Organization-based document isolation
  • Advanced Analytics - Usage metrics and conversation insights
  • Plugin System - Extensible document processors
  • Mobile App - React Native companion app
  • Voice Interface - Speech-to-text integration
  • Collaborative Features - Shared documents and conversations

Built with ❀️ for intelligent document interaction

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages