Caching
Understanding Mixpeek’s caching system for improved performance
The Mixpeek caching system provides efficient caching of retriever results and collection data to improve performance and reduce computational overhead.
Overview
Mixpeek’s caching system is designed to optimize performance by reducing computational overhead and improving response times. The system caches both retriever results and collection data, providing significant benefits:
- Reducing Computational Overhead: Caching expensive retrieval operations and feature computations
- Improving Response Times: Serving frequently accessed results from cache instead of recomputing
- Optimizing Resource Usage: Minimizing redundant processing of the same queries
- Enabling Scalability: Supporting high-throughput retrieval operations efficiently
The caching system operates at two levels:
-
Retriever-level Caching: Caches the results of specific retriever operations, particularly useful for:
- Frequently repeated queries
- Expensive vector similarity searches
- Complex multimodal retrieval pipelines
- High-traffic search endpoints
-
Collection-level Caching: Caches collection-specific data and metadata, beneficial for:
- Frequently accessed documents
- Stable reference data
- Metadata that doesn’t change often
- Feature store lookups
Cache Configuration
Retriever Cache Configuration
Retrievers can be configured with specific caching parameters:
Collection Cache Configuration
Collections can also be configured with caching parameters:
Cache Invalidation Strategies
The system supports three invalidation strategies:
- REPLACE_IF_BETTER: Replace cache entry only if new score is better
- REPLACE_ALWAYS: Always replace cache entry on invalidation
- KEEP_EXISTING: Keep existing cache entry regardless of new data
Recompute Strategies
When cache entries are invalidated, you can choose how to handle recomputation:
- IMMEDIATE: Recompute the result immediately
- BACKGROUND: Recompute in the background
- LAZY: Recompute only when the result is next accessed
Cache Entry Structure
Each cache entry contains:
key
: Unique identifier for the cache entryvalue
: The cached resultscore
: Score of the cached resultcreated_at
: Timestamp of creationexpires_at
: Optional expiration timestamp
Usage with Collections
Collections can be configured with caching to improve performance:
- Collection-level caching is controlled by
CollectionCacheConfig
- Cache entries are automatically invalidated when collection data changes
- Collections can specify their own TTL and invalidation strategies
Usage with Retrievers
Retrievers can leverage caching to improve performance:
- Retriever-level caching is controlled by
RetrieverCacheConfig
- Cache keys are generated based on retriever ID and source document ID
- Results are cached only if they meet the score threshold
- Cache invalidation can be triggered by specific events
Best Practices
- Configure Appropriate TTLs: Set TTLs based on data volatility
- Use Score Thresholds: Only cache high-quality results
- Monitor Cache Statistics: Track hit ratios and adjust configurations
- Implement Proper Invalidation: Configure invalidation events for data changes
- Balance Cache Size: Use max_entries_per_key to prevent cache bloat
Example Usage
Configure Retriever Caching
Configure Collection Caching
Get Cache Statistics
Invalidate Cache
Cache Key Generation
Cache keys are automatically generated by the system based on:
- Retriever ID
- Query parameters
- Source document IDs
- Collection IDs
- Timestamp (for time-sensitive queries)
The system uses a consistent hashing algorithm to ensure:
- Unique keys for different queries
- Consistent keys for identical queries
- Proper cache invalidation when data changes
You don’t need to configure cache key generation - it’s handled automatically by the system to ensure consistency and reliability.
Next Steps
Was this page helpful?