Skip to main content

EmbeddingModel

Trait EmbeddingModel 

Source
pub trait EmbeddingModel: WasmCompatSend + WasmCompatSync {
    type Client;

    const MAX_DOCUMENTS: usize;

    // Required methods
    fn make(
        client: &Self::Client,
        model: impl Into<String>,
        dims: Option<usize>,
    ) -> Self;
    fn ndims(&self) -> usize;
    fn embed_texts(
        &self,
        texts: impl IntoIterator<Item = String> + WasmCompatSend,
    ) -> impl Future<Output = Result<Vec<Embedding>, EmbeddingError>> + WasmCompatSend;

    // Provided methods
    fn embed_text(
        &self,
        text: &str,
    ) -> impl Future<Output = Result<Embedding, EmbeddingError>> + WasmCompatSend { ... }
    fn embed_texts_with_usage(
        &self,
        texts: impl IntoIterator<Item = String> + WasmCompatSend,
    ) -> impl Future<Output = Result<EmbeddingResponse, EmbeddingError>> + WasmCompatSend { ... }
    fn embed_text_with_usage(
        &self,
        text: &str,
    ) -> impl Future<Output = Result<EmbeddingResponse, EmbeddingError>> + WasmCompatSend { ... }
}
Expand description

Trait for embedding models that can generate embeddings for documents.

Required Associated Constants§

Source

const MAX_DOCUMENTS: usize

The maximum number of documents that can be embedded in a single request.

Required Associated Types§

Source

type Client

Provider client type used to construct this embedding model.

Required Methods§

Source

fn make( client: &Self::Client, model: impl Into<String>, dims: Option<usize>, ) -> Self

Construct a model handle from a provider client, model identifier, and optional dimensions.

Source

fn ndims(&self) -> usize

The number of dimensions in the embedding vector.

Source

fn embed_texts( &self, texts: impl IntoIterator<Item = String> + WasmCompatSend, ) -> impl Future<Output = Result<Vec<Embedding>, EmbeddingError>> + WasmCompatSend

Embed multiple text documents in a single request

Provided Methods§

Source

fn embed_text( &self, text: &str, ) -> impl Future<Output = Result<Embedding, EmbeddingError>> + WasmCompatSend

Embed a single text document.

Source

fn embed_texts_with_usage( &self, texts: impl IntoIterator<Item = String> + WasmCompatSend, ) -> impl Future<Output = Result<EmbeddingResponse, EmbeddingError>> + WasmCompatSend

Embed multiple text documents in a single request and return token usage.

The default implementation delegates to EmbeddingModel::embed_texts and returns zero-valued usage. Providers that expose usage information from their embedding API should override this method.

Source

fn embed_text_with_usage( &self, text: &str, ) -> impl Future<Output = Result<EmbeddingResponse, EmbeddingError>> + WasmCompatSend

Embed a single text document and return token usage.

The default implementation delegates to EmbeddingModel::embed_texts_with_usage.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl EmbeddingModel for MockEmbeddingModel

Available on crate feature test-utils only.
Source§

impl<H> EmbeddingModel for rig_core::providers::copilot::EmbeddingModel<H>

Source§

impl<T> EmbeddingModel for rig_core::providers::gemini::embedding::EmbeddingModel<T>
where T: Clone + HttpClientExt + 'static,

Source§

impl<T> EmbeddingModel for rig_core::providers::mistral::embedding::EmbeddingModel<T>
where T: HttpClientExt + Clone + 'static,

Source§

impl<T> EmbeddingModel for rig_core::providers::ollama::EmbeddingModel<T>
where T: HttpClientExt + Clone + 'static,

Source§

impl<T> EmbeddingModel for rig_core::providers::voyageai::EmbeddingModel<T>
where T: HttpClientExt + Clone + Debug + Default + 'static,

Source§

impl<T> EmbeddingModel for rig_core::providers::llamafile::EmbeddingModel<T>
where T: HttpClientExt + Clone + Debug + Default + Send + 'static,

Source§

impl<T> EmbeddingModel for rig_core::providers::openrouter::embedding::EmbeddingModel<T>
where T: HttpClientExt + Clone + Debug + Default + WasmCompatSend + 'static,

Source§

impl<T> EmbeddingModel for rig_core::providers::cohere::embeddings::EmbeddingModel<T>

Source§

impl<T> EmbeddingModel for rig_core::providers::azure::EmbeddingModel<T>
where T: HttpClientExt + Default + Clone + 'static,

Source§

impl<T> EmbeddingModel for rig_core::providers::together::embedding::EmbeddingModel<T>
where T: HttpClientExt + Default + Clone + Send + 'static,