Spaces:
Sleeping
Sleeping
Current System Architecture
Request Flow Diagram
βββββββββββββββββββ
β User Request β
βββββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββββ
β FastAPI β
β Chat Endpoint β
βββββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββββ
β Extract Search β
β Terms (NLP) β
βββββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Phase 1: βββββΊβ Phase 2: β
β Rule-Based β β AI-Enhanced β
β Decision β β Decision β
βββββββββββ¬ββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββ
βSearch? βββββββββββββ No βββββββββββββ
βββββββββββ β
β Yes β
βΌ β
βββββββββββββββββββ β
β Phase 3: β β
β Universal Cache β β
β Check β β
βββββββββββ¬ββββββββ β
β β
βΌ β
βββββββββββ β
βCache βββββ Hit βββ β
βHit? β β β
βββββββββββ β β
β Miss β β
βΌ β β
βββββββββββββββββββ β β
β Web Search β β β
β Combined β β β
β (Brave+DDG) β β β
βββββββββββ¬ββββββββ β β
β β β
βΌ β β
βββββββββββββββββββ β β
β Store in Cache β β β
βββββββββββ¬ββββββββ β β
β β β
βΌ β β
βββββββββββββββββββ β β
β Format Results βββββββββ β
βββββββββββ¬ββββββββ β
β β
βΌ β
βββββββββββββββββββββββββββββββββββββββββββ
β AI Response β
β Generation β
β (Gemini) β
βββββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββββ
β Analytics β
β Tracking β
βββββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββββ
β JSON Response β
β to Client β
βββββββββββββββββββ
Current Cache Implementation
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Universal Search Cache β
β β
β βββββββββββββββββββ βββββββββββββββββββββββββββββββββββ β
β β Hash Table β β Cache Entry β β
β β (OrderedDict) β β β β
β β β β β’ search_results: List[Dict] β β
β β MD5(terms) βββΊ ββββββ€ β’ search_query: str β β
β β β β β’ search_terms: List[str] β β
β β β β β’ timestamp: float β β
β β β β β’ ttl: int β β
β β β β β’ hit_count: int β β
β β β β β’ last_accessed: float β β
β βββββββββββββββββββ βββββββββββββββββββββββββββββββββββ β
β β
β Lookup Strategy: β
β 1. Exact Match: O(1) hash lookup β
β 2. Semantic Search: O(n) spaCy similarity β
β β
β Max Size: 1000 entries β
β Default TTL: 3600 seconds β
β Memory: ~2-10MB per entry β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Performance Characteristics
| Operation | Time Complexity | Typical Duration | Resource Usage |
|---|---|---|---|
| Exact Cache Hit | O(1) | 1-5ΞΌs | RAM only |
| Semantic Cache Search | O(n) | 10-500ms | CPU + RAM |
| Rule-Based Decision | O(1) | 50-200ms | CPU intensive |
| AI-Based Decision | O(1) | 200-500ms | Network + GPU |
| Web Search | O(1) | 2-5s | Network + APIs |
Current Limitations
- Decision-First Approach: Always runs search decision logic before cache check
- Dual Lookup Complexity: Two different cache lookup strategies
- Poor Semantic Scaling: O(n) performance degrades with cache size
- Memory-Only: Cache lost on server restart
- Session Complexity: Removed but left complex patterns in codebase