Skip to main content

VisionEmbeddings

Trait VisionEmbeddings 

Source
pub trait VisionEmbeddings: Send + Sync {
    // Required methods
    fn embed_image<'life0, 'life1, 'async_trait>(
        &'life0 self,
        image: &'life1 ImageInput,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn embed_text<'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_images<'life0, 'life1, 'async_trait>(
        &'life0 self,
        images: &'life1 [ImageInput],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

Cross-modal embedding model: images and text mapped to one shared space.

§Contract

  • embed_text and embed_image return vectors of identical dimension (VisionEmbeddings::dimension) that are directly comparable (cosine similarity) across modalities;
  • all vectors are L2-normalized;
  • empty/whitespace text or image payloads raise EmbeddingError::EmptyInput;
  • an empty image slice is Ok(vec![]) (nothing to do is not an error).

Required Methods§

Source

fn embed_image<'life0, 'life1, 'async_trait>( &'life0 self, image: &'life1 ImageInput, ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, EmbeddingError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Embeds a single image.

Source

fn embed_text<'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,

Embeds text into the same vector space as the images.

Use this (not a text-only crate::Embeddings model) when building text-to-image retrieval: the query vector and the stored image vectors must come from one model family.

Source

fn dimension(&self) -> usize

Embedding dimension (identical for both modalities).

Source

fn model_name(&self) -> &str

Model name.

Provided Methods§

Source

fn embed_images<'life0, 'life1, 'async_trait>( &'life0 self, images: &'life1 [ImageInput], ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, EmbeddingError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Embeds multiple images. The default loops one-by-one; HTTP backends override it with a single batched request and must enforce batch alignment (requested count == returned count).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§