use kalosm_language_model::Embedder;
use crate::context::Document;
use super::Chunk;
mod chunking;
pub use chunking::*;
mod hypothetical;
pub use hypothetical::*;
mod summary;
pub use summary::*;
mod sentence;
pub use sentence::*;
mod semantic;
pub use semantic::*;
mod html;
pub use html::*;
pub trait Chunker {
fn chunk<E: Embedder + Send>(
&self,
document: &Document,
embedder: &E,
) -> impl std::future::Future<Output = anyhow::Result<Vec<Chunk<E::VectorSpace>>>> + Send;
fn chunk_batch<'a, I, E: Embedder + Send>(
&self,
documents: I,
embedder: &E,
) -> impl std::future::Future<Output = anyhow::Result<Vec<Vec<Chunk<E::VectorSpace>>>>> + Send
where
I: IntoIterator<Item = &'a Document> + Send,
I::IntoIter: Send,
Self: Sync,
{
async {
let mut chunks = Vec::new();
for document in documents {
chunks.push(self.chunk(document, embedder).await?);
}
Ok(chunks)
}
}
}