EmbeddingProvider

Trait EmbeddingProvider 

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

    // Provided methods
    fn embed_query<'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 health_check<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn max_batch_size(&self) -> usize { ... }
    fn embed_documents_batched<'life0, 'async_trait>(
        &'life0 self,
        texts: Vec<String>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait for embedding generation providers

Implementors generate vector embeddings from text, supporting both single queries and batch document processing.

Required Methods§

Source

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

Generate embeddings for multiple documents

§Arguments
  • texts - List of text documents to embed
§Returns

Vector of embeddings, one per input document, in the same order

Source

fn dimensions(&self) -> usize

Get the embedding dimension size

Source

fn model_name(&self) -> &str

Get the model name/identifier

Source

fn provider_name(&self) -> &str

Get the provider name (e.g., “fastembed”, “openai”, “ollama”)

Provided Methods§

Source

fn embed_query<'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 query

Some providers optimize query embeddings differently than document embeddings. By default, this calls embed_documents with a single item.

§Arguments
  • text - The query text to embed
Source

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

Check if the provider is available (API key set, server running, etc.)

Source

fn max_batch_size(&self) -> usize

Get the maximum batch size for embed_documents

Source

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

Embed documents in batches, respecting max_batch_size

Implementors§