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
}
}