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 methods
    fn embed_document(&self, text: &str) -> Result<EmbeddingResult> { ... }
    fn embed_batch(&self, texts: &[&str]) -> Result<Vec<EmbeddingResult>> { ... }
    fn embed_documents(&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.

For asymmetric models (E5, BGE) this applies the query prefix — use it for search queries. Use embed_document for corpus/passage text so the query/passage asymmetry the model was trained with is respected.

Source

fn name(&self) -> &str

Provider name for display.

Provided Methods§

Source

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

Embed a single document/passage text.

Default delegates to embed; providers whose model has a distinct passage prefix override this so corpus text gets the right prefix.

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.

Source

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

Embed multiple documents/passages in batch.

Default delegates to embed_batch; asymmetric providers override to apply the passage prefix.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§