Skip to main content

EmbeddingModel

Trait EmbeddingModel 

Source
pub trait EmbeddingModel:
    Send
    + Sync
    + Debug {
    // Required methods
    fn provider(&self) -> &str;
    fn model_id(&self) -> &str;
    fn do_embed<'life0, 'async_trait>(
        &'life0 self,
        options: EmbedOptions,
    ) -> Pin<Box<dyn Future<Output = Result<EmbedResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn specification_version(&self) -> &'static str { ... }
    fn max_embeddings_per_call<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Option<u32>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn supports_parallel_calls<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Contract every text-embedding model implements.

Mirrors EmbeddingModelV4. We pin the input type to String for now — audio / image embeddings will introduce a parallel trait when needed.

Required Methods§

Source

fn provider(&self) -> &str

Provider id, e.g. "openai".

Source

fn model_id(&self) -> &str

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

Source

fn do_embed<'life0, 'async_trait>( &'life0 self, options: EmbedOptions, ) -> Pin<Box<dyn Future<Output = Result<EmbedResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Embed a batch of inputs.

§Errors

Returns a crate::ProviderError when the upstream call fails or the response is malformed.

Provided Methods§

Source

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

Specification version (currently "v4").

Mirrors EmbeddingModelV4.specificationVersion (ai-sdk embedding-model-v4.ts). Provider impls inherit the default.

Source

fn max_embeddings_per_call<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Option<u32>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Maximum inputs the provider accepts per call.

None means “no documented limit”; callers should still batch conservatively. Defaults to None.

Source

fn supports_parallel_calls<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Whether the model can handle multiple embed calls in parallel.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§