use crate::indexing_stream::IndexingStream;
use crate::node::Node;
use crate::Embeddings;
use std::fmt::Debug;
use crate::prompt::Prompt;
use anyhow::Result;
use async_trait::async_trait;
#[cfg(feature = "test-utils")]
#[doc(hidden)]
use mockall::{automock, predicate::str};
#[cfg_attr(feature = "test-utils", automock)]
#[async_trait]
pub trait Transformer: Send + Sync {
async fn transform_node(&self, node: Node) -> Result<Node>;
fn concurrency(&self) -> Option<usize> {
None
}
}
#[async_trait]
impl<F> Transformer for F
where
F: Fn(Node) -> Result<Node> + Send + Sync,
{
async fn transform_node(&self, node: Node) -> Result<Node> {
self(node)
}
}
#[cfg_attr(feature = "test-utils", automock)]
#[async_trait]
pub trait BatchableTransformer: Send + Sync {
async fn batch_transform(&self, nodes: Vec<Node>) -> IndexingStream;
fn concurrency(&self) -> Option<usize> {
None
}
}
#[async_trait]
impl<F> BatchableTransformer for F
where
F: Fn(Vec<Node>) -> IndexingStream + Send + Sync,
{
async fn batch_transform(&self, nodes: Vec<Node>) -> IndexingStream {
self(nodes)
}
}
#[cfg_attr(feature = "test-utils", automock, doc(hidden))]
pub trait Loader {
fn into_stream(self) -> IndexingStream;
}
#[cfg_attr(feature = "test-utils", automock, doc(hidden))]
#[async_trait]
pub trait ChunkerTransformer: Send + Sync + Debug {
async fn transform_node(&self, node: Node) -> IndexingStream;
fn concurrency(&self) -> Option<usize> {
None
}
}
#[cfg_attr(feature = "test-utils", automock)]
#[async_trait]
pub trait NodeCache: Send + Sync + Debug {
async fn get(&self, node: &Node) -> bool;
async fn set(&self, node: &Node);
}
#[cfg_attr(feature = "test-utils", automock)]
#[async_trait]
pub trait EmbeddingModel: Send + Sync + Debug {
async fn embed(&self, input: Vec<String>) -> Result<Embeddings>;
}
#[cfg_attr(feature = "test-utils", automock)]
#[async_trait]
pub trait SimplePrompt: Debug + Send + Sync {
async fn prompt(&self, prompt: Prompt) -> Result<String>;
}
#[cfg_attr(feature = "test-utils", automock)]
#[async_trait]
pub trait Persist: Debug + Send + Sync {
async fn setup(&self) -> Result<()>;
async fn store(&self, node: Node) -> Result<Node>;
async fn batch_store(&self, nodes: Vec<Node>) -> IndexingStream;
fn batch_size(&self) -> Option<usize> {
None
}
}