Skip to main content

EmbeddingProvider

Trait EmbeddingProvider 

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

    // Provided methods
    fn embed_batch(&self, texts: &[&str]) -> EmbeddingResult<Vec<Vec<f32>>> { ... }
    fn normalize(&self, embedding: &mut [f32]) { ... }
}
Expand description

Embedding provider trait

Required Methods§

Source

fn model_name(&self) -> &str

Get the model name

Source

fn dimension(&self) -> usize

Get the embedding dimension

Source

fn max_length(&self) -> usize

Maximum text length (in characters or tokens)

Source

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

Generate embedding for a single text

Provided Methods§

Source

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

Generate embeddings for multiple texts (batch)

Source

fn normalize(&self, embedding: &mut [f32])

Normalize an embedding vector (L2 normalization)

Implementors§