pub trait EmbeddingModel: Send + Sync {
// Required methods
fn provider(&self) -> &str;
fn model_id(&self) -> &str;
fn max_embeddings_per_call(&self) -> Option<u32>;
fn supports_parallel_calls(&self) -> bool;
fn do_embed<'life0, 'life1, 'async_trait>(
&'life0 self,
options: &'life1 EmbeddingCallOptions,
) -> Pin<Box<dyn Future<Output = Result<EmbeddingResult, AiMuxError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn specification_version(&self) -> &'static str { ... }
fn retry_config(&self) -> RetryConfig { ... }
}Expand description
The unified embedding model trait (provider-facing).
Aligned with V4 EmbeddingModelV4. Specific to text embeddings.
§Implementation notes
do_embedis not user-facing API.embeddingsin the result must be in the same order as the inputvalues.- Providers that cannot serve a request in a single call because
values.len() > max_embeddings_per_call()should batch internally only whensupports_parallel_callsreturnstrue; otherwise they should return an error.
Required Methods§
Sourcefn max_embeddings_per_call(&self) -> Option<u32>
fn max_embeddings_per_call(&self) -> Option<u32>
Limit of how many embeddings can be generated in a single API call.
None means the model has no fixed limit. The TS spec allows this to
be a promise/function; in Rust we resolve it to a plain Option<u32>.
Sourcefn supports_parallel_calls(&self) -> bool
fn supports_parallel_calls(&self) -> bool
true if the model can handle multiple embedding calls in parallel.
Sourcefn do_embed<'life0, 'life1, 'async_trait>(
&'life0 self,
options: &'life1 EmbeddingCallOptions,
) -> Pin<Box<dyn Future<Output = Result<EmbeddingResult, AiMuxError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn do_embed<'life0, 'life1, 'async_trait>(
&'life0 self,
options: &'life1 EmbeddingCallOptions,
) -> Pin<Box<dyn Future<Output = Result<EmbeddingResult, AiMuxError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Generate a list of embeddings for the given input text.
Naming: the do_ prefix prevents accidental direct usage by users.
Provided Methods§
Sourcefn specification_version(&self) -> &'static str
fn specification_version(&self) -> &'static str
Specification version (always "v4").
fn retry_config(&self) -> RetryConfig
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".