Skip to main content

EmbeddingProvider

Trait EmbeddingProvider 

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

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

Trait for embedding providers.

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

Required Methods§

Source

fn dim(&self) -> usize

The dimensionality of the embedding vectors.

Source

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

Embed a single text string.

Source

fn name(&self) -> &str

Provider name for display.

Provided Methods§

Source

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

Embed multiple texts in batch.

The default implementation calls embed for each text. Returns an error on the first failure — successful results up to that point are discarded. For fine-grained error handling, call embed individually and collect results manually.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§