CoolFace
Apppublic

findEthics/Atlas

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
search-optimization.md454 linesDownload Raw Back to features
1# Search Optimization Features2 3## Overview4 5Atlas includes an intelligent search optimization system that automatically determines when web searches are necessary, reducing unnecessary searches by 40-60% while maintaining high response quality. This results in faster responses, lower costs, and better conversation flow.6 7## How It Works8 9### Smart Decision Engine10 11Atlas uses a sophisticated hybrid system to decide when to search:12 13```14User Question → Analyze Context → Make Decision → Respond15     ↓              ↓               ↓           ↓16"Tell me more" → Has history? → Skip search → Use history17"Latest news" → No context → Perform search → Web + AI18```19 20### Two-Phase Analysis21 221. **Fast Rule-Based Patterns** (< 1ms)23   - Detects follow-up questions ("tell me more", "elaborate")24   - Identifies referential questions ("what about that?")25   - Recognizes clarification requests ("what do you mean?")26 272. **AI-Powered Analysis** (for ambiguous cases)28   - Deep semantic understanding using Google Gemini29   - Context sufficiency assessment30   - Information recency requirements31 32## Key Features33 34### 🧠 Intelligent Pattern Recognition35 36**Follow-up Questions**: Automatically detected37- "Tell me more about that"38- "Can you elaborate?"39- "Explain that better"40- "What else should I know?"41 42**Referential Questions**: Context-aware43- "How does this work?"44- "What about the previous point?"45- "Can you expand on it?"46 47**New Information Requests**: Always searched48- "Latest news about AI"49- "Current stock prices"50- "What happened today?"51 52### ⚡ Context-Aware Request Flow53 54**First Message (No History)**:55- Cache-first approach for performance56- Check vector database for similar queries57- Search only if no relevant cached results58 59**Follow-up Messages (Has History)**:60- Analyze conversation context first61- Search only when new information needed62- Leverage existing conversation knowledge63 64### 🗄️ ChromaDB Vector Caching65 66**Semantic Similarity Matching**:67- Finds similar queries even with different wording68- "machine learning basics" matches "intro to ML"69- Persistent storage across server restarts70 71**Performance Benefits**:72- Instant responses for cached queries73- Reduced API costs and latency74- Automatic cache cleanup and management75 76## Configuration Options77 78### Search Decision Modes79 80Control how aggressively the system searches:81 82#### Conservative Mode83```json84{85  "prompt": "Tell me about AI",86  "search_decision_mode": "conservative"87}88```89- **Behavior**: Strongly prefers conversation history90- **Use Case**: Follow-up heavy conversations, cost optimization91- **Search Reduction**: ~60-70%92 93#### Balanced Mode (Default)  94```json95{96  "prompt": "Tell me about AI", 97  "search_decision_mode": "balanced"98}99```100- **Behavior**: Smart balance between search and history101- **Use Case**: General purpose usage102- **Search Reduction**: ~40-50%103 104#### Aggressive Mode105```json106{107  "prompt": "Tell me about AI",108  "search_decision_mode": "aggressive"  109}110```111- **Behavior**: Prefers fresh web search results112- **Use Case**: News, current events, frequently changing topics113- **Search Reduction**: ~20-30%114 115### Force Search Override116 117Complete control over search behavior:118 119```json120{121  "prompt": "What is 2+2?",122  "force_search": true123}124```125 126**Values**:127- `true`: Always search, ignore optimization128- `false`: Never search, use only conversation history129- `null` (default): Use intelligent optimization130 131## Usage Examples132 133### Basic Usage134 135**Let the system optimize automatically:**136```bash137curl -X POST /chat -d '{138  "prompt": "What is machine learning?"139}'140# System will search (no conversation history)141```142 143```bash144curl -X POST /chat -d '{145  "prompt": "Tell me more about neural networks",146  "history": [147    {"role": "user", "content": "What is machine learning?"},148    {"role": "assistant", "content": "Machine learning is..."}149  ]150}'151# System will likely skip search (elaboration request)152```153 154### Advanced Configuration155 156**Conservative approach for cost optimization:**157```javascript158const response = await fetch('/chat', {159  method: 'POST',160  headers: { 'Content-Type': 'application/json' },161  body: JSON.stringify({162    prompt: "Can you explain that concept better?",163    search_decision_mode: "conservative",164    history: conversationHistory165  })166});167```168 169**Aggressive approach for current events:**170```javascript171const response = await fetch('/chat', {172  method: 'POST', 173  headers: { 'Content-Type': 'application/json' },174  body: JSON.stringify({175    prompt: "What are today's tech headlines?",176    search_decision_mode: "aggressive"177  })178});179```180 181**Force search for specific needs:**182```javascript183const response = await fetch('/chat', {184  method: 'POST',185  headers: { 'Content-Type': 'application/json' },186  body: JSON.stringify({187    prompt: "Company internal policy on remote work",188    force_search: true  // Ensure fresh search189  })190});191```192 193## Response Information194 195### Search Decision Details196 197Every response includes detailed search decision information:198 199```json200{201  "response": "Neural networks are...",202  "search_decision": {203    "should_search": false,204    "reason": "Elaboration request with sufficient context",205    "confidence": 0.85,206    "decision_method": "rule_based"207  },208  "cache_info": {209    "cache_hit": false,210    "flow_type": "search_decision_skip"211  }212}213```214 215**search_decision fields**:216- `should_search`: Final decision made217- `reason`: Human-readable explanation  218- `confidence`: Decision confidence (0.0-1.0)219- `decision_method`: "rule_based", "hybrid", or "fallback"220 221**cache_info fields**:222- `cache_hit`: Whether results came from cache223- `flow_type`: Request processing flow used224- `cache_type`: Caching system used (e.g., "chromadb_vector")225 226### Flow Types227 228**Cache-First Flows** (No conversation history):229- `cache_first_hit`: Found cached results230- `cache_first_miss`: No cache, performed search231 232**Search-Decision-First Flows** (Has conversation history):  233- `search_decision_skip`: Smart system skipped search234- `search_decision_cache_hit`: Decided to search, found in cache235- `search_decision_cache_miss`: Decided to search, performed web search236 237## Performance Benefits238 239### Response Time Improvements240 241**Cached Responses**: < 200ms242- Instant retrieval from ChromaDB243- No web search delays244- No API rate limiting245 246**Skipped Searches**: < 500ms  247- Fast rule-based decisions (< 1ms)248- Direct conversation history usage249- No external API calls250 251**Regular Searches**: 2-5 seconds252- Only when truly needed253- Fresh information guaranteed254- Full web search capabilities255 256### Cost Optimization257 258**API Call Reduction**:259- Search API calls: -40 to -60%260- AI model calls: Optimized caching261- Rate limit utilization: More efficient262 263**Resource Usage**:264- Server CPU: Reduced search processing265- Network bandwidth: Fewer external requests266- Storage: Efficient vector caching267 268## Best Practices269 270### For Different Use Cases271 272**Customer Support Chatbots**:273```json274{275  "search_decision_mode": "conservative",276  "force_search": false277}278```279- Rely heavily on conversation context280- Minimize external searches for common questions281- Use aggressive mode only for account-specific queries282 283**News and Information Services**:284```json285{286  "search_decision_mode": "aggressive", 287  "force_search": null288}289```290- Prioritize fresh information291- Let system decide on follow-up questions292- Cache recent searches for popular topics293 294**Educational Applications**:295```json296{297  "search_decision_mode": "balanced",298  "force_search": null299}300```301- Balance between comprehensive info and follow-ups302- Trust the system's optimization303- Use force_search for specific research needs304 305### Conversation Design306 307**Effective Follow-ups** (will skip search):308- "Can you explain that in simpler terms?"309- "What are some examples of this?"310- "How does this relate to what we discussed?"311 312**New Topic Indicators** (will trigger search):313- "Now tell me about [different topic]"314- "What's the latest on [topic]?"315- "I have a question about [new subject]"316 317## Monitoring and Analytics318 319### Cache Performance320 321Check cache effectiveness at `/analytics/cache`:322 323```json324{325  "cache_statistics": {326    "hit_rate_percentage": 65.4,327    "cache_size": 1250,328    "memory_usage_mb": 45.2329  },330  "cache_effectiveness": "High"331}332```333 334### Search Decision Analytics335 336View optimization impact at `/analytics/dashboard`:337 338- **Search reduction percentage**339- **Response time improvements** 340- **Decision accuracy metrics**341- **Cache hit rates over time**342 343### Individual Query Analysis344 345Each response includes optimization details for monitoring:346 347```javascript348// Log search decisions for analysis349console.log(`Decision: ${response.search_decision.should_search}`);350console.log(`Reason: ${response.search_decision.reason}`);351console.log(`Confidence: ${response.search_decision.confidence}`);352console.log(`Cache hit: ${response.cache_info.cache_hit}`);353```354 355## Troubleshooting356 357### Common Issues358 359**Too Many Searches**:360- Use "conservative" mode361- Check conversation history format362- Verify follow-up question patterns363 364**Missing Information**:365- Use "aggressive" mode for current events366- Check cache expiration settings367- Use force_search for critical updates368 369**Slow Responses**:370- Monitor cache hit rates371- Check ChromaDB performance372- Verify conversation history size373 374### Performance Optimization375 376**For High Traffic**:377- Use conservative mode to maximize cache hits378- Implement client-side conversation management379- Monitor cache performance metrics380 381**For Accuracy**:382- Use aggressive mode for dynamic content383- Implement domain-specific force_search logic384- Monitor false negative rates385 386## Advanced Features387 388### Custom Integration Patterns389 390**Progressive Enhancement**:391```javascript392class SmartChatClient {393  constructor() {394    this.mode = "balanced";  // Start balanced395  }396  397  // Adapt based on conversation type398  setContextMode(conversationType) {399    switch(conversationType) {400      case "support": this.mode = "conservative"; break;401      case "news": this.mode = "aggressive"; break;402      default: this.mode = "balanced";403    }404  }405}406```407 408**Domain-Specific Rules**:409```javascript410function getSearchMode(prompt) {411  if (prompt.includes("latest") || prompt.includes("current")) {412    return "aggressive";413  }414  if (prompt.includes("explain") || prompt.includes("clarify")) {415    return "conservative";  416  }417  return "balanced";418}419```420 421### Integration with Analytics422 423**Track Optimization Impact**:424```javascript425// Monitor search reduction426const searchReduction = (totalRequests - actualSearches) / totalRequests;427 428// Track response time improvements  429const avgResponseTime = responseTimes.reduce((a, b) => a + b) / responseTimes.length;430 431// Measure user satisfaction432const satisfactionScore = positiveResponses / totalResponses;433```434 435## Future Enhancements436 437### Planned Features438 439- **User Learning**: Personalized optimization based on usage patterns440- **Domain Adaptation**: Industry-specific optimization rules441- **Multimodal Context**: Support for image and document context442- **Real-time Adaptation**: Dynamic threshold adjustment based on performance443 444### Feedback and Improvement445 446The search optimization system continuously improves based on:447- **Usage patterns**: Common conversation flows  448- **Performance metrics**: Response times and accuracy449- **User feedback**: Explicit and implicit satisfaction signals450- **Cache effectiveness**: Hit rates and relevance scoring451 452---453 454The search optimization system makes Atlas smarter, faster, and more cost-effective while maintaining the high-quality responses users expect. By intelligently determining when fresh information is needed versus when conversation history suffices, Atlas provides an optimal balance of performance and accuracy.