Skip to main content

Embedder

Trait Embedder 

Source
pub trait Embedder: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn version(&self) -> &str;
    fn dim(&self) -> usize;
    fn dtype(&self) -> EmbeddingDtype;
    fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        texts: &'life1 [&'life2 str],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

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

Pluggable embedder. Production impls live in solo-storage (or a future solo-embed crate); this trait is the contract.

Required Methods§

Source

fn name(&self) -> &str

Embedder identity. The migration tool solo reembed keys on (name, version) to decide whether stored embeddings need to be regenerated.

Source

fn version(&self) -> &str

Embedder version. Bump on any change that produces different vectors for the same input.

Source

fn dim(&self) -> usize

Output dimension. Must be invariant across calls for a given Embedder instance.

Source

fn dtype(&self) -> EmbeddingDtype

Output dtype. Determines how raw bytes in Embedding::data are interpreted.

Source

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

Embed a batch of texts. Output is in input order with the same length as the input. Implementations should batch internally for throughput; callers may pass any number of texts (including 1).

Provided Methods§

Source

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

Convenience: embed a single text. Default impl calls embed_batch.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§