pub mod ann;
mod blobs;
pub mod bm25;
mod dtype;
pub mod error;
pub mod graph;
mod inspect;
mod materialize;
mod mmap_cold;
mod mmap_file;
mod order;
mod rerank;
mod search;
pub mod simd;
mod space_search;
mod spaces;
pub use dtype::DType;
pub use error::RuntimeError;
pub use mmap_file::MmapUrnaFile;
pub use simd::SimdBackend;
#[derive(Clone, Debug, PartialEq)]
pub struct SearchHit {
pub chunk_id: String,
pub score: f32,
pub score_type: &'static str,
pub source_uri: String,
pub offset_start: u64,
pub offset_end: u64,
pub embedding_model: String,
pub index_type: &'static str,
pub reranked: bool,
pub file_hash: String,
pub content_hash: String,
pub citation_id: String,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RerankSourceKind {
FullPrecision,
StoredPrecision,
}
impl RerankSourceKind {
pub fn from_dtype(dtype: DType) -> Self {
match dtype {
DType::Float32 => Self::FullPrecision,
DType::Float16 | DType::Int8 | DType::Int4 => Self::StoredPrecision,
}
}
pub fn disclosure(self) -> &'static str {
match self {
Self::FullPrecision => "real cosine",
Self::StoredPrecision => "real cosine at stored precision",
}
}
pub fn as_str(self) -> &'static str {
match self {
Self::FullPrecision => "full_precision",
Self::StoredPrecision => "stored_precision",
}
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct SearchExplain {
pub route: &'static str,
pub exact_candidates: usize,
pub ann_candidates: usize,
pub bm25_candidates: usize,
pub graph_candidates: usize,
pub fusion_mode: &'static str,
pub rerank_source: RerankSourceKind,
pub recall_estimate: f32,
}
impl SearchExplain {
pub(crate) fn exact(n: usize, src: RerankSourceKind) -> Self {
Self {
route: "exact",
exact_candidates: n,
ann_candidates: 0,
bm25_candidates: 0,
graph_candidates: 0,
fusion_mode: "none",
rerank_source: src,
recall_estimate: 1.0,
}
}
pub(crate) fn hnsw(ann: usize, src: RerankSourceKind) -> Self {
Self {
route: "hnsw",
exact_candidates: 0,
ann_candidates: ann,
bm25_candidates: 0,
graph_candidates: 0,
fusion_mode: "none",
rerank_source: src,
recall_estimate: f32::NAN,
}
}
pub(crate) fn graph(seed: usize, frontier: usize, src: RerankSourceKind) -> Self {
Self {
route: "graph",
exact_candidates: seed,
ann_candidates: 0,
bm25_candidates: 0,
graph_candidates: frontier,
fusion_mode: "none",
rerank_source: src,
recall_estimate: f32::NAN,
}
}
pub(crate) fn hybrid(ann: usize, exact: usize, bm25: usize, src: RerankSourceKind) -> Self {
Self {
route: "hybrid",
exact_candidates: exact,
ann_candidates: ann,
bm25_candidates: bm25,
graph_candidates: 0,
fusion_mode: "rrf",
rerank_source: src,
recall_estimate: f32::NAN,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct SearchResult {
pub hits: Vec<SearchHit>,
pub query_time_ms: f64,
pub index_type: &'static str,
pub recall: f32,
pub truncated: bool,
pub k_requested: i32,
pub k_returned: usize,
pub explain: SearchExplain,
}