An advanced Retrieval-Augmented Generation (RAG) chatbot featuring an agent-based architecture using Model Context Protocol (MCP) for seamless communication between components. This implementation uses FastAPI for the backend and includes a modular agent system for processing and responding to user queries.
- Multi-format Document Support: Process PDF, DOCX, PPTX, CSV, and TXT files
- Agent-Based Architecture: Modular design with specialized agents for ingestion, retrieval, and response generation
- Model Context Protocol (MCP): Standardized communication protocol between agents
- Vector Search: Semantic search capabilities using FAISS and sentence-transformers
- Web Interface: Interactive UI for document uploads and chat
- Local-First: Runs entirely on your machine with local models by default
- Asynchronous Processing: Non-blocking operations for better performance
IngestionAgent: Processes and chunks uploaded documents, handles text extraction and splittingRetrievalAgent: Performs semantic search using sentence-transformers and FAISSResponseAgent: Generates contextual responses using language modelsCoordinatorAgent: Manages workflow and message routing between agents using MCP
- FAISS Vector Store: Efficient similarity search with
all-MiniLM-L6-v2embeddings (384 dimensions) - Local File System: Stores uploaded documents in the
uploads/directory
POST /api/upload: Upload and process documentsPOST /api/chat: Send chat messages and get responsesGET /health: Check service statusPOST /api/clear_kb: Clear the knowledge base
- Python 3.10+
- pip (Python package manager)
- Git
-
Clone the repository:
git clone https://github.com/yourusername/agentic-chatbot.git cd agentic-chatbot -
Create and activate a virtual environment:
python -m venv venv # Windows: venv\Scripts\activate # Unix/MacOS: source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
Note: The first run will download the
all-MiniLM-L6-v2model (~80MB) -
Set up environment variables:
cp .env.example .env
The default configuration in
.envis pre-configured for local development:# Server HOST=0.0.0.0 PORT=8000 DEBUG=true # Models EMBEDDING_MODEL=all-MiniLM-L6-v2 LLM_MODEL=distilgpt2 # Storage UPLOAD_FOLDER=uploads # Optional: Set to "cuda" if you have a CUDA-compatible GPU # DEVICE=cuda
-
Start the FastAPI server with auto-reload for development:
uvicorn main:app --reload
-
Access the application:
- Web Interface: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
-
Using the Web Interface:
- Navigate to http://localhost:8000
- Click "Upload Document"
- Select a file (PDF, DOCX, PPTX, CSV, or TXT)
- Wait for processing to complete
-
Using the API:
curl -X 'POST' \ 'http://localhost:8000/api/upload' \ -H 'accept: application/json' \ -H 'Content-Type: multipart/form-data' \ -F 'file=@your_document.pdf;type=application/pdf'
-
Web Interface:
- Type your question in the input box
- Press Enter or click "Send"
- View the response with relevant document sources
-
API Usage:
curl -X 'POST' \ 'http://localhost:8000/api/chat' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "message": "What is this document about?", "conversation_id": "optional_conversation_id" }'
The application can be configured using environment variables in the .env file:
# Server Configuration
HOST=0.0.0.0 # Bind address
PORT=8000 # Port to run the server on
DEBUG=true # Enable debug mode (not recommended for production)
# Model Configuration
EMBEDDING_MODEL=all-MiniLM-L6-v2 # Sentence transformer model for embeddings
LLM_MODEL=distilgpt2 # Language model for response generation
# Storage Configuration
UPLOAD_FOLDER=uploads # Directory to store uploaded files
# Hardware Configuration
# DEVICE=cpu # Set to "cuda" if you have a CUDA-compatible GPU
# Logging
LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR, CRITICAL
VECTOR_STORE_PATH=vector_store.faissagentic-chatbot/
├── main.py # Main application and web server
├── document_processor.py # Document parsing and text extraction
├── embedding_service.py # Text embeddings and similarity search
├── agents.py # Agent system with MCP implementation
├── minimal_requirements.txt # Python dependencies
├── uploads/ # Directory for uploaded files
└── README.md
-
Model Loading Issues:
- Ensure you have enough disk space for the models
- Check your internet connection if downloading models for the first time
- Verify the model names in your
.envfile are correct
-
Document Processing Failures:
- Make sure the uploaded files are not corrupted
- Check that the file formats are supported
- Verify file permissions in the uploads directory
-
Performance Issues:
- The application runs locally and may be slow on less powerful machines
- Consider using a smaller model if performance is a concern
MIT License - see the LICENSE file for details.
- FastAPI - Modern Python web framework
- Hugging Face - Transformers and models
- sentence-transformers - For text embeddings