File size: 4,779 Bytes
acb11a4
11d9dfb
 
 
acb11a4
 
11d9dfb
acb11a4
 
11d9dfb
9b9fa1c
acb11a4
 
11d9dfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Professional RAG Assistant
emoji: πŸ€–
colorFrom: purple
colorTo: blue
sdk: gradio
sdk_version: 5.44.0
app_file: app.py
pinned: false
license: apache-2.0
short_description: Professional RAG system for document Q&A and search
---

# Professional RAG Document Assistant

A comprehensive, production-ready Retrieval-Augmented Generation (RAG) system built with Gradio for document question-answering. This application combines vector similarity search, keyword search (BM25), and cross-encoder re-ranking to provide highly relevant answers from your documents.

## 🌟 Features

### Document Processing
- **Multi-format Support**: PDF, DOCX, and TXT files
- **Smart Chunking**: Intelligent text segmentation with overlapping chunks
- **Metadata Extraction**: Automatic extraction of document metadata
- **Progress Tracking**: Real-time processing status updates

### Advanced Search
- **Hybrid Search**: Combines vector similarity and BM25 keyword search
- **Re-ranking**: Cross-encoder models for improved result relevance
- **Configurable**: Adjustable search parameters and weights
- **Metadata Filtering**: Filter results by document properties

### User Interface
- **Professional Design**: Clean, modern Gradio interface
- **Multi-tab Layout**: Organized workflow from upload to search
- **Real-time Updates**: Live progress and status indicators
- **Analytics Dashboard**: Usage metrics and system performance

### Performance & Scalability
- **Caching System**: Multi-level caching for embeddings and queries
- **Memory Efficient**: Optimized for resource-constrained environments
- **Error Handling**: Comprehensive error management and recovery
- **Analytics**: Built-in usage tracking and performance monitoring

## πŸš€ Quick Start

### Running Locally

1. **Clone the repository**:
   ```bash
   git clone <repository-url>
   cd professional-rag-assistant
   ```

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

3. **Run the application**:
   ```bash
   python app.py
   ```

4. **Open your browser** to `http://localhost:7860`

### Configuration

The system uses YAML configuration files:
- `config.yaml`: Production configuration
- `config-local.yaml`: Local development overrides

Key configuration sections:
```yaml
models:
  embedding:
    name: "sentence-transformers/all-MiniLM-L6-v2"
    batch_size: 32
  reranker:
    name: "cross-encoder/ms-marco-MiniLM-L-6-v2"
    enabled: true

search:
  default_k: 10
  vector_weight: 0.7
  bm25_weight: 0.3
```

## πŸ“– Usage Guide

### 1. Document Upload
- Navigate to the "πŸ“ Document Upload" tab
- Select PDF, DOCX, or TXT files (up to 50MB each)
- Click "Process Documents" to index your files
- Monitor progress and view processing results

### 2. Searching Documents
- Go to the "πŸ” Search" tab
- Enter your question or search query
- Configure search options:
  - **Search Mode**: hybrid, vector, or bm25
  - **Number of Results**: 1-20
  - **Re-ranking**: Enable for better relevance
- View results with source attribution and relevance scores

### 3. Document Management
- Use the "πŸ“š Documents" tab to view indexed documents
- See document statistics (chunks, file size, type)
- Remove individual documents or clear all

### 4. Analytics
- Monitor system performance in the "πŸ“Š Analytics" tab
- View query patterns and usage statistics
- Track system health and resource usage

## πŸ—οΈ Architecture

The system follows a modular architecture:

```
src/
β”œβ”€β”€ rag_system.py          # Main orchestrator
β”œβ”€β”€ document_processor.py  # Multi-format parsing
β”œβ”€β”€ embedding_manager.py   # HF embeddings with caching
β”œβ”€β”€ vector_store.py        # In-memory vector storage
β”œβ”€β”€ search_engine.py       # Hybrid search implementation
β”œβ”€β”€ reranker.py           # Cross-encoder re-ranking
β”œβ”€β”€ cache_manager.py      # Multi-level caching
β”œβ”€β”€ error_handler.py      # Error management
└── analytics.py          # Usage tracking

ui/
β”œβ”€β”€ main_interface.py     # Primary Gradio interface
β”œβ”€β”€ components.py         # Reusable UI components
β”œβ”€β”€ themes.py            # Custom styling
└── utils.py             # UI utilities
```

## πŸ§ͺ Testing

Run the test suite:
```bash
# Install test dependencies
pip install -r requirements-dev.txt

# Run all tests
pytest

# Run with coverage
pytest --cov=src --cov-report=html
```

## πŸ› οΈ Development

### Setup Development Environment

1. **Install development dependencies**:
   ```bash
   pip install -r requirements-dev.txt
   ```

2. **Run in development mode**:
   ```bash
   python app.py --debug --config config-local.yaml
   ```

## πŸ“„ License

This project is licensed under the Apache License 2.0. See the [LICENSE](LICENSE) file for details.