use crate::{
Embed,
client::Nothing,
embeddings::{
Embedding, EmbeddingError, EmbeddingModel,
embed::{EmbedError, TextEmbedder},
},
wasm_compat::WasmCompatSend,
};
#[derive(Clone, Debug, Default)]
pub struct MockEmbeddingModel;
impl EmbeddingModel for MockEmbeddingModel {
const MAX_DOCUMENTS: usize = 5;
type Client = Nothing;
fn make(_: &Self::Client, _: impl Into<String>, _: Option<usize>) -> Self {
Self
}
fn ndims(&self) -> usize {
10
}
async fn embed_texts(
&self,
documents: impl IntoIterator<Item = String> + WasmCompatSend,
) -> Result<Vec<Embedding>, EmbeddingError> {
Ok(documents
.into_iter()
.map(|document| Embedding {
document,
vec: vec![0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
})
.collect())
}
}
#[derive(Clone, Debug)]
pub struct MockTextDocument {
pub id: String,
pub text: String,
}
impl MockTextDocument {
pub fn new(id: impl Into<String>, text: impl Into<String>) -> Self {
Self {
id: id.into(),
text: text.into(),
}
}
}
impl Embed for MockTextDocument {
fn embed(&self, embedder: &mut TextEmbedder) -> Result<(), EmbedError> {
embedder.embed(self.text.clone());
Ok(())
}
}
#[derive(Clone, Debug)]
pub struct MockMultiTextDocument {
pub id: String,
pub texts: Vec<String>,
}
impl MockMultiTextDocument {
pub fn new(id: impl Into<String>, texts: impl IntoIterator<Item = impl Into<String>>) -> Self {
Self {
id: id.into(),
texts: texts.into_iter().map(Into::into).collect(),
}
}
}
impl Embed for MockMultiTextDocument {
fn embed(&self, embedder: &mut TextEmbedder) -> Result<(), EmbedError> {
for text in &self.texts {
embedder.embed(text.clone());
}
Ok(())
}
}