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§
Sourceconst MAX_DOCUMENTS: usize
const MAX_DOCUMENTS: usize
The maximum number of documents that can be embedded in a single request.
Required Associated Types§
Required Methods§
Sourcefn make(
client: &Self::Client,
model: impl Into<String>,
dims: Option<usize>,
) -> Self
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.
Sourcefn embed_texts(
&self,
texts: impl IntoIterator<Item = String> + WasmCompatSend,
) -> impl Future<Output = Result<Vec<Embedding>, EmbeddingError>> + WasmCompatSend
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§
Sourcefn embed_text(
&self,
text: &str,
) -> impl Future<Output = Result<Embedding, EmbeddingError>> + WasmCompatSend
fn embed_text( &self, text: &str, ) -> impl Future<Output = Result<Embedding, EmbeddingError>> + WasmCompatSend
Embed a single text document.
Sourcefn embed_texts_with_usage(
&self,
texts: impl IntoIterator<Item = String> + WasmCompatSend,
) -> impl Future<Output = Result<EmbeddingResponse, EmbeddingError>> + WasmCompatSend
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.
Sourcefn embed_text_with_usage(
&self,
text: &str,
) -> impl Future<Output = Result<EmbeddingResponse, EmbeddingError>> + WasmCompatSend
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.
impl EmbeddingModel for MockEmbeddingModel
test-utils only.