Spaces:
Running
Running
fix: Improve DuckDuckGo error handling + deployment tools
Browse files- Better error handling for DecodeError and rate limits
- Graceful fallback to database when live search fails
- Added upgrade_dependencies.sh script
- Added DEPLOYMENT_FIXES.md guide
Run ./upgrade_dependencies.sh to fix reranker
- DEPLOYMENT_FIXES.md +151 -0
- src/infrastructure/adapters/duckduckgo_adapter.py +13 -2
- upgrade_dependencies.sh +25 -0
DEPLOYMENT_FIXES.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deployment Fixes for RAG API v2.4
|
| 2 |
+
|
| 3 |
+
## Issues Fixed
|
| 4 |
+
|
| 5 |
+
### 1. β
Qdrant `order_by` Error (FIXED IN CODE)
|
| 6 |
+
- **Status:** Fixed in commit `7110008`
|
| 7 |
+
- **Action:** Already deployed, no action needed
|
| 8 |
+
|
| 9 |
+
### 2. β
DuckDuckGo Decode Error (FIXED IN CODE)
|
| 10 |
+
- **Status:** Fixed with better error handling
|
| 11 |
+
- **Action:** Deploy latest code
|
| 12 |
+
- **Details:** System now gracefully handles decode errors and falls back to database
|
| 13 |
+
|
| 14 |
+
### 3. β οΈ Reranker Tokenizer Error (NEEDS DEPLOYMENT)
|
| 15 |
+
- **Status:** Fix ready, needs dependency upgrade
|
| 16 |
+
- **Action:** Run upgrade script (see below)
|
| 17 |
+
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
## Deployment Steps
|
| 21 |
+
|
| 22 |
+
### Option A: Automatic Upgrade (Recommended)
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
cd services/apis/rag-api
|
| 26 |
+
chmod +x upgrade_dependencies.sh
|
| 27 |
+
./upgrade_dependencies.sh
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
### Option B: Manual Upgrade
|
| 31 |
+
|
| 32 |
+
```bash
|
| 33 |
+
pip install --upgrade FlagEmbedding>=1.2.11
|
| 34 |
+
pip install --upgrade transformers>=4.45.0
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
### Option C: Fresh Install
|
| 38 |
+
|
| 39 |
+
```bash
|
| 40 |
+
cd services/apis/rag-api
|
| 41 |
+
pip install -r requirements.txt --upgrade
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
|
| 46 |
+
## Verification
|
| 47 |
+
|
| 48 |
+
After deployment, check logs for:
|
| 49 |
+
|
| 50 |
+
### β
Success Indicators:
|
| 51 |
+
```
|
| 52 |
+
# No more Qdrant errors
|
| 53 |
+
β No "order_by not supported" warnings
|
| 54 |
+
|
| 55 |
+
# No more reranker errors
|
| 56 |
+
β No "XLMRobertaTokenizer has no attribute prepare_for_model" errors
|
| 57 |
+
|
| 58 |
+
# DuckDuckGo graceful handling
|
| 59 |
+
β "DuckDuckGo decode error (likely rate limit)" β Falls back to DB
|
| 60 |
+
β System continues working with database results
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
### β If Still Broken:
|
| 64 |
+
```bash
|
| 65 |
+
# Check installed versions
|
| 66 |
+
pip show FlagEmbedding transformers
|
| 67 |
+
|
| 68 |
+
# Should show:
|
| 69 |
+
# FlagEmbedding: 1.2.11 or higher
|
| 70 |
+
# transformers: 4.45.0 or higher
|
| 71 |
+
|
| 72 |
+
# If not, force reinstall:
|
| 73 |
+
pip uninstall FlagEmbedding transformers -y
|
| 74 |
+
pip install FlagEmbedding==1.2.11 transformers==4.45.0
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
---
|
| 78 |
+
|
| 79 |
+
## Testing
|
| 80 |
+
|
| 81 |
+
### Test 1: Check Reranker
|
| 82 |
+
```bash
|
| 83 |
+
# Query the API and check logs
|
| 84 |
+
curl -X POST http://localhost:7860/api/v1/rag/chat/stream \
|
| 85 |
+
-H "Content-Type: application/json" \
|
| 86 |
+
-d '{"query": "Ethiopia news today"}'
|
| 87 |
+
|
| 88 |
+
# Check logs - should NOT see:
|
| 89 |
+
# β "Reranker scoring failed"
|
| 90 |
+
|
| 91 |
+
# Should see:
|
| 92 |
+
# β
"DEBUG: After hybrid ranking: 15 results"
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
### Test 2: Check DuckDuckGo
|
| 96 |
+
```bash
|
| 97 |
+
# Query with temporal intent
|
| 98 |
+
curl -X POST http://localhost:7860/api/v1/rag/chat/stream \
|
| 99 |
+
-H "Content-Type: application/json" \
|
| 100 |
+
-d '{"query": "breaking news today"}'
|
| 101 |
+
|
| 102 |
+
# Check logs:
|
| 103 |
+
# β
"DEBUG: Hybrid search returned X DB + Y live results"
|
| 104 |
+
# If Y=0, check for:
|
| 105 |
+
# β
"DuckDuckGo decode error (likely rate limit)" β Graceful fallback
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
### Test 3: Check News Endpoint
|
| 109 |
+
```bash
|
| 110 |
+
# Test browse endpoint
|
| 111 |
+
curl http://localhost:7860/api/v1/news/latest?limit=10
|
| 112 |
+
|
| 113 |
+
# Should return:
|
| 114 |
+
# β
200 OK with recent articles
|
| 115 |
+
# β
No 400 errors in logs
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
---
|
| 119 |
+
|
| 120 |
+
## Rollback Plan
|
| 121 |
+
|
| 122 |
+
If issues occur after deployment:
|
| 123 |
+
|
| 124 |
+
```bash
|
| 125 |
+
# Rollback to previous versions
|
| 126 |
+
pip install FlagEmbedding==1.2.5 transformers==4.40.0
|
| 127 |
+
|
| 128 |
+
# Or rollback code
|
| 129 |
+
git revert 7110008
|
| 130 |
+
git push
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
---
|
| 134 |
+
|
| 135 |
+
## Support
|
| 136 |
+
|
| 137 |
+
If issues persist:
|
| 138 |
+
1. Check logs for specific error messages
|
| 139 |
+
2. Verify Python version (should be 3.10+)
|
| 140 |
+
3. Check if running in virtual environment
|
| 141 |
+
4. Try fresh install in clean environment
|
| 142 |
+
|
| 143 |
+
---
|
| 144 |
+
|
| 145 |
+
## Version History
|
| 146 |
+
|
| 147 |
+
- **v2.4** (2026-05-04): Fixed Qdrant order_by, DuckDuckGo errors, upgraded reranker
|
| 148 |
+
- **v2.3** (2026-05-04): Interactive thinking indicator with Lucide icons
|
| 149 |
+
- **v2.2** (2026-05-03): Time-based filtering for news endpoint
|
| 150 |
+
- **v2.1** (2026-05-03): Query enhancements and flexible prompting
|
| 151 |
+
- **v2.0** (2026-05-02): Hybrid RAG with live search
|
src/infrastructure/adapters/duckduckgo_adapter.py
CHANGED
|
@@ -153,8 +153,19 @@ class DuckDuckGoAdapter:
|
|
| 153 |
results.append(normalized)
|
| 154 |
|
| 155 |
except Exception as e:
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
return results
|
| 160 |
|
|
|
|
| 153 |
results.append(normalized)
|
| 154 |
|
| 155 |
except Exception as e:
|
| 156 |
+
# Handle specific DuckDuckGo errors gracefully
|
| 157 |
+
error_msg = str(e)
|
| 158 |
+
if "DecodeError" in error_msg or "Body collection error" in error_msg:
|
| 159 |
+
logger.warning(f"DuckDuckGo decode error (likely rate limit or API issue): {e}")
|
| 160 |
+
# Return empty results instead of raising - system will use database fallback
|
| 161 |
+
return []
|
| 162 |
+
elif "No results found" in error_msg:
|
| 163 |
+
logger.debug(f"DuckDuckGo: No results for query '{query[:50]}'")
|
| 164 |
+
return []
|
| 165 |
+
else:
|
| 166 |
+
logger.error(f"DuckDuckGo API error: {e}")
|
| 167 |
+
# Return empty results for graceful degradation
|
| 168 |
+
return []
|
| 169 |
|
| 170 |
return results
|
| 171 |
|
upgrade_dependencies.sh
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# Upgrade script for fixing reranker tokenizer issue
|
| 3 |
+
# Run this on HF Spaces or production server
|
| 4 |
+
|
| 5 |
+
echo "=========================================="
|
| 6 |
+
echo "Upgrading RAG API Dependencies"
|
| 7 |
+
echo "=========================================="
|
| 8 |
+
|
| 9 |
+
echo ""
|
| 10 |
+
echo "π¦ Upgrading FlagEmbedding (reranker fix)..."
|
| 11 |
+
pip install --upgrade FlagEmbedding>=1.2.11
|
| 12 |
+
|
| 13 |
+
echo ""
|
| 14 |
+
echo "π¦ Upgrading transformers (tokenizer fix)..."
|
| 15 |
+
pip install --upgrade transformers>=4.45.0
|
| 16 |
+
|
| 17 |
+
echo ""
|
| 18 |
+
echo "β
Dependencies upgraded successfully!"
|
| 19 |
+
echo ""
|
| 20 |
+
echo "π Please restart the service for changes to take effect:"
|
| 21 |
+
echo " - HF Spaces: Will auto-restart"
|
| 22 |
+
echo " - Docker: docker-compose restart rag-api"
|
| 23 |
+
echo " - Systemd: systemctl restart rag-api"
|
| 24 |
+
echo ""
|
| 25 |
+
echo "=========================================="
|