File size: 21,763 Bytes
6dc9d46
 
aefac4f
6dc9d46
 
 
aefac4f
6dc9d46
 
 
aefac4f
 
6dc9d46
 
aefac4f
 
 
6dc9d46
 
 
 
 
 
 
 
 
aefac4f
6dc9d46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# RagBot API - Architecture Diagrams

## System Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      RagBot API Server                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚  Cloud LLM API  │◄──────────────   FastAPI Server         β”‚ β”‚
β”‚  β”‚  (Groq/Gemini)  β”‚  LLM Calls   β”‚   Port: 8000             β”‚ β”‚
β”‚  β”‚                 β”‚              β”‚                          β”‚ β”‚
β”‚  β”‚  Models:        β”‚              β”‚  Endpoints:              β”‚ β”‚
β”‚  β”‚  - LLaMA 3.3-70Bβ”‚              β”‚  - /api/v1/health        β”‚ β”‚
β”‚  β”‚  - Gemini Flash β”‚              β”‚  - /api/v1/biomarkers    β”‚ β”‚
β”‚  β”‚  (or Ollama)    β”‚              β”‚  - /api/v1/analyze/*     β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                                β”‚                β”‚
β”‚                                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚                                    β”‚   RagBot Core System     β”‚ β”‚
β”‚                                    β”‚   (Imported Package)     β”‚ β”‚
β”‚                                    β”‚                          β”‚ β”‚
β”‚                                    β”‚  - 6 Specialist Agents   β”‚ β”‚
β”‚                                    β”‚  - LangGraph Workflow    β”‚ β”‚
β”‚                                    β”‚  - FAISS Vector Store    β”‚ β”‚
β”‚                                    β”‚  - 2,609 medical chunks  β”‚ β”‚
β”‚                                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β–²
                              β”‚
                   HTTP Requests (JSON)
                              β”‚
                              β”‚
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚   Your Backend Server  β”‚
                  β”‚   (Node.js/Python/etc) β”‚
                  β”‚   Port: 3000           β”‚
                  β”‚                        β”‚
                  β”‚   - Receives frontend  β”‚
                  β”‚     requests           β”‚
                  β”‚   - Calls RagBot API   β”‚
                  β”‚   - Returns results    β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β”‚
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚   Your Frontend        β”‚
                  β”‚   (React/Vue/etc)      β”‚
                  β”‚                        β”‚
                  β”‚   - User inputs data   β”‚
                  β”‚   - Displays results   β”‚
                  β”‚   - Shows analysis     β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## πŸ“‘ Request Flow

### Natural Language Analysis Flow

```
User Types:
"My glucose is 185 and HbA1c is 8.2"
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Frontend (React)  β”‚
β”‚  User Interface    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚ POST /api/analyze
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Your Backend      β”‚
β”‚  (Express/Flask)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚ POST /api/v1/analyze/natural
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  RagBot API (FastAPI)               β”‚
β”‚                                     β”‚
β”‚  1. Receive request                 β”‚
β”‚     {"message": "glucose 185..."}   β”‚
β”‚                                     β”‚
β”‚  2. Extract biomarkers              β”‚
β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚     β”‚  Extraction      β”‚            β”‚
β”‚     β”‚  Service         β”‚            β”‚
β”‚     β”‚  (LLM: llama3.1) β”‚            β”‚
β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β”‚              β–Ό                      β”‚
β”‚     {"Glucose": 185, "HbA1c": 8.2} β”‚
β”‚                                     β”‚
β”‚  3. Predict disease                 β”‚
β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚     β”‚  Rule-based      β”‚            β”‚
β”‚     β”‚  Predictor       β”‚            β”‚
β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β”‚              β–Ό                      β”‚
β”‚     {"disease": "Diabetes", ...}   β”‚
β”‚                                     β”‚
β”‚  4. Run RAG Workflow                β”‚
β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚     β”‚  RagBot Service  β”‚            β”‚
β”‚     β”‚  (6 agents)      β”‚            β”‚
β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β”‚              β–Ό                      β”‚
β”‚     Full analysis response          β”‚
β”‚                                     β”‚
β”‚  5. Format response                 β”‚
β”‚     - Biomarker flags               β”‚
β”‚     - Safety alerts                 β”‚
β”‚     - Recommendations               β”‚
β”‚     - Disease explanation           β”‚
β”‚     - Conversational summary        β”‚
β”‚                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚ JSON Response
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Your Backend      β”‚
β”‚  Processes data    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚ JSON Response
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Frontend          β”‚
β”‚  Displays results  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## πŸ”„ Component Interaction

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              FastAPI Application                  β”‚
β”‚              (app/main.py)                        β”‚
β”‚                                                   β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚  β”‚          Route Handlers                     β”‚ β”‚
β”‚  β”‚                                             β”‚ β”‚
β”‚  β”‚  /health      /biomarkers    /analyze/*    β”‚ β”‚
β”‚  β”‚    β”‚               β”‚              β”‚         β”‚ β”‚
β”‚  β””β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚       β”‚               β”‚              β”‚           β”‚
β”‚       β–Ό               β–Ό              β–Ό           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Health  β”‚   β”‚Biomarkerβ”‚   β”‚  Analyze     β”‚  β”‚
β”‚  β”‚ Route   β”‚   β”‚ Route   β”‚   β”‚  Route       β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                       β”‚           β”‚
β”‚                                       β–Ό           β”‚
β”‚                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚                          β”‚   Services Layer    β”‚ β”‚
β”‚                          β”‚                     β”‚ β”‚
β”‚                          β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
β”‚                          β”‚  β”‚  Extraction   β”‚ β”‚ β”‚
β”‚                          β”‚  β”‚  Service      β”‚ β”‚ β”‚
β”‚                          β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
β”‚                          β”‚          β”‚         β”‚ β”‚
β”‚                          β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
β”‚                          β”‚  β”‚  RagBot       β”‚ β”‚ β”‚
β”‚                          β”‚  β”‚  Service      β”‚ β”‚ β”‚
β”‚                          β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
β”‚                          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚                                     β”‚           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                      β”‚
                                      β–Ό
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚   RagBot Core System   β”‚
                         β”‚   (src/workflow.py)    β”‚
                         β”‚                        β”‚
                         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                         β”‚  β”‚ 6 Agent Workflow β”‚  β”‚
                         β”‚  β”‚ (LangGraph)      β”‚  β”‚
                         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                         β”‚                        β”‚
                         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
                         β”‚  β”‚ Vector Store     β”‚  β”‚
                         β”‚  β”‚ (FAISS)          β”‚  β”‚
                         β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## πŸ“Š Data Flow

### Request β†’ Response Journey

```
1. INPUT (from user)
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ "My glucose is 185 and HbA1c   β”‚
   β”‚  is 8.2, I'm 52 years old"     β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
2. EXTRACTION (LLM Processing)
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Biomarkers:                     β”‚
   β”‚  - Glucose: 185.0               β”‚
   β”‚  - HbA1c: 8.2                   β”‚
   β”‚ Context:                        β”‚
   β”‚  - age: 52                      β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
3. PREDICTION (Rule-based)
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Disease: Diabetes               β”‚
   β”‚ Confidence: 0.87 (87%)          β”‚
   β”‚ Probabilities:                  β”‚
   β”‚  - Diabetes: 87%                β”‚
   β”‚  - Heart Disease: 8%            β”‚
   β”‚  - Others: 5%                   β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
4. WORKFLOW (6 Agents Execute)
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Agent 1: Biomarker Analyzer     β”‚
   β”‚  βœ“ Validates 2 biomarkers       β”‚
   β”‚  βœ“ Flags: 2 out of range        β”‚
   β”‚  βœ“ Alerts: 2 critical           β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Agent 2: Disease Explainer (RAG)β”‚
   β”‚  βœ“ Retrieved 5 medical docs     β”‚
   β”‚  βœ“ Citations: 5 sources         β”‚
   β”‚  βœ“ Pathophysiology explained    β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Agent 3: Biomarker Linker (RAG) β”‚
   β”‚  βœ“ Linked 2 key drivers         β”‚
   β”‚  βœ“ Evidence from literature     β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Agent 4: Guidelines (RAG)       β”‚
   β”‚  βœ“ Retrieved 3 guidelines       β”‚
   β”‚  βœ“ Recommendations: 5 actions   β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Agent 5: Confidence Assessor    β”‚
   β”‚  βœ“ Reliability: MODERATE        β”‚
   β”‚  βœ“ Evidence: STRONG             β”‚
   β”‚  βœ“ Limitations: 2 noted         β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Agent 6: Response Synthesizer   β”‚
   β”‚  βœ“ Compiled all findings        β”‚
   β”‚  βœ“ Structured output            β”‚
   β”‚  βœ“ Conversational summary       β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚
                β–Ό
5. OUTPUT (to user)
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚ Full JSON Response:             β”‚
   β”‚                                 β”‚
   β”‚ - prediction                    β”‚
   β”‚ - biomarker_flags               β”‚
   β”‚ - safety_alerts                 β”‚
   β”‚ - key_drivers                   β”‚
   β”‚ - disease_explanation           β”‚
   β”‚ - recommendations               β”‚
   β”‚ - confidence_assessment         β”‚
   β”‚ - agent_outputs                 β”‚
   β”‚ - conversational_summary        β”‚
   β”‚                                 β”‚
   β”‚ Processing time: 3.5 seconds    β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## 🎯 API Endpoint Map

```
RagBot API Root: http://localhost:8000
β”‚
β”œβ”€β”€ /                         GET   API info
β”‚
β”œβ”€β”€ /docs                     GET   Swagger UI
β”‚
β”œβ”€β”€ /redoc                    GET   ReDoc
β”‚
└── /api/v1/
    β”‚
    β”œβ”€β”€ /health               GET   System status
    β”‚   Returns: {
    β”‚     status: "healthy",
    β”‚     ollama_status: "connected",
    β”‚     vector_store_loaded: true
    β”‚   }
    β”‚
    β”œβ”€β”€ /biomarkers           GET   List all biomarkers
    β”‚   Returns: {
    β”‚     biomarkers: [...],
    β”‚     total_count: 24
    β”‚   }
    β”‚
    └── /analyze/
        β”‚
        β”œβ”€β”€ /natural          POST  Natural language
        β”‚   Input: {
        β”‚     message: "glucose 185...",
        β”‚     patient_context: {...}
        β”‚   }
        β”‚   Output: Full analysis
        β”‚
        β”œβ”€β”€ /structured       POST  Direct biomarkers
        β”‚   Input: {
        β”‚     biomarkers: {...},
        β”‚     patient_context: {...}
        β”‚   }
        β”‚   Output: Full analysis
        β”‚
        └── /example          GET   Demo case
            Output: Full analysis
```

---

## πŸ”Œ Integration Points

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           Your Application Stack               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                β”‚
β”‚  Frontend (React/Vue/Angular)                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ User inputs: "glucose 185, HbA1c 8.2"    β”‚  β”‚
β”‚  β”‚ Button click: "Analyze"                  β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                 β”‚ HTTP POST                     β”‚
β”‚                 β–Ό                               β”‚
β”‚  Backend (Node.js/Python/Java)                 β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚ Endpoint: POST /api/analyze              β”‚  β”‚
β”‚  β”‚                                          β”‚  β”‚
β”‚  β”‚ Code:                                    β”‚  β”‚
β”‚  β”‚   const result = await fetch(           β”‚  β”‚
β”‚  β”‚     'http://localhost:8000/api/v1/      β”‚  β”‚
β”‚  β”‚      analyze/natural',                  β”‚  β”‚
β”‚  β”‚     {body: {message: userInput}}        β”‚  β”‚
β”‚  β”‚   );                                     β”‚  β”‚
β”‚  β”‚                                          β”‚  β”‚
β”‚  β”‚   return result.data;                   β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                 β”‚ HTTP POST                     β”‚
β”‚                 β–Ό                               β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚    RagBot API (localhost:8000)           │◄─┼─ This is what we built!
β”‚  β”‚                                          β”‚  β”‚
β”‚  β”‚    - Extracts biomarkers                 β”‚  β”‚
β”‚  β”‚    - Runs analysis                       β”‚  β”‚
β”‚  β”‚    - Returns JSON                        β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                 β”‚ JSON Response                 β”‚
β”‚                 β–Ό                               β”‚
β”‚  Backend processes and returns to frontend     β”‚
β”‚                 β”‚                               β”‚
β”‚                 β–Ό                               β”‚
β”‚  Frontend displays results to user             β”‚
β”‚                                                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

---

## πŸ’Ύ File Structure

```
api/
β”‚
β”œβ”€β”€ app/                      # Application code
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ main.py              # FastAPI app (entry point)
β”‚   β”‚
β”‚   β”œβ”€β”€ models/              # Data schemas
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── schemas.py       # Pydantic models
β”‚   β”‚
β”‚   β”œβ”€β”€ routes/              # API endpoints
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ health.py        # Health check
β”‚   β”‚   β”œβ”€β”€ biomarkers.py    # List biomarkers
β”‚   β”‚   └── analyze.py       # Analysis endpoints
β”‚   β”‚
β”‚   └── services/            # Business logic
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ extraction.py    # Natural language extraction
β”‚       └── ragbot.py        # Workflow orchestration
β”‚
β”œβ”€β”€ .env                     # Configuration
β”œβ”€β”€ .env.example             # Template
β”œβ”€β”€ .gitignore               # Git ignore rules
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ Dockerfile               # Container image
β”œβ”€β”€ docker-compose.yml       # Deployment config
β”‚
└── Documentation/
    β”œβ”€β”€ README.md            # Complete guide
    β”œβ”€β”€ GETTING_STARTED.md   # Quick start
    β”œβ”€β”€ QUICK_REFERENCE.md   # Cheat sheet
    └── ARCHITECTURE.md      # This file
```

---

**Created:** November 23, 2025  
**Purpose:** Visual guide to RagBot API architecture  
**For:** Understanding system design and integration points