Trait Embedder

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

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

Trait for converting text to embedding vectors.

Implementations may use local models (ONNX, TorchScript) or remote APIs (OpenAI, Cohere).

Required Methods§

Source

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

Embed a single text string into a vector.

Source

fn dimension(&self) -> usize

Output dimensionality of the embedding model.

Source

fn model_name(&self) -> &str

Name of the embedding model.

Provided Methods§

Source

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

Embed multiple texts in a batch (more efficient for APIs).

Implementors§