Spaces:
Running
Running
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
|