diff options
author | Geir Storli <geirst@yahooinc.com> | 2022-04-11 15:07:16 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahooinc.com> | 2022-04-11 15:07:16 +0000 |
commit | 0ae79683fb9ed342c68d9ec5d35274b13e803d61 (patch) | |
tree | 577b9d14b3fa49a0b4b98b18566bb822f030ce57 /searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp | |
parent | 53420d91425d7b456ac25cb74a68fdff94db2cde (diff) |
Simplify calculation of global filter and fallback to brute force when using nearest neighbor search.
With this change only two parameters are used to adjust the algorithm:
- vespa.matching.global_filter.lower_limit
- vespa.matching.global_filter.upper_limit
Diffstat (limited to 'searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp')
-rw-r--r-- | searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp index c77dfb2c2d2..1d3305d2c1a 100644 --- a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp +++ b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp @@ -1031,7 +1031,7 @@ public: return SimpleValue::from_spec(spec); } - std::unique_ptr<NearestNeighborBlueprint> make_blueprint(bool approximate = true, double brute_force_limit = 0.05) { + std::unique_ptr<NearestNeighborBlueprint> make_blueprint(bool approximate = true, double global_filter_lower_limit = 0.05) { search::queryeval::FieldSpec field("foo", 0, 0); auto bp = std::make_unique<NearestNeighborBlueprint>( field, @@ -1039,7 +1039,7 @@ public: createDenseTensor(vec_2d(17, 42)), 3, approximate, 5, 100100.25, - brute_force_limit); + global_filter_lower_limit, 1.0); EXPECT_EQUAL(11u, bp->getState().estimate().estHits); EXPECT_EQUAL(approximate, bp->may_approximate()); EXPECT_EQUAL(100100.25 * 100100.25, bp->get_distance_threshold()); @@ -1052,9 +1052,16 @@ public: DenseTensorAttributeWithoutIndex() : Fixture(vec_2d_spec, FixtureTraits().dense()) {} }; +using NNBA = NearestNeighborBlueprint::Algorithm; using NearestNeighborBlueprintFixture = NearestNeighborBlueprintFixtureBase<DenseTensorAttributeMockIndex>; using NearestNeighborBlueprintWithoutIndexFixture = NearestNeighborBlueprintFixtureBase<DenseTensorAttributeWithoutIndex>; +TEST_F("NN blueprint can use brute force", NearestNeighborBlueprintFixture) +{ + auto bp = f.make_blueprint(false); + EXPECT_EQUAL(NNBA::BRUTE_FORCE, bp->get_algorithm()); +} + TEST_F("NN blueprint handles empty filter", NearestNeighborBlueprintFixture) { auto bp = f.make_blueprint(); @@ -1062,6 +1069,7 @@ TEST_F("NN blueprint handles empty filter", NearestNeighborBlueprintFixture) bp->set_global_filter(*empty_filter); EXPECT_EQUAL(3u, bp->getState().estimate().estHits); EXPECT_TRUE(bp->may_approximate()); + EXPECT_EQUAL(NNBA::INDEX_TOP_K, bp->get_algorithm()); } TEST_F("NN blueprint handles strong filter", NearestNeighborBlueprintFixture) @@ -1074,6 +1082,7 @@ TEST_F("NN blueprint handles strong filter", NearestNeighborBlueprintFixture) bp->set_global_filter(*strong_filter); EXPECT_EQUAL(1u, bp->getState().estimate().estHits); EXPECT_TRUE(bp->may_approximate()); + EXPECT_EQUAL(NNBA::INDEX_TOP_K_WITH_FILTER, bp->get_algorithm()); } TEST_F("NN blueprint handles weak filter", NearestNeighborBlueprintFixture) @@ -1091,6 +1100,7 @@ TEST_F("NN blueprint handles weak filter", NearestNeighborBlueprintFixture) bp->set_global_filter(*weak_filter); EXPECT_EQUAL(3u, bp->getState().estimate().estHits); EXPECT_TRUE(bp->may_approximate()); + EXPECT_EQUAL(NNBA::INDEX_TOP_K_WITH_FILTER, bp->get_algorithm()); } TEST_F("NN blueprint handles strong filter triggering brute force search", NearestNeighborBlueprintFixture) @@ -1103,6 +1113,7 @@ TEST_F("NN blueprint handles strong filter triggering brute force search", Neare bp->set_global_filter(*strong_filter); EXPECT_EQUAL(11u, bp->getState().estimate().estHits); EXPECT_FALSE(bp->may_approximate()); + EXPECT_EQUAL(NNBA::BRUTE_FORCE_FALLBACK, bp->get_algorithm()); } TEST_F("NN blueprint wants global filter when having index", NearestNeighborBlueprintFixture) |