Expand description
Query result caching for improved search performance.
This module provides caching mechanisms for vector search results to avoid recomputing identical or similar queries. Particularly useful for production RAG systems with repeated queries.
§Features
- LRU (Least Recently Used) eviction
- TTL (Time-To-Live) expiration
- Approximate query matching with configurable tolerance
- Cache statistics and monitoring
- Thread-safe concurrent access
§Example
use oxify_vector::cache::{QueryCache, CacheConfig};
use oxify_vector::{SearchResult, DistanceMetric};
let config = CacheConfig::default();
let mut cache = QueryCache::new(config);
let query = vec![1.0, 2.0, 3.0];
let results = vec![
SearchResult {
entity_id: "doc1".to_string(),
score: 0.95,
distance: 0.05,
rank: 1,
},
];
// Cache the results
cache.put(&query, DistanceMetric::Cosine, 10, results.clone());
// Retrieve from cache
if let Some(cached) = cache.get(&query, DistanceMetric::Cosine, 10) {
println!("Cache hit! Found {} results", cached.len());
}Structs§
- Cache
Config - Configuration for query result caching.
- Cache
Stats - Statistics for cache performance monitoring.
- Query
Cache - Thread-safe query result cache with LRU eviction.