Skip to main content

EmbeddingModel

Trait EmbeddingModel 

Source
pub trait EmbeddingModel: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn dimensions(&self) -> usize;
    fn embed<'life0, 'life1, 'async_trait>(
        &'life0 self,
        input: EmbedInput,
        settings: &'life1 EmbeddingSettings,
    ) -> Pin<Box<dyn Future<Output = Result<EmbeddingOutput, EmbeddingError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn max_tokens(&self) -> usize { ... }
    fn embed_query<'life0, 'life1, 'async_trait>(
        &'life0 self,
        query: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<EmbeddingOutput, EmbeddingError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn embed_documents<'life0, 'async_trait>(
        &'life0 self,
        docs: Vec<String>,
    ) -> Pin<Box<dyn Future<Output = Result<EmbeddingOutput, EmbeddingError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
    fn count_tokens<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _text: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<u64, EmbeddingError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
}
Available on crate feature embeddings only.
Expand description

Core trait for embedding models.

Required Methods§

Source

fn name(&self) -> &str

Get the model name.

Source

fn dimensions(&self) -> usize

Get the default embedding dimensions.

Source

fn embed<'life0, 'life1, 'async_trait>( &'life0 self, input: EmbedInput, settings: &'life1 EmbeddingSettings, ) -> Pin<Box<dyn Future<Output = Result<EmbeddingOutput, EmbeddingError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Generate embeddings.

Provided Methods§

Source

fn max_tokens(&self) -> usize

Get the maximum tokens per input.

Source

fn embed_query<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<EmbeddingOutput, EmbeddingError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Embed a single query.

Source

fn embed_documents<'life0, 'async_trait>( &'life0 self, docs: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<EmbeddingOutput, EmbeddingError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Embed multiple documents.

Source

fn count_tokens<'life0, 'life1, 'async_trait>( &'life0 self, _text: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<u64, EmbeddingError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Count tokens in text (if supported).

Implementors§