Skip to main content

EmbeddingProvider

Trait EmbeddingProvider 

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

    // Provided methods
    fn embed_batch<'life0, 'life1, 'async_trait>(
        &'life0 self,
        texts: &'life1 [String],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn similarity<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        text1: &'life1 str,
        text2: &'life2 str,
    ) -> Pin<Box<dyn Future<Output = Result<f32>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn is_available<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn warmup<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn metadata(&self) -> Value { ... }
}
Expand description

Trait for embedding providers that convert text to vectors

Required Methods§

Source

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

Generate embedding for a single text

§Arguments
  • text - Input text to embed
§Returns

Vector representation of the text

Source

fn embedding_dimension(&self) -> usize

Get the embedding dimension for this provider

Source

fn model_name(&self) -> &str

Get the model name/identifier

Provided Methods§

Source

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

Generate embeddings for multiple texts in batch

More efficient than calling embed_text multiple times. Default implementation calls embed_text for each text.

§Arguments
  • texts - Batch of texts to embed
§Returns

Vector of embeddings in the same order as input texts

Source

fn similarity<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, text1: &'life1 str, text2: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<f32>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Calculate semantic similarity between two texts

§Arguments
  • text1 - First text
  • text2 - Second text
§Returns

Similarity score between 0.0 and 1.0 (higher = more similar)

Source

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

Check if the provider is available/configured

Source

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

Warm up the provider (load models, test connections, etc.)

Source

fn metadata(&self) -> Value

Get provider-specific metadata

Implementors§