EmbeddingsClient

Trait EmbeddingsClient 

Source
pub trait EmbeddingsClient: ProviderClient + Clone {
    type EmbeddingModel: EmbeddingModel;

    // Required methods
    fn embedding_model(&self, model: &str) -> Self::EmbeddingModel;
    fn embedding_model_with_ndims(
        &self,
        model: &str,
        ndims: usize,
    ) -> Self::EmbeddingModel;

    // Provided methods
    fn embeddings<D: Embed>(
        &self,
        model: &str,
    ) -> EmbeddingsBuilder<Self::EmbeddingModel, D> { ... }
    fn embeddings_with_ndims<D: Embed>(
        &self,
        model: &str,
        ndims: usize,
    ) -> EmbeddingsBuilder<Self::EmbeddingModel, D> { ... }
}
Expand description

A provider client with embedding capabilities. Clone is required for conversions between client types.

Required Associated Types§

Source

type EmbeddingModel: EmbeddingModel

The type of EmbeddingModel used by the Client

Required Methods§

Source

fn embedding_model(&self, model: &str) -> Self::EmbeddingModel

Create an embedding model with the given name. Note: default embedding dimension of 0 will be used if model is not known. If this is the case, it’s better to use function embedding_model_with_ndims

§Example
use rig::prelude::*;
use rig::providers::openai::{Client, self};

// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");

let embedding_model = openai.embedding_model(openai::TEXT_EMBEDDING_3_LARGE);
Source

fn embedding_model_with_ndims( &self, model: &str, ndims: usize, ) -> Self::EmbeddingModel

Create an embedding model with the given name and the number of dimensions in the embedding generated by the model.

§Example with OpenAI
use rig::prelude::*;
use rig::providers::openai::{Client, self};

// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");

let embedding_model = openai.embedding_model("model-unknown-to-rig", 3072);

Provided Methods§

Source

fn embeddings<D: Embed>( &self, model: &str, ) -> EmbeddingsBuilder<Self::EmbeddingModel, D>

Create an embedding builder with the given embedding model.

§Example with OpenAI
use rig::prelude::*;
use rig::providers::openai::{Client, self};

// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");

let embeddings = openai.embeddings(openai::TEXT_EMBEDDING_3_LARGE)
    .simple_document("doc0", "Hello, world!")
    .simple_document("doc1", "Goodbye, world!")
    .build()
    .await
    .expect("Failed to embed documents");
Source

fn embeddings_with_ndims<D: Embed>( &self, model: &str, ndims: usize, ) -> EmbeddingsBuilder<Self::EmbeddingModel, D>

Create an embedding builder with the given name and the number of dimensions in the embedding generated by the model.

§Example with OpenAI
use rig::prelude::*;
use rig::providers::openai::{Client, self};

// Initialize the OpenAI client
let openai = Client::new("your-open-ai-api-key");

let embeddings = openai.embeddings_with_ndims(openai::TEXT_EMBEDDING_3_LARGE, 3072)
    .simple_document("doc0", "Hello, world!")
    .simple_document("doc1", "Goodbye, world!")
    .build()
    .await
    .expect("Failed to embed documents");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> EmbeddingsClient for rig::providers::azure::Client<T>
where T: HttpClientExt + Clone + Debug + Default + Send + 'static,

Source§

impl<T> EmbeddingsClient for rig::providers::cohere::client::Client<T>
where T: HttpClientExt + Clone + Debug + Default + WasmCompatSend + 'static,

Source§

impl<T> EmbeddingsClient for rig::providers::gemini::client::Client<T>
where T: HttpClientExt + Clone + Debug + Default + 'static, Client<T>: CompletionClient,

Source§

impl<T> EmbeddingsClient for rig::providers::mistral::client::Client<T>
where T: HttpClientExt + Clone + Default + Debug + Send + 'static,

Source§

impl<T> EmbeddingsClient for rig::providers::ollama::Client<T>
where T: HttpClientExt + Clone + Debug + Default + Send + 'static,

Source§

impl<T> EmbeddingsClient for rig::providers::openai::client::Client<T>
where T: HttpClientExt + Debug + Clone + Default + Send + 'static,

Source§

impl<T> EmbeddingsClient for rig::providers::together::client::Client<T>
where T: HttpClientExt + Clone + Default + Debug + Send + 'static,

Source§

impl<T> EmbeddingsClient for rig::providers::voyageai::Client<T>
where T: HttpClientExt + Clone + Debug + Default + 'static,

Although the models have default embedding dimensions, there are additional alternatives for increasing and decreasing the dimensions to your requirements. See Voyage AI’s documentation: https://docs.voyageai.com/docs/embeddings