nodedb_vector/collection/lifecycle_reindex.rs
1// SPDX-License-Identifier: Apache-2.0
2
3//! Rebuild-related accessors on `VectorCollection`.
4//!
5//! Provides the methods needed by the concurrent REINDEX path:
6//! snapshot extraction, tombstone compaction, and atomic sealed-segment
7//! replacement.
8
9use crate::flat::FlatIndex;
10use crate::hnsw::HnswParams;
11
12use super::lifecycle::VectorCollection;
13use super::segment::SealedSegment;
14
15impl VectorCollection {
16 /// Return the HNSW construction parameters for this collection.
17 pub fn hnsw_params(&self) -> HnswParams {
18 self.params.clone()
19 }
20
21 /// Immutable access to the growing flat index.
22 ///
23 /// The growing index holds vectors that have not yet been sealed into an
24 /// HNSW segment. Its contents should be included in any full-collection
25 /// rebuild that wants to produce a complete result.
26 pub fn growing_flat(&self) -> &FlatIndex {
27 &self.growing
28 }
29
30 /// Replace all sealed segments with `new_segments`.
31 ///
32 /// Used by the concurrent REINDEX cutover: after the background thread
33 /// finishes rebuilding the HNSW graph the Data Plane swaps in the single
34 /// rebuilt segment. The growing segment is preserved unchanged.
35 ///
36 /// Caller is responsible for ensuring that `new_segments` covers all
37 /// vectors that were in the old sealed set; any vector not present in the
38 /// new segments will return no result on subsequent searches until the
39 /// growing segment is sealed.
40 pub fn replace_sealed(&mut self, new_segments: Vec<SealedSegment>) {
41 self.sealed = new_segments;
42 }
43
44 /// Compact tombstoned nodes from all sealed segments.
45 ///
46 /// This is the same operation as `compact()` — the alias exists so
47 /// call sites that want to express "remove tombstones" read clearly.
48 pub fn compact_tombstones(&mut self) -> usize {
49 self.compact()
50 }
51}