Get or create a vector collection, validating dimension compatibility.
(
&mut self,
tid: u64,
collection: &str,
dim: usize,
field_name: &str,
)
| 45 | impl CoreLoop { |
| 46 | /// Get or create a vector collection, validating dimension compatibility. |
| 47 | pub(in crate::data::executor) fn get_or_create_vector_index( |
| 48 | &mut self, |
| 49 | tid: u64, |
| 50 | collection: &str, |
| 51 | dim: usize, |
| 52 | field_name: &str, |
| 53 | ) -> Result<&mut VectorCollection, ErrorCode> { |
| 54 | let index_key = CoreLoop::vector_index_key(tid, collection, field_name); |
| 55 | if let Some(existing) = self.vector_collections.get(&index_key) |
| 56 | && existing.dim() != dim |
| 57 | { |
| 58 | return Err(ErrorCode::RejectedConstraint { |
| 59 | detail: String::new(), |
| 60 | constraint: format!( |
| 61 | "dimension mismatch: index has {}, got {dim}", |
| 62 | existing.dim() |
| 63 | ), |
| 64 | }); |
| 65 | } |
| 66 | let core_id = self.core_id; |
| 67 | let params = self |
| 68 | .vector_params |
| 69 | .get(&index_key) |
| 70 | .cloned() |
| 71 | .unwrap_or_default(); |
| 72 | Ok(self.vector_collections.entry(index_key).or_insert_with(|| { |
| 73 | debug!(core = core_id, dim, m = params.m, ef = params.ef_construction, ?params.metric, "creating vector collection"); |
| 74 | VectorCollection::new(dim, params) |
| 75 | })) |
| 76 | } |
| 77 | |
| 78 | pub(in crate::data::executor) fn execute_vector_insert( |
| 79 | &mut self, |
no test coverage detected