omendb_core/vector/
mod.rs

1//! Vector storage with HNSW indexing for approximate nearest neighbor search.
2
3pub mod hnsw;
4pub mod hnsw_index;
5pub mod store;
6pub mod types;
7
8// Re-export main types
9pub use crate::compression::{QuantizationBits, QuantizedVector, RaBitQ, RaBitQParams};
10pub use hnsw_index::{HNSWIndex, HNSWIndexBuilder, HNSWQuantization};
11pub use store::{MetadataFilter, VectorStore, VectorStoreOptions};
12pub use types::Vector;
13
14/// Quantization mode for vector storage
15///
16/// Controls how vectors are compressed for memory/disk efficiency.
17#[derive(Debug, Clone)]
18pub enum QuantizationMode {
19    /// Binary Quantization (BBQ): f32 → 1 bit
20    /// - 32x compression
21    /// - 2-4x faster than SQ8 (SIMD Hamming)
22    /// - ~85% raw recall, ~95-98% with rescore
23    Binary,
24
25    /// Scalar Quantization (SQ8): f32 → u8
26    /// - 4x compression
27    /// - ~2x faster than f32 (direct SIMD)
28    /// - ~99% recall with rescore
29    SQ8,
30
31    /// Extended `RaBitQ`: f32 → 2-8 bits
32    /// - 4-16x compression
33    /// - ~0.5x slower than f32 (ADC lookup tables)
34    /// - 93-99% recall depending on bits
35    RaBitQ(RaBitQParams),
36}
37
38impl QuantizationMode {
39    /// Create Binary quantization mode (32x compression)
40    #[must_use]
41    pub fn binary() -> Self {
42        Self::Binary
43    }
44
45    /// Create SQ8 quantization mode (4x compression, fastest)
46    #[must_use]
47    pub fn sq8() -> Self {
48        Self::SQ8
49    }
50
51    /// Create `RaBitQ` with 4-bit quantization (8x compression)
52    #[must_use]
53    pub fn rabitq() -> Self {
54        Self::RaBitQ(RaBitQParams::bits4())
55    }
56
57    /// Create `RaBitQ` with 2-bit quantization (16x compression)
58    #[must_use]
59    pub fn rabitq_2bit() -> Self {
60        Self::RaBitQ(RaBitQParams::bits2())
61    }
62
63    /// Create `RaBitQ` with 8-bit quantization (4x compression)
64    #[must_use]
65    pub fn rabitq_8bit() -> Self {
66        Self::RaBitQ(RaBitQParams::bits8())
67    }
68
69    /// Check if this is Binary mode
70    #[must_use]
71    pub fn is_binary(&self) -> bool {
72        matches!(self, Self::Binary)
73    }
74
75    /// Check if this is SQ8 mode
76    #[must_use]
77    pub fn is_sq8(&self) -> bool {
78        matches!(self, Self::SQ8)
79    }
80
81    /// Check if this is `RaBitQ` mode
82    #[must_use]
83    pub fn is_rabitq(&self) -> bool {
84        matches!(self, Self::RaBitQ(_))
85    }
86}