Skip to main content

nodedb_lite/engine/sparse_vector/
state.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Shared runtime state for sparse-vector search on Lite.
4//!
5//! Held as `Arc<SparseVectorState>` on both `NodeDbLite` (user-facing write
6//! path) and `LiteQueryEngine` (PhysicalPlan executor) so `VectorOp::Sparse*`
7//! sees exactly the index the document writes maintain.
8
9use std::sync::Mutex;
10
11use super::manager::SparseVectorManager;
12
13/// Arc-shareable wrapper around the per-collection sparse index manager.
14///
15/// The manager is purely in-memory and independent of the storage parameter
16/// `S` — persistence happens through the checkpoint module at flush time — so
17/// no generic parameter is needed here.
18pub struct SparseVectorState {
19    pub(crate) manager: Mutex<SparseVectorManager>,
20}
21
22impl SparseVectorState {
23    /// Create a new, empty `SparseVectorState`.
24    pub fn new() -> Self {
25        Self {
26            manager: Mutex::new(SparseVectorManager::new()),
27        }
28    }
29
30    /// Wrap an already-restored `SparseVectorManager`.
31    pub fn from_restored(manager: SparseVectorManager) -> Self {
32        Self {
33            manager: Mutex::new(manager),
34        }
35    }
36}
37
38impl Default for SparseVectorState {
39    fn default() -> Self {
40        Self::new()
41    }
42}