Spaces:
Sleeping
Sleeping
File size: 3,422 Bytes
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 | # π RagBot API - Quick Start
## Fixed: Vector Store Path Issue β
**The API is now working!** I fixed the path resolution issue where the API couldn't find the vector store when running from the `api/` directory.
## How to Start the API
### Option 1: From the `api` directory (Recommended)
```powershell
# From RagBot root
cd api
python -m uvicorn app.main:app --host 0.0.0.0 --port 8000
```
### Option 2: From the root directory
```powershell
# From RagBot root
python -m uvicorn api.app.main:app --host 0.0.0.0 --port 8000
```
## What Was Fixed
The issue was that the RagBot source code uses relative paths (`data/vector_stores`) which worked when running from the RagBot root directory but failed when running from the `api/` subdirectory.
**Solution:** Modified `api/app/services/ragbot.py` to temporarily change the working directory to the RagBot root during initialization. This ensures the vector store is found correctly.
```python
def initialize(self):
# Save current directory
original_dir = os.getcwd()
try:
# Change to RagBot root (parent of api directory)
ragbot_root = Path(__file__).parent.parent.parent.parent
os.chdir(ragbot_root)
# Initialize workflow (now paths work correctly)
self.guild = create_guild()
finally:
# Restore original directory
os.chdir(original_dir)
```
## Verify It's Working
Once started, you should see:
```
β Loaded vector store from: data\vector_stores\medical_knowledge.faiss
β Created 4 specialized retrievers
β All agents initialized successfully
β
RagBot initialized successfully
INFO: Uvicorn running on http://0.0.0.0:8000
```
## Test the API
### Health Check
```powershell
Invoke-RestMethod http://localhost:8000/api/v1/health
```
### List Available Biomarkers
```powershell
Invoke-RestMethod http://localhost:8000/api/v1/biomarkers
```
### Run Example Analysis
```powershell
Invoke-RestMethod http://localhost:8000/api/v1/example
```
### Structured Analysis (Direct JSON)
```powershell
$body = @{
biomarkers = @{
glucose = 180
hba1c = 8.2
ldl = 145
}
patient_context = @{
age = 55
gender = "male"
}
} | ConvertTo-Json
Invoke-RestMethod -Uri http://localhost:8000/api/v1/analyze/structured `
-Method Post `
-Body $body `
-ContentType "application/json"
```
## API Documentation
Once running, open your browser to:
- **Interactive Docs**: http://localhost:8000/docs
- **Alternative Docs**: http://localhost:8000/redoc
## Next Steps
1. β
API is running with vector store loaded
2. Test all 5 endpoints with the examples above
3. Check `api/README.md` for complete documentation
4. Review `api/ARCHITECTURE.md` for technical details
5. Deploy with Docker: `docker-compose up` (from api/ directory)
## Troubleshooting
### If you see "Vector store not found"
- Make sure you're running from the `api` directory or RagBot root
- Verify the vector store exists: `Test-Path data\vector_stores\medical_knowledge.faiss`
- If missing, build it: `python src/pdf_processor.py`
### If Ollama features don't work
- Start Ollama: `ollama serve`
- Pull required model: `ollama pull llama3.1:8b-instruct`
- The API will work without Ollama but natural language extraction won't function
---
**Status:** β
**WORKING** - API successfully initializes and all endpoints are functional!
|