use crate::error::Result;
use async_trait::async_trait;
#[async_trait]
pub trait Embedder: Send + Sync {
async fn embed(&self, text: &str) -> Result<Vec<f32>>;
async fn embed_batch(&self, texts: &[String]) -> Result<Vec<Vec<f32>>>;
fn dimensions(&self) -> usize;
fn model_name(&self) -> &str;
}
#[async_trait]
pub trait Reranker: Send + Sync {
async fn rerank(&self, query: &str, documents: &[RerankDocument]) -> Result<Vec<RerankResult>>;
fn model_name(&self) -> &str;
}
#[derive(Debug, Clone)]
pub struct RerankDocument {
pub id: String,
pub text: String,
}
#[derive(Debug, Clone)]
pub struct RerankResult {
pub id: String,
pub score: f64,
}
#[async_trait]
pub trait QueryExpander: Send + Sync {
async fn expand(&self, query: &str, context: Option<&str>) -> Result<ExpandedQuery>;
fn model_name(&self) -> &str;
}
#[derive(Debug, Clone, Default)]
pub struct ExpandedQuery {
pub lexical: Vec<String>,
pub semantic: Vec<String>,
pub hyde: Option<String>,
}
#[async_trait]
pub trait Tokenizer: Send + Sync {
async fn tokenize(&self, text: &str) -> Result<Vec<u32>>;
async fn detokenize(&self, tokens: &[u32]) -> Result<String>;
async fn count_tokens(&self, text: &str) -> Result<usize>;
}