Skip to main content

Embedder

Trait Embedder 

Source
pub trait Embedder: Send + Sync {
    // Required methods
    fn embed(&self, texts: &[&str]) -> Result<Vec<Vec<f32>>>;
    fn model_id(&self) -> &str;
    fn dim(&self) -> usize;

    // Provided method
    fn embed_one(&self, text: &str) -> Result<Vec<f32>> { ... }
}
Expand description

A text embedder. Implementations return exactly one vector per input, all of the same dim, produced by the model named by model_id.

Required Methods§

Source

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

Embed a batch of texts. out[i] corresponds to texts[i].

Source

fn model_id(&self) -> &str

Stable identifier of the model (stored per vector so a model change can trigger a re-embed and we never compare vectors across models).

Source

fn dim(&self) -> usize

Output dimensionality.

Provided Methods§

Source

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

Convenience: embed a single text.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl Embedder for HashEmbedder

Source§

impl Embedder for Model2VecEmbedder

Available on crate feature embed only.