When to Optimize
Don’t prematurely optimize. Focus on performance when you notice:- Slow search - Queries taking more than 2-3 seconds
- Memory issues - Out of memory errors during content loading
- Poor results - Search returning irrelevant chunks or missing obvious matches
- Slow loading - Content processing taking unusually long
The 80/20 of Performance
These five changes give you the biggest performance boost for the least effort:1. Pick the Right Vector Database
Your database choice has the biggest impact on performance at scale:- LanceDB for development and testing (no setup required)
- PgVector for production (up to 1M documents, need SQL features)
- Pinecone for managed services (no ops overhead, auto-scaling)
2. Skip Already-Processed Files
The single biggest speed-up for re-running your ingestion:3. Use Metadata Filters
Narrow searches before vector comparison for faster, more accurate results:4. Match Chunking Strategy to Your Content
Different strategies have different performance characteristics:5. Use Async for Batch Operations
Process multiple items concurrently:Common Performance Pitfalls
Issue: Search Returns Irrelevant Results
What’s happening: Chunks are too large, too small, or chunking strategy doesn’t match your content. Quick fixes:- Check your chunking strategy - try semantic chunking for better context
- Verify content actually loaded:
knowledge.get_content_status(content_id) - Increase
max_resultsto see if relevant results are just ranked lower - Add metadata filters to narrow the search scope
Issue: Content Loading is Slow
What’s happening: Processing large files without batching, or using semantic chunking on huge datasets. Quick fixes:- Use
skip_if_exists=Trueto avoid reprocessing - Switch to fixed-size chunking for faster processing
- Process in batches instead of all at once
- Use file filters to only process what you need
Issue: Running Out of Memory
What’s happening: Loading too many large files at once, or chunk sizes are too large. Quick fixes:- Process content in smaller batches (see code above)
- Reduce chunk size in your chunking strategy
- Use
includeandexcludepatterns to limit what gets processed - Clear old/outdated content regularly with
knowledge.remove_content_by_id()
Advanced Optimizations
Once you’ve applied the quick wins above, consider these for further improvements:Use Hybrid Search
Combine vector and keyword search for better results:Add Reranking
Improve result quality by reranking with Cohere:Optimize Embedder Dimensions
Reduce dimensions for faster search (with slight quality trade-off):Monitoring Performance
Keep an eye on these metrics:Next Steps
Chunking Strategies
Learn how different chunking strategies affect performance
Vector Databases
Compare vector database options for your scale
Embedders
Choose the right embedder for your use case
Hybrid Search
Combine vector and keyword search for better results