MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / from_checkpoint

Method from_checkpoint

nodedb/src/engine/vector/sparse/index.rs:174–199  ·  view source on GitHub ↗

Restore from checkpoint bytes.

(bytes: &[u8])

Source from the content-addressed store, hash-verified

172
173 /// Restore from checkpoint bytes.
174 pub fn from_checkpoint(bytes: &[u8]) -> Option<Self> {
175 let snapshot: SparseIndexSnapshot = zerompk::from_msgpack(bytes).ok()?;
176 let mut index = Self::new();
177 index.next_id = snapshot.next_id;
178
179 for doc in snapshot.documents {
180 index
181 .doc_id_forward
182 .insert(doc.doc_id.clone(), doc.internal_id);
183 index.doc_id_reverse.insert(doc.internal_id, doc.doc_id);
184
185 let mut dims = Vec::with_capacity(doc.entries.len());
186 for (dim, weight) in doc.entries {
187 index
188 .postings
189 .entry(dim)
190 .or_default()
191 .push((doc.internal_id, weight));
192 dims.push(dim);
193 }
194 index.doc_dims.insert(doc.internal_id, dims);
195 index.doc_count += 1;
196 }
197
198 Some(index)
199 }
200}
201
202/// Checkpoint serialization format.

Callers

nothing calls this directly

Calls 6

entryMethod · 0.80
okMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected