Skip to main content

Embedder

Trait Embedder 

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

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

A backend that maps text to a fixed-dimension embedding vector.

Implementations must be Send + Sync so the capability can share one instance across every Harn VM / thread, matching the code_index concurrency model. Vectors returned SHOULD be L2-normalized so the cosine math degenerates to a dot product, but [super::similarity] normalizes defensively regardless.

Required Methods§

Source

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

Embed a single string. Empty/degenerate input returns a zero vector of length Embedder::dim (cosine against it is 0.0).

Source

fn dim(&self) -> usize

Output dimensionality. Stable for the life of the backend.

Source

fn name(&self) -> &str

Stable backend identifier surfaced in hostlib_embed_info so consumers (and evals) can record which backend produced a score.

Provided Methods§

Source

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

Embed a batch. Default maps Embedder::embed; backends with a cheaper batched path may override.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§