mod batch;
mod graph_build;
mod graph_helpers;
mod graph_insert;
mod graph_search;
mod index_build;
mod index_search;
mod policy;
mod routing;
mod scratch;
use crate::config::IndexConfig;
use crate::vector::{Candidate, RoutingCandidate, VectorStore};
use std::cmp::Reverse;
use std::collections::BinaryHeap;
use std::sync::Arc;
pub use policy::{FilterSearchPolicy, SearchPolicy};
pub(super) const MAX_LEVEL: usize = 32;
#[derive(Debug)]
pub struct VectorIndex {
pub(super) config: IndexConfig,
pub(super) vectors: Arc<VectorStore>,
pub(super) graphs: Vec<Graph>,
pub(super) routing: RoutingIndex,
}
#[derive(Debug)]
pub(crate) struct RoutingIndex {
pub(crate) entries: Vec<(u16, u32)>,
}
#[derive(Debug)]
pub(crate) struct NodeLinks {
pub(crate) layers: Vec<Vec<u32>>,
}
#[derive(Debug)]
pub(crate) struct Graph {
pub(crate) entry: Option<usize>,
pub(crate) max_level: usize,
pub(crate) nodes: Vec<NodeLinks>,
}
pub(super) struct InsertionPlan {
pub(super) index: usize,
pub(super) level: usize,
pub(super) links: Vec<(usize, Vec<usize>)>,
}
pub(super) struct SearchScratch {
pub(super) marks: Vec<u32>,
pub(super) generation: u32,
pub(super) candidates: BinaryHeap<Reverse<Candidate>>,
pub(super) results: BinaryHeap<Candidate>,
pub(super) routing_probes: Vec<u16>,
pub(super) routing_probe_heap: BinaryHeap<Reverse<RoutingCandidate>>,
pub(super) routing_nodes: Vec<u32>,
pub(super) merged: Vec<Candidate>,
}