pub trait Embeddings: Send + Sync {
// Required methods
fn embed_query<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn dimension(&self) -> usize;
fn model_name(&self) -> &str;
// Provided method
fn embed_documents<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait { ... }
}Expand description
Embedding model trait — re-exported from lc-embeddings.
Used by vector store implementations that need to embed documents on the fly
(e.g., Pinecone’s upsert method).
Embedding model trait
Defines the interface for generating text embedding vectors.
§Normalization contract (P2-8)
All returned vectors are L2-normalized unit vectors (except zero vectors),
regardless of whether the provider normalizes internally. This guarantees downstream
cosine, dot-product, or L2-distance results do not drift across providers. HTTP
providers call l2_normalize uniformly before returning.
Required Methods§
Sourcefn embed_query<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn embed_query<'life0, 'life1, 'async_trait>(
&'life0 self,
text: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Sourcefn model_name(&self) -> &str
fn model_name(&self) -> &str
Get the model name.
Provided Methods§
Sourcefn embed_documents<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn embed_documents<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
texts: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Generate embedding vectors for multiple documents.
§Arguments
texts- List of input texts
§Returns
List of embedding vectors
§Semantic contract (P1-1)
- Any empty or all-whitespace text (
trim().is_empty()) →Err(EmbeddingError::EmptyInput); - An empty slice
&[]is treated as “no text to embed” →Ok(vec![])(nothing to do is not an error).
The default implementation loops over Self::embed_query with a uniform emptiness
check up front; providers that override it must follow the same contract and not diverge.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".