pub trait EmbeddingModel {
type Error: Error + 'static;
const MAX_DOCUMENTS: usize;
// Required methods
fn ndims(&self) -> usize;
fn embed_texts(
&self,
texts: Vec<String>,
) -> impl Future<Output = Result<Vec<Embedding>, Self::Error>>;
// Provided method
fn embed_text(
&self,
text: &str,
) -> impl Future<Output = Result<Embedding, Self::Error>> { ... }
}Expand description
Trait for models that can generate vector embeddings from text.
Implement this for each provider. The EmbeddingsBuilder
uses MAX_DOCUMENTS to chunk requests so you never exceed the provider’s
per-request batch limit.
§Example
ⓘ
use irig::embeddings::{EmbeddingModel, Embedding, EmbeddingError};
pub struct MyEmbedder<H> { client: H, model: String }
impl<H: HttpClient> EmbeddingModel for MyEmbedder<H> {
const MAX_DOCUMENTS: usize = 100;
type Error = EmbeddingError;
fn ndims(&self) -> usize { 1536 }
async fn embed_texts(&self, texts: Vec<String>) -> Result<Vec<Embedding>, EmbeddingError> {
// call API, return one Embedding per input text (same order)
todo!()
}
}Required Associated Constants§
Sourceconst MAX_DOCUMENTS: usize
const MAX_DOCUMENTS: usize
Maximum number of texts the provider accepts in a single request.
Required Associated Types§
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".