Skip to main content

EmbeddingProvider

Trait EmbeddingProvider 

Source
pub trait EmbeddingProvider: Send + Sync {
    // Required methods
    fn info(&self) -> ProviderInfo;
    fn is_available(&self) -> impl Future<Output = bool> + Send;
    fn generate_embedding(
        &self,
        text: &str,
    ) -> impl Future<Output = Result<Vec<f32>>> + Send;

    // Provided method
    fn generate_embeddings(
        &self,
        texts: &[&str],
    ) -> impl Future<Output = Result<Vec<Vec<f32>>>> + Send { ... }
}
Expand description

Trait for embedding providers.

Implemented by Ollama and HuggingFace providers. The trait is object-safe to allow runtime provider selection.

Required Methods§

Source

fn info(&self) -> ProviderInfo

Get provider metadata.

Source

fn is_available(&self) -> impl Future<Output = bool> + Send

Check if the provider is available.

For Ollama, this checks if the server is running and the model is available. For HuggingFace, this checks if the API token is valid.

Source

fn generate_embedding( &self, text: &str, ) -> impl Future<Output = Result<Vec<f32>>> + Send

Generate embedding for a single text.

Provided Methods§

Source

fn generate_embeddings( &self, texts: &[&str], ) -> impl Future<Output = Result<Vec<Vec<f32>>>> + Send

Generate embeddings for multiple texts (batch).

Default implementation calls generate_embedding for each text.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§