|
@@ 540-557 (lines=18) @@
|
| 537 |
|
assert abs(np.sqrt(res[0]._distances[0]) - min_distance) <= gen_inaccuracy(res[0]._distances[0]) |
| 538 |
|
|
| 539 |
|
# TODO |
| 540 |
|
@pytest.mark.level(2) |
| 541 |
|
def test_search_distance_ip(self, connect, collection): |
| 542 |
|
''' |
| 543 |
|
target: search collection, and check the result: distance |
| 544 |
|
method: compare the return distance value with value computed with Inner product |
| 545 |
|
expected: the return distance equals to the computed value |
| 546 |
|
''' |
| 547 |
|
nq = 2 |
| 548 |
|
metirc_type = "IP" |
| 549 |
|
search_param = {"nprobe": 1} |
| 550 |
|
entities, ids = init_data(connect, collection, nb=nq) |
| 551 |
|
query, vecs = gen_query_vectors(field_name, entities, top_k, nq, rand_vector=True, metric_type=metirc_type, |
| 552 |
|
search_params=search_param) |
| 553 |
|
inside_query, inside_vecs = gen_query_vectors(field_name, entities, top_k, nq, search_params=search_param) |
| 554 |
|
distance_0 = ip(vecs[0], inside_vecs[0]) |
| 555 |
|
distance_1 = ip(vecs[0], inside_vecs[1]) |
| 556 |
|
res = connect.search(collection, query) |
| 557 |
|
assert abs(res[0]._distances[0] - max(distance_0, distance_1)) <= gen_inaccuracy(res[0]._distances[0]) |
| 558 |
|
|
| 559 |
|
# TODO: distance problem |
| 560 |
|
def _test_search_distance_ip_after_index(self, connect, collection, get_simple_index): |
|
@@ 501-515 (lines=15) @@
|
| 498 |
|
with pytest.raises(Exception) as e: |
| 499 |
|
res = connect.search(collection_name, default_query) |
| 500 |
|
|
| 501 |
|
def test_search_distance_l2(self, connect, collection): |
| 502 |
|
''' |
| 503 |
|
target: search collection, and check the result: distance |
| 504 |
|
method: compare the return distance value with value computed with Euclidean |
| 505 |
|
expected: the return distance equals to the computed value |
| 506 |
|
''' |
| 507 |
|
nq = 2 |
| 508 |
|
search_param = {"nprobe": 1} |
| 509 |
|
entities, ids = init_data(connect, collection, nb=nq) |
| 510 |
|
query, vecs = gen_query_vectors(field_name, entities, top_k, nq, rand_vector=True, search_params=search_param) |
| 511 |
|
inside_query, inside_vecs = gen_query_vectors(field_name, entities, top_k, nq, search_params=search_param) |
| 512 |
|
distance_0 = l2(vecs[0], inside_vecs[0]) |
| 513 |
|
distance_1 = l2(vecs[0], inside_vecs[1]) |
| 514 |
|
res = connect.search(collection, query) |
| 515 |
|
assert abs(np.sqrt(res[0]._distances[0]) - min(distance_0, distance_1)) <= gen_inaccuracy(res[0]._distances[0]) |
| 516 |
|
|
| 517 |
|
# TODO: distance problem |
| 518 |
|
def _test_search_distance_l2_after_index(self, connect, collection, get_simple_index): |