use std::error::Error;
use async_trait::async_trait;
#[derive(Debug, Clone)]
pub struct TextEmbedding(Vec<f32>);
impl TextEmbedding {
pub fn new(embedding: Vec<f32>) -> Self {
Self(embedding)
}
pub fn as_slice(&self) -> &[f32] {
&self.0
}
}
impl From<Vec<f32>> for TextEmbedding {
fn from(embedding: Vec<f32>) -> TextEmbedding {
TextEmbedding::new(embedding)
}
}
impl From<TextEmbedding> for Vec<f32> {
fn from(embedding: TextEmbedding) -> Vec<f32> {
embedding.0
}
}
pub type EmbedTextResult = Result<TextEmbedding, Box<dyn Error>>;
#[async_trait]
pub trait TextEmbeddingModel: Send + Sync {
async fn embed_text(&self, text: &str) -> EmbedTextResult;
}