Skip to main content

EmbeddingsClient

Trait EmbeddingsClient 

Source
pub trait EmbeddingsClient {
    type EmbeddingModel: EmbeddingModel;

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

    // Provided methods
    fn embeddings<D: Embed>(
        &self,
        model: impl Into<String>,
    ) -> 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: impl Into<String>) -> Self::EmbeddingModel

Create an embedding model with the given model.

§Example
use rig_core::prelude::*;
use rig_core::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: impl Into<String>, ndims: usize, ) -> Self::EmbeddingModel

Create an embedding model with the given model identifier string and the number of dimensions in the embedding generated by the model. Use this when the provider supports a model whose dimensionality is not known by Rig.

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

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

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

Provided Methods§

Source

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

Create an embedding builder with the given embedding model.

§Example with OpenAI
use rig_core::prelude::*;
use rig_core::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)
    .documents(vec!["Hello, world!", "Goodbye, world!"])?
    .build()
    .await?;
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_core::prelude::*;
use rig_core::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)
    .documents(vec!["Hello, world!", "Goodbye, world!"])?
    .build()
    .await?;

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<M, Ext, H> EmbeddingsClient for Client<Ext, H>
where Ext: Capabilities<H, Embeddings = Capable<M>>, M: EmbeddingModel<Client = Self>,