1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//! IVF-PQ vector index -- disk-first approximate nearest neighbor search.
//!
//! This module implements an Inverted File Index with Product Quantization
//! (IVF-PQ) built on shodh-redb's B-tree storage. It replaces brute-force
//! `nearest_k` scans with O(sqrt(n)) approximate search that scales to
//! 100M+ vectors.
//!
//! # Architecture
//!
//! - **IVF**: Partitions the vector space into clusters via k-means. At query
//! time, only the `nprobe` nearest clusters are scanned.
//! - **PQ**: Compresses each vector from `dim * 4` bytes to `num_subvectors`
//! bytes (one byte per sub-quantizer). Trained codebooks map each sub-vector
//! to its nearest centroid index.
//! - **ADC**: At search time, a precomputed distance lookup table enables
//! approximate distance computation via `num_subvectors` table lookups per
//! candidate.
//!
//! All index data is stored in regular B-tree tables with prefixed names,
//! fully ACID and crash-safe.
//!
//! # Example
//!
//! ```rust,ignore
//! use shodh_redb::{Database, DistanceMetric, IvfPqIndexDefinition, SearchParams};
//!
//! const INDEX: IvfPqIndexDefinition = IvfPqIndexDefinition::new(
//! "embeddings", 384, 256, 48, DistanceMetric::EuclideanSq,
//! ).with_raw_vectors().with_nprobe(16);
//!
//! let db = Database::create("vectors.redb")?;
//!
//! // Train + insert
//! let write_txn = db.begin_write()?;
//! let mut idx = write_txn.open_ivfpq_index(&INDEX)?;
//! idx.train(training_data.into_iter(), 25)?;
//! idx.insert(1, &embedding)?;
//! write_txn.commit()?;
//!
//! // Search
//! let read_txn = db.begin_read()?;
//! let idx = read_txn.open_ivfpq_index(&INDEX)?;
//! let results = idx.search(&read_txn, &query, &SearchParams::top_k(10))?;
//! ```
pub
// Wired into index.rs in upcoming commit.
pub
pub
pub
pub
pub
pub use ;
pub use ;
pub use ;
pub use Codebooks;