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§
Sourcetype EmbeddingModel: EmbeddingModel
type EmbeddingModel: EmbeddingModel
The type of EmbeddingModel used by the Client
Required Methods§
Sourcefn embedding_model(&self, model: &str) -> Self::EmbeddingModel
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);
Sourcefn embedding_model_with_ndims(
&self,
model: &str,
ndims: usize,
) -> Self::EmbeddingModel
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§
Sourcefn embeddings<D: Embed>(
&self,
model: &str,
) -> EmbeddingsBuilder<Self::EmbeddingModel, D>
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");
Sourcefn embeddings_with_ndims<D: Embed>(
&self,
model: &str,
ndims: usize,
) -> EmbeddingsBuilder<Self::EmbeddingModel, D>
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 EmbeddingsClient for rig::providers::azure::Client
impl EmbeddingsClient for rig::providers::azure::Client
Source§impl EmbeddingsClient for rig::providers::cohere::client::Client
impl EmbeddingsClient for rig::providers::cohere::client::Client
Source§impl EmbeddingsClient for rig::providers::gemini::client::Client
impl EmbeddingsClient for rig::providers::gemini::client::Client
Source§impl EmbeddingsClient for rig::providers::mistral::client::Client
impl EmbeddingsClient for rig::providers::mistral::client::Client
Source§impl EmbeddingsClient for rig::providers::ollama::Client
impl EmbeddingsClient for rig::providers::ollama::Client
Source§impl EmbeddingsClient for rig::providers::openai::client::Client
impl EmbeddingsClient for rig::providers::openai::client::Client
Source§impl EmbeddingsClient for rig::providers::together::client::Client
impl EmbeddingsClient for rig::providers::together::client::Client
Source§impl EmbeddingsClient for rig::providers::voyageai::Client
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
impl EmbeddingsClient for rig::providers::voyageai::Client
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