Skip to main content

EmbeddingProvider

Trait EmbeddingProvider 

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

    // Provided method
    fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        texts: &'life1 [&'life2 str],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Trait for generating text embeddings

Required Methods§

Source

fn name(&self) -> &str

Provider name for logging

Source

fn dimension(&self) -> usize

Embedding dimension (e.g., 1536 for OpenAI text-embedding-3-small)

Source

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

Generate embedding for a single text

Provided Methods§

Source

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

Generate embeddings for multiple texts (batch)

Default implementation calls embed() sequentially.

Implementors§