|
| 1 | +## RAG Chatbot |
| 2 | + |
| 3 | +A full-stack Retrieval-Augmented Generation (RAG) application that enables intelligent, document-based question answering. |
| 4 | +The system integrates a FastAPI backend powered by LangChain, FAISS, and AI models, alongside a modern React + Vite + Tailwind CSS frontend for an intuitive chat experience. |
| 5 | + |
| 6 | +## Table of Contents |
| 7 | + |
| 8 | +- [Project Overview](#project-overview) |
| 9 | +- [Features](#features) |
| 10 | +- [Architecture](#architecture) |
| 11 | +- [Prerequisites](#prerequisites) |
| 12 | +- [Quick Start Deployment](#quick-start-deployment) |
| 13 | +- [User Interface](#user-interface) |
| 14 | +- [Troubleshooting](#troubleshooting) |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Project Overview |
| 19 | + |
| 20 | +The **RAG Chatbot** demonstrates how retrieval-augmented generation can be used to build intelligent, document-grounded conversational systems. It retrieves relevant information from a knowledge base, passes it to a large language model, and generates a concise and reliable answer to the user’s query. This project integrates seamlessly with cloud-hosted APIs or local model endpoints, offering flexibility for research, enterprise, or educational use. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Features |
| 25 | + |
| 26 | +**Backend** |
| 27 | + |
| 28 | +- Clean PDF upload with validation |
| 29 | +- LangChain-powered document processing |
| 30 | +- FAISS-CPU vector store for efficient similarity search |
| 31 | +- Enterprise inference endpoints for embeddings and LLM |
| 32 | +- Keycloak authentication for secure API access |
| 33 | +- Comprehensive error handling and logging |
| 34 | +- File validation and size limits |
| 35 | +- CORS enabled for web integration |
| 36 | +- Health check endpoints |
| 37 | +- Modular architecture (routes + services) |
| 38 | + |
| 39 | +**Frontend** |
| 40 | + |
| 41 | +- PDF file upload with drag-and-drop support |
| 42 | +- Real-time chat interface |
| 43 | +- Modern, responsive design with Tailwind CSS |
| 44 | +- Built with Vite for fast development |
| 45 | +- Live status updates |
| 46 | +- Mobile-friendly |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## Architecture |
| 51 | + |
| 52 | +Below is the architecture as it consists of a server that waits for documents to embed and index into a vector database. Once documents have been uploaded, the server will wait for user queries which initiates a similarity search in the vector database before calling the LLM service to summarize the findings. |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +**Service Components:** |
| 57 | + |
| 58 | +1. **React Web UI (Port 3000)** - Provides intuitive chat interface with drag-and-drop PDF upload, real-time messaging, and document-grounded Q&A interaction |
| 59 | + |
| 60 | +2. **FastAPI Backend (Port 5001)** - Handles document processing, FAISS vector storage, LangChain integration, and orchestrates retrieval-augmented generation for accurate responses |
| 61 | + |
| 62 | +**Typical Flow:** |
| 63 | + |
| 64 | +1. User uploads a document through the web UI. |
| 65 | +2. The backend processes the document by splitting it and transforming it into embeddings before storing it in the vector database. |
| 66 | +3. User sends a question through the web UI. |
| 67 | +4. The backend retrieves relevant content from stored documents. |
| 68 | +5. The model generates a response based on retrieved context. |
| 69 | +6. The answer is displayed to the user via the UI. |
| 70 | + |
| 71 | +--- |
| 72 | + |
| 73 | +## Prerequisites |
| 74 | + |
| 75 | +### System Requirements |
| 76 | + |
| 77 | +Before you begin, ensure you have the following installed: |
| 78 | + |
| 79 | +- **Docker and Docker Compose** |
| 80 | +- **Enterprise inference endpoint access** (Keycloak authentication) |
| 81 | + |
| 82 | +### Verify Docker Installation |
| 83 | + |
| 84 | +```bash |
| 85 | +# Check Docker version |
| 86 | +docker --version |
| 87 | + |
| 88 | +# Check Docker Compose version |
| 89 | +docker compose version |
| 90 | + |
| 91 | +# Verify Docker is running |
| 92 | +docker ps |
| 93 | +``` |
| 94 | + |
| 95 | +## Quick Start Deployment |
| 96 | + |
| 97 | +### Clone the Repository |
| 98 | + |
| 99 | +```bash |
| 100 | +git clone https://github.com/opea-project/GenAIExamples.git |
| 101 | +cd GenAIExamples/RAGChatbot |
| 102 | +``` |
| 103 | + |
| 104 | +### Set up the Environment |
| 105 | + |
| 106 | +This application requires an `.env` file in the `api` directory for proper configuration. Create it with the commands below: |
| 107 | + |
| 108 | +```bash |
| 109 | +# Create the .env file in the api directory |
| 110 | +mkdir -p api |
| 111 | +cat > api/.env << EOF |
| 112 | +# Backend API URL (accessible from frontend) |
| 113 | +VITE_API_URL=https://backend:5000 |
| 114 | +
|
| 115 | +# Required - Enterprise/Keycloak Configuration |
| 116 | +BASE_URL=https://api.example.com |
| 117 | +KEYCLOAK_REALM=master |
| 118 | +KEYCLOAK_CLIENT_ID=api |
| 119 | +KEYCLOAK_CLIENT_SECRET=your_client_secret |
| 120 | +
|
| 121 | +# Required - Model Configuration |
| 122 | +EMBEDDING_MODEL_ENDPOINT=bge-base-en-v1.5 |
| 123 | +INFERENCE_MODEL_ENDPOINT=Llama-3.1-8B-Instruct |
| 124 | +EMBEDDING_MODEL_NAME=bge-base-en-v1.5 |
| 125 | +INFERENCE_MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct |
| 126 | +EOF |
| 127 | +``` |
| 128 | + |
| 129 | +Or manually create `api/.env` with: |
| 130 | + |
| 131 | +```bash |
| 132 | +# Backend API URL (accessible from frontend) |
| 133 | +VITE_API_URL=https://backend:5000 |
| 134 | + |
| 135 | +# Required - Enterprise/Keycloak Configuration |
| 136 | +BASE_URL=https://api.example.com |
| 137 | +KEYCLOAK_REALM=master |
| 138 | +KEYCLOAK_CLIENT_ID=api |
| 139 | +KEYCLOAK_CLIENT_SECRET=your_client_secret |
| 140 | + |
| 141 | +# Required - Model Configuration |
| 142 | +EMBEDDING_MODEL_ENDPOINT=bge-base-en-v1.5 |
| 143 | +INFERENCE_MODEL_ENDPOINT=Llama-3.1-8B-Instruct |
| 144 | +EMBEDDING_MODEL_NAME=bge-base-en-v1.5 |
| 145 | +INFERENCE_MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct |
| 146 | +``` |
| 147 | + |
| 148 | +**Note**: The docker-compose.yml file automatically loads environment variables from `./api/.env` for the backend service. |
| 149 | + |
| 150 | +### Running the Application |
| 151 | + |
| 152 | +Start both API and UI services together with Docker Compose: |
| 153 | + |
| 154 | +```bash |
| 155 | +# From the rag-chatbot directory |
| 156 | +docker compose up --build |
| 157 | + |
| 158 | +# Or run in detached mode (background) |
| 159 | +docker compose up -d --build |
| 160 | +``` |
| 161 | + |
| 162 | +The API will be available at: `http://localhost:5001` |
| 163 | +The UI will be available at: `http://localhost:3000` |
| 164 | + |
| 165 | +**View logs**: |
| 166 | + |
| 167 | +```bash |
| 168 | +# All services |
| 169 | +docker compose logs -f |
| 170 | + |
| 171 | +# Backend only |
| 172 | +docker compose logs -f backend |
| 173 | + |
| 174 | +# Frontend only |
| 175 | +docker compose logs -f frontend |
| 176 | +``` |
| 177 | + |
| 178 | +**Verify the services are running**: |
| 179 | + |
| 180 | +```bash |
| 181 | +# Check API health |
| 182 | +curl http://localhost:5001/health |
| 183 | + |
| 184 | +# Check if containers are running |
| 185 | +docker compose ps |
| 186 | +``` |
| 187 | + |
| 188 | +## User Interface |
| 189 | + |
| 190 | +**Using the Application** |
| 191 | + |
| 192 | +Make sure you are at the localhost:3000 url |
| 193 | + |
| 194 | +You will be directed to the main page which has each feature |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | +Upload a PDF: |
| 199 | + |
| 200 | +- Drag and drop a PDF file, or |
| 201 | +- Click "Browse Files" to select a file |
| 202 | +- Wait for processing to complete |
| 203 | + |
| 204 | +Start chatting: |
| 205 | + |
| 206 | +- Type your question in the input field |
| 207 | +- Press Enter or click Send |
| 208 | +- Get AI-powered answers based on your document |
| 209 | + |
| 210 | +**UI Configuration** |
| 211 | + |
| 212 | +When running with Docker Compose, the UI automatically connects to the backend API. The frontend is available at `http://localhost:3000` and the API at `http://localhost:5001`. |
| 213 | + |
| 214 | +For production deployments, you may want to configure a reverse proxy or update the API URL in the frontend configuration. |
| 215 | + |
| 216 | +### Stopping the Application |
| 217 | + |
| 218 | + |
| 219 | +```bash |
| 220 | +docker compose down |
| 221 | +``` |
| 222 | + |
| 223 | +## Troubleshooting |
| 224 | + |
| 225 | +For comprehensive troubleshooting guidance, common issues, and solutions, refer to: |
| 226 | + |
| 227 | +[Troubleshooting Guide - TROUBLESHOOTING.md](./TROUBLESHOOTING.md) |
0 commit comments