File size: 5,749 Bytes
cf1035d
 
 
 
 
 
 
 
 
 
39f9b19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d11700
39f9b19
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
---
title: CompifAI
emoji: πŸ’»
colorFrom: gray
colorTo: green
sdk: docker
pinned: false
license: apache-2.0
---

# Competence Standards RAG Chatbot

## πŸ“‹ Table of Contents

- [About the Project](#about-the-project)
- [Features](#features)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Configuration](#configuration)
- [Starting the Application](#starting-the-application)
- [Database Population](#database-population)
- [Data Management](#data-management)
- [Testing](#testing)

## 🎯 About the Project

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.

The system uses advanced natural language processing to understand queries and retrieve relevant information from the document corpus, providing contextually appropriate responses.

## ✨ Features

- **Interactive Chat Interface**: Built with Chainlit for an intuitive user experience
- **Vector Search**: Powered by Milvus for efficient similarity search
- **Advanced Embeddings**: Uses Nebius AI Qwen3-Embedding-8B model
- **Document Processing**: Supports multiple formats (PDF, DOCX, HTML)
- **Authentication**: Integrated with Chainlit's authentication system
- **Persistent Storage**: Database integration with PostgreSQL
- **Containerized Deployment**: Docker Compose setup for easy deployment
- **Testing Suite**: Comprehensive testing with RAGAS evaluation


## πŸš€ Installation

1. **Clone the repository**
   ```bash
   git clone https://github.com/daniel-was-taken/prod-rag-chat.git
   cd prod-rag-chat
   ```

2. **Create a virtual environment**
   ```bash
   python -m venv venv
   
   # On Windows
   .\venv\Scripts\activate
   
   # On macOS/Linux
   source venv/bin/activate
   ```

3. **Install dependencies**
   ```bash
   pip install -r requirements.txt
   ```

## βš™οΈ Configuration

1. **Create environment file**
   ```bash
   cp .env.example .env  # If available, or create manually
   ```

2. **Configure environment variables**
   Create a `.env` file in the root directory with the following variables:
   ```env
   # Nebius AI Configuration
   NEBIUS_API_KEY=your_nebius_api_key_here
   OPENAI_API_KEY=your_openai_api_key_here  # Fallback
   
   # Milvus Configuration
   MILVUS_URI=http://localhost:19530
   
   # Chainlit Configuration
   CHAINLIT_AUTH_SECRET=your_auth_secret_here
   
   # Database Configuration (if using PostgreSQL)
   DATABASE_URL=postgresql://user:password@localhost:5432/dbname
   ```

## 🎬 Starting the Application

### Method 1: Using Docker Compose (Recommended)

1. **Start the infrastructure services**
   ```bash
   docker-compose up -d
   ```
   This will start:
   - Milvus vector database
   - etcd (for Milvus coordination)
   - MinIO (for Milvus storage)

2. **Wait for services to be ready** 

3. **Start the Chainlit application**
   ```bash
   chainlit run app.py -w
   ```

### Method 2: Manual Setup

1. **Install and configure Milvus standalone**
   Follow the [Milvus installation guide](https://milvus.io/docs/install_standalone-docker.md)

2. **Start the application**
   ```bash
   chainlit run app.py -w
   ```

The application will be available at `http://localhost:8000`

## πŸ“Š Database Population

The system automatically populates the vector database on first startup. However, you can manually manage the data:

### Automatic Population

The application automatically checks if the Milvus collection exists and has data. If not, it runs the population script automatically.

### Manual Population

To manually populate or repopulate the database:

```bash
python populate_db.py
```

### Adding New Documents

1. **Add documents to the data directory**
   ```bash
   # Place your documents in the data/ folder
   cp your_new_document.pdf data/
   cp your_new_document.docx data/
   ```

2. **Supported file formats:**
   - PDF files (`.pdf`)
   - Microsoft Word documents (`.docx`)
   - HTML files (`.html`)

3. **Repopulate the database**
   ```bash
   # Delete existing collection
   python delete_collection.py
   
   # Repopulate with new documents
   python populate_db.py
   ```

### Database Configuration

The population script uses the following configuration:

- **Embedding Model**: Qwen/Qwen3-Embedding-8B (4096 dimensions)
- **Chunk Size**: 1500 characters maximum
- **Combine Threshold**: 200 characters minimum
- **Batch Size**: 5 documents per batch
- **Collection Name**: `my_rag_collection`

### Document Processing Pipeline

1. **Loading**: Documents are loaded using UnstructuredLoader
2. **Cleaning**: Text is cleaned and normalized
3. **Chunking**: Documents are split into manageable chunks
4. **Embedding**: Chunks are converted to vector embeddings
5. **Storage**: Embeddings are stored in Milvus with metadata

## πŸ—ƒοΈ Data Management


### Deleting the Collection

```bash
python delete_collection.py
```


### Updating Documents

To update the document corpus:

1. Add/remove documents in the `data/` directory
2. Delete the existing collection: `python delete_collection.py`
3. Restart the application (it will automatically repopulate)

## πŸ§ͺ Testing

The project includes comprehensive testing:

### Running Unit Tests

```bash

# Run specific test files
python -m unittest tests/test_chainlit.py -v
```

### RAGAS Evaluation

Evaluate the RAG system performance:

```bash
# Run RAGAS evaluation
python tests/test_ragas.py

# Or use the Jupyter notebook
jupyter notebook tests/test_ragas.ipynb
```

### Manual Testing

Test individual components:

```bash
# Test vector search functionality
python tests/test_vector_search.py

```


## πŸ“„ License

This project is licensed under the MIT license.