pub mod cache;
#[cfg(feature = "ollama")]
pub mod ollama;
#[cfg(feature = "openai")]
pub mod openai;
#[cfg(feature = "voyage")]
pub mod voyage;
use async_trait::async_trait;
use crate::error::Result;
#[async_trait]
pub trait Embedder: Send + Sync {
async fn embed(&self, text: &str) -> Result<Vec<f32>>;
async fn embed_batch(&self, texts: &[String]) -> Result<Vec<Vec<f32>>> {
let mut results = Vec::with_capacity(texts.len());
for text in texts {
results.push(self.embed(text).await?);
}
Ok(results)
}
fn dimensions(&self) -> usize;
fn model_name(&self) -> &str;
}
pub struct NoOpEmbedder;
#[async_trait]
impl Embedder for NoOpEmbedder {
async fn embed(&self, _text: &str) -> Result<Vec<f32>> {
Err(crate::error::Error::NoEmbedder)
}
async fn embed_batch(&self, _texts: &[String]) -> Result<Vec<Vec<f32>>> {
Err(crate::error::Error::NoEmbedder)
}
fn dimensions(&self) -> usize {
0
}
fn model_name(&self) -> &str {
"none"
}
}