(
&mut self,
params: VectorInsertParams<'_>,
)
| 76 | } |
| 77 | |
| 78 | pub(in crate::data::executor) fn execute_vector_insert( |
| 79 | &mut self, |
| 80 | params: VectorInsertParams<'_>, |
| 81 | ) -> Response { |
| 82 | let VectorInsertParams { |
| 83 | task, |
| 84 | tid, |
| 85 | collection, |
| 86 | vector, |
| 87 | dim, |
| 88 | field_name, |
| 89 | surrogate, |
| 90 | } = params; |
| 91 | debug!(core = self.core_id, %collection, dim, "vector insert"); |
| 92 | if vector.len() != dim { |
| 93 | return self.response_error( |
| 94 | task, |
| 95 | ErrorCode::RejectedConstraint { |
| 96 | detail: String::new(), |
| 97 | constraint: format!( |
| 98 | "vector dimension mismatch: expected {dim}, got {}", |
| 99 | vector.len() |
| 100 | ), |
| 101 | }, |
| 102 | ); |
| 103 | } |
| 104 | let index_key = CoreLoop::vector_index_key(tid, collection, field_name); |
| 105 | |
| 106 | // Check if this collection uses IVF-PQ index. |
| 107 | if let Some(cfg) = self.index_configs.get(&index_key) |
| 108 | && cfg.index_type == crate::engine::vector::index_config::IndexType::IvfPq |
| 109 | { |
| 110 | let key = index_key.clone(); |
| 111 | return self.ivf_insert(task, &key, vector, dim, surrogate); |
| 112 | } |
| 113 | |
| 114 | // Default: HNSW (with or without PQ). |
| 115 | match self.get_or_create_vector_index(tid, collection, dim, field_name) { |
| 116 | Ok(collection_ref) => { |
| 117 | collection_ref.insert_with_surrogate(vector.to_vec(), surrogate); |
| 118 | let seal_key = CoreLoop::vector_checkpoint_filename(&index_key); |
| 119 | if collection_ref.needs_seal() |
| 120 | && let Some(req) = collection_ref.seal(&seal_key) |
| 121 | && let Some(tx) = &self.build_tx |
| 122 | && let Err(e) = tx.send(req) |
| 123 | { |
| 124 | warn!(core = self.core_id, error = %e, "failed to send HNSW build request"); |
| 125 | } |
| 126 | self.checkpoint_coordinator.mark_dirty("vector", 1); |
| 127 | self.response_ok(task) |
| 128 | } |
| 129 | Err(err) => self.response_error(task, err), |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /// Insert into an IVF-PQ index, returning the assigned vector ID. |
| 134 | fn ivf_insert( |
no test coverage detected