Skip to main content

Embedder

Trait Embedder 

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

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

Text → vector encoder.

Implementations are typically backed by a remote API (OpenAI / Voyage / Cohere). Per F10, instances are wrapped in Arc at the call boundary; do not create a new client per call.

Override embed_batch when the underlying API supports batch inference. The provided default loops sequentially via embed, which is correct but allocates one HTTP call per document — avoid in production.

Required Methods§

Source

fn dimension(&self) -> usize

Output vector dimension. Used by VectorStore impls to validate inserts against the configured index dimension.

Source

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

Embed one input string. Returns the vector plus optional usage metadata so downstream cost meters can charge the call without a second round-trip.

Provided Methods§

Source

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

Batch embed. Default impl runs sequentially via embed, polling ExecutionContext::is_cancelled between iterations so a long batch bails out within one embed round-trip of cancellation rather than draining the full pool. Implementations that support a true batch endpoint should override — sequential calls amplify network latency by N.

Implementors§