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

Method execute_vector_batch_insert

nodedb/src/data/executor/handlers/vector.rs:183–234  ·  view source on GitHub ↗

Execute batch vector insert (always to the default/unnamed field).

(
        &mut self,
        task: &ExecutionTask,
        tid: u64,
        collection: &str,
        vectors: &[Vec<f32>],
        dim: usize,
        surrogates: &[Surrogate],
    )

Source from the content-addressed store, hash-verified

181
182 /// Execute batch vector insert (always to the default/unnamed field).
183 pub(in crate::data::executor) fn execute_vector_batch_insert(
184 &mut self,
185 task: &ExecutionTask,
186 tid: u64,
187 collection: &str,
188 vectors: &[Vec<f32>],
189 dim: usize,
190 surrogates: &[Surrogate],
191 ) -> Response {
192 debug!(core = self.core_id, %collection, dim, count = vectors.len(), "vector batch insert");
193 let index_key = CoreLoop::vector_index_key(tid, collection, "");
194 match self.get_or_create_vector_index(tid, collection, dim, "") {
195 Ok(collection_ref) => {
196 for (i, vector) in vectors.iter().enumerate() {
197 if vector.len() != dim {
198 return self.response_error(
199 task,
200 ErrorCode::RejectedConstraint {
201 detail: String::new(),
202 constraint: format!(
203 "dimension mismatch in batch: expected {dim}, got {}",
204 vector.len()
205 ),
206 },
207 );
208 }
209 let s = surrogates.get(i).copied().unwrap_or(Surrogate::ZERO);
210 collection_ref.insert_with_surrogate(vector.clone(), s);
211 }
212 let seal_key = CoreLoop::vector_checkpoint_filename(&index_key);
213 if collection_ref.needs_seal()
214 && let Some(req) = collection_ref.seal(&seal_key)
215 && let Some(tx) = &self.build_tx
216 && let Err(e) = tx.send(req)
217 {
218 warn!(core = self.core_id, error = %e, "failed to send HNSW build request");
219 }
220 self.checkpoint_coordinator
221 .mark_dirty("vector", vectors.len());
222 match super::super::response_codec::encode_count("inserted", vectors.len()) {
223 Ok(bytes) => self.response_with_payload(task, bytes),
224 Err(e) => self.response_error(
225 task,
226 ErrorCode::Internal {
227 detail: e.to_string(),
228 },
229 ),
230 }
231 }
232 Err(err) => self.response_error(task, err),
233 }
234 }
235
236 pub(in crate::data::executor) fn execute_vector_delete(
237 &mut self,

Callers 1

dispatch_vectorMethod · 0.80

Calls 14

encode_countFunction · 0.85
response_errorMethod · 0.80
needs_sealMethod · 0.80
mark_dirtyMethod · 0.80
response_with_payloadMethod · 0.80
to_stringMethod · 0.80
iterMethod · 0.45
lenMethod · 0.45
getMethod · 0.45
insert_with_surrogateMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected