Skip to main content

EmbeddingModel

Trait EmbeddingModel 

Source
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_embed is not user-facing API.
  • embeddings in the result must be in the same order as the input values.
  • Providers that cannot serve a request in a single call because values.len() > max_embeddings_per_call() should batch internally only when supports_parallel_calls returns true; otherwise they should return an error.

Required Methods§

Source

fn provider(&self) -> &str

Provider name, e.g. "openai".

Source

fn model_id(&self) -> &str

Provider-specific model ID, e.g. "text-embedding-3-small".

Source

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>.

Source

fn supports_parallel_calls(&self) -> bool

true if the model can handle multiple embedding calls in parallel.

Source

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§

Source

fn specification_version(&self) -> &'static str

Specification version (always "v4").

Source

fn retry_config(&self) -> RetryConfig

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§