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§
Sourcefn embed(&self, text: &str) -> Result<EmbeddingResult>
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.
Provided Methods§
Sourcefn embed_document(&self, text: &str) -> Result<EmbeddingResult>
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.
Sourcefn embed_batch(&self, texts: &[&str]) -> Result<Vec<EmbeddingResult>>
fn embed_batch(&self, texts: &[&str]) -> Result<Vec<EmbeddingResult>>
Sourcefn embed_documents(&self, texts: &[&str]) -> Result<Vec<EmbeddingResult>>
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".