pub struct RagContext {
pub id: Option<String>,
pub content: String,
pub score: Option<f32>,
pub retrieval_score: Option<f32>,
pub source: Option<String>,
}
pub struct RagResult {
pub query: String,
pub contexts: Vec<RagContext>,
}
pub trait Chunker: Send + Sync {
type Error: std::error::Error + Send + Sync + 'static;
fn chunk(&self, text: &str) -> Result<Vec<String>, Self::Error>;
}
pub trait RagStrategy: Send + Sync {
type Error: std::error::Error + Send + Sync + 'static;
fn search(&self, query: &str) -> Result<RagResult, Self::Error>;
fn search_contexts(&self, query: &str) -> Result<Vec<RagContext>, Self::Error>;
}
pub trait Reranker: Send + Sync {
type Error: std::error::Error + Send + Sync + 'static;
fn rerank(
&self,
query: &str,
contexts: Vec<RagContext>,
top_k: Option<usize>,
) -> Result<Vec<RagContext>, Self::Error>;
}
pub trait OutputFilter: Send + Sync {
type Error: std::error::Error + Send + Sync + 'static;
fn name(&self) -> &'static str;
fn filter(&self, result: RagResult, query: &str) -> Result<RagResult, Self::Error>;
}
pub trait EvaluationMetric: Send + Sync {
type Error: std::error::Error + Send + Sync + 'static;
fn name(&self) -> &'static str;
fn score(&self, result: &RagResult, reference: &str) -> Result<f32, Self::Error>;
}