Skip to main content

Embedder

Trait Embedder 

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

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

Trait for generating embeddings from text

Implementations can use:

  • Local models (e.g., sentence-transformers, embeddinggemma)
  • Remote APIs (e.g., OpenAI, Cohere)
  • Mock implementations for testing

Required Methods§

Source

fn dimension(&self) -> usize

Get the embedding dimension

Source

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

Generate an embedding for the given text

Source

fn model_name(&self) -> &str

Get the model name/identifier

Provided Methods§

Source

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

Generate embeddings for multiple texts (batch) Default implementation calls embed() for each text

Implementors§