pub trait EmbeddingProvider: Send + Sync {
// Required methods
fn model_name(&self) -> &str;
fn dimension(&self) -> usize;
fn max_length(&self) -> usize;
fn embed(&self, text: &str) -> EmbeddingResult<Vec<f32>>;
// Provided methods
fn is_semantic(&self) -> bool { ... }
fn embed_query(&self, text: &str) -> EmbeddingResult<Vec<f32>> { ... }
fn embed_batch(&self, texts: &[&str]) -> EmbeddingResult<Vec<Vec<f32>>> { ... }
fn normalize(&self, embedding: &mut [f32]) { ... }
}Expand description
Embedding provider trait
Required Methods§
Sourcefn model_name(&self) -> &str
fn model_name(&self) -> &str
Get the model name
Sourcefn max_length(&self) -> usize
fn max_length(&self) -> usize
Maximum text length (in characters or tokens)
Provided Methods§
Sourcefn is_semantic(&self) -> bool
fn is_semantic(&self) -> bool
Whether this provider produces SEMANTICALLY meaningful embeddings.
Real model-backed providers return true (the default). The hash-based
MockEmbeddingProvider returns false — callers use this to avoid fusing
a meaningless cosine lane into hybrid results (which would corrupt recall
silently). Defaulted so real providers need not implement it.
Sourcefn embed_query(&self, text: &str) -> EmbeddingResult<Vec<f32>>
fn embed_query(&self, text: &str) -> EmbeddingResult<Vec<f32>>
Embed a QUERY for asymmetric retrieval. Defaults to embed (symmetric).
Providers for instruction-tuned models (e.g. BGE) override this to apply
the query-side instruction so query and document embeddings align — a
large recall lever for those models.
Sourcefn embed_batch(&self, texts: &[&str]) -> EmbeddingResult<Vec<Vec<f32>>>
fn embed_batch(&self, texts: &[&str]) -> EmbeddingResult<Vec<Vec<f32>>>
Generate embeddings for multiple texts (batch)
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".