use super::error::EmbedError; use super::DistributionShift; use crate::vector::Embedding; #[derive(Debug, Clone, Copy)] pub struct Embedder { dimensions: usize, distribution: Option, } #[derive(Debug, Clone, Hash, PartialEq, Eq, serde::Deserialize, serde::Serialize)] pub struct EmbedderOptions { pub dimensions: usize, pub distribution: Option, } impl Embedder { pub fn new(options: EmbedderOptions) -> Self { Self { dimensions: options.dimensions, distribution: options.distribution } } pub fn embed>(&self, texts: &[S]) -> Result, EmbedError> { texts.as_ref().iter().map(|text| self.embed_one(text)).collect() } pub fn embed_one>(&self, text: S) -> Result { Err(EmbedError::embed_on_manual_embedder(text.as_ref().chars().take(250).collect())) } pub fn dimensions(&self) -> usize { self.dimensions } pub fn embed_chunks( &self, text_chunks: Vec>, ) -> Result>, EmbedError> { text_chunks.into_iter().map(|prompts| self.embed(&prompts)).collect() } pub fn distribution(&self) -> Option { self.distribution } pub(crate) fn embed_chunks_ref(&self, texts: &[&str]) -> Result, EmbedError> { texts.iter().map(|text| self.embed_one(text)).collect() } }