pub trait EmbeddingProvider: Send + Sync {
// Required methods
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, RagError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn dimensions(&self) -> usize;
// Provided method
fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, RagError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
}Available on crate feature
rag only.Expand description
A provider that generates vector embeddings from text input.
Implementations wrap specific embedding backends (Gemini, OpenAI, etc.)
behind a unified async interface. The default embed_batch
implementation calls embed sequentially;
backends that support native batching should override it.
§Example
ⓘ
use adk_rag::EmbeddingProvider;
let provider = MyEmbeddingProvider::new();
let embedding = provider.embed("hello world").await?;
assert_eq!(embedding.len(), provider.dimensions());Required Methods§
Sourcefn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, RagError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, RagError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Generate an embedding vector for a single text input.
Sourcefn dimensions(&self) -> usize
fn dimensions(&self) -> usize
Return the dimensionality of embeddings produced by this provider.
Provided Methods§
Sourcefn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, RagError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, RagError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Generate embedding vectors for a batch of text inputs.
The default implementation calls embed
sequentially for each input. Override this method if the backend
supports native batch embedding for better throughput.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".