pub trait Embedder: Send + Sync {
// Required methods
fn model_id(&self) -> &str;
fn dimensions(&self) -> usize;
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Turns text into vectors. Implement this to use an embedding API or
another local model; crate::Memory only sees Arc<dyn Embedder>.
Vectors should be L2-normalized so cosine similarity is a dot product,
but cosine normalizes anyway.
Required Methods§
Sourcefn model_id(&self) -> &str
fn model_id(&self) -> &str
Stable identifier persisted beside every vector. Changing the model
changes this id, and old vectors are then ignored (lexical recall
still works) instead of being compared across models, until
crate::Memory::reembed_batch replaces them.
Sourcefn dimensions(&self) -> usize
fn dimensions(&self) -> usize
Length of every returned vector.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".