weavatrix_search_vector/mutable/
mod.rs1mod lifecycle;
2mod mutations;
3mod rebuild;
4mod search;
5mod support;
6
7use crate::config::IndexConfig;
8use crate::hnsw::VectorIndex;
9use crate::metadata::{Metadata, MetadataIndex};
10use crate::simd::DistanceKernel;
11use std::collections::{BTreeMap, BTreeSet};
12use std::sync::{Arc, RwLock};
13
14#[derive(Debug, Clone, PartialEq)]
16pub struct VectorRecord {
17 pub key: u64,
18 pub vector: Vec<f32>,
19 pub metadata: Metadata,
20}
21
22impl VectorRecord {
23 #[must_use]
24 pub fn new(key: u64, vector: Vec<f32>) -> Self {
25 Self {
26 key,
27 vector,
28 metadata: Metadata::new(),
29 }
30 }
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub enum MutationOutcome {
36 Inserted,
37 Updated,
38}
39
40#[derive(Debug)]
46pub struct MutableVectorIndex {
47 pub(super) config: IndexConfig,
48 pub(super) state: RwLock<MutableState>,
49 pub(super) distance_kernel: DistanceKernel,
50}
51
52#[derive(Debug)]
53pub(super) struct MutableState {
54 pub(super) base: Arc<VectorIndex>,
55 pub(super) sealed: Option<Arc<VectorIndex>>,
56 pub(super) pending: BTreeMap<u64, Vec<f32>>,
57 pub(super) deleted: BTreeSet<u64>,
58 pub(super) metadata: MetadataIndex,
59 pub(super) generation: u64,
60}
61
62pub(crate) struct MutableSnapshot {
63 pub(crate) config: IndexConfig,
64 pub(crate) base: Arc<VectorIndex>,
65 pub(crate) sealed: Option<Arc<VectorIndex>>,
66 pub(crate) pending: BTreeMap<u64, Vec<f32>>,
67 pub(crate) deleted: BTreeSet<u64>,
68 pub(crate) metadata: MetadataIndex,
69}