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§
Provided Methods§
Sourcefn 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 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.
Sourcefn model_name(&self) -> &str
fn model_name(&self) -> &str
Returns the model name or identifier.