Trait EmbeddingModel

Source
pub trait EmbeddingModel: Send + Sync {
    type Config: Send + Sync;

    // Required methods
    fn embed_text<'life0, 'life1, 'async_trait>(
        &'life0 self,
        text: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, VectorError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn embed_batch<'life0, 'life1, 'async_trait>(
        &'life0 self,
        texts: &'life1 [String],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, VectorError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn dimensions(&self) -> usize;
    fn model_name(&self) -> &str;
    fn max_input_length(&self) -> Option<usize>;
    fn health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), VectorError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
}
Expand description

Trait for embedding models

This trait abstracts over different embedding providers like OpenAI, Ollama, local models, etc.

Required Associated Types§

Source

type Config: Send + Sync

Model-specific configuration type

Required Methods§

Source

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

Generate embedding for a single text

Source

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

Generate embeddings for multiple texts (batch processing)

Source

fn dimensions(&self) -> usize

Get the dimension of embeddings produced by this model

Source

fn model_name(&self) -> &str

Get the model name/identifier

Source

fn max_input_length(&self) -> Option<usize>

Get the maximum input length supported by the model

Source

fn health_check<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), VectorError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Check if the model is available/healthy

Implementors§