Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

AI Chat with Custom Data

A modern .NET 10 Blazor Web Application that enables intelligent conversations with your custom documents using semantic search and vector embeddings.

🚀 Quick Start

Prerequisites

  • .NET 10 SDK
  • Visual Studio 2022 or VS Code
  • GitHub Models API Token (free tier available)

Setup

  1. Add your documents

    • Place PDF files in wwwroot/Data/ directory
    • Example PDFs included: Example_Emergency_Survival_Kit.pdf, Example_GPS_Watch.pdf
  2. Configure GitHub Models Token

    • Right-click project in Solution Explorer → "Manage User Secrets"
    • Add: { "GitHubModels:Token": "YOUR-GITHUB-TOKEN" }
    • Get token here
  3. Run the application

    dotnet run
    • Open https://localhost:5001 and start chatting!

📊 How It Works

Data Flow:

  1. User embeds message to vector representation
  2. Semantic search finds top 5 relevant document chunks in SQLite
  3. AI receives message + context chunks
  4. Response with citations displayed to user

Ingestion Pipeline:

  • PDFs loaded from /wwwroot/Data/
  • Split into semantic chunks
  • Embedded to 1536-dimensional vectors
  • Stored in SQLite vector database

🏗️ Architecture

Component Purpose
Chat.razor Main chat interface
ChatHeader/Input/MessageList.razor UI components
SemanticSearch.cs Vector similarity search
DataIngestor.cs Document ingestion & embedding
PDFDirectorySource.cs PDF loader
IngestedChunk/Document.cs Data models

⚙️ Configuration

appsettings.json

{
  "AiModels": {
    "ChatModel": "gpt-4o-mini",
    "EmbeddingModel": "text-embedding-3-small",
    "Endpoint": "https://models.inference.ai.azure.com"
  }
}

Supported Models

Model Speed Cost Best For
gpt-4o-mini ⚡ Fast $ Low Current (default)
gpt-4o Fast $$ Medium General use
o1 Slow $$$ High Complex reasoning
o1-mini Medium $$ Medium Balanced reasoning
llama-2-70b Fast $ Free Budget option

To switch models: Edit AiModels:ChatModel in appsettings.json


🎯 Key Features

Semantic Search - Find relevant info using meaning, not keywords
Auto Tool Calling - AI decides when to search documents
Citations - Exact quotes with document sources
Copy & Listen - One-click copy and text-to-speech
Edit Questions - Modify and re-ask instantly
Multi-turn Chat - Full conversation context
Configurable Models - Easy model switching
Local Vector DB - Fast, private search


🔒 Security

✅ API keys in User Secrets (not in source control)
✅ Semantic search limits AI to ingested documents
✅ System prompt prevents out-of-context responses
✅ Vector DB local (no cloud content storage)

⚠️ Only ingest trusted documents to prevent prompt injection


📁 Project Structure

AIChatBotS/
├── Components/Pages/Chat/
│   ├── Chat.razor, ChatHeader.razor, ChatInput.razor
│   └── ChatMessageList.razor, ChatMessageItem.razor
├── Services/
│   ├── SemanticSearch.cs
│   └── Ingestion/
│       ├── DataIngestor.cs, PDFDirectorySource.cs
│       └── IngestedChunk.cs, IngestedDocument.cs
├── wwwroot/Data/          (Add PDFs here)
├── Program.cs
├── appsettings.json
└── README.md

🔄 Extending

Add New Document Source

// Implement IIngestionSource interface
// Add to Program.cs:
await DataIngestor.IngestDataAsync(app.Services, new YourCustomSource());

Customize AI Behavior

  • System Prompt: Edit Chat.razor SystemPrompt constant
  • Button Actions: Edit ChatMessageItem.razor
  • Embedding Model: Change EmbeddingModel in appsettings.json

📚 Resources


📞 Troubleshooting

  1. ❌ Chat not working → Verify GitHub token in User Secrets
  2. ❌ No results → Ensure PDFs are in wwwroot/Data/
  3. ❌ Model errors → Check model supports tool calling
  4. ❌ Slow responses → Consider gpt-4o-mini for speed

Built with ❤️ using .NET 10 and Blazor

About

My AI ChatBot Project with latest .Net framework.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages