pub struct IndexPersistence { /* private fields */ }Expand description
Manages saving and loading IndexSnapshot files
§Example
use ipfrs_semantic::persistence::{IndexPersistence, IndexSnapshot};
let p = IndexPersistence::new("/path/to/my_index.snap");
// p.save(&snapshot)?;
// let snapshot = p.load()?;Implementations§
Source§impl IndexPersistence
impl IndexPersistence
Sourcepub fn new(path: impl Into<PathBuf>) -> Self
pub fn new(path: impl Into<PathBuf>) -> Self
Create a new IndexPersistence that reads/writes to path
Sourcepub fn save(&self, snapshot: &IndexSnapshot) -> Result<()>
pub fn save(&self, snapshot: &IndexSnapshot) -> Result<()>
Serialize snapshot and write it atomically to the configured path
Uses a write-to-temp-then-rename strategy so partial writes never corrupt an existing good snapshot.
Sourcepub fn load(&self) -> Result<IndexSnapshot>
pub fn load(&self) -> Result<IndexSnapshot>
Deserialize and return the IndexSnapshot stored at the configured path
Sourcepub fn delete(&self) -> Result<()>
pub fn delete(&self) -> Result<()>
Delete the snapshot file. No-ops silently if the file is absent.
Sourcepub fn save_smart(&self, index: &VectorIndex) -> Result<()>
pub fn save_smart(&self, index: &VectorIndex) -> Result<()>
Smart save: use an incremental delta when fewer than 10 % of total entries are dirty, otherwise fall back to a full snapshot.
This is the preferred entry-point for Node::stop because it avoids
re-writing the entire index on every shutdown when only a handful of
embeddings have changed.
After a successful write the tracker inside index is marked clean.
§Decision rule
- If the index is empty → full snapshot (no-op, but valid state).
- If
dirty_count / total_count < 0.10AND a full base snapshot already exists on disk → incremental delta. - Otherwise → full snapshot.
Sourcepub fn incremental_path(&self) -> PathBuf
pub fn incremental_path(&self) -> PathBuf
Path for the incremental (delta) snapshot alongside the full snapshot
For a base path of foo/index.snap this returns foo/index.snap.delta.
Sourcepub fn save_incremental(&self, snapshot: &IncrementalSnapshot) -> Result<()>
pub fn save_incremental(&self, snapshot: &IncrementalSnapshot) -> Result<()>
Serialize snapshot and write it as an incremental (delta) snapshot
The delta file sits alongside the full snapshot at <base>.delta.
Uses the same atomic write-then-rename strategy as save.
Sourcepub fn load_incremental(&self) -> Result<IncrementalSnapshot>
pub fn load_incremental(&self) -> Result<IncrementalSnapshot>
Deserialize and return the IncrementalSnapshot stored at the delta path
Sourcepub fn apply_incremental(
base: &mut IndexSnapshot,
delta: &IncrementalSnapshot,
) -> Result<()>
pub fn apply_incremental( base: &mut IndexSnapshot, delta: &IncrementalSnapshot, ) -> Result<()>
Apply an incremental delta to an existing full IndexSnapshot in place
Entries whose IDs appear in delta.deleted_ids are removed, then all
delta.changed_entries are upserted (replacing existing entries with
the same id or appending new ones).
Auto Trait Implementations§
impl Freeze for IndexPersistence
impl RefUnwindSafe for IndexPersistence
impl Send for IndexPersistence
impl Sync for IndexPersistence
impl Unpin for IndexPersistence
impl UnsafeUnpin for IndexPersistence
impl UnwindSafe for IndexPersistence
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.