pub struct CacheManager { /* private fields */ }Expand description
Multi-level caching system for embeddings and computations
Implementations§
Source§impl CacheManager
impl CacheManager
Sourcepub fn new(config: CacheConfig) -> Self
pub fn new(config: CacheConfig) -> Self
Create a new cache manager
Sourcepub fn get_embedding(&self, entity: &str) -> Option<Vector>
pub fn get_embedding(&self, entity: &str) -> Option<Vector>
Get cached embedding
Sourcepub fn put_embedding(&self, entity: String, embedding: Vector)
pub fn put_embedding(&self, entity: String, embedding: Vector)
Cache an embedding
Sourcepub fn get_computation(&self, key: &ComputationKey) -> Option<ComputationResult>
pub fn get_computation(&self, key: &ComputationKey) -> Option<ComputationResult>
Get cached computation result
Sourcepub fn put_computation(
&self,
key: ComputationKey,
result: ComputationResult,
computation_time_us: u64,
)
pub fn put_computation( &self, key: ComputationKey, result: ComputationResult, computation_time_us: u64, )
Cache a computation result
Sourcepub fn get_similarity_cache(&self, query: &str) -> Option<Vec<(String, f64)>>
pub fn get_similarity_cache(&self, query: &str) -> Option<Vec<(String, f64)>>
Get cached similarity results
Sourcepub fn put_similarity_cache(&self, query: String, results: Vec<(String, f64)>)
pub fn put_similarity_cache(&self, query: String, results: Vec<(String, f64)>)
Cache similarity results
Sourcepub async fn warm_cache(
&self,
model: &dyn EmbeddingModel,
entities: Vec<String>,
) -> Result<usize>
pub async fn warm_cache( &self, model: &dyn EmbeddingModel, entities: Vec<String>, ) -> Result<usize>
Warm up cache with frequently accessed entities
Sourcepub async fn precompute_common_operations(
&self,
model: &dyn EmbeddingModel,
common_queries: Vec<(String, String)>,
) -> Result<usize>
pub async fn precompute_common_operations( &self, model: &dyn EmbeddingModel, common_queries: Vec<(String, String)>, ) -> Result<usize>
Precompute and cache common operations
Sourcepub fn get_stats(&self) -> CacheStats
pub fn get_stats(&self) -> CacheStats
Get cache statistics
Sourcepub fn estimate_memory_usage(&self) -> usize
pub fn estimate_memory_usage(&self) -> usize
Get memory usage estimation
Sourcepub fn cache_attention_weights(
&self,
layer_id: &str,
input_hash: &str,
model_id: Uuid,
attention_weights: Vec<f64>,
computation_time_us: u64,
)
pub fn cache_attention_weights( &self, layer_id: &str, input_hash: &str, model_id: Uuid, attention_weights: Vec<f64>, computation_time_us: u64, )
Cache attention weights for a specific layer and input
Sourcepub fn get_attention_weights(
&self,
layer_id: &str,
input_hash: &str,
model_id: Uuid,
) -> Option<Vec<f64>>
pub fn get_attention_weights( &self, layer_id: &str, input_hash: &str, model_id: Uuid, ) -> Option<Vec<f64>>
Get cached attention weights
Sourcepub fn cache_intermediate_activations(
&self,
layer_id: &str,
input_hash: &str,
model_id: Uuid,
activations: Vec<f64>,
computation_time_us: u64,
)
pub fn cache_intermediate_activations( &self, layer_id: &str, input_hash: &str, model_id: Uuid, activations: Vec<f64>, computation_time_us: u64, )
Cache intermediate activations for a specific layer and input
Sourcepub fn get_intermediate_activations(
&self,
layer_id: &str,
input_hash: &str,
model_id: Uuid,
) -> Option<Vec<f64>>
pub fn get_intermediate_activations( &self, layer_id: &str, input_hash: &str, model_id: Uuid, ) -> Option<Vec<f64>>
Get cached intermediate activations
Sourcepub fn cache_gradients(
&self,
layer_id: &str,
batch_hash: &str,
model_id: Uuid,
gradients: Vec<Vec<f64>>,
computation_time_us: u64,
)
pub fn cache_gradients( &self, layer_id: &str, batch_hash: &str, model_id: Uuid, gradients: Vec<Vec<f64>>, computation_time_us: u64, )
Cache gradients for training optimization
Sourcepub fn get_gradients(
&self,
layer_id: &str,
batch_hash: &str,
model_id: Uuid,
) -> Option<Vec<Vec<f64>>>
pub fn get_gradients( &self, layer_id: &str, batch_hash: &str, model_id: Uuid, ) -> Option<Vec<Vec<f64>>>
Get cached gradients
Sourcepub fn cache_model_weights(
&self,
model_name: &str,
checkpoint: &str,
model_id: Uuid,
weights: Vec<Vec<f64>>,
computation_time_us: u64,
)
pub fn cache_model_weights( &self, model_name: &str, checkpoint: &str, model_id: Uuid, weights: Vec<Vec<f64>>, computation_time_us: u64, )
Cache model weights for quick model switching
Sourcepub fn get_model_weights(
&self,
model_name: &str,
checkpoint: &str,
model_id: Uuid,
) -> Option<Vec<Vec<f64>>>
pub fn get_model_weights( &self, model_name: &str, checkpoint: &str, model_id: Uuid, ) -> Option<Vec<Vec<f64>>>
Get cached model weights
Sourcepub fn cache_feature_vectors(
&self,
task_name: &str,
input_hash: &str,
model_id: Uuid,
features: Vec<f64>,
computation_time_us: u64,
)
pub fn cache_feature_vectors( &self, task_name: &str, input_hash: &str, model_id: Uuid, features: Vec<f64>, computation_time_us: u64, )
Cache feature vectors for downstream tasks
Sourcepub fn get_feature_vectors(
&self,
task_name: &str,
input_hash: &str,
model_id: Uuid,
) -> Option<Vec<f64>>
pub fn get_feature_vectors( &self, task_name: &str, input_hash: &str, model_id: Uuid, ) -> Option<Vec<f64>>
Get cached feature vectors
Sourcepub fn cache_embedding_matrices(
&self,
operation: &str,
batch_hash: &str,
model_id: Uuid,
matrices: Vec<Vec<f64>>,
computation_time_us: u64,
)
pub fn cache_embedding_matrices( &self, operation: &str, batch_hash: &str, model_id: Uuid, matrices: Vec<Vec<f64>>, computation_time_us: u64, )
Cache embedding matrices for batch operations
Sourcepub fn get_embedding_matrices(
&self,
operation: &str,
batch_hash: &str,
model_id: Uuid,
) -> Option<Vec<Vec<f64>>>
pub fn get_embedding_matrices( &self, operation: &str, batch_hash: &str, model_id: Uuid, ) -> Option<Vec<Vec<f64>>>
Get cached embedding matrices
Sourcepub fn cache_loss_values(
&self,
loss_type: &str,
epoch_batch: &str,
model_id: Uuid,
losses: Vec<f64>,
computation_time_us: u64,
)
pub fn cache_loss_values( &self, loss_type: &str, epoch_batch: &str, model_id: Uuid, losses: Vec<f64>, computation_time_us: u64, )
Cache loss values for training monitoring
Sourcepub fn get_loss_values(
&self,
loss_type: &str,
epoch_batch: &str,
model_id: Uuid,
) -> Option<Vec<f64>>
pub fn get_loss_values( &self, loss_type: &str, epoch_batch: &str, model_id: Uuid, ) -> Option<Vec<f64>>
Get cached loss values
Sourcepub fn cache_generic_result(
&self,
operation: &str,
input_hash: &str,
model_id: Uuid,
result: Vec<f64>,
computation_time_us: u64,
)
pub fn cache_generic_result( &self, operation: &str, input_hash: &str, model_id: Uuid, result: Vec<f64>, computation_time_us: u64, )
Cache generic computation results for extensibility
Sourcepub fn get_generic_result(
&self,
operation: &str,
input_hash: &str,
model_id: Uuid,
) -> Option<Vec<f64>>
pub fn get_generic_result( &self, operation: &str, input_hash: &str, model_id: Uuid, ) -> Option<Vec<f64>>
Get cached generic result
Sourcepub fn clear_computation_cache(&self, operation_prefix: &str) -> usize
pub fn clear_computation_cache(&self, operation_prefix: &str) -> usize
Clear cache for specific computation type
Sourcepub fn get_cache_hit_rates(&self) -> HashMap<String, f64>
pub fn get_cache_hit_rates(&self) -> HashMap<String, f64>
Get cache hit rates by computation type
Sourcepub fn adaptive_resize(&mut self)
pub fn adaptive_resize(&mut self)
Adaptive cache resizing based on usage patterns
Sourcepub fn batch_cache_computations(
&self,
computations: Vec<(ComputationKey, ComputationResult)>,
)
pub fn batch_cache_computations( &self, computations: Vec<(ComputationKey, ComputationResult)>, )
Batch cache multiple computation results efficiently
Auto Trait Implementations§
impl Freeze for CacheManager
impl RefUnwindSafe for CacheManager
impl Send for CacheManager
impl Sync for CacheManager
impl Unpin for CacheManager
impl UnwindSafe for CacheManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.