pub trait EmbeddingProvider: Send + Sync {
// Required method
fn embed<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<String>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Trait for providers that can generate embedding vectors.
Implement this alongside Provider if your backend supports embeddings.
§Example
use cognate_core::EmbeddingProvider;
async fn embed<E: EmbeddingProvider>(embedder: &E) -> cognate_core::Result<()> {
let vecs = embedder.embed(vec!["Hello world".to_string()]).await?;
println!("Embedding dimension: {}", vecs[0].len());
Ok(())
}Required Methods§
Sourcefn embed<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<String>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn embed<'life0, 'async_trait>(
&'life0 self,
inputs: Vec<String>,
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Generate embedding vectors for the given list of input strings.
Returns one vector per input in the same order as inputs.