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

Method insert

nodedb-vector/src/multivec/storage.rs:58–81  ·  view source on GitHub ↗

Insert a document, validating dimensions and (for MetaToken mode) vector count.

(&mut self, doc: MultiVectorDoc)

Source from the content-addressed store, hash-verified

56
57 /// Insert a document, validating dimensions and (for MetaToken mode) vector count.
58 pub fn insert(&mut self, doc: MultiVectorDoc) -> Result<(), MultivecError> {
59 // Validate each vector's dimension.
60 for v in &doc.vectors {
61 if v.len() != self.dim {
62 return Err(MultivecError::DimMismatch {
63 expected: self.dim,
64 actual: v.len(),
65 });
66 }
67 }
68
69 // In MetaToken mode the count must equal k exactly.
70 if let MultiVecMode::MetaToken { k } = self.mode
71 && doc.vectors.len() != k as usize
72 {
73 return Err(MultivecError::MetaTokenCountMismatch {
74 expected: k,
75 actual: doc.vectors.len(),
76 });
77 }
78
79 self.docs.insert(doc.doc_id, doc);
80 Ok(())
81 }
82
83 /// Look up a document by ID.
84 pub fn get(&self, doc_id: u32) -> Option<&MultiVectorDoc> {

Callers 6

build_storeFunction · 0.45
build_storeFunction · 0.45
insert_dim_mismatchFunction · 0.45
get_returns_inserted_docFunction · 0.45
iter_yields_all_docsFunction · 0.45

Calls 1

lenMethod · 0.45

Tested by 4

insert_dim_mismatchFunction · 0.36
get_returns_inserted_docFunction · 0.36
iter_yields_all_docsFunction · 0.36