rabitq_rs/
lib.rs

1#![cfg_attr(target_arch = "x86_64", feature(avx512_target_feature))]
2#![cfg_attr(target_arch = "x86_64", feature(stdarch_x86_avx512))]
3
4pub mod brute_force;
5pub mod index;
6pub mod io;
7pub mod ivf;
8pub mod mstg;
9
10#[cfg(feature = "python")]
11pub mod python_bindings;
12
13mod kmeans;
14mod math;
15mod memory;
16mod quantizer;
17mod rotation;
18mod simd;
19
20pub use brute_force::{BruteForceRabitqIndex, BruteForceSearchParams, BruteForceSearchResult};
21pub use index::RabitqIndex;
22pub use ivf::{IvfRabitqIndex, SearchParams, SearchResult};
23pub use quantizer::{QuantizedVector, RabitqConfig};
24pub use rotation::RotatorType;
25
26// Re-export RoaringBitmap for user convenience
27pub use roaring::RoaringBitmap;
28
29#[cfg(test)]
30mod tests;
31
32/// Distance metric supported by the RaBitQ IVF index.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
34pub enum Metric {
35    /// Euclidean distance (L2).
36    L2,
37    /// Inner product (maximum similarity).
38    InnerProduct,
39}
40
41/// Errors that can occur when building or querying the RaBitQ IVF index.
42#[derive(thiserror::Error, Debug)]
43pub enum RabitqError {
44    /// Returned when the dimension of an input vector does not match the trained index.
45    #[error("dimension mismatch: expected {expected}, got {got}")]
46    DimensionMismatch { expected: usize, got: usize },
47    /// Returned when an invalid configuration is supplied.
48    #[error("invalid configuration: {0}")]
49    InvalidConfig(&'static str),
50    /// Returned when the index has not been trained before use.
51    #[error("index is empty; call `train` first")]
52    EmptyIndex,
53    /// Returned when persistence encounters an I/O failure.
54    #[error("i/o error while reading or writing an index: {0}")]
55    Io(#[from] std::io::Error),
56    /// Returned when the persisted bytes are inconsistent or corrupt.
57    #[error("invalid persisted index: {0}")]
58    InvalidPersistence(&'static str),
59}