Skip to main content

Embeddings

Trait Embeddings 

Source
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.

Required Methods§

Source

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,

Generate an embedding vector for a single text.

§Arguments
  • text - Input text
§Returns

Embedding vector (typically 1536 dimensions or higher)

Source

fn dimension(&self) -> usize

Get the embedding vector dimension.

Source

fn model_name(&self) -> &str

Get the model name.

Provided Methods§

Source

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

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§