Skip to main content

EmbeddingBackend

Trait EmbeddingBackend 

Source
pub trait EmbeddingBackend: Send + Sync {
    // Required methods
    fn embed_batch<'life0, 'life1, 'async_trait>(
        &'life0 self,
        texts: &'life1 [String],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn dimension(&self) -> usize;
    fn backend_kind(&self) -> BackendKind;
}
Expand description

Core embedding backend trait. All backends must be Send + Sync so they can be held behind an Arc and called from async tasks.

Required Methods§

Source

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

Embed a batch of raw texts and return a float32 embedding per input.

Callers must pre-process texts (apply prefixes, truncation) before calling this method. The returned Vec has the same length as texts. Empty input returns an empty vec immediately.

Source

fn dimension(&self) -> usize

Embedding dimensionality (fixed for the lifetime of the backend).

Source

fn backend_kind(&self) -> BackendKind

The concrete backend kind — used for metrics and re-embed bookkeeping.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§