Skip to main content

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>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn dimensions(&self) -> usize;

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

Trait for domain-specific embedding model implementations.

Provides text-to-vector embeddings for semantic search and similarity computation. When registered with HiveMind, all experiences are embedded via this provider before storage in PulseDB (External mode).

Must be Send + Sync for concurrent use across Tokio tasks.

§Default batch implementation

embed_batch has a default implementation that calls embed sequentially. Override it for providers that support native batching (e.g., OpenAI, Cohere).

Required Methods§

Source

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

Embed a single text string into a vector.

Source

fn dimensions(&self) -> usize

Return the dimensionality of embeddings produced by this provider.

Must be constant for a given provider instance. Used to configure PulseDB’s HNSW index when opening in External mode.

Provided Methods§

Source

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

Embed a batch of text strings.

Default implementation calls embed sequentially. Override for providers that support native batch embedding (significantly faster for large batches).

Implementors§