EmbeddingProvider

Trait EmbeddingProvider 

Source
pub trait EmbeddingProvider: Send + Sync {
    // Required methods
    fn embed<'life0, 'life1, 'async_trait>(
        &'life0 self,
        text: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn dimension(&self) -> usize;

    // Provided methods
    fn embed_batch<'life0, 'life1, 'async_trait>(
        &'life0 self,
        texts: &'life1 [String],
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Vec<f32>>, String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn model_name(&self) -> &str { ... }
}
Expand description

Trait for generating vector embeddings from text.

Implementations can use different embedding models:

  • OpenAI’s text-embedding models
  • Local models via Ollama
  • Hugging Face models
  • Custom embedding models

§Example

use ceylon_next::memory::vector::EmbeddingProvider;
use async_trait::async_trait;

struct MyEmbedder;

#[async_trait]
impl EmbeddingProvider for MyEmbedder {
    async fn embed(&self, text: &str) -> Result<Vec<f32>, String> {
        // Generate embedding...
        Ok(vec![0.1, 0.2, 0.3])
    }

    fn dimension(&self) -> usize {
        3
    }
}

Required Methods§

Source

fn embed<'life0, 'life1, 'async_trait>( &'life0 self, text: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>, String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Generates an embedding vector for the given text.

§Arguments
  • text - The text to embed
§Returns

A vector of floats representing the embedding, or an error message.

Source

fn dimension(&self) -> usize

Returns the dimensionality of the embeddings produced by this provider.

Provided Methods§

Source

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

Generates embeddings for multiple texts in batch.

Default implementation calls embed for each text sequentially. Providers can override this for more efficient batch processing.

Source

fn model_name(&self) -> &str

Returns the model name or identifier.

Implementors§