pub trait EmbeddingProvider:
Send
+ Sync
+ 'static {
type Error: EmbeddingError;
// Required methods
fn model_id(&self) -> &str;
fn dimensions(&self) -> usize;
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
The seam between the tool-search engine and any concrete embedding backend.
One implementation per backend, dispatched behind a trait object so the
retrieval layer swaps backends without recompiling. The 'static bound and
Send + Sync make providers storable in the control plane and
shareable across tasks. Self::Error is bounded by EmbeddingError so
failures are uniform across backends while each keeps its own concrete error.
model_id and dimensions are pinned, cheap getters: the model_id is
recorded in the event log alongside a retrieval set so a result is
reproducible, and dimensions lets callers size an index without a probe
embed.
Required Associated Types§
Sourcetype Error: EmbeddingError
type Error: EmbeddingError
The provider’s concrete error type. Bounded by EmbeddingError.
Required Methods§
Sourcefn model_id(&self) -> &str
fn model_id(&self) -> &str
Stable identifier for the embedding model (e.g. "potion-base-8M").
Pinned per backend instance and recorded next to any retrieval set so
the result can be reproduced. Two providers with the same model_id
must produce comparable vectors.
Sourcefn dimensions(&self) -> usize
fn dimensions(&self) -> usize
Dimensionality of the vectors this provider produces.
Sourcefn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn embed<'life0, 'life1, 'async_trait>(
&'life0 self,
texts: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, Self::Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Embed a batch of texts, returning one vector per input in order.
Batched because the static backend amortises almost nothing per-call but
callers (indexing a connector’s whole tool catalogue) embed many short
strings at once. Each returned vector has Self::dimensions elements.
§Errors
Returns Self::Error if the model cannot embed the batch (e.g. an
uninitialised model or, for transformer backends, a tokenisation fault).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".