Trait EmbeddingProvider
Source pub trait EmbeddingProvider: Send + Sync {
// Required methods
fn embed(&self, text: &str) -> Result<Vec<f32>>;
fn dimension(&self) -> usize;
fn model_name(&self) -> &str;
// Provided method
fn embed_batch(&self, texts: &[String]) -> Result<Vec<Vec<f32>>> { ... }
}
Expand description
Trait for text embedding generation.
Implementations should be thread-safe and reusable across concurrent contexts.
§Example
ⓘuse brainwires_core::EmbeddingProvider;
fn search(provider: &dyn EmbeddingProvider, query: &str) -> anyhow::Result<Vec<f32>> {
provider.embed(query)
}
Generate an embedding for a single text.
Get the dimensionality of the embedding vectors.
Get the model name (e.g. “all-MiniLM-L6-v2”).
Generate embeddings for a batch of texts.
Default implementation calls embed in a loop. Backends that support
native batching should override this for better performance.