pub struct CachingEmbeddingModel<M>where
M: EmbeddingModel,{ /* private fields */ }Expand description
缓存型 Embedding 模型适配器
包装一个内部 EmbeddingModel,对相同输入文本返回缓存的向量, 避免重复计算。适用于嵌入计算成本高的场景(如调用远程 API)。
§泛型参数
M: 内部嵌入模型
Implementations§
Source§impl<M> CachingEmbeddingModel<M>where
M: EmbeddingModel,
impl<M> CachingEmbeddingModel<M>where
M: EmbeddingModel,
Sourcepub fn cache_size(&self) -> usize
pub fn cache_size(&self) -> usize
获取缓存大小
Sourcepub fn cache_hits(&self) -> u64
pub fn cache_hits(&self) -> u64
获取缓存命中次数
Sourcepub fn cache_misses(&self) -> u64
pub fn cache_misses(&self) -> u64
获取缓存未命中次数
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
清空缓存
Trait Implementations§
Source§impl<M> EmbeddingModel for CachingEmbeddingModel<M>where
M: EmbeddingModel,
impl<M> EmbeddingModel for CachingEmbeddingModel<M>where
M: EmbeddingModel,
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, AiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn embed_batch<'life0, 'life1, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, AiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn dimension(&self) -> usize
fn model_name(&self) -> &str
Auto Trait Implementations§
impl<M> !Freeze for CachingEmbeddingModel<M>
impl<M> !RefUnwindSafe for CachingEmbeddingModel<M>
impl<M> Send for CachingEmbeddingModel<M>
impl<M> Sync for CachingEmbeddingModel<M>
impl<M> Unpin for CachingEmbeddingModel<M>where
M: Unpin,
impl<M> UnsafeUnpin for CachingEmbeddingModel<M>where
M: UnsafeUnpin,
impl<M> UnwindSafe for CachingEmbeddingModel<M>where
M: UnwindSafe,
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
Mutably borrows from an owned value. Read more