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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Competence Standards RAG Chatbot
|
| 2 |
+
|
| 3 |
+
A production-ready Retrieval-Augmented Generation (RAG) chatbot designed to provide assistance with competence standards in higher education. This application uses Chainlit for the user interface, Milvus for vector storage, and Nebius AI for embeddings and chat completion.
|
| 4 |
+
|
| 5 |
+
## π Table of Contents
|
| 6 |
+
|
| 7 |
+
- [About the Project](#about-the-project)
|
| 8 |
+
- [Features](#features)
|
| 9 |
+
- [Prerequisites](#prerequisites)
|
| 10 |
+
- [Installation](#installation)
|
| 11 |
+
- [Configuration](#configuration)
|
| 12 |
+
- [Starting the Application](#starting-the-application)
|
| 13 |
+
- [Database Population](#database-population)
|
| 14 |
+
- [Data Management](#data-management)
|
| 15 |
+
- [Testing](#testing)
|
| 16 |
+
|
| 17 |
+
## π― About the Project
|
| 18 |
+
|
| 19 |
+
This RAG chatbot is specifically designed to assist with competence standards in higher education settings. It provides intelligent responses based on a curated knowledge base of documents.
|
| 20 |
+
|
| 21 |
+
The system uses advanced natural language processing to understand queries and retrieve relevant information from the document corpus, providing contextually appropriate responses.
|
| 22 |
+
|
| 23 |
+
## β¨ Features
|
| 24 |
+
|
| 25 |
+
- **Interactive Chat Interface**: Built with Chainlit for an intuitive user experience
|
| 26 |
+
- **Vector Search**: Powered by Milvus for efficient similarity search
|
| 27 |
+
- **Advanced Embeddings**: Uses Nebius AI Qwen3-Embedding-8B model
|
| 28 |
+
- **Document Processing**: Supports multiple formats (PDF, DOCX, HTML)
|
| 29 |
+
- **Authentication**: Integrated with Chainlit's authentication system
|
| 30 |
+
- **Persistent Storage**: Database integration with PostgreSQL
|
| 31 |
+
- **Containerized Deployment**: Docker Compose setup for easy deployment
|
| 32 |
+
- **Testing Suite**: Comprehensive testing with RAGAS evaluation
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
## π Installation
|
| 36 |
+
|
| 37 |
+
1. **Clone the repository**
|
| 38 |
+
```bash
|
| 39 |
+
git clone https://github.com/daniel-was-taken/prod-rag-chat.git
|
| 40 |
+
cd prod-rag-chat
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
2. **Create a virtual environment**
|
| 44 |
+
```bash
|
| 45 |
+
python -m venv venv
|
| 46 |
+
|
| 47 |
+
# On Windows
|
| 48 |
+
.\venv\Scripts\activate
|
| 49 |
+
|
| 50 |
+
# On macOS/Linux
|
| 51 |
+
source venv/bin/activate
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
3. **Install dependencies**
|
| 55 |
+
```bash
|
| 56 |
+
pip install -r requirements.txt
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
## βοΈ Configuration
|
| 60 |
+
|
| 61 |
+
1. **Create environment file**
|
| 62 |
+
```bash
|
| 63 |
+
cp .env.example .env # If available, or create manually
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
+
2. **Configure environment variables**
|
| 67 |
+
Create a `.env` file in the root directory with the following variables:
|
| 68 |
+
```env
|
| 69 |
+
# Nebius AI Configuration
|
| 70 |
+
NEBIUS_API_KEY=your_nebius_api_key_here
|
| 71 |
+
OPENAI_API_KEY=your_openai_api_key_here # Fallback
|
| 72 |
+
|
| 73 |
+
# Milvus Configuration
|
| 74 |
+
MILVUS_URI=http://localhost:19530
|
| 75 |
+
|
| 76 |
+
# Chainlit Configuration
|
| 77 |
+
CHAINLIT_AUTH_SECRET=your_auth_secret_here
|
| 78 |
+
|
| 79 |
+
# Database Configuration (if using PostgreSQL)
|
| 80 |
+
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
## π¬ Starting the Application
|
| 84 |
+
|
| 85 |
+
### Method 1: Using Docker Compose (Recommended)
|
| 86 |
+
|
| 87 |
+
1. **Start the infrastructure services**
|
| 88 |
+
```bash
|
| 89 |
+
docker-compose up -d
|
| 90 |
+
```
|
| 91 |
+
This will start:
|
| 92 |
+
- Milvus vector database
|
| 93 |
+
- etcd (for Milvus coordination)
|
| 94 |
+
- MinIO (for Milvus storage)
|
| 95 |
+
|
| 96 |
+
2. **Wait for services to be ready**
|
| 97 |
+
|
| 98 |
+
3. **Start the Chainlit application**
|
| 99 |
+
```bash
|
| 100 |
+
chainlit run app.py -w
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
### Method 2: Manual Setup
|
| 104 |
+
|
| 105 |
+
1. **Install and configure Milvus standalone**
|
| 106 |
+
Follow the [Milvus installation guide](https://milvus.io/docs/install_standalone-docker.md)
|
| 107 |
+
|
| 108 |
+
2. **Start the application**
|
| 109 |
+
```bash
|
| 110 |
+
chainlit run app.py -w
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
The application will be available at `http://localhost:8000`
|
| 114 |
+
|
| 115 |
+
## π Database Population
|
| 116 |
+
|
| 117 |
+
The system automatically populates the vector database on first startup. However, you can manually manage the data:
|
| 118 |
+
|
| 119 |
+
### Automatic Population
|
| 120 |
+
|
| 121 |
+
The application automatically checks if the Milvus collection exists and has data. If not, it runs the population script automatically.
|
| 122 |
+
|
| 123 |
+
### Manual Population
|
| 124 |
+
|
| 125 |
+
To manually populate or repopulate the database:
|
| 126 |
+
|
| 127 |
+
```bash
|
| 128 |
+
python populate_db.py
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
### Adding New Documents
|
| 132 |
+
|
| 133 |
+
1. **Add documents to the data directory**
|
| 134 |
+
```bash
|
| 135 |
+
# Place your documents in the data/ folder
|
| 136 |
+
cp your_new_document.pdf data/
|
| 137 |
+
cp your_new_document.docx data/
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
2. **Supported file formats:**
|
| 141 |
+
- PDF files (`.pdf`)
|
| 142 |
+
- Microsoft Word documents (`.docx`)
|
| 143 |
+
- HTML files (`.html`)
|
| 144 |
+
|
| 145 |
+
3. **Repopulate the database**
|
| 146 |
+
```bash
|
| 147 |
+
# Delete existing collection
|
| 148 |
+
python delete_collection.py
|
| 149 |
+
|
| 150 |
+
# Repopulate with new documents
|
| 151 |
+
python populate_db.py
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
### Database Configuration
|
| 155 |
+
|
| 156 |
+
The population script uses the following configuration:
|
| 157 |
+
|
| 158 |
+
- **Embedding Model**: Qwen/Qwen3-Embedding-8B (4096 dimensions)
|
| 159 |
+
- **Chunk Size**: 1500 characters maximum
|
| 160 |
+
- **Combine Threshold**: 200 characters minimum
|
| 161 |
+
- **Batch Size**: 5 documents per batch
|
| 162 |
+
- **Collection Name**: `my_rag_collection`
|
| 163 |
+
|
| 164 |
+
### Document Processing Pipeline
|
| 165 |
+
|
| 166 |
+
1. **Loading**: Documents are loaded using UnstructuredLoader
|
| 167 |
+
2. **Cleaning**: Text is cleaned and normalized
|
| 168 |
+
3. **Chunking**: Documents are split into manageable chunks
|
| 169 |
+
4. **Embedding**: Chunks are converted to vector embeddings
|
| 170 |
+
5. **Storage**: Embeddings are stored in Milvus with metadata
|
| 171 |
+
|
| 172 |
+
## ποΈ Data Management
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
### Deleting the Collection
|
| 176 |
+
|
| 177 |
+
```bash
|
| 178 |
+
python delete_collection.py
|
| 179 |
+
```
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
### Updating Documents
|
| 183 |
+
|
| 184 |
+
To update the document corpus:
|
| 185 |
+
|
| 186 |
+
1. Add/remove documents in the `data/` directory
|
| 187 |
+
2. Delete the existing collection: `python delete_collection.py`
|
| 188 |
+
3. Restart the application (it will automatically repopulate)
|
| 189 |
+
|
| 190 |
+
## π§ͺ Testing
|
| 191 |
+
|
| 192 |
+
The project includes comprehensive testing:
|
| 193 |
+
|
| 194 |
+
### Running Unit Tests
|
| 195 |
+
|
| 196 |
+
```bash
|
| 197 |
+
|
| 198 |
+
# Run specific test files
|
| 199 |
+
python -m unittest tests/test_chainlit.py -v
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
### RAGAS Evaluation
|
| 203 |
+
|
| 204 |
+
Evaluate the RAG system performance:
|
| 205 |
+
|
| 206 |
+
```bash
|
| 207 |
+
# Run RAGAS evaluation
|
| 208 |
+
python tests/test_ragas.py
|
| 209 |
+
|
| 210 |
+
# Or use the Jupyter notebook
|
| 211 |
+
jupyter notebook tests/test_ragas.ipynb
|
| 212 |
+
```
|
| 213 |
+
|
| 214 |
+
### Manual Testing
|
| 215 |
+
|
| 216 |
+
Test individual components:
|
| 217 |
+
|
| 218 |
+
```bash
|
| 219 |
+
# Test vector search functionality
|
| 220 |
+
python tests/test_vector_search.py
|
| 221 |
+
|
| 222 |
+
```
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
## π License
|
| 226 |
+
|
| 227 |
+
This project is licensed under the terms specified in the LICENSE file.
|
| 228 |
+
|
| 229 |
+
|
test_chainlit.py β tests/test_chainlit.py
RENAMED
|
File without changes
|
test_ragas.ipynb β tests/test_ragas.ipynb
RENAMED
|
File without changes
|
test_ragas.py β tests/test_ragas.py
RENAMED
|
File without changes
|
test_vector_search.py β tests/test_vector_search.py
RENAMED
|
File without changes
|