Skip to main content

HybridEmbeddingModel

Trait HybridEmbeddingModel 

Source
pub trait HybridEmbeddingModel: ModelInfo {
    // Required methods
    fn embed<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        texts: &'life1 [&'life2 str],
        heads: HeadSet,
    ) -> Pin<Box<dyn Future<Output = Result<HybridEmbedResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn available_heads(&self) -> HeadSet;

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

A model that produces several embedding heads from one shared forward pass.

Backed by multi-output exports such as BGE-M3 (aapot/bge-m3-onnx): one encoder run feeds the dense, sparse, and ColBERT post-processors, so a hybrid retrieval pipeline pays for one weight load and one forward pass instead of three. Select the heads to materialize with a HeadSet.

Required Methods§

Source

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

Embed a batch of text strings, populating the heads in heads ∩ available_heads() from a single forward pass.

Heads outside that intersection are left None on the result; the others are computed and returned in input order.

§Errors

Returns an error if tokenization fails, the model session errors, or a requested head’s output cannot be read from the graph.

Source

fn available_heads(&self) -> HeadSet

The heads this model’s graph actually exposes.

Parallels NlpModel::supported_tasks: requesting a head outside this set yields None for it rather than an error.

Provided Methods§

Source

fn warmup<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Optional warmup hook (e.g. load weights into memory on first access). The default is a no-op.

§Errors

Returns an error if the underlying model fails to initialize.

Implementors§