Skip to content

Commit 03441be

Browse files
LiuRuoyu01rock-git
authored andcommitted
[fix][test] Fixup binary index unit test error
1 parent f1a5ffd commit 03441be

File tree

2 files changed

+31
-61
lines changed

2 files changed

+31
-61
lines changed

test/unit_test/vector/test_vector_index_binary_flat.cc

+16-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ TEST_F(VectorIndexBinaryFlatTest, Create) {
101101
pb::common::VectorIndexParameter index_parameter;
102102
index_parameter.set_vector_index_type(::dingodb::pb::common::VectorIndexType::VECTOR_INDEX_TYPE_BINARY_FLAT);
103103
index_parameter.mutable_binary_flat_parameter()->set_dimension(dimension);
104-
index_parameter.mutable_binary_flat_parameter()->set_metric_type(::dingodb::pb::common::MetricType::METRIC_TYPE_NONE);
104+
index_parameter.mutable_binary_flat_parameter()->set_metric_type(
105+
::dingodb::pb::common::MetricType::METRIC_TYPE_NONE);
105106
vector_index_binary_flat =
106107
VectorIndexFactory::NewBinaryFlat(id, index_parameter, kEpoch, kRange, vector_index_thread_pool);
107108
EXPECT_EQ(vector_index_binary_flat.get(), nullptr);
@@ -113,7 +114,8 @@ TEST_F(VectorIndexBinaryFlatTest, Create) {
113114
pb::common::VectorIndexParameter index_parameter;
114115
index_parameter.set_vector_index_type(::dingodb::pb::common::VectorIndexType::VECTOR_INDEX_TYPE_BINARY_FLAT);
115116
index_parameter.mutable_binary_flat_parameter()->set_dimension(dimension);
116-
index_parameter.mutable_binary_flat_parameter()->set_metric_type(::dingodb::pb::common::MetricType::METRIC_TYPE_HAMMING);
117+
index_parameter.mutable_binary_flat_parameter()->set_metric_type(
118+
::dingodb::pb::common::MetricType::METRIC_TYPE_HAMMING);
117119
vector_index_binary_flat =
118120
VectorIndexFactory::NewBinaryFlat(id, index_parameter, kEpoch, kRange, vector_index_thread_pool);
119121
EXPECT_NE(vector_index_binary_flat.get(), nullptr);
@@ -403,6 +405,8 @@ TEST_F(VectorIndexBinaryFlatTest, Add) {
403405
std::string byte_to_str(1, static_cast<char>(value));
404406
vector_with_id.mutable_vector()->add_binary_values(byte_to_str);
405407
}
408+
vector_with_id.mutable_vector()->set_dimension(dimension);
409+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
406410

407411
vector_with_ids.push_back(vector_with_id);
408412

@@ -423,6 +427,8 @@ TEST_F(VectorIndexBinaryFlatTest, Add) {
423427
std::string byte_to_str(1, static_cast<char>(value));
424428
vector_with_id.mutable_vector()->add_binary_values(byte_to_str);
425429
}
430+
vector_with_id.mutable_vector()->set_dimension(dimension);
431+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
426432

427433
vector_with_ids.push_back(vector_with_id);
428434
}
@@ -530,6 +536,8 @@ TEST_F(VectorIndexBinaryFlatTest, UpsertWithDuplicated) {
530536
std::string byte_to_str(1, static_cast<char>(value));
531537
vector_with_id.mutable_vector()->add_binary_values(byte_to_str);
532538
}
539+
vector_with_id.mutable_vector()->set_dimension(dimension);
540+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
533541

534542
vector_with_ids.push_back(vector_with_id);
535543
}
@@ -543,6 +551,8 @@ TEST_F(VectorIndexBinaryFlatTest, UpsertWithDuplicated) {
543551
std::string byte_to_str(1, static_cast<char>(value));
544552
vector_with_id.mutable_vector()->add_binary_values(byte_to_str);
545553
}
554+
vector_with_id.mutable_vector()->set_dimension(dimension);
555+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
546556

547557
vector_with_ids.push_back(vector_with_id);
548558
}
@@ -594,6 +604,8 @@ TEST_F(VectorIndexBinaryFlatTest, Upsert) {
594604
std::string byte_to_str(1, static_cast<char>(value));
595605
vector_with_id.mutable_vector()->add_binary_values(byte_to_str);
596606
}
607+
vector_with_id.mutable_vector()->set_dimension(dimension);
608+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
597609

598610
vector_with_ids.push_back(vector_with_id);
599611
}
@@ -659,6 +671,8 @@ TEST_F(VectorIndexBinaryFlatTest, Upsert) {
659671
std::string byte_to_str(1, static_cast<char>(value));
660672
vector_with_id.mutable_vector()->add_binary_values(byte_to_str);
661673
}
674+
vector_with_id.mutable_vector()->set_dimension(dimension);
675+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
662676

663677
vector_with_ids.push_back(vector_with_id);
664678
}

test/unit_test/vector/test_vector_index_binary_ivf_flat.cc

+15-59
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ TEST_F(VectorIndexBinaryIvfFlatTest, Create) {
121121
pb::common::VectorIndexParameter index_parameter;
122122
index_parameter.set_vector_index_type(::dingodb::pb::common::VectorIndexType::VECTOR_INDEX_TYPE_BINARY_IVF_FLAT);
123123
index_parameter.mutable_binary_ivf_flat_parameter()->set_dimension(64);
124-
index_parameter.mutable_binary_ivf_flat_parameter()->set_metric_type(::dingodb::pb::common::MetricType::METRIC_TYPE_NONE);
124+
index_parameter.mutable_binary_ivf_flat_parameter()->set_metric_type(
125+
::dingodb::pb::common::MetricType::METRIC_TYPE_NONE);
125126
vector_index_binary_ivf_flat =
126127
VectorIndexFactory::NewBinaryIVFFlat(id, index_parameter, k_epoch, kRange, vector_index_thread_pool);
127128
EXPECT_EQ(vector_index_binary_ivf_flat.get(), nullptr);
@@ -148,7 +149,7 @@ TEST_F(VectorIndexBinaryIvfFlatTest, Create) {
148149
index_parameter.mutable_binary_ivf_flat_parameter()->set_dimension(dimension);
149150
index_parameter.mutable_binary_ivf_flat_parameter()->set_metric_type(
150151
::dingodb::pb::common::MetricType::METRIC_TYPE_HAMMING);
151-
index_parameter.mutable_binary_ivf_flat_parameter()->set_ncentroids(0);
152+
index_parameter.mutable_binary_ivf_flat_parameter()->set_ncentroids(0);
152153
vector_index_binary_ivf_flat =
153154
VectorIndexFactory::NewBinaryIVFFlat(id, index_parameter, k_epoch, kRange, vector_index_thread_pool);
154155
EXPECT_NE(vector_index_binary_ivf_flat.get(), nullptr);
@@ -226,18 +227,6 @@ TEST_F(VectorIndexBinaryIvfFlatTest, SearchNotTrain) {
226227
for (int j = 0; j < dim; j++) data_base[dim * i + j] = distrib(rng);
227228
data_base[dim * i] += i / 255;
228229
}
229-
230-
for (size_t i = 0; i < data_base_size; i++) {
231-
LOG(INFO) << "[" << i << "]" << " [";
232-
for (faiss::idx_t j = 0; j < dim; j++) {
233-
if (0 != j) {
234-
LOG(INFO) << ",";
235-
}
236-
LOG(INFO) << std::setw(10) << data_base[i * dim + j];
237-
}
238-
239-
LOG(INFO) << "]";
240-
}
241230
}
242231

243232
// ok
@@ -275,18 +264,6 @@ TEST_F(VectorIndexBinaryIvfFlatTest, RangeSearchNotTrain) {
275264
for (int j = 0; j < dim; j++) data_base[dim * i + j] = distrib(rng);
276265
data_base[dim * i] += i / 255;
277266
}
278-
279-
for (size_t i = 0; i < data_base_size; i++) {
280-
LOG(INFO) << "[" << i << "]" << " [";
281-
for (faiss::idx_t j = 0; j < dim; j++) {
282-
if (0 != j) {
283-
LOG(INFO) << ",";
284-
}
285-
LOG(INFO) << std::setw(10) << data_base[i * dim + j];
286-
}
287-
288-
LOG(INFO) << "]";
289-
}
290267
}
291268

292269
// ok
@@ -324,6 +301,8 @@ TEST_F(VectorIndexBinaryIvfFlatTest, AddNotTrain) {
324301
std::string byte_data(1, static_cast<char>(data_base[i]));
325302
vector_with_id.mutable_vector()->add_binary_values(byte_data);
326303
}
304+
vector_with_id.mutable_vector()->set_dimension(dimension);
305+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
327306

328307
vector_with_ids.push_back(vector_with_id);
329308

@@ -362,18 +341,6 @@ TEST_F(VectorIndexBinaryIvfFlatTest, TrainVectorWithId) {
362341
for (int j = 0; j < dim; j++) data_base[dim * i + j] = distrib(rng);
363342
data_base[dim * i] += i / 255;
364343
}
365-
366-
for (size_t i = 0; i < data_base_size; i++) {
367-
LOG(INFO) << "[" << i << "]" << " [";
368-
for (faiss::idx_t j = 0; j < dim; j++) {
369-
if (0 != j) {
370-
LOG(INFO) << ",";
371-
}
372-
LOG(INFO) << std::setw(10) << data_base[i * dim + j];
373-
}
374-
375-
LOG(INFO) << "]";
376-
}
377344
}
378345

379346
// invalid. no data
@@ -398,9 +365,9 @@ TEST_F(VectorIndexBinaryIvfFlatTest, TrainVectorWithId) {
398365
vector_with_ids.push_back(vector_with_id);
399366
}
400367

401-
//not align
368+
// not align
402369
pb::common::VectorWithId vector_with_id;
403-
for (int j = 0; j < dim-1; j++) {
370+
for (int j = 0; j < dim - 1; j++) {
404371
std::string byte_data(1, static_cast<char>(data_base_not_align[(data_base_size - 1) * dim + j]));
405372
vector_with_id.mutable_vector()->add_binary_values(byte_data);
406373
}
@@ -470,18 +437,6 @@ TEST_F(VectorIndexBinaryIvfFlatTest, Train) {
470437
for (int j = 0; j < dim; j++) data_base[dim * i + j] = distrib(rng);
471438
data_base[dim * i] += i / 255;
472439
}
473-
474-
for (size_t i = 0; i < data_base_size; i++) {
475-
LOG(INFO) << "[" << i << "]" << " [";
476-
for (faiss::idx_t j = 0; j < dim; j++) {
477-
if (0 != j) {
478-
LOG(INFO) << ",";
479-
}
480-
LOG(INFO) << std::setw(10) << data_base[i * dim + j];
481-
}
482-
483-
LOG(INFO) << "]";
484-
}
485440
}
486441

487442
// invalid. no data
@@ -567,6 +522,8 @@ TEST_F(VectorIndexBinaryIvfFlatTest, Add) {
567522
std::string byte_data(1, static_cast<char>(data_base[i]));
568523
vector_with_id.mutable_vector()->add_binary_values(byte_data);
569524
}
525+
vector_with_id.mutable_vector()->set_dimension(dimension);
526+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
570527

571528
vector_with_ids.push_back(vector_with_id);
572529

@@ -586,6 +543,8 @@ TEST_F(VectorIndexBinaryIvfFlatTest, Add) {
586543
std::string byte_data(1, static_cast<char>(data_base[id * dim + i]));
587544
vector_with_id.mutable_vector()->add_binary_values(byte_data);
588545
}
546+
vector_with_id.mutable_vector()->set_dimension(dimension);
547+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
589548

590549
vector_with_ids.push_back(vector_with_id);
591550
}
@@ -648,6 +607,8 @@ TEST_F(VectorIndexBinaryIvfFlatTest, Upsert) {
648607
std::string byte_data(1, static_cast<char>(data_base[id * dim + i]));
649608
vector_with_id.mutable_vector()->add_binary_values(byte_data);
650609
}
610+
vector_with_id.mutable_vector()->set_dimension(dimension);
611+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
651612

652613
vector_with_ids.push_back(vector_with_id);
653614
}
@@ -675,6 +636,8 @@ TEST_F(VectorIndexBinaryIvfFlatTest, Upsert) {
675636
std::string byte_data(1, static_cast<char>(data_base[id * dim + i]));
676637
vector_with_id.mutable_vector()->add_binary_values(byte_data);
677638
}
639+
vector_with_id.mutable_vector()->set_dimension(dimension);
640+
vector_with_id.mutable_vector()->set_value_type(::dingodb::pb::common::ValueType::UINT8);
678641

679642
vector_with_ids.push_back(vector_with_id);
680643
}
@@ -1008,12 +971,10 @@ TEST_F(VectorIndexBinaryIvfFlatTest, SearchAfterLoad) {
1008971
ok = vector_index_binary_ivf_flat->Search(vector_with_ids, topk, {}, false, {}, results);
1009972
EXPECT_EQ(ok.error_code(), pb::error::Errno::OK);
1010973

1011-
1012974
for (const auto& result : results) {
1013975
DINGO_LOG(INFO) << "results:" << result.DebugString();
1014976
DINGO_LOG(INFO) << "";
1015977
}
1016-
1017978
}
1018979

1019980
// ok with param
@@ -1070,7 +1031,6 @@ TEST_F(VectorIndexBinaryIvfFlatTest, SearchAfterLoad) {
10701031
if (is_all_in_vector) {
10711032
DINGO_LOG(INFO) << "All Id in vectors ";
10721033
}
1073-
10741034
}
10751035
}
10761036

@@ -1086,7 +1046,6 @@ TEST_F(VectorIndexBinaryIvfFlatTest, RangeSearchAfterLoad) {
10861046
std::vector<pb::index::VectorWithDistanceResult> results;
10871047
ok = vector_index_binary_ivf_flat->RangeSearch(vector_with_ids, radius, {}, false, {}, results);
10881048
EXPECT_EQ(ok.error_code(), pb::error::Errno::EVECTOR_INVALID);
1089-
10901049
}
10911050

10921051
// invalid param failed, topk == 0, return OK
@@ -1106,7 +1065,6 @@ TEST_F(VectorIndexBinaryIvfFlatTest, RangeSearchAfterLoad) {
11061065

11071066
ok = vector_index_binary_ivf_flat->RangeSearch(vector_with_ids, radius, {}, false, {}, results);
11081067
EXPECT_EQ(ok.error_code(), pb::error::Errno::OK);
1109-
11101068
}
11111069

11121070
// ok
@@ -1127,12 +1085,10 @@ TEST_F(VectorIndexBinaryIvfFlatTest, RangeSearchAfterLoad) {
11271085
ok = vector_index_binary_ivf_flat->RangeSearch(vector_with_ids, radius, {}, false, {}, results);
11281086
EXPECT_EQ(ok.error_code(), pb::error::Errno::OK);
11291087

1130-
11311088
for (const auto& result : results) {
11321089
DINGO_LOG(INFO) << "results:" << result.DebugString();
11331090
DINGO_LOG(INFO) << "";
11341091
}
1135-
11361092
}
11371093

11381094
// ok with param

0 commit comments

Comments
 (0)