Skip to main content

Embedder

Trait Embedder 

Source
pub trait Embedder: Send + Sync {
    // Required methods
    fn dim(&self) -> usize;
    fn model_name(&self) -> &str;
    fn embed<'life0, 'life1, 'async_trait>(
        &'life0 self,
        text: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbedderError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;

    // Provided method
    fn embed_batch<'life0, 'life1, 'async_trait>(
        &'life0 self,
        texts: &'life1 [String],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbedderError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

An embedder turns text into a fixed-dimension vector.

Implementations must produce vectors of Embedder::dim length on every call; the storage layer validates and rejects mismatches.

Required Methods§

Source

fn dim(&self) -> usize

Vector dimensionality.

Source

fn model_name(&self) -> &str

Stable model identifier (e.g., "bge-small-en-v1.5").

Source

fn embed<'life0, 'life1, 'async_trait>( &'life0 self, text: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbedderError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Embed one piece of text.

Provided Methods§

Source

fn embed_batch<'life0, 'life1, 'async_trait>( &'life0 self, texts: &'life1 [String], ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbedderError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Embed a batch of texts. Default implementation calls embed sequentially; production embedders should override for batching.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§