File size: 5,182 Bytes
a9cc6d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
239
240
241
242
243
244
245
246
# 🧪 Project Testing Roadmap

Complete sequential guide to test all components of DocuMind AI.

---

## Prerequisites

```bash
cd "f:\LLM projects\rag-docs-assistant"

# Ensure virtual environment is activated
# Create .env file with your API key
echo "GOOGLE_API_KEY=your_actual_api_key" > .env
```

---

## Phase 1: Unit Tests (5 min)

### 1.1 Run All Unit Tests
```bash
python -m pytest tests/unit/ -v --tb=short
```

**Expected:** All tests pass ✅

### 1.2 Run Specific Test Modules
```bash
# Test caching
python -m pytest tests/unit/test_caching.py -v

# Test async utilities
python -m pytest tests/unit/test_async_utils.py -v

# Test loaders
python -m pytest tests/unit/test_loaders.py -v

# Test embeddings
python -m pytest tests/unit/test_embeddings.py -v
```

---

## Phase 2: Integration Tests (5 min)

### 2.1 Run API Integration Tests
```bash
python -m pytest tests/integration/test_api.py -v
```

**Expected:** Health endpoints, query, ingest tests pass ✅

---

## Phase 3: Backend API Testing (10 min)

### 3.1 Start FastAPI Server
```bash
uvicorn src.api.main:app --reload --port 8000
```

### 3.2 Test Health Endpoint
Open browser or use curl:
```bash
curl http://localhost:8000/health
```
**Expected:** `{"status": "healthy", ...}`

### 3.3 Test API Docs
Open: http://localhost:8000/docs

**Expected:** Swagger UI with all endpoints visible

### 3.4 Test Ingest Endpoint (with sample file)
Create a test document:
```bash
echo "RAG stands for Retrieval-Augmented Generation. It combines retrieval and generation." > test_doc.txt
```

```bash
curl -X POST "http://localhost:8000/api/ingest" \
  -F "files=@test_doc.txt" \
  -F "collection_name=test_collection"
```

**Expected:** `{"success": true, "documents_processed": 1, ...}`

### 3.5 Test Query Endpoint
```bash
curl -X POST "http://localhost:8000/api/query" \
  -H "Content-Type: application/json" \
  -d '{"query": "What is RAG?", "collection_name": "test_collection"}'
```

**Expected:** JSON response with `answer` and `sources`

---

## Phase 4: Frontend Testing (10 min)

### 4.1 Start Streamlit (in new terminal)
```bash
streamlit run src/frontend/app.py
```

### 4.2 Open Browser
Navigate to: http://localhost:8501

### 4.3 Test UI Components
| Test | Action | Expected |
|------|--------|----------|
| Page loads | Open URL | Chat interface visible |
| Sidebar | Check left panel | Collection settings, file uploader |
| Upload file | Drag test_doc.txt | Success message |
| Send query | Type "What is RAG?" | Answer with sources |
| Sources shown | Check response | Citations displayed |

---

## Phase 5: RAG Pipeline Testing (10 min)

### 5.1 Python REPL Test
```python
# Start Python
python

# Test imports
from src.rag import create_rag_pipeline, load_documents, chunk_documents
from src.core.config import settings

# Test document loading
docs = load_documents("test_doc.txt")
print(f"Loaded {len(docs)} documents")

# Test chunking
chunks = chunk_documents(docs)
print(f"Created {len(chunks)} chunks")

# Test pipeline (requires GOOGLE_API_KEY in .env)
pipeline = create_rag_pipeline(collection_name="test_cli")
result = pipeline.query("What is RAG?")
print(f"Answer: {result['answer']}")
print(f"Sources: {len(result['sources'])}")
```

---

## Phase 6: Evaluation Testing (5 min)

### 6.1 Run Promptfoo Evaluation
```bash
cd eval
npx promptfoo eval --config promptfooconfig.yaml
```

**Expected:** Evaluation results with pass/fail metrics

### 6.2 View Results
```bash
npx promptfoo view
```

Opens browser with evaluation dashboard.

---

## Phase 7: End-to-End Flow (10 min)

### 7.1 Full Workflow Test

1. **Start both servers:**
   ```bash
   # Terminal 1: Backend
   uvicorn src.api.main:app --port 8000
   
   # Terminal 2: Frontend
   streamlit run src/frontend/app.py
   ```

2. **Upload documents:**
   - Go to http://localhost:8501
   - Upload a PDF/MD/TXT file via sidebar

3. **Query documents:**
   - Type a question about uploaded content
   - Verify answer is relevant
   - Check sources are cited

4. **Verify observability:**
   - Check terminal logs for traces
   - If Langfuse configured, check dashboard

---

## Quick Validation Checklist

| Component | Test Command | Pass Criteria |
|-----------|--------------|---------------|
| Unit Tests | `pytest tests/unit/ -v` | All green |
| API Health | `curl localhost:8000/health` | 200 OK |
| Swagger UI | Open `/docs` | Renders correctly |
| Streamlit | Open `:8501` | Chat UI loads |
| File Upload | Upload test file | Success message |
| Query | Ask question | Gets answer |
| Sources | Check response | Citations shown |

---

## Troubleshooting

### Import Errors
```bash
pip install -r requirements.txt
```

### API Key Missing
```bash
# Check .env file exists with:
GOOGLE_API_KEY=your_key_here
```

### Port Already in Use
```bash
# Kill existing process
netstat -ano | findstr :8000
taskkill /PID <PID> /F
```

### ChromaDB Errors
```bash
# Reset vector store
rm -rf data/chroma
```

---

## Success Criteria

✅ All unit tests pass  
✅ API endpoints respond correctly  
✅ Frontend loads and is interactive  
✅ File upload works  
✅ Queries return relevant answers  
✅ Sources are properly cited