Skip to content

Commit d93c548

Browse files
committed
fix: distinguish error types in GetCentroid for untrained vs invalid bucket_id
- Use WRONG_STATUS when partition is not trained - Use INVALID_ARGUMENT when bucket_id is out of range
1 parent 8a163f1 commit d93c548

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/algorithm/ivf_partition/gno_imi_partition.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,12 @@ GNOIMIPartition::inner_joint_classify_datas(const float* datas,
423423

424424
void
425425
GNOIMIPartition::GetCentroid(BucketIdType bucket_id, Vector<float>& centroid) {
426-
if (!is_trained_ || bucket_id >= bucket_count_) {
426+
if (!is_trained_) {
427427
throw VsagException(ErrorType::WRONG_STATUS, "Partition not trained");
428428
}
429+
if (bucket_id >= bucket_count_) {
430+
throw VsagException(ErrorType::INVALID_ARGUMENT, "Invalid bucket_id");
431+
}
429432
auto bucket_id_s = bucket_id / bucket_count_t_;
430433
auto bucket_id_t = bucket_id % bucket_count_t_;
431434
FP32Add(data_centroids_s_.data() + bucket_id_s * dim_,

src/algorithm/ivf_partition/ivf_nearest_partition.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,12 @@ IVFNearestPartition::factory_router_index(const IndexCommonParam& common_param)
163163
}
164164
void
165165
IVFNearestPartition::GetCentroid(BucketIdType bucket_id, Vector<float>& centroid) {
166-
if (!is_trained_ || bucket_id >= bucket_count_) {
166+
if (!is_trained_) {
167167
throw VsagException(ErrorType::WRONG_STATUS, "Partition not trained");
168168
}
169+
if (bucket_id >= bucket_count_) {
170+
throw VsagException(ErrorType::INVALID_ARGUMENT, "Invalid bucket_id");
171+
}
169172
this->route_index_ptr_->GetCodeByInnerId(bucket_id, (uint8_t*)centroid.data());
170173
}
171174

0 commit comments

Comments
 (0)