A powerful AI-powered document search application that allows you to upload PDF documents and ask questions about their content using Retrieval-Augmented Generation (RAG) technology.
- π PDF Upload: Upload PDF documents for processing
- π€ AI Chat: Ask questions about your documents using Mistral AI
- π Vector Search: Uses FAISS for efficient document retrieval
- π¨ Modern UI: Clean, responsive interface built with React and Tailwind CSS
- π³ Docker Support: Easy deployment with Docker Compose
- FastAPI: Modern Python web framework
- LangChain: Framework for building LLM applications
- FAISS: Vector database for similarity search
- Mistral AI: Large language model for question answering
- HuggingFace Embeddings: Sentence transformers for document embeddings
- React: JavaScript library for building user interfaces
- Vite: Fast build tool and development server
- Tailwind CSS: Utility-first CSS framework
- Node.js (v14 or higher) and npm
- Python (3.9 or higher)
- Mistral API key (get one from Mistral AI)
- Docker and Docker Compose (optional, for containerized deployment)
-
Clone the repository
git clone https://github.com/Sayeem3051/Chatbot-RAG-.git cd Chatbot-RAG- -
Get your Mistral API key
- Sign up at Mistral AI
- Copy your API key
-
Edit the batch script
- Open
start_backend.batin a text editor - Replace
your-mistral-api-key-herewith your actual API key
- Open
-
Start the application
# Option A: Start both frontend and backend automatically start_all.bat # Option B: Start them separately start_backend.bat # Then in another terminal: cd frontend && npm run dev
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
-
Set up environment variables
# Copy the example environment file cp env.example .env # Edit .env and add your Mistral API key MISTRAL_API_KEY=your-actual-api-key-here
-
Run with Docker Compose
docker-compose up --build
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
-
Navigate to backend directory
cd backend -
Create virtual environment
python -m venv venv # Activate virtual environment # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Set environment variable
# Windows PowerShell: $env:MISTRAL_API_KEY="your-mistral-api-key-here" # Windows Command Prompt: set MISTRAL_API_KEY=your-mistral-api-key-here # macOS/Linux: export MISTRAL_API_KEY="your-mistral-api-key-here"
-
Run the server (IMPORTANT: Must be run from backend directory)
# Make sure you're in the backend directory! uvicorn main:app --reload --host 0.0.0.0 --port 8000
-
Navigate to frontend directory
cd frontend -
Install dependencies
npm install
-
Run development server
npm run dev
- Backend: Always run
uvicornfrom thebackenddirectory, not the project root - Frontend: Always run
npm run devfrom thefrontenddirectory, not the project root - API Key: Make sure your Mistral API key is set before starting the backend
- Upload a PDF: Click "Choose File" and select a PDF document, then click "Upload PDF"
- Ask Questions: Type your question in the input field and click "Ask"
- View Responses: The AI will provide answers based on the content of your uploaded document
Upload a PDF file for processing.
Request: Multipart form data with PDF file Response:
{
"status": "success",
"message": "PDF processed successfully."
}Ask a question about the uploaded document.
Request:
{
"question": "Your question here"
}Response:
{
"answer": "AI-generated answer based on document content"
}MISTRAL_API_KEY: Your Mistral AI API key (required)
- Never commit your actual API key to version control
- The
.envfile is already included in.gitignoreto prevent accidental commits - Use the
env.examplefile as a template for your environment variables - Keep your API keys secure and rotate them regularly
The application uses the following models by default:
- Embeddings:
sentence-transformers/all-MiniLM-L6-v2 - LLM:
open-mistral-7b
You can modify these in backend/main.py if needed.
This project includes convenient batch scripts to simplify startup:
- Automatically navigates to the backend directory
- Activates the Python virtual environment
- Sets the Mistral API key
- Starts the FastAPI server
- Starts both backend and frontend servers automatically
- Opens two terminal windows (one for each server)
- Handles all directory navigation and environment setup
To customize the API key:
- Open
start_backend.batin a text editor - Replace
your-mistral-api-key-herewith your actual Mistral API key - Save the file
Usage:
# Start both servers
start_all.bat
# Or start backend only
start_backend.bat-
"Could not import module 'main'" error
- Cause: Running uvicorn from the wrong directory
- Solution: Always run
uvicorn main:appfrom thebackenddirectory, not the project root - Check: Your terminal should show
C:\path\to\project\backend>notC:\path\to\project>
-
"Missing script: 'dev'" error
- Cause: Running
npm run devfrom the wrong directory - Solution: Always run
npm run devfrom thefrontenddirectory, not the project root - Check: Your terminal should show
C:\path\to\project\frontend>notC:\path\to\project>
- Cause: Running
-
"localhost refused to connect" (ERR_CONNECTION_REFUSED)
- Backend not running: Check if backend is running on http://localhost:8000
- Frontend not running: Check if frontend is running on http://localhost:3000
- Solution: Use
start_all.batto start both servers automatically
-
"No document uploaded yet" error
- Make sure to upload a PDF file before asking questions
-
API key issues
- Verify your Mistral API key is correctly set
- Check that the API key has sufficient credits
- Make sure the API key is set before starting the backend
-
CORS errors
- The backend is configured to allow all origins for development
- For production, update the CORS settings in
backend/main.py
If you see any import errors:
# Navigate to the correct directory first!
cd backend
uvicorn main:app --host 0.0.0.0 --port 8000If frontend won't start:
# Navigate to the correct directory first!
cd frontend
npm run devEasy solution - Use the batch scripts:
# This handles everything automatically
start_all.batBackend is working correctly when you see:
INFO: Started server process [XXXX]
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: 127.0.0.1:XXXXX - "POST /upload HTTP/1.1" 200 OK
INFO: 127.0.0.1:XXXXX - "POST /chat HTTP/1.1" 200 OK
Frontend is working correctly when you see:
VITE v4.5.14 ready in XXX ms
β Local: http://localhost:3000/
β Network: http://192.168.1.X:3000/
Normal log messages (not errors):
"GET / HTTP/1.1" 404 Not Found- This is normal, the root path doesn't existLangChainDeprecationWarning- This is just a warning, the app still works
- For large PDFs, the processing time may be longer
- The vector database is stored in memory and will be lost when the server restarts
- Consider implementing persistent storage for production use
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
For issues and questions, please open an issue on GitHub.