Skip to main content

EmbeddingProvider

Trait EmbeddingProvider 

Source
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§

Source

fn model_name(&self) -> &str

Get the model name

Source

fn dimension(&self) -> usize

Get the embedding dimension

Source

fn max_length(&self) -> usize

Maximum text length (in characters or tokens)

Source

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

Generate embedding for a single text (document side).

Provided Methods§

Source

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.

Source

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.

Source

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

Generate embeddings for multiple texts (batch)

Source

fn normalize(&self, embedding: &mut [f32])

Normalize an embedding vector (L2 normalization)

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§