pub mod gpu;
pub mod hardware;
pub mod hnsw;
pub mod ivf_pq;
pub mod mmap_loader;
pub mod rabitq;
pub mod serialize;
pub use hardware::{detect_backend, detect_cuda, detect_rocm, HardwareBackend, HardwareProfile};
pub use hnsw::{HnswBuilder, HnswConfig, HnswIndex};
pub use ivf_pq::{find_valid_pq_m, IvfPqCodebook, IvfPqConfig, IvfPqIndex, IvfPqSerializer};
pub use mmap_loader::MmapLoader;
pub use rabitq::{RaBitQConfig, RaBitQIndex, RaBitQSerializer};
pub use serialize::HnswSerializer;
use ailake_core::RowId;
pub enum AnyIndex {
Hnsw(HnswIndex),
IvfPq(IvfPqIndex),
RaBitQ(RaBitQIndex),
}
impl AnyIndex {
pub fn search(&self, query: &[f32], top_k: usize, ef: usize) -> Vec<(RowId, f32)> {
match self {
AnyIndex::Hnsw(idx) => idx.search(query, top_k, ef),
AnyIndex::IvfPq(idx) => idx.search(query, top_k, None),
AnyIndex::RaBitQ(idx) => idx.search(query, top_k, Some(3)),
}
}
pub fn node_count(&self) -> u64 {
match self {
AnyIndex::Hnsw(idx) => idx.node_count(),
AnyIndex::IvfPq(idx) => idx.node_count(),
AnyIndex::RaBitQ(idx) => idx.node_count(),
}
}
pub fn quantize_to_f16(&mut self) {
if let AnyIndex::Hnsw(idx) = self {
idx.quantize_to_f16();
}
}
pub fn is_hnsw(&self) -> bool {
matches!(self, AnyIndex::Hnsw(_))
}
pub fn is_ivf_pq(&self) -> bool {
matches!(self, AnyIndex::IvfPq(_))
}
pub fn is_rabitq(&self) -> bool {
matches!(self, AnyIndex::RaBitQ(_))
}
}