Skip to main content

Embedder

Trait Embedder 

Source
pub trait Embedder: Send + Sync {
    // Required method
    fn embed(&self, text: &str) -> Result<Vec<f32>>;

    // Provided method
    fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>> { ... }
}
Expand description

Sync embedding interface.

ONNX inference is CPU-bound and cannot yield to the async runtime. Callers must wrap calls in tokio::task::spawn_blocking.

Required Methods§

Source

fn embed(&self, text: &str) -> Result<Vec<f32>>

Embed a single text into a dense float vector.

§Errors

Returns an error if the embedding model fails.

Provided Methods§

Source

fn embed_batch(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>

Embed a batch of texts. Default implementation calls Self::embed once per text; concrete types may override for batched inference.

§Errors

Returns an error if any embedding fails.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§