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

Method insert

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

Insert a sparse vector for a document. Returns the internal doc ID. If the doc_id already exists, the old entries are removed first (upsert).

(&mut self, doc_id: &str, vector: &SparseVector)

Source from the content-addressed store, hash-verified

56 ///
57 /// If the doc_id already exists, the old entries are removed first (upsert).
58 pub fn insert(&mut self, doc_id: &str, vector: &SparseVector) -> u32 {
59 // Upsert: remove old entries if doc already exists.
60 if let Some(&existing_id) = self.doc_id_forward.get(doc_id) {
61 self.remove_internal(existing_id);
62 self.doc_id_forward.remove(doc_id);
63 self.doc_id_reverse.remove(&existing_id);
64 self.doc_count -= 1;
65 }
66
67 let internal_id = self.next_id;
68 self.next_id += 1;
69
70 self.doc_id_forward.insert(doc_id.to_string(), internal_id);
71 self.doc_id_reverse.insert(internal_id, doc_id.to_string());
72
73 let mut dims = Vec::with_capacity(vector.nnz());
74 for &(dim, weight) in vector.entries() {
75 self.postings
76 .entry(dim)
77 .or_default()
78 .push((internal_id, weight));
79 dims.push(dim);
80 }
81 self.doc_dims.insert(internal_id, dims);
82 self.doc_count += 1;
83
84 internal_id
85 }
86
87 /// Delete a document by string ID. Returns true if found and removed.
88 pub fn delete(&mut self, doc_id: &str) -> bool {

Callers 10

from_checkpointMethod · 0.45
insert_and_lookupFunction · 0.45
upsert_replacesFunction · 0.45
deleteFunction · 0.45
checkpoint_roundtripFunction · 0.45
multiple_docs_same_dimFunction · 0.45
basic_searchFunction · 0.45
topk_limits_resultsFunction · 0.45
empty_queryFunction · 0.45
no_overlapFunction · 0.45

Calls 8

remove_internalMethod · 0.80
to_stringMethod · 0.80
entryMethod · 0.80
getMethod · 0.45
removeMethod · 0.45
nnzMethod · 0.45
entriesMethod · 0.45
pushMethod · 0.45

Tested by 9

insert_and_lookupFunction · 0.36
upsert_replacesFunction · 0.36
deleteFunction · 0.36
checkpoint_roundtripFunction · 0.36
multiple_docs_same_dimFunction · 0.36
basic_searchFunction · 0.36
topk_limits_resultsFunction · 0.36
empty_queryFunction · 0.36
no_overlapFunction · 0.36