(
&mut self,
params: SetVectorParamsInput<'_>,
)
| 347 | } |
| 348 | |
| 349 | pub(in crate::data::executor) fn execute_set_vector_params( |
| 350 | &mut self, |
| 351 | params: SetVectorParamsInput<'_>, |
| 352 | ) -> Response { |
| 353 | let SetVectorParamsInput { |
| 354 | task, |
| 355 | tid, |
| 356 | collection, |
| 357 | field_name, |
| 358 | m, |
| 359 | ef_construction, |
| 360 | metric, |
| 361 | index_type, |
| 362 | pq_m, |
| 363 | ivf_cells, |
| 364 | ivf_nprobe, |
| 365 | } = params; |
| 366 | debug!(core = self.core_id, %collection, field = field_name, m, ef_construction, %metric, %index_type, "set vector params"); |
| 367 | let index_key = CoreLoop::vector_index_key(tid, collection, field_name); |
| 368 | |
| 369 | if self.vector_collections.contains_key(&index_key) { |
| 370 | return self.response_error( |
| 371 | task, |
| 372 | ErrorCode::RejectedConstraint { |
| 373 | detail: String::new(), |
| 374 | constraint: "cannot change index params after creation; drop and recreate the collection".into(), |
| 375 | }, |
| 376 | ); |
| 377 | } |
| 378 | |
| 379 | // Zero / empty inputs mean "preserve existing value if present, else default". |
| 380 | // This keeps ALTER SET (index_type = ...) from clobbering m / ef_construction |
| 381 | // that were set at CREATE time but not re-specified in the ALTER clause. |
| 382 | let existing = self.index_configs.get(&index_key).cloned(); |
| 383 | |
| 384 | let resolved_metric_str: String = if metric.is_empty() { |
| 385 | existing |
| 386 | .as_ref() |
| 387 | .map(|c| { |
| 388 | match c.hnsw.metric { |
| 389 | DistanceMetric::L2 => "l2", |
| 390 | DistanceMetric::Cosine => "cosine", |
| 391 | DistanceMetric::InnerProduct => "inner_product", |
| 392 | DistanceMetric::Manhattan => "manhattan", |
| 393 | DistanceMetric::Chebyshev => "chebyshev", |
| 394 | DistanceMetric::Hamming => "hamming", |
| 395 | DistanceMetric::Jaccard => "jaccard", |
| 396 | DistanceMetric::Pearson => "pearson", |
| 397 | _ => "cosine", |
| 398 | } |
| 399 | .to_string() |
| 400 | }) |
| 401 | .unwrap_or_else(|| "cosine".into()) |
| 402 | } else { |
| 403 | metric.to_string() |
| 404 | }; |
| 405 | |
| 406 | let metric_enum = match resolved_metric_str.as_str() { |
no test coverage detected