EmbeddingFunction

Trait EmbeddingFunction 

Source
pub trait EmbeddingFunction: Send + Sync {
    // Required methods
    fn generate_embedding(&self, text: &str) -> Result<Vec<f64>>;
    fn dimension(&self) -> usize;
}
Expand description

Trait for embedding generation functions

This trait allows for pluggable embedding implementations, enabling custom models or different embedding strategies.

§Thread Safety

Implementations must be Send + Sync to work with the thread-safe client.

§Examples

use vectorlite::{EmbeddingFunction, embeddings::EmbeddingError};
use std::result::Result;

struct CustomEmbedding;

impl EmbeddingFunction for CustomEmbedding {
    fn generate_embedding(&self, text: &str) -> Result<Vec<f64>, EmbeddingError> {
        // Custom embedding logic
        Ok(vec![0.1; 384])
    }
     
    fn dimension(&self) -> usize {
        384
    }
}

Required Methods§

Source

fn generate_embedding(&self, text: &str) -> Result<Vec<f64>>

Generate an embedding vector for the given text

Source

fn dimension(&self) -> usize

Get the dimension of embeddings produced by this function

Implementors§