Skip to main content

Embedder

Trait Embedder 

Source
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§

Source

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.

Source

fn dimensions(&self) -> usize

Length of every returned vector.

Source

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,

One vector per input text, in order.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<E: Embedder + ?Sized> Embedder for Arc<E>

Source§

fn model_id(&self) -> &str

Source§

fn dimensions(&self) -> usize

Source§

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,

Implementors§