AI Chatbot with DeepSeek R1 and Local RAG- 🤖 Dual-Mode Chat: Switches between campus-specific and general knowledge
A full-stack, Retrieval-Augmented Generation (RAG) powered chatbot application for campus information. This AI system answers campus-specific questions using a local Q&A dataset and the deepseek-r1:1.5b model via Ollama. It also works as a general-purpose chatbot for unrelated queries.
- ✨ Features
- 🏗️ Project Structure
- ⚙️ Installation
- 🚀 Running the App
- 🔄 How RAG Works
- 🛠️ Customization
- 🧪 Testing
- ❓ FAQ
- 🤝 Contributing
- 📄 License
- 🎯 Accurate Campus Information: Uses
srec_qa.jsonwith RAG for precise answers about your campus - � Dual-Mode Chat: Switches between campus-specific and general knowledge
- ⚡ Local & Private: Runs completely offline with Ollama models
- 🎨 Modern Web Interface: Clean design with real-time chat updates
- 🔄 RAG Integration: Smart context retrieval for accurate campus-related responses
- 🛠️ Modular Architecture: Easy to customize and extend with utils/ helpers
- 🧪 Test Suite: Includes test_chatbot.py for reliability
AI-ChatBot/
├── app.py # Flask backend with RAG integration
├── requirements.txt # Python dependencies
├── test_chatbot.py # Test suite for chatbot functionality
├── Campus_qa.json # Q&A dataset for RAG
├── frontend/ # Frontend assets
│ ├── index.html # Main UI template
│ ├── app.js # Frontend logic and API calls
│ ├── style.css # UI styling
│ └── brain.png # Logo asset
└── utils/ # Utility modules
└── time_helper.py # Time-related utilities
Choose your platform:
📦 Windows
- Download from ollama.com/download
- Run the installer
- Start Ollama from Start Menu
🐧 Linux
curl -fsSL https://ollama.com/install.sh | sh🍎 macOS
curl -fsSL https://ollama.com/install.sh | sh# Pull required models
ollama pull deepseek-r1:1.5b
ollama pull mxbai-embed-large
# Verify installation
ollama list# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt-
Start Ollama Server
ollama serve
-
Launch Backend
python app.py
-
Access the UI
- Open http://localhost:5000
- Start chatting! 💬
-
Question Analysis 🔍
- Detects campus-specific queries
- Routes general queries to standard chat
-
Vector Search 📊
- Embeds questions using mxbai-embed-large
- Performs similarity search in campus Q&A
-
Context Injection 🎯
- Enriches prompts with relevant campus info
- Ensures accurate, grounded responses
-
Response Generation ✨
- Uses Gemma2:2b for natural language
- Maintains conversation context
// campus_qa.json
{
"questions": [
{
"q": "What are the campus timings?",
"a": "Your custom answer here"
}
]
}- Swap models in
app.py:
CHAT_MODEL = "deepseek-r1:1.5b" # Or any Ollama model
EMBED_MODEL = "mxbai-embed-large"Run the test suite:
python test_chatbot.pyAPI Testing:
# Health check
curl http://localhost:5000/health
# Chat endpoint
curl -X POST http://localhost:5000/chat/simple \
-H "Content-Type: application/json" \
-d '{"message": "What are the campus timings?"}'Q: How is data privacy maintained?
All processing happens locally. No data leaves your system.Q: Can I extend the campus knowledge?
Yes! Add Q&A pairs to campus_qa.json.Q: What's the recommended hardware?
- RAM: 8GB minimum, 16GB recommended - GPU: Optional, CPU works fine - Storage: 10GB for modelsWe welcome contributions! See our Contributing Guide for details.
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ❤️ using Gemma2 and Flask