Skip to main content

EmbeddingBackend

Trait EmbeddingBackend 

Source
pub trait EmbeddingBackend:
    Send
    + Sync
    + Debug {
    // Required methods
    fn backend_name(&self) -> &str;
    fn vector_dimension(&self) -> usize;
    fn embed<'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;
}
Expand description

Unified embedding backend for RAG and skill matching.

Implementations may be local (FastEmbed, Candle) or hosted (OpenAI, Voyage, Cohere). Callers operate against the trait and do not depend on a specific provider.

Required Methods§

Source

fn backend_name(&self) -> &str

Return the provider name for logging and diagnostics.

Source

fn vector_dimension(&self) -> usize

Return the expected output vector dimension.

Source

fn embed<'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,

Embed a batch of texts. The returned outer vector has the same length as texts (unless texts is empty, in which case an empty vector is returned). Each inner vector has vector_dimension() elements.

Implementations§

Source§

impl dyn EmbeddingBackend

Source

pub async fn embed_one(&self, text: &str) -> Result<Vec<f32>, EmbeddingError>

Embed a single text and return the first (only) embedding.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§