mod lifecycle;
mod mutations;
mod rebuild;
mod search;
mod support;
use crate::config::IndexConfig;
use crate::hnsw::VectorIndex;
use crate::metadata::{Metadata, MetadataIndex};
use crate::simd::DistanceKernel;
use std::collections::{BTreeMap, BTreeSet};
use std::sync::{Arc, RwLock};
#[derive(Debug, Clone, PartialEq)]
pub struct VectorRecord {
pub key: u64,
pub vector: Vec<f32>,
pub metadata: Metadata,
}
impl VectorRecord {
#[must_use]
pub fn new(key: u64, vector: Vec<f32>) -> Self {
Self {
key,
vector,
metadata: Metadata::new(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MutationOutcome {
Inserted,
Updated,
}
#[derive(Debug)]
pub struct MutableVectorIndex {
pub(super) config: IndexConfig,
pub(super) state: RwLock<MutableState>,
pub(super) distance_kernel: DistanceKernel,
}
#[derive(Debug)]
pub(super) struct MutableState {
pub(super) base: Arc<VectorIndex>,
pub(super) sealed: Option<Arc<VectorIndex>>,
pub(super) pending: BTreeMap<u64, Vec<f32>>,
pub(super) deleted: BTreeSet<u64>,
pub(super) metadata: MetadataIndex,
pub(super) generation: u64,
}
pub(crate) struct MutableSnapshot {
pub(crate) config: IndexConfig,
pub(crate) base: Arc<VectorIndex>,
pub(crate) sealed: Option<Arc<VectorIndex>>,
pub(crate) pending: BTreeMap<u64, Vec<f32>>,
pub(crate) deleted: BTreeSet<u64>,
pub(crate) metadata: MetadataIndex,
}