EmbeddingProvider

Trait EmbeddingProvider 

Source
pub trait EmbeddingProvider: Send + Sync {
    // Required methods
    fn embed<'life0, 'life1, 'async_trait>(
        &'life0 self,
        text: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        texts: &'life1 [&'life2 str],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn dimensions(&self) -> usize;
    fn name(&self) -> &'static str;
    fn is_simulation(&self) -> bool;
}
Expand description

Trait for embedding providers.

TigerStyle: Unified interface for simulation and production.

All providers implement this trait, allowing higher-level components to work with any provider without knowing the concrete type.

§Example

use umi_memory::embedding::{EmbeddingProvider, SimEmbeddingProvider};

async fn generate_embedding<P: EmbeddingProvider>(provider: &P, text: &str) -> Vec<f32> {
    provider.embed(text).await.unwrap()
}

Required Methods§

Source

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

Generate embedding for a single text.

§Arguments
  • text - The text to embed
§Returns

Vector of floats representing the embedding (normalized to unit vector)

§Errors

Returns EmbeddingError on failure (rate limit, network error, etc.)

Source

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

Generate embeddings for multiple texts (batch).

This is more efficient than calling embed multiple times as it can leverage API batching capabilities.

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

Vector of embeddings, one per input text

§Errors

Returns EmbeddingError on failure

Source

fn dimensions(&self) -> usize

Get the embedding dimensions (e.g., 1536 for text-embedding-3-small).

Source

fn name(&self) -> &'static str

Provider name for logging and debugging.

Source

fn is_simulation(&self) -> bool

Check if this is a simulation provider.

Returns true for SimEmbeddingProvider, false for real providers.

Implementors§