Best Practices
Quick Wins
1. Choose the Right Mode
// ❌ BAD - Slow and expensive for simple queries
await query({ query: 'Alice', mode: 'mix' });// ✅ GOOD - Fast for entity lookups
await query({ query: 'Alice', mode: 'local' });
// ✅ GOOD - Fast for keywords
await query({ query: 'API refactor', mode: 'naive' });
// ✅ GOOD - Use mix for complex questions
await query({
query: 'What did Alice say about the API refactor last week?',
mode: 'mix',
});2. Adjust top_k Based on Needs
top_k Based on Needs3. Cache Frequently Asked Questions
4. Use Progressive Enhancement
Query Mode Selection
Decision Tree
Mode Comparison Table
Mode
Speed
Accuracy
Cost
Best For
Real-World Examples
✅ Good Mode Choices
❌ Poor Mode Choices
Parameter Tuning
top_k (Candidates Retrieved)
top_k (Candidates Retrieved)chunk_top_k (Final Results)
chunk_top_k (Final Results)score_threshold (Quality Filter)
score_threshold (Quality Filter)Performance Optimization
1. Parallel Queries
2. Request Batching
3. Debounce User Input
4. Prefetch Common Queries
5. Use Streaming for Long Results
Cost Optimization
1. Minimize Reranking
2. Use Appropriate Embedding Models
3. Batch Indexing
Error Handling
1. Graceful Degradation
2. Timeout Handling
3. Retry Logic
Query Optimization Patterns
Pattern 1: Query Expansion
Pattern 2: Query Rewriting
Pattern 3: Multi-Step Queries
Common Pitfalls
❌ Don't: Always Use Maximum Settings
✅ Do: Match Settings to Needs
❌ Don't: Ignore Error Responses
✅ Do: Handle Errors Gracefully
❌ Don't: Query Without Validation
✅ Do: Validate and Sanitize
Monitoring & Analytics
Track Query Performance
A/B Testing Query Modes
Summary: Quick Reference
Speed Priority
Accuracy Priority
Balanced (Recommended)
Cost Priority
Next Steps
Last updated
Was this helpful?