test_delete_vectors.py 22.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
import time
import random
import pdb
import threading
import logging
from multiprocessing import Pool, Process
import pytest
from milvus import IndexType, MetricType
from utils import *


dim = 128
index_file_size = 10
X
Xiaohai Xu 已提交
14
collection_id = "test_delete"
15 16 17 18 19 20 21 22 23 24
DELETE_TIMEOUT = 60
nprobe = 1
epsilon = 0.001
tag = "1970-01-01"
top_k = 1
nb = 6000

class TestDeleteBase:
    """
    ******************************************************************
D
del-zhenwu 已提交
25
      The following cases are used to test `delete_entity_by_id` function
26 27 28 29 30
    ******************************************************************
    """

    @pytest.fixture(
        scope="function",
31
        params=gen_simple_index()
32
    )
33
    def get_simple_index(self, request, connect):
D
del-zhenwu 已提交
34 35 36 37 38 39
        if str(connect._cmd("mode")[1]) == "GPU":
            if request.param["index_type"] not in [IndexType.IVF_SQ8, IndexType.IVFLAT, IndexType.FLAT, IndexType.IVF_PQ, IndexType.IVF_SQ8H]:
                pytest.skip("Only support index_type: idmap/ivf")
        elif str(connect._cmd("mode")[1]) == "CPU":
            if request.param["index_type"] in [IndexType.IVF_SQ8H]:
                pytest.skip("CPU not support index_type: ivf_sq8h")
40 41
        return request.param

X
Xiaohai Xu 已提交
42
    def test_delete_vector_search(self, connect, collection, get_simple_index):
43 44 45 46 47
        '''
        target: test delete vector
        method: add vector and delete
        expected: status ok, vector deleted
        '''
48 49
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
50
        vector = gen_single_vector(dim)
D
del-zhenwu 已提交
51
        status, ids = connect.insert(collection, vector)
52
        assert status.OK()
X
Xiaohai Xu 已提交
53
        status = connect.flush([collection])
54
        assert status.OK()
D
del-zhenwu 已提交
55
        status = connect.delete_entity_by_id(collection, ids)
56
        assert status.OK()
X
Xiaohai Xu 已提交
57
        status = connect.flush([collection])
58
        search_param = get_search_param(index_type)
X
Xiaohai Xu 已提交
59
        status = connect.flush([collection])
60
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
61
        status, res = connect.search(collection, top_k, vector, params=search_param)
62 63 64 65
        logging.getLogger().info(res)
        assert status.OK()
        assert len(res) == 0

X
Xiaohai Xu 已提交
66
    def test_delete_vector_multi_same_ids(self, connect, collection, get_simple_index):
67 68 69 70 71
        '''
        target: test delete vector, with some same ids
        method: add vector and delete
        expected: status ok, vector deleted
        '''
72 73
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
74
        vectors = gen_vectors(nb, dim)
D
del-zhenwu 已提交
75
        connect.insert(collection, vectors, ids=[1 for i in range(nb)])
X
Xiaohai Xu 已提交
76
        status = connect.flush([collection])
77
        # Bloom filter error
78
        assert status.OK()
D
del-zhenwu 已提交
79
        status = connect.delete_entity_by_id(collection, [1])
80
        assert status.OK()
X
Xiaohai Xu 已提交
81
        status = connect.flush([collection])
82
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
83
        status, res = connect.search(collection, top_k, [vectors[0]], params=search_param)
84 85 86 87
        logging.getLogger().info(res)
        assert status.OK()
        assert len(res) == 0

X
Xiaohai Xu 已提交
88
    def test_delete_vector_collection_count(self, connect, collection):
89 90 91 92 93 94
        '''
        target: test delete vector
        method: add vector and delete
        expected: status ok, vector deleted
        '''
        vector = gen_single_vector(dim)
D
del-zhenwu 已提交
95
        status, ids = connect.insert(collection, vector)
96
        assert status.OK()
X
Xiaohai Xu 已提交
97
        status = connect.flush([collection])
98
        assert status.OK()
D
del-zhenwu 已提交
99
        status = connect.delete_entity_by_id(collection, ids)
100
        assert status.OK()
X
Xiaohai Xu 已提交
101
        status = connect.flush([collection])
D
del-zhenwu 已提交
102
        status, res = connect.count_entities(collection)
103
        assert status.OK()
104
        assert res == 0
105

X
Xiaohai Xu 已提交
106
    def test_delete_vector_collection_count_no_flush(self, connect, collection):
107 108 109 110 111 112
        '''
        target: test delete vector
        method: add vector and delete, no flush(using auto flush)
        expected: status ok, vector deleted
        '''
        vector = gen_single_vector(dim)
D
del-zhenwu 已提交
113
        status, ids = connect.insert(collection, vector)
114
        assert status.OK()
X
Xiaohai Xu 已提交
115
        status = connect.flush([collection])
116
        assert status.OK()
X
Xiaohai Xu 已提交
117
        status = connect.flush([collection])
118
        assert status.OK()
D
del-zhenwu 已提交
119
        status = connect.delete_entity_by_id(collection, ids)
120 121
        assert status.OK()
        time.sleep(2)
D
del-zhenwu 已提交
122
        status, res = connect.count_entities(collection)
123
        assert status.OK()
124
        assert res == 0
125

X
Xiaohai Xu 已提交
126
    def test_delete_vector_id_not_exised(self, connect, collection, get_simple_index):
127 128 129 130 131
        '''
        target: test delete vector, params vector_id not existed
        method: add vector and delete
        expected: status ok, search with vector have result
        '''
132 133
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
134
        vector = gen_single_vector(dim)
D
del-zhenwu 已提交
135
        status, ids = connect.insert(collection, vector)
136
        assert status.OK()
X
Xiaohai Xu 已提交
137
        status = connect.flush([collection])
138
        assert status.OK()
D
del-zhenwu 已提交
139
        status = connect.delete_entity_by_id(collection, [0])
140
        assert status.OK()
X
Xiaohai Xu 已提交
141
        status = connect.flush([collection])
142
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
143
        status, res = connect.search(collection, top_k, vector, params=search_param)
144 145 146
        assert status.OK()
        assert res[0][0].id == ids[0]

X
Xiaohai Xu 已提交
147
    def test_delete_vector_collection_not_existed(self, connect, collection):
148
        '''
X
Xiaohai Xu 已提交
149
        target: test delete vector, params collection_name not existed
150 151 152 153
        method: add vector and delete
        expected: status not ok
        '''
        vector = gen_single_vector(dim)
D
del-zhenwu 已提交
154
        status, ids = connect.insert(collection, vector)
155
        assert status.OK()
X
Xiaohai Xu 已提交
156
        status = connect.flush([collection])
157
        assert status.OK()
X
Xiaohai Xu 已提交
158
        collection_new = gen_unique_str()
D
del-zhenwu 已提交
159
        status = connect.delete_entity_by_id(collection_new, [0])
160 161
        assert not status.OK()

D
del-zhenwu 已提交
162
    def test_insert_delete_vector(self, connect, collection, get_simple_index):
163 164 165 166
        '''
        method: add vectors and delete
        expected: status ok, vectors deleted
        '''
167 168
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
169
        vectors = gen_vector(nb, dim)
D
del-zhenwu 已提交
170
        status, ids = connect.insert(collection, vectors)
171
        assert status.OK()
X
Xiaohai Xu 已提交
172
        status = connect.flush([collection])
173 174 175
        assert status.OK()
        delete_ids = [ids[0], ids[-1]]
        query_vecs = [vectors[0], vectors[1], vectors[-1]]
D
del-zhenwu 已提交
176
        status = connect.delete_entity_by_id(collection, delete_ids)
177
        assert status.OK()
X
Xiaohai Xu 已提交
178
        status = connect.flush([collection])
179
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
180
        status, res = connect.search(collection, top_k, query_vecs, params=search_param)
181 182 183 184 185 186 187
        assert status.OK()
        logging.getLogger().info(res)
        assert res[0][0].distance > epsilon
        assert res[1][0].distance < epsilon
        assert res[1][0].id == ids[1]
        assert res[2][0].distance > epsilon

X
Xiaohai Xu 已提交
188
    def test_create_index_after_delete(self, connect, collection, get_simple_index):
189 190 191 192
        '''
        method: add vectors and delete, then create index
        expected: status ok, vectors deleted, index created
        '''
193 194
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
195
        vectors = gen_vector(nb, dim)
D
del-zhenwu 已提交
196
        status, ids = connect.insert(collection, vectors)
197
        assert status.OK()
X
Xiaohai Xu 已提交
198
        status = connect.flush([collection])
199 200 201
        assert status.OK()
        delete_ids = [ids[0], ids[-1]]
        query_vecs = [vectors[0], vectors[1], vectors[-1]]
D
del-zhenwu 已提交
202
        status = connect.delete_entity_by_id(collection, delete_ids)
203
        assert status.OK()
X
Xiaohai Xu 已提交
204 205
        status = connect.flush([collection])
        status = connect.create_index(collection, index_type, index_param)
206
        assert status.OK()
207
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
208
        status, res = connect.search(collection, top_k, query_vecs, params=search_param)
209 210
        assert status.OK()
        logging.getLogger().info(res)
211 212 213 214
        logging.getLogger().info(ids[0])
        logging.getLogger().info(ids[1])
        logging.getLogger().info(ids[-1])
        assert res[0][0].id != ids[0]
215
        assert res[1][0].id == ids[1]
216
        assert res[2][0].id != ids[-1]
217

X
Xiaohai Xu 已提交
218
    def test_add_vector_after_delete(self, connect, collection, get_simple_index):
219 220 221 222
        '''
        method: add vectors and delete, then add vector
        expected: status ok, vectors deleted, vector added
        '''
223 224
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
225
        vectors = gen_vector(nb, dim)
D
del-zhenwu 已提交
226
        status, ids = connect.insert(collection, vectors)
227
        assert status.OK()
X
Xiaohai Xu 已提交
228
        status = connect.flush([collection])
229
        assert status.OK()
X
Xiaohai Xu 已提交
230
        status = connect.flush([collection])
231
        assert status.OK()
232 233
        delete_ids = [ids[0], ids[-1]]
        query_vecs = [vectors[0], vectors[1], vectors[-1]]
D
del-zhenwu 已提交
234
        status = connect.delete_entity_by_id(collection, delete_ids)
235
        assert status.OK()
X
Xiaohai Xu 已提交
236
        status = connect.flush([collection])
D
del-zhenwu 已提交
237
        status, tmp_ids = connect.insert(collection, [vectors[0], vectors[-1]])
238
        assert status.OK()
X
Xiaohai Xu 已提交
239
        status = connect.flush([collection])
240
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
241
        status, res = connect.search(collection, top_k, query_vecs, params=search_param)
242 243 244 245 246 247 248 249
        assert status.OK()
        logging.getLogger().info(res)
        assert res[0][0].id == tmp_ids[0]
        assert res[0][0].distance < epsilon
        assert res[1][0].distance < epsilon
        assert res[2][0].id == tmp_ids[-1]
        assert res[2][0].distance < epsilon

X
Xiaohai Xu 已提交
250
    def test_delete_multiable_times(self, connect, collection):
251 252 253 254 255
        '''
        method: add vectors and delete id serveral times
        expected: status ok, vectors deleted, and status ok for next delete operation
        '''
        vectors = gen_vector(nb, dim)
D
del-zhenwu 已提交
256
        status, ids = connect.insert(collection, vectors)
257
        assert status.OK()
X
Xiaohai Xu 已提交
258
        status = connect.flush([collection])
259 260 261
        assert status.OK()
        delete_ids = [ids[0], ids[-1]]
        query_vecs = [vectors[0], vectors[1], vectors[-1]]
D
del-zhenwu 已提交
262
        status = connect.delete_entity_by_id(collection, delete_ids)
263
        assert status.OK()
X
Xiaohai Xu 已提交
264
        status = connect.flush([collection])
265
        for i in range(10):
D
del-zhenwu 已提交
266
            status = connect.delete_entity_by_id(collection, delete_ids)
267 268
            assert status.OK()

X
Xiaohai Xu 已提交
269
    def test_delete_no_flush_multiable_times(self, connect, collection):
270 271 272 273 274
        '''
        method: add vectors and delete id serveral times
        expected: status ok, vectors deleted, and status ok for next delete operation
        '''
        vectors = gen_vector(nb, dim)
D
del-zhenwu 已提交
275
        status, ids = connect.insert(collection, vectors)
276
        assert status.OK()
X
Xiaohai Xu 已提交
277
        status = connect.flush([collection])
278 279 280
        assert status.OK()
        delete_ids = [ids[0], ids[-1]]
        query_vecs = [vectors[0], vectors[1], vectors[-1]]
D
del-zhenwu 已提交
281
        status = connect.delete_entity_by_id(collection, delete_ids)
282 283
        assert status.OK()
        for i in range(10):
D
del-zhenwu 已提交
284
            status = connect.delete_entity_by_id(collection, delete_ids)
285
            assert status.OK()
286 287
            assert status.OK()

288 289 290 291

class TestDeleteIndexedVectors:
    """
    ******************************************************************
D
del-zhenwu 已提交
292
      The following cases are used to test `delete_entity_by_id` function
293 294 295 296
    ******************************************************************
    """
    @pytest.fixture(
        scope="function",
297
        params=gen_simple_index()
298
    )
299
    def get_simple_index(self, request, connect):
D
del-zhenwu 已提交
300 301 302 303 304 305
        if str(connect._cmd("mode")[1]) == "GPU":
            if request.param["index_type"] not in [IndexType.IVF_SQ8, IndexType.IVFLAT, IndexType.FLAT, IndexType.IVF_PQ, IndexType.IVF_SQ8H]:
                pytest.skip("Only support index_type: idmap/ivf")
        elif str(connect._cmd("mode")[1]) == "CPU":
            if request.param["index_type"] in [IndexType.IVF_SQ8H]:
                pytest.skip("CPU not support index_type: ivf_sq8h")
306 307
        return request.param

X
Xiaohai Xu 已提交
308
    def test_delete_vectors_after_index_created_search(self, connect, collection, get_simple_index):
309 310 311 312 313
        '''
        target: test delete vector after index created
        method: add vector, create index and delete vector
        expected: status ok, vector deleted
        '''
314 315
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
316
        vector = gen_single_vector(dim)
D
del-zhenwu 已提交
317
        status, ids = connect.insert(collection, vector)
318
        assert status.OK()
X
Xiaohai Xu 已提交
319
        status = connect.flush([collection])
320
        assert status.OK()
X
Xiaohai Xu 已提交
321
        status = connect.create_index(collection, index_type, index_param)
322
        assert status.OK()
D
del-zhenwu 已提交
323
        status = connect.delete_entity_by_id(collection, ids)
324
        assert status.OK()
X
Xiaohai Xu 已提交
325
        status = connect.flush([collection])
326
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
327
        status, res = connect.search(collection, top_k, vector, params=search_param)
328 329 330 331
        logging.getLogger().info(res)
        assert status.OK()
        assert len(res) == 0

D
del-zhenwu 已提交
332
    def test_insert_delete_vector(self, connect, collection, get_simple_index):
333 334 335 336
        '''
        method: add vectors and delete
        expected: status ok, vectors deleted
        '''
337 338
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
339
        vectors = gen_vector(nb, dim)
D
del-zhenwu 已提交
340
        status, ids = connect.insert(collection, vectors)
341
        assert status.OK()
X
Xiaohai Xu 已提交
342
        status = connect.flush([collection])
343
        assert status.OK()
X
Xiaohai Xu 已提交
344
        status = connect.flush([collection])
345
        assert status.OK()
X
Xiaohai Xu 已提交
346
        status = connect.create_index(collection, index_type, index_param)
347 348 349
        assert status.OK()
        delete_ids = [ids[0], ids[-1]]
        query_vecs = [vectors[0], vectors[1], vectors[-1]]
D
del-zhenwu 已提交
350
        status = connect.delete_entity_by_id(collection, delete_ids)
351
        assert status.OK()
X
Xiaohai Xu 已提交
352
        status = connect.flush([collection])
353
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
354
        status, res = connect.search(collection, top_k, query_vecs, params=search_param)
355
        assert status.OK()
356 357 358
        logging.getLogger().info(ids[0])
        logging.getLogger().info(ids[1])
        logging.getLogger().info(ids[-1])
359
        logging.getLogger().info(res)
360
        assert res[0][0].id != ids[0]
361
        assert res[1][0].id == ids[1]
362
        assert res[2][0].id != ids[-1]
363 364 365 366 367


class TestDeleteBinary:
    """
    ******************************************************************
D
del-zhenwu 已提交
368
      The following cases are used to test `delete_entity_by_id` function
369 370
    ******************************************************************
    """
371 372 373 374 375 376 377 378 379 380 381
    @pytest.fixture(
        scope="function",
        params=gen_simple_index()
    )
    def get_simple_index(self, request, connect):
        logging.getLogger().info(request.param)
        if request.param["index_type"] == IndexType.IVFLAT or request.param["index_type"] == IndexType.FLAT:
            return request.param
        else:
            pytest.skip("Skip index Temporary")

X
Xiaohai Xu 已提交
382
    def test_delete_vector_search(self, connect, jac_collection, get_simple_index):
383 384 385 386 387
        '''
        target: test delete vector
        method: add vector and delete
        expected: status ok, vector deleted
        '''
388 389
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
390
        tmp, vector = gen_binary_vectors(1, dim)
D
del-zhenwu 已提交
391
        status, ids = connect.insert(jac_collection, vector)
392
        assert status.OK()
X
Xiaohai Xu 已提交
393
        status = connect.flush([jac_collection])
394
        assert status.OK()
D
del-zhenwu 已提交
395
        status = connect.delete_entity_by_id(jac_collection, ids)
396
        assert status.OK()
X
Xiaohai Xu 已提交
397
        status = connect.flush([jac_collection])
398
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
399
        status, res = connect.search(jac_collection, top_k, vector, params=search_param)
400 401 402
        logging.getLogger().info(res)
        assert status.OK()
        assert len(res) == 0
403 404
        assert status.OK()
        assert len(res) == 0
405 406

    # TODO: soft delete
X
Xiaohai Xu 已提交
407
    def test_delete_vector_collection_count(self, connect, jac_collection):
408 409 410 411 412 413
        '''
        target: test delete vector
        method: add vector and delete
        expected: status ok, vector deleted
        '''
        tmp, vector = gen_binary_vectors(1, dim)
D
del-zhenwu 已提交
414
        status, ids = connect.insert(jac_collection, vector)
415
        assert status.OK()
X
Xiaohai Xu 已提交
416
        status = connect.flush([jac_collection])
417
        assert status.OK()
D
del-zhenwu 已提交
418
        status = connect.delete_entity_by_id(jac_collection, ids)
419
        assert status.OK()
X
Xiaohai Xu 已提交
420
        status = connect.flush([jac_collection])
D
del-zhenwu 已提交
421
        status, res = connect.count_entities(jac_collection)
422 423 424
        assert status.OK()
        assert res == 0

X
Xiaohai Xu 已提交
425
    def test_delete_vector_id_not_exised(self, connect, jac_collection, get_simple_index):
426 427 428 429 430
        '''
        target: test delete vector, params vector_id not existed
        method: add vector and delete
        expected: status ok, search with vector have result
        '''
431 432
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
433
        tmp, vector = gen_binary_vectors(1, dim)
D
del-zhenwu 已提交
434
        status, ids = connect.insert(jac_collection, vector)
435
        assert status.OK()
X
Xiaohai Xu 已提交
436
        status = connect.flush([jac_collection])
437
        assert status.OK()
D
del-zhenwu 已提交
438
        status = connect.delete_entity_by_id(jac_collection, [0])
439
        assert status.OK()
X
Xiaohai Xu 已提交
440 441
        status = connect.flush([jac_collection])
        status = connect.flush([jac_collection])
442
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
443
        status, res = connect.search(jac_collection, top_k, vector, params=search_param)
444 445 446
        assert status.OK()
        assert res[0][0].id == ids[0]

X
Xiaohai Xu 已提交
447
    def test_delete_vector_collection_not_existed(self, connect, jac_collection):
448
        '''
X
Xiaohai Xu 已提交
449
        target: test delete vector, params collection_name not existed
450 451 452 453
        method: add vector and delete
        expected: status not ok
        '''
        tmp, vector = gen_binary_vectors(1, dim)
D
del-zhenwu 已提交
454
        status, ids = connect.insert(jac_collection, vector)
455
        assert status.OK()
X
Xiaohai Xu 已提交
456
        status = connect.flush([jac_collection])
457
        assert status.OK()
X
Xiaohai Xu 已提交
458
        collection_new = gen_unique_str()
D
del-zhenwu 已提交
459
        status = connect.delete_entity_by_id(collection_new, [0])
X
Xiaohai Xu 已提交
460
        collection_new = gen_unique_str()
D
del-zhenwu 已提交
461
        status = connect.delete_entity_by_id(collection_new, [0])
462 463
        assert not status.OK()

D
del-zhenwu 已提交
464
    def test_insert_delete_vector(self, connect, jac_collection, get_simple_index):
465 466 467 468
        '''
        method: add vectors and delete
        expected: status ok, vectors deleted
        '''
469 470
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
471
        tmp, vectors = gen_binary_vectors(nb, dim)
D
del-zhenwu 已提交
472
        status, ids = connect.insert(jac_collection, vectors)
473
        assert status.OK()
X
Xiaohai Xu 已提交
474
        status = connect.flush([jac_collection])
475 476 477
        assert status.OK()
        delete_ids = [ids[0], ids[-1]]
        query_vecs = [vectors[0], vectors[1], vectors[-1]]
D
del-zhenwu 已提交
478
        status = connect.delete_entity_by_id(jac_collection, delete_ids)
479
        assert status.OK()
X
Xiaohai Xu 已提交
480
        status = connect.flush([jac_collection])
481
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
482
        status, res = connect.search(jac_collection, top_k, query_vecs, params=search_param)
483 484 485 486 487 488
        assert status.OK()
        logging.getLogger().info(res)
        assert res[0][0].id != ids[0]
        assert res[1][0].id == ids[1]
        assert res[2][0].id != ids[-1]

X
Xiaohai Xu 已提交
489
    def test_add_after_delete_vector(self, connect, jac_collection, get_simple_index):
490 491 492 493
        '''
        method: add vectors and delete, add
        expected: status ok, vectors added
        '''
494 495
        index_param = get_simple_index["index_param"]
        index_type = get_simple_index["index_type"]
496
        tmp, vectors = gen_binary_vectors(nb, dim)
D
del-zhenwu 已提交
497
        status, ids = connect.insert(jac_collection, vectors)
498
        assert status.OK()
X
Xiaohai Xu 已提交
499
        status = connect.flush([jac_collection])
500 501 502
        assert status.OK()
        delete_ids = [ids[0], ids[-1]]
        query_vecs = [vectors[0], vectors[1], vectors[-1]]
D
del-zhenwu 已提交
503
        status = connect.delete_entity_by_id(jac_collection, delete_ids)
504
        assert status.OK()
X
Xiaohai Xu 已提交
505
        status = connect.flush([jac_collection])
D
del-zhenwu 已提交
506
        status, tmp_ids = connect.insert(jac_collection, [vectors[0], vectors[-1]])
507
        assert status.OK()
X
Xiaohai Xu 已提交
508
        status = connect.flush([jac_collection])
509
        search_param = get_search_param(index_type)
D
del-zhenwu 已提交
510
        status, res = connect.search(jac_collection, top_k, query_vecs, params=search_param)
511 512 513 514 515
        assert status.OK()
        logging.getLogger().info(res)
        assert res[0][0].id == tmp_ids[0]
        assert res[1][0].id == ids[1]
        assert res[2][0].id == tmp_ids[-1]
516
        assert res[2][0].id == tmp_ids[-1]
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532


class TestDeleteIdsIngalid(object):
    single_vector = gen_single_vector(dim)

    """
    Test adding vectors with invalid vectors
    """
    @pytest.fixture(
        scope="function",
        params=gen_invalid_vector_ids()
    )
    def gen_invalid_id(self, request):
        yield request.param

    @pytest.mark.level(1)
X
Xiaohai Xu 已提交
533
    def test_delete_vector_id_invalid(self, connect, collection, gen_invalid_id):
534 535
        invalid_id = gen_invalid_id
        with pytest.raises(Exception) as e:
D
del-zhenwu 已提交
536
            status = connect.delete_entity_by_id(collection, [invalid_id])
537 538

    @pytest.mark.level(2)
X
Xiaohai Xu 已提交
539
    def test_delete_vector_ids_invalid(self, connect, collection, gen_invalid_id):
540 541
        invalid_id = gen_invalid_id
        with pytest.raises(Exception) as e:
D
del-zhenwu 已提交
542
            status = connect.delete_entity_by_id(collection, [1, invalid_id])
543 544


S
sahuang 已提交
545
class TestCollectionNameInvalid(object):
546
    """
X
Xiaohai Xu 已提交
547
    Test adding vectors with invalid collection names
548 549 550
    """
    @pytest.fixture(
        scope="function",
X
Xiaohai Xu 已提交
551
        params=gen_invalid_collection_names()
552
    )
X
Xiaohai Xu 已提交
553
    def get_collection_name(self, request):
554 555 556
        yield request.param

    @pytest.mark.level(2)
X
Xiaohai Xu 已提交
557 558
    def test_delete_vectors_with_invalid_collection_name(self, connect, get_collection_name):
        collection_name = get_collection_name
D
del-zhenwu 已提交
559
        status = connect.delete_entity_by_id(collection_name, [1])
560 561
        assert not status.OK()