weavatrix_search_vector/hnsw/
mod.rs1mod batch;
2mod graph_build;
3mod graph_helpers;
4mod graph_insert;
5mod graph_search;
6mod index_build;
7mod index_search;
8mod policy;
9mod routing;
10mod scratch;
11
12use crate::config::IndexConfig;
13use crate::vector::{Candidate, RoutingCandidate, VectorStore};
14use std::cmp::Reverse;
15use std::collections::BinaryHeap;
16use std::sync::Arc;
17
18pub use policy::{FilterSearchPolicy, SearchPolicy};
19
20pub(super) const MAX_LEVEL: usize = 32;
21
22#[derive(Debug)]
24pub struct VectorIndex {
25 pub(super) config: IndexConfig,
26 pub(super) vectors: Arc<VectorStore>,
27 pub(super) graphs: Vec<Graph>,
28 pub(super) routing: RoutingIndex,
29}
30
31#[derive(Debug)]
32pub(crate) struct RoutingIndex {
33 pub(crate) entries: Vec<(u16, u32)>,
34}
35
36#[derive(Debug)]
37pub(crate) struct NodeLinks {
38 pub(crate) layers: Vec<Vec<u32>>,
39}
40
41#[derive(Debug)]
42pub(crate) struct Graph {
43 pub(crate) entry: Option<usize>,
44 pub(crate) max_level: usize,
45 pub(crate) nodes: Vec<NodeLinks>,
46}
47
48pub(super) struct InsertionPlan {
49 pub(super) index: usize,
50 pub(super) level: usize,
51 pub(super) links: Vec<(usize, Vec<usize>)>,
52}
53
54pub(super) struct SearchScratch {
55 pub(super) marks: Vec<u32>,
56 pub(super) generation: u32,
57 pub(super) candidates: BinaryHeap<Reverse<Candidate>>,
58 pub(super) results: BinaryHeap<Candidate>,
59 pub(super) routing_probes: Vec<u16>,
60 pub(super) routing_probe_heap: BinaryHeap<Reverse<RoutingCandidate>>,
61 pub(super) routing_nodes: Vec<u32>,
62 pub(super) merged: Vec<Candidate>,
63}