Commit 19c5058
feat: Complete RAG API optimization suite with intelligent backup embeddings
This comprehensive update adds intelligent backup embedding providers,
performance optimizations, and comprehensive error handling:
## 🚀 New Features
### Intelligent Backup Embedding System
- **Ultra-fast failover**: Socket check detects dead ports in 0.5 seconds
- **Immediate failover**: Primary failure triggers instant backup attempt (no retries)
- **Smart cooldown**: 1-minute cooldown after primary provider failure
- **Seamless switching**: LibreChat receives 200 status when backup succeeds
- **Fast recovery**: Optimized retry logic prevents cascading failures
- **Clear logging**: Prominent failure messages and accurate provider tracking
### Custom NVIDIA Embeddings Provider
- **Full NVIDIA API compatibility** for LLaMA embedding models
- **Fast port detection**: Socket check fails immediately if nothing listening
- **Optimized timeouts**: 0.5s socket check, 2s connection, 3s read timeout
- **Configurable parameters**: batch size, retries, timeout, input types
- **Fast failover mode**: Reduced retries when backup provider configured
- **Proper error handling** for NVIDIA-specific API responses
### Enhanced AWS Bedrock Support
- **Titan V2 embeddings** with configurable dimensions (256/512/1024)
- **Reactive rate limiting** - only activates when AWS throttles requests
- **Graceful error handling** with user-friendly configuration messages
- **Backward compatibility** with Titan V1 models
### Database & Performance Optimizations
- **Graceful PostgreSQL error handling** - 503 responses for connection issues
- **Optimized chunking strategy** - adaptive batch sizes based on chunk size
- **Request throttling middleware** - prevents LibreChat overload (configurable)
- **Improved UTF-8 file processing** with proper cleanup and null checks
- **Enhanced connection pooling** with optimized timeout settings
## 📋 Configuration
### Backup Provider Setup
```env
# Primary Provider
EMBEDDINGS_PROVIDER=nvidia
EMBEDDINGS_MODEL=nvidia/llama-3.2-nemoretriever-300m-embed-v1
NVIDIA_TIMEOUT=3 # Fast failover - 3 second read timeout
# Backup Provider
EMBEDDINGS_PROVIDER_BACKUP=bedrock
EMBEDDINGS_MODEL_BACKUP=amazon.titan-embed-text-v2:0
PRIMARY_FAILOVER_COOLDOWN_MINUTES=1
# Performance Tuning
EMBED_CONCURRENCY_LIMIT=3
```
### Bedrock Titan V2 Configuration
```env
BEDROCK_EMBEDDING_DIMENSIONS=512 # 256, 512, or 1024
BEDROCK_EMBEDDING_NORMALIZE=true
BEDROCK_MAX_BATCH_SIZE=15
```
## 🧪 Testing
- **31 comprehensive tests** covering V1/V2 compatibility
- **Error simulation and recovery** testing
- **Integration tests** for backup failover scenarios
## 🛠️ Technical Improvements
- **Ultra-fast port detection** - Socket check with 0.5s timeout before connection
- **Immediate failover logic** - no retry delays when backup is available
- **Triple-layer timeout strategy** - socket (0.5s), connection (2s), read (3s)
- **Conditional AWS credential loading** - only when Bedrock is configured
- **Thread-safe state management** with proper locking
- **Pydantic v2 compatibility** with proper field declarations
- **Comprehensive error categorization** and user-friendly messages
## 📚 Documentation
- **Complete environment variable documentation** in README.md
- **High availability configuration examples** with NVIDIA + Bedrock setup
- **Detailed provider configuration guides** for all supported embedding services
This update ensures robust, production-ready embedding operations with
lightning-fast failover (0.5-3 seconds), optimal performance, and excellent user experience.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 2f08fc3 commit 19c5058
File tree
17 files changed
+2104
-42
lines changed- app
- routes
- services
- embeddings
- vector_store
- utils
- tests
- services
17 files changed
+2104
-42
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
74 | 74 | | |
75 | 75 | | |
76 | 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 | + | |
77 | 108 | | |
78 | 109 | | |
79 | 110 | | |
| |||
125 | 156 | | |
126 | 157 | | |
127 | 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 | + | |
128 | 198 | | |
129 | 199 | | |
130 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
236 | 240 | | |
237 | 241 | | |
238 | 242 | | |
239 | | - | |
| 243 | + | |
240 | 244 | | |
241 | 245 | | |
242 | 246 | | |
| |||
248 | 252 | | |
249 | 253 | | |
250 | 254 | | |
251 | | - | |
252 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
253 | 278 | | |
254 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
255 | 302 | | |
256 | 303 | | |
257 | 304 | | |
| |||
285 | 332 | | |
286 | 333 | | |
287 | 334 | | |
288 | | - | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
289 | 339 | | |
290 | 340 | | |
291 | 341 | | |
292 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
293 | 348 | | |
294 | | - | |
| 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 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
295 | 465 | | |
296 | 466 | | |
297 | 467 | | |
| |||
0 commit comments