Skip to main content

Embedder

Trait Embedder 

Source
pub trait Embedder: Send + Sync {
    // Required methods
    fn embed(&self, text: &str) -> Result<Vec<f32>, EmbedderError>;
    fn dimension(&self) -> usize;

    // Provided method
    fn embed_batch(
        &self,
        texts: &[&str],
    ) -> Result<Vec<Vec<f32>>, EmbedderError> { ... }
}
Expand description

Trait for text embedding backends.

Implementations convert text strings into dense vector representations suitable for semantic similarity search.

Required Methods§

Source

fn embed(&self, text: &str) -> Result<Vec<f32>, EmbedderError>

Embed a single text string into a vector.

Source

fn dimension(&self) -> usize

Return the dimensionality of the output embedding vectors.

Provided Methods§

Source

fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, EmbedderError>

Embed a batch of text strings into vectors.

Default implementation calls embed for each text sequentially. Backends should override this for batch-optimized inference.

Trait Implementations§

Source§

impl Embedder for Box<dyn Embedder>

Blanket implementation for boxed trait objects.

Source§

fn embed(&self, text: &str) -> Result<Vec<f32>, EmbedderError>

Embed a single text string into a vector.
Source§

fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, EmbedderError>

Embed a batch of text strings into vectors. Read more
Source§

fn dimension(&self) -> usize

Return the dimensionality of the output embedding vectors.

Implementations on Foreign Types§

Source§

impl Embedder for Box<dyn Embedder>

Blanket implementation for boxed trait objects.

Source§

fn embed(&self, text: &str) -> Result<Vec<f32>, EmbedderError>

Source§

fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>, EmbedderError>

Source§

fn dimension(&self) -> usize

Implementors§