1818#include < cstdint>
1919#include < cstdio>
2020#include < cstdlib>
21+ #include < iomanip>
2122#include < iostream>
2223#include < memory>
2324#include < random>
2425#include < string>
2526#include < vector>
26- #include < iomanip>
27-
2827
2928#include " butil/status.h"
3029#include " common/helper.h"
3130#include " common/logging.h"
3231#include " faiss/MetricType.h"
32+ #include " fmt/format.h"
3333#include " proto/common.pb.h"
3434#include " proto/error.pb.h"
3535#include " proto/index.pb.h"
@@ -151,13 +151,13 @@ TEST_F(VectorIndexFlatTest, DeleteNoData) {
151151 std::vector<int64_t > ids;
152152 ids.push_back (id);
153153 ok = vector_index_flat_l2->Delete (ids);
154- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
154+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
155155
156156 ok = vector_index_flat_ip->Delete (ids);
157- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
157+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
158158
159159 ok = vector_index_flat_cosine->Delete (ids);
160- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
160+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
161161 }
162162
163163 // id exist
@@ -166,13 +166,13 @@ TEST_F(VectorIndexFlatTest, DeleteNoData) {
166166 std::vector<int64_t > ids;
167167 ids.push_back (id);
168168 ok = vector_index_flat_l2->Delete (ids);
169- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
169+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
170170
171171 ok = vector_index_flat_ip->Delete (ids);
172- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
172+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
173173
174174 ok = vector_index_flat_cosine->Delete (ids);
175- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
175+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
176176 }
177177
178178 // id exist batch
@@ -182,13 +182,13 @@ TEST_F(VectorIndexFlatTest, DeleteNoData) {
182182 ids.push_back (i);
183183 }
184184 ok = vector_index_flat_l2->Delete (ids);
185- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
185+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
186186
187187 ok = vector_index_flat_ip->Delete (ids);
188- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
188+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
189189
190190 ok = vector_index_flat_cosine->Delete (ids);
191- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
191+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
192192 }
193193
194194 // id exist batch again
@@ -198,13 +198,13 @@ TEST_F(VectorIndexFlatTest, DeleteNoData) {
198198 ids.push_back (i);
199199 }
200200 ok = vector_index_flat_l2->Delete (ids);
201- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
201+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
202202
203203 ok = vector_index_flat_ip->Delete (ids);
204- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
204+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
205205
206206 ok = vector_index_flat_cosine->Delete (ids);
207- EXPECT_EQ (ok.error_code (), pb::error::Errno::EVECTOR_INVALID );
207+ EXPECT_EQ (ok.error_code (), pb::error::Errno::OK );
208208 }
209209}
210210
@@ -547,6 +547,7 @@ TEST_F(VectorIndexFlatTest, Add) {
547547 for (size_t i = 0 ; i < dimension; i++) {
548548 vector_with_id.mutable_vector ()->add_float_values (data_base[i]);
549549 }
550+ vector_with_id.mutable_vector ()->set_dimension (dimension);
550551
551552 vector_with_ids.push_back (vector_with_id);
552553
@@ -569,6 +570,7 @@ TEST_F(VectorIndexFlatTest, Add) {
569570 for (size_t i = 0 ; i < dimension; i++) {
570571 vector_with_id.mutable_vector ()->add_float_values (data_base[id * dimension + i]);
571572 }
573+ vector_with_id.mutable_vector ()->set_dimension (dimension);
572574
573575 vector_with_ids.push_back (vector_with_id);
574576 }
@@ -617,11 +619,11 @@ TEST_F(VectorIndexFlatTest, Delete) {
617619 std::vector<int64_t > ids;
618620 ids.push_back (id);
619621 ok = vector_index_flat_l2->Delete (ids);
620- EXPECT_EQ (ok.error_code (), pb::error::EVECTOR_INVALID );
622+ EXPECT_EQ (ok.error_code (), pb::error::OK );
621623 ok = vector_index_flat_ip->Delete (ids);
622- EXPECT_EQ (ok.error_code (), pb::error::EVECTOR_INVALID );
624+ EXPECT_EQ (ok.error_code (), pb::error::OK );
623625 ok = vector_index_flat_cosine->Delete (ids);
624- EXPECT_EQ (ok.error_code (), pb::error::EVECTOR_INVALID );
626+ EXPECT_EQ (ok.error_code (), pb::error::OK );
625627 }
626628
627629 // id exist
@@ -651,18 +653,21 @@ TEST_F(VectorIndexFlatTest, Delete) {
651653 EXPECT_EQ (ok.error_code (), pb::error::OK);
652654 }
653655
654- // id exist batch again
656+ // vector_count=0 id exist batch again
655657 {
658+ int64_t count = 0 ;
659+ vector_index_flat_l2->GetCount (count);
660+ std::cout << " vector_index_flat_l2 count: " << count << std::endl;
656661 std::vector<int64_t > ids;
657662 for (size_t i = 0 + data_base_size; i < data_base_size + data_base_size; i++) {
658663 ids.push_back (i);
659664 }
660665 ok = vector_index_flat_l2->Delete (ids);
661- EXPECT_EQ (ok.error_code (), pb::error::EVECTOR_INVALID );
666+ EXPECT_EQ (ok.error_code (), pb::error::OK );
662667 ok = vector_index_flat_ip->Delete (ids);
663- EXPECT_EQ (ok.error_code (), pb::error::EVECTOR_INVALID );
668+ EXPECT_EQ (ok.error_code (), pb::error::OK );
664669 ok = vector_index_flat_cosine->Delete (ids);
665- EXPECT_EQ (ok.error_code (), pb::error::EVECTOR_INVALID );
670+ EXPECT_EQ (ok.error_code (), pb::error::OK );
666671 }
667672}
668673
@@ -706,6 +711,7 @@ TEST_F(VectorIndexFlatTest, UpsertWithDuplicated) {
706711 for (size_t i = 0 ; i < dimension; i++) {
707712 vector_with_id.mutable_vector ()->add_float_values (data_base[id * dimension + i]);
708713 }
714+ vector_with_id.mutable_vector ()->set_dimension (dimension);
709715
710716 vector_with_ids.push_back (vector_with_id);
711717 }
@@ -717,6 +723,7 @@ TEST_F(VectorIndexFlatTest, UpsertWithDuplicated) {
717723 for (size_t i = 0 ; i < dimension; i++) {
718724 vector_with_id.mutable_vector ()->add_float_values (data_base[id * dimension + i]);
719725 }
726+ vector_with_id.mutable_vector ()->set_dimension (dimension);
720727
721728 vector_with_ids.push_back (vector_with_id);
722729 }
@@ -770,6 +777,7 @@ TEST_F(VectorIndexFlatTest, Upsert) {
770777 for (size_t i = 0 ; i < dimension; i++) {
771778 vector_with_id.mutable_vector ()->add_float_values (data_base[id * dimension + i]);
772779 }
780+ vector_with_id.mutable_vector ()->set_dimension (dimension);
773781
774782 vector_with_ids.push_back (vector_with_id);
775783 }
@@ -845,6 +853,7 @@ TEST_F(VectorIndexFlatTest, Upsert) {
845853 for (size_t i = 0 ; i < dimension; i++) {
846854 vector_with_id.mutable_vector ()->add_float_values (data_base[id * dimension + i]);
847855 }
856+ vector_with_id.mutable_vector ()->set_dimension (dimension);
848857
849858 vector_with_ids.push_back (vector_with_id);
850859 }
0 commit comments