Skip to main content

weavatrix_search_vector/storage/
mod.rs

1mod decoder;
2mod encoder;
3mod format;
4mod header;
5mod index_io;
6mod mapped_access;
7mod mapped_batch;
8mod mapped_exact;
9mod mapped_graph;
10mod mapped_owned;
11mod mapped_search;
12mod mapped_validation;
13mod validation;
14mod writer;
15
16use crate::config::IndexConfig;
17use crate::mmap::Mapping;
18use crate::simd::DistanceKernel;
19
20pub(super) const MAGIC: &[u8; 8] = b"WVSVEC02";
21pub(super) const FORMAT_VERSION: u32 = 1;
22pub(super) const HEADER_LEN: usize = 192;
23pub(super) const GRAPH_HEADER_LEN: usize = 40;
24pub(super) const NONE_ENTRY: u64 = u64::MAX;
25pub(super) const FNV_OFFSET: u64 = 0xcbf2_9ce4_8422_2325;
26pub(super) const FNV_PRIME: u64 = 0x0000_0100_0000_01b3;
27
28/// Integrity policy used while opening a memory-mapped snapshot.
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
30pub enum SnapshotValidation {
31    /// Validate structure, finite vectors, and the full payload checksum.
32    #[default]
33    Full,
34    /// Validate all ranges and graph references without scanning the checksum.
35    StructureOnly,
36}
37
38/// Read-only HNSW index backed directly by a versioned memory-mapped snapshot.
39#[derive(Debug)]
40pub struct MappedVectorIndex {
41    pub(super) mapping: Mapping,
42    pub(super) header: Header,
43    pub(super) graphs: Vec<MappedGraph>,
44    pub(super) distance_kernel: DistanceKernel,
45}
46
47/// Header-only snapshot description.
48#[derive(Debug, Clone, PartialEq, Eq)]
49pub struct SnapshotMetadata {
50    pub format_version: u32,
51    pub vector_count: usize,
52    pub serialized_bytes: usize,
53    pub config: IndexConfig,
54}
55
56#[derive(Debug)]
57pub(super) struct MappedGraph {
58    pub(super) entry: Option<usize>,
59    pub(super) max_level: usize,
60    pub(super) node_count: usize,
61    pub(super) node_layers_offset: usize,
62    pub(super) total_layers: usize,
63    pub(super) layer_neighbors_offset: usize,
64    pub(super) neighbors_offset: usize,
65    pub(super) neighbor_count: usize,
66}
67
68#[derive(Debug, Clone)]
69pub(super) struct Header {
70    pub(super) checksum: u64,
71    pub(super) file_len: usize,
72    pub(super) count: usize,
73    pub(super) config: IndexConfig,
74    pub(super) keys_offset: usize,
75    pub(super) vectors_offset: usize,
76    pub(super) routing_codes_offset: usize,
77    pub(super) routing_nodes_offset: usize,
78    pub(super) graphs_offset: usize,
79}