pub trait Embedder:
Send
+ Sync
+ 'static {
// Required methods
fn dimension(&self) -> usize;
fn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
text: &'life1 str,
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<Embedding>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided method
fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
}Expand description
Text → vector encoder.
Implementations are typically backed by a remote API
(OpenAI / Voyage / Cohere). Per F10, instances are wrapped in Arc
at the call boundary; do not create a new client per call.
Override embed_batch when the underlying API supports
batch inference. The provided default loops sequentially via
embed, which is correct but allocates one HTTP call per
document — avoid in production.
Required Methods§
Sourcefn dimension(&self) -> usize
fn dimension(&self) -> usize
Output vector dimension. Used by VectorStore impls to validate
inserts against the configured index dimension.
Sourcefn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
text: &'life1 str,
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<Embedding>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
text: &'life1 str,
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<Embedding>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Embed one input string. Returns the vector plus optional usage metadata so downstream cost meters can charge the call without a second round-trip.
Provided Methods§
Sourcefn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn embed_batch<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
ctx: &'life2 ExecutionContext,
) -> Pin<Box<dyn Future<Output = Result<Vec<Embedding>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Batch embed. Default impl runs sequentially via embed,
polling ExecutionContext::is_cancelled between iterations
so a long batch bails out within one embed round-trip of
cancellation rather than draining the full pool.
Implementations that support a true batch endpoint
should override — sequential calls amplify network
latency by N.