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::*;
#[async_trait::async_trait]
pub trait Chunker {
async fn chunk<E: Embedder + Send>(
&self,
document: &Document,
embedder: &E,
) -> anyhow::Result<Vec<Chunk<E::VectorSpace>>>;
async fn chunk_batch<'a, I, E: Embedder + Send>(
&self,
documents: I,
embedder: &E,
) -> anyhow::Result<Vec<Vec<Chunk<E::VectorSpace>>>>
where
I: IntoIterator<Item = &'a Document> + Send,
I::IntoIter: Send,
{
let mut chunks = Vec::new();
for document in documents {
chunks.push(self.chunk(document, embedder).await?);
}
Ok(chunks)
}
}