aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorArne Juul <arnej@verizonmedia.com>2020-03-16 15:35:22 +0000
committerArne Juul <arnej@verizonmedia.com>2020-03-16 15:35:22 +0000
commit1cb87fd70dcffd3d9549f21988dec6ca96670548 (patch)
tree31d73b62e45deff454271de965c2be112a31a42f /searchlib
parent1a217c1590afc4f5a1f8ea4b9cf72eb71c7404b7 (diff)
update unit test
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp36
1 files changed, 25 insertions, 11 deletions
diff --git a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
index 1604a39eaf3..a6c4ac61ba2 100644
--- a/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
+++ b/searchlib/src/tests/tensor/hnsw_index/hnsw_index_test.cpp
@@ -243,9 +243,11 @@ TEST_F(HnswIndexTest, 2d_vectors_inserted_in_hierarchic_graph_with_heuristic_sel
// Doc 3 is also added to level 1
add_document(3, 1);
expect_entry_point(3, 1);
+ // Doc 3 is closest to 1 and they are linked.
+ // Doc 3 is NOT linked to 2, since that is closer to 1 also.
expect_level_0(1, {2, 3});
- expect_level_0(2, {1, 3});
- expect_levels(3, {{1, 2}, {}});
+ expect_level_0(2, {1});
+ expect_levels(3, {{1}, {}});
// Doc 4 is closest to 1 and they are linked.
// Doc 4 is NOT linked to 3 as the distance between 4 and 3 is greater than the distance between 3 and 1.
@@ -253,8 +255,8 @@ TEST_F(HnswIndexTest, 2d_vectors_inserted_in_hierarchic_graph_with_heuristic_sel
add_document(4);
expect_entry_point(3, 1);
expect_level_0(1, {2, 3, 4});
- expect_level_0(2, {1, 3});
- expect_levels(3, {{1, 2}, {}});
+ expect_level_0(2, {1});
+ expect_levels(3, {{1}, {}});
expect_level_0(4, {1});
// Doc 5 is closest to 2 and they are linked.
@@ -262,8 +264,8 @@ TEST_F(HnswIndexTest, 2d_vectors_inserted_in_hierarchic_graph_with_heuristic_sel
add_document(5);
expect_entry_point(3, 1);
expect_level_0(1, {2, 3, 4});
- expect_level_0(2, {1, 3, 5});
- expect_levels(3, {{1, 2}, {}});
+ expect_level_0(2, {1, 5});
+ expect_levels(3, {{1}, {}});
expect_level_0(4, {1});
expect_level_0(5, {2});
@@ -273,8 +275,8 @@ TEST_F(HnswIndexTest, 2d_vectors_inserted_in_hierarchic_graph_with_heuristic_sel
add_document(6, 2);
expect_entry_point(6, 2);
expect_level_0(1, {2, 3, 4});
- expect_level_0(2, {1, 3, 5, 6});
- expect_levels(3, {{1, 2}, {6}});
+ expect_level_0(2, {1, 5, 6});
+ expect_levels(3, {{1}, {6}});
expect_level_0(4, {1});
expect_level_0(5, {2, 6});
expect_levels(6, {{2, 5}, {3}, {}});
@@ -285,12 +287,24 @@ TEST_F(HnswIndexTest, 2d_vectors_inserted_in_hierarchic_graph_with_heuristic_sel
add_document(7);
expect_entry_point(6, 2);
expect_level_0(1, {2, 3, 4});
- expect_level_0(2, {1, 3, 5, 6});
- expect_levels(3, {{1, 2, 7}, {6}});
+ expect_level_0(2, {1, 5, 6});
+ expect_levels(3, {{1, 7}, {6}});
expect_level_0(4, {1});
expect_level_0(5, {2, 6});
expect_levels(6, {{2, 5, 7}, {3}, {}});
expect_level_0(7, {3, 6});
+
+ // removing 1, its neighbors {2,3,4} will try to
+ // link together, but since 2 already has enough links
+ // only 3 and 4 will become neighbors:
+ remove_document(1);
+ expect_entry_point(6, 2);
+ expect_level_0(2, {5, 6});
+ expect_levels(3, {{4, 7}, {6}});
+ expect_level_0(4, {3});
+ expect_level_0(5, {2, 6});
+ expect_levels(6, {{2, 5, 7}, {3}, {}});
+ expect_level_0(7, {3, 6});
}
TEST_F(HnswIndexTest, manual_insert)
@@ -328,7 +342,7 @@ TEST_F(HnswIndexTest, manual_insert)
TEST_F(HnswIndexTest, memory_is_reclaimed_when_doing_changes_to_graph)
{
- init(true);
+ init(false);
add_document(1);
add_document(3);