diff options
author | Geir Storli <geirst@yahooinc.com> | 2022-07-11 12:22:34 +0000 |
---|---|---|
committer | Geir Storli <geirst@yahooinc.com> | 2022-07-11 12:46:38 +0000 |
commit | 059b45a1d6d0ec813f9875827741d0157840601f (patch) | |
tree | 0bb6abbd263e42a05975fbc5ad7dd4ba7b05a9c9 /searchlib/src/tests/features | |
parent | f97130213c9a2546788a5e5a6299cdbbd7fee94e (diff) |
Test lazy distance calculation in distance and closeness features.
Diffstat (limited to 'searchlib/src/tests/features')
-rw-r--r-- | searchlib/src/tests/features/nns_closeness/nns_closeness_test.cpp | 29 | ||||
-rw-r--r-- | searchlib/src/tests/features/nns_distance/nns_distance_test.cpp | 34 |
2 files changed, 60 insertions, 3 deletions
diff --git a/searchlib/src/tests/features/nns_closeness/nns_closeness_test.cpp b/searchlib/src/tests/features/nns_closeness/nns_closeness_test.cpp index 661ee884e46..e67370d48f6 100644 --- a/searchlib/src/tests/features/nns_closeness/nns_closeness_test.cpp +++ b/searchlib/src/tests/features/nns_closeness/nns_closeness_test.cpp @@ -1,5 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <vespa/eval/eval/tensor_spec.h> #include <vespa/searchlib/features/closenessfeature.h> #include <vespa/searchlib/features/setup.h> #include <vespa/searchlib/fef/test/dummy_dependency_handler.h> @@ -15,6 +16,8 @@ using namespace search::features; using namespace search::fef::test; using namespace search::fef; +using vespalib::eval::TensorSpec; + const vespalib::string labelFeatureName("closeness(label,nns)"); const vespalib::string fieldFeatureName("closeness(bar)"); @@ -76,4 +79,30 @@ TEST_FF("require that stale data is ignored", SingleLabel("nns", 2), RankFixture EXPECT_EQUAL(0, f2.getScore(10)); } +void +expect_raw_score_calculated_on_the_fly(RankFixture& f) +{ + f.setBarScore(0, 8, 13.0); + f.set_attribute_tensor(9, TensorSpec::from_expr("tensor(x[2]):[5,11]")); + f.set_attribute_tensor(10, TensorSpec::from_expr("tensor(x[2]):[7,11]")); + + // For docids 9 and 10 the raw score is calculated on the fly + // using a distance calculator over the attribute and query tensors. + EXPECT_EQUAL(1/(1+13.0), f.getScore(8)); + EXPECT_EQUAL(1/(1+(5.0-3.0)), f.getScore(9)); + EXPECT_EQUAL(1/(1+(7.0-3.0)), f.getScore(10)); +} + +TEST_FF("raw score is calculated on the fly (using field setup)", + NoLabel(), RankFixture(0, 1, f1, fieldFeatureName, "tensor(x[2]):[3,11]")) +{ + expect_raw_score_calculated_on_the_fly(f2); +} + +TEST_FF("raw score is calculated on the fly (using label setup)", + SingleLabel("nns", 1), RankFixture(0, 1, f1, labelFeatureName, "tensor(x[2]):[3,11]")) +{ + expect_raw_score_calculated_on_the_fly(f2); +} + TEST_MAIN() { TEST_RUN_ALL(); } diff --git a/searchlib/src/tests/features/nns_distance/nns_distance_test.cpp b/searchlib/src/tests/features/nns_distance/nns_distance_test.cpp index 6b2669367ad..fff4c9f1c0e 100644 --- a/searchlib/src/tests/features/nns_distance/nns_distance_test.cpp +++ b/searchlib/src/tests/features/nns_distance/nns_distance_test.cpp @@ -1,12 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include <vespa/vespalib/testkit/test_kit.h> -#include <vespa/searchlib/features/setup.h> -#include <vespa/searchlib/fef/test/labels.h> +#include <vespa/eval/eval/tensor_spec.h> #include <vespa/searchlib/features/distancefeature.h> #include <vespa/searchlib/fef/test/dummy_dependency_handler.h> +#include <vespa/searchlib/fef/test/labels.h> #include <vespa/searchlib/test/features/distance_closeness_fixture.h> #include <vespa/vespalib/stllike/asciistream.h> +#include <vespa/vespalib/testkit/test_kit.h> #include <vespa/vespalib/util/stringfmt.h> using search::feature_t; @@ -15,6 +15,8 @@ using namespace search::features; using namespace search::fef::test; using namespace search::fef; +using vespalib::eval::TensorSpec; + const vespalib::string labelFeatureName("distance(label,nns)"); const vespalib::string fieldFeatureName("distance(bar)"); @@ -82,4 +84,30 @@ TEST_FF("require that stale data is ignored", SingleLabel("nns", 2), RankFixture EXPECT_EQUAL(std::numeric_limits<feature_t>::max(), f2.getScore(10)); } +void +expect_raw_score_calculated_on_the_fly(RankFixture& f) +{ + f.setBarScore(0, 8, 13.0); + f.set_attribute_tensor(9, TensorSpec::from_expr("tensor(x[2]):[5,11]")); + f.set_attribute_tensor(10, TensorSpec::from_expr("tensor(x[2]):[7,11]")); + + // For docids 9 and 10 the raw score is calculated on the fly + // using a distance calculator over the attribute and query tensors. + EXPECT_EQUAL(13.0, f.getScore(8)); + EXPECT_EQUAL((5-3), f.getScore(9)); + EXPECT_EQUAL((7-3), f.getScore(10)); +} + +TEST_FF("raw score is calculated on the fly (using field setup)", + NoLabel(), RankFixture(0, 1, f1, fieldFeatureName, "tensor(x[2]):[3,11]")) +{ + expect_raw_score_calculated_on_the_fly(f2); +} + +TEST_FF("raw score is calculated on the fly (using label setup)", + SingleLabel("nns", 1), RankFixture(0, 1, f1, labelFeatureName, "tensor(x[2]):[3,11]")) +{ + expect_raw_score_calculated_on_the_fly(f2); +} + TEST_MAIN() { TEST_RUN_ALL(); } |