Skip to main content

EmbeddingModelMiddleware

Trait EmbeddingModelMiddleware 

Source
pub trait EmbeddingModelMiddleware:
    Send
    + Sync
    + Debug {
    // Provided methods
    fn override_provider(&self, _inner: &dyn EmbeddingModel) -> Option<String> { ... }
    fn override_model_id(&self, _inner: &dyn EmbeddingModel) -> Option<String> { ... }
    fn override_max_embeddings_per_call<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _inner: &'life1 dyn EmbeddingModel,
    ) -> Pin<Box<dyn Future<Output = Option<Option<u32>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn override_supports_parallel_calls<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _inner: &'life1 dyn EmbeddingModel,
    ) -> Pin<Box<dyn Future<Output = Option<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn transform_params<'life0, 'life1, 'async_trait>(
        &'life0 self,
        params: EmbedOptions,
        _inner: &'life1 dyn EmbeddingModel,
    ) -> Pin<Box<dyn Future<Output = Result<EmbedOptions>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn wrap_embed<'life0, 'life1, 'async_trait>(
        &'life0 self,
        next: &'life1 dyn EmbeddingModel,
        params: EmbedOptions,
    ) -> Pin<Box<dyn Future<Output = Result<EmbedResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Contract for middleware that decorates an EmbeddingModel.

Every method has a sensible default; an implementor only overrides the hooks it cares about. The combinator wrap_embedding_model composes any number of middlewares into a fresh EmbeddingModel instance.

Provided Methods§

Source

fn override_provider(&self, _inner: &dyn EmbeddingModel) -> Option<String>

Override the provider id exposed by the wrapped model.

Source

fn override_model_id(&self, _inner: &dyn EmbeddingModel) -> Option<String>

Override the model id exposed by the wrapped model.

Source

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

Override EmbeddingModel::max_embeddings_per_call.

Returns None to defer to the inner model.

Source

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

Source

fn transform_params<'life0, 'life1, 'async_trait>( &'life0 self, params: EmbedOptions, _inner: &'life1 dyn EmbeddingModel, ) -> Pin<Box<dyn Future<Output = Result<EmbedOptions>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Transform the embed options before they reach the inner model.

§Errors

Return a crate::ProviderError to fail the call without invoking the model.

Source

fn wrap_embed<'life0, 'life1, 'async_trait>( &'life0 self, next: &'life1 dyn EmbeddingModel, params: EmbedOptions, ) -> Pin<Box<dyn Future<Output = Result<EmbedResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Wrap an embedding call.

Default: forwards to next.do_embed(params). Override to add retry, caching, telemetry, etc.

§Errors

Returns whatever error next returns, or a middleware-introduced failure.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§