pub trait EmbeddingBackend:
Send
+ Sync
+ Debug {
// Required methods
fn backend_name(&self) -> &str;
fn vector_dimension(&self) -> usize;
fn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided methods
fn model_id(&self) -> &str { ... }
fn endpoint(&self) -> Option<&str> { ... }
fn provenance(&self) -> Option<BackendProvenance> { ... }
fn embed_with_usage<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<EmbeddingBatch, EmbeddingError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), EmbeddingError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Unified embedding backend for RAG and skill matching.
Implementations may be local (FastEmbed, Candle) or hosted (OpenAI, Voyage, Cohere). Callers operate against the trait and do not depend on a specific provider.
Required Methods§
Sourcefn backend_name(&self) -> &str
fn backend_name(&self) -> &str
Return the provider name for logging and diagnostics.
Sourcefn vector_dimension(&self) -> usize
fn vector_dimension(&self) -> usize
Return the expected output vector dimension.
Sourcefn embed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + 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,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Embed a batch of texts. The returned outer vector has the same length as
texts (unless texts is empty, in which case an empty vector is
returned). Each inner vector has vector_dimension() elements.
Provided Methods§
Sourcefn model_id(&self) -> &str
fn model_id(&self) -> &str
Return the model identifier, used to fingerprint the embedding space a knowledge base was indexed in. Implementations with a configurable model must override this; two models of equal dimension are not interchangeable.
Sourcefn endpoint(&self) -> Option<&str>
fn endpoint(&self) -> Option<&str>
Actual remote endpoint, if this backend sends embedding requests over HTTP. Host settings inspection exposes only its host, never credentials.
Sourcefn provenance(&self) -> Option<BackendProvenance>
fn provenance(&self) -> Option<BackendProvenance>
Operator-visible provenance of the serving INSTANCE (where its assets
were resolved from, plus their digest). This is instance identity, not
space identity: two byte-identical asset copies are one embedding
space served by two instances, and a failover between them must stay
visible in status surfaces instead of silent. Defaults to None for
backends without local assets.
Sourcefn embed_with_usage<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<EmbeddingBatch, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn embed_with_usage<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<EmbeddingBatch, EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Embed with optional accounting on this same backend instance. Existing adapters keep their vector API and report unavailable counters.
Sourcefn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), EmbeddingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Release local inference resources after the trusted host has closed admission and joined all accepted work. Backends without owned local resources retain the default no-op implementation.
Implementations§
Source§impl dyn EmbeddingBackend
impl dyn EmbeddingBackend
Sourcepub fn fingerprint(&self) -> EmbeddingFingerprint
pub fn fingerprint(&self) -> EmbeddingFingerprint
The embedding space this backend produces vectors in.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".