Skip to main content

EmbeddingProvider

Trait EmbeddingProvider 

Source
pub trait EmbeddingProvider: Send + Sync {
    // Required methods
    fn embed<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        texts: &'life1 [&'life2 str],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding>, EmbedError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn dimensions(&self) -> usize;
    fn model_id(&self) -> &str;

    // Provided methods
    fn max_batch_size(&self) -> usize { ... }
    fn embed_one<'life0, 'life1, 'async_trait>(
        &'life0 self,
        text: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Embedding, EmbedError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Core embedding provider trait.

All implementations must be Send + Sync for use across async boundaries. embed is async to support both local inference (via spawn_blocking) and API-based providers (network IO).

Required Methods§

Source

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

Generate embeddings for a batch of texts.

Returns one embedding per input text, in the same order.

Source

fn dimensions(&self) -> usize

Vector dimensionality of this provider.

Source

fn model_id(&self) -> &str

Human-readable model identifier.

Provided Methods§

Source

fn max_batch_size(&self) -> usize

Maximum batch size supported.

Source

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

Embed a single text (convenience method).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§