|
@@ 825-848 (lines=24) @@
|
| 822 |
|
assert result[1][0].id in ids |
| 823 |
|
assert result[1][0].distance <= epsilon |
| 824 |
|
|
| 825 |
|
def test_search_distance_tanimoto_flat_index(self, connect, tanimoto_collection): |
| 826 |
|
''' |
| 827 |
|
target: search ip_collection, and check the result: distance |
| 828 |
|
method: compare the return distance value with value computed with Inner product |
| 829 |
|
expected: the return distance equals to the computed value |
| 830 |
|
''' |
| 831 |
|
# from scipy.spatial import distance |
| 832 |
|
nprobe = 512 |
| 833 |
|
int_vectors, vectors, ids = self.init_binary_data(connect, tanimoto_collection, nb=2) |
| 834 |
|
index_type = IndexType.FLAT |
| 835 |
|
index_param = { |
| 836 |
|
"nlist": 16384 |
| 837 |
|
} |
| 838 |
|
connect.create_index(tanimoto_collection, index_type, index_param) |
| 839 |
|
logging.getLogger().info(connect.get_collection_info(tanimoto_collection)) |
| 840 |
|
logging.getLogger().info(connect.get_index_info(tanimoto_collection)) |
| 841 |
|
query_int_vectors, query_vecs, tmp_ids = self.init_binary_data(connect, tanimoto_collection, nb=1, insert=False) |
| 842 |
|
distance_0 = tanimoto(query_int_vectors[0], int_vectors[0]) |
| 843 |
|
distance_1 = tanimoto(query_int_vectors[0], int_vectors[1]) |
| 844 |
|
search_param = get_search_param(index_type) |
| 845 |
|
status, result = connect.search(tanimoto_collection, top_k, query_vecs, params=search_param) |
| 846 |
|
logging.getLogger().info(status) |
| 847 |
|
logging.getLogger().info(result) |
| 848 |
|
assert abs(result[0][0].distance - min(distance_0, distance_1)) <= epsilon |
| 849 |
|
|
| 850 |
|
def test_search_distance_ip_index_params(self, connect, ip_collection, get_index): |
| 851 |
|
''' |
|
@@ 690-713 (lines=24) @@
|
| 687 |
|
logging.getLogger().info(result) |
| 688 |
|
assert abs(result[0][0].distance - min(distance_0, distance_1).astype(float)) <= epsilon |
| 689 |
|
|
| 690 |
|
def test_search_distance_hamming_flat_index(self, connect, ham_collection): |
| 691 |
|
''' |
| 692 |
|
target: search ip_collection, and check the result: distance |
| 693 |
|
method: compare the return distance value with value computed with Inner product |
| 694 |
|
expected: the return distance equals to the computed value |
| 695 |
|
''' |
| 696 |
|
# from scipy.spatial import distance |
| 697 |
|
nprobe = 512 |
| 698 |
|
int_vectors, vectors, ids = self.init_binary_data(connect, ham_collection, nb=2) |
| 699 |
|
index_type = IndexType.FLAT |
| 700 |
|
index_param = { |
| 701 |
|
"nlist": 16384 |
| 702 |
|
} |
| 703 |
|
connect.create_index(ham_collection, index_type, index_param) |
| 704 |
|
logging.getLogger().info(connect.get_collection_info(ham_collection)) |
| 705 |
|
logging.getLogger().info(connect.get_index_info(ham_collection)) |
| 706 |
|
query_int_vectors, query_vecs, tmp_ids = self.init_binary_data(connect, ham_collection, nb=1, insert=False) |
| 707 |
|
distance_0 = hamming(query_int_vectors[0], int_vectors[0]) |
| 708 |
|
distance_1 = hamming(query_int_vectors[0], int_vectors[1]) |
| 709 |
|
search_param = get_search_param(index_type) |
| 710 |
|
status, result = connect.search(ham_collection, top_k, query_vecs, params=search_param) |
| 711 |
|
logging.getLogger().info(status) |
| 712 |
|
logging.getLogger().info(result) |
| 713 |
|
assert abs(result[0][0].distance - min(distance_0, distance_1).astype(float)) <= epsilon |
| 714 |
|
|
| 715 |
|
def test_search_distance_substructure_flat_index(self, connect, substructure_collection): |
| 716 |
|
''' |
|
@@ 638-661 (lines=24) @@
|
| 635 |
|
status, result = connect.search(ip_collection, top_k, query_vecs, params=search_param) |
| 636 |
|
assert abs(result[0][0].distance - max(distance_0, distance_1)) <= gen_inaccuracy(result[0][0].distance) |
| 637 |
|
|
| 638 |
|
def test_search_distance_jaccard_flat_index(self, connect, jac_collection): |
| 639 |
|
''' |
| 640 |
|
target: search ip_collection, and check the result: distance |
| 641 |
|
method: compare the return distance value with value computed with Inner product |
| 642 |
|
expected: the return distance equals to the computed value |
| 643 |
|
''' |
| 644 |
|
# from scipy.spatial import distance |
| 645 |
|
nprobe = 512 |
| 646 |
|
int_vectors, vectors, ids = self.init_binary_data(connect, jac_collection, nb=2) |
| 647 |
|
index_type = IndexType.FLAT |
| 648 |
|
index_param = { |
| 649 |
|
"nlist": 16384 |
| 650 |
|
} |
| 651 |
|
connect.create_index(jac_collection, index_type, index_param) |
| 652 |
|
logging.getLogger().info(connect.get_collection_info(jac_collection)) |
| 653 |
|
logging.getLogger().info(connect.get_index_info(jac_collection)) |
| 654 |
|
query_int_vectors, query_vecs, tmp_ids = self.init_binary_data(connect, jac_collection, nb=1, insert=False) |
| 655 |
|
distance_0 = jaccard(query_int_vectors[0], int_vectors[0]) |
| 656 |
|
distance_1 = jaccard(query_int_vectors[0], int_vectors[1]) |
| 657 |
|
search_param = get_search_param(index_type) |
| 658 |
|
status, result = connect.search(jac_collection, top_k, query_vecs, params=search_param) |
| 659 |
|
logging.getLogger().info(status) |
| 660 |
|
logging.getLogger().info(result) |
| 661 |
|
assert abs(result[0][0].distance - min(distance_0, distance_1)) <= epsilon |
| 662 |
|
|
| 663 |
|
def test_search_distance_jaccard_flat_index_metric_type(self, connect, jac_collection): |
| 664 |
|
''' |