diff options
author | Tor Egge <Tor.Egge@online.no> | 2023-06-05 16:42:45 +0200 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2023-06-05 16:42:45 +0200 |
commit | c0d9b10280db007e376bbc28d75f8b774db2f9a8 (patch) | |
tree | 3b35a69f6006dc36ab139b24fa057f200a3fe03e /searchlib | |
parent | 678fa9ff6d6e363416ec7fe400395c9f3003934e (diff) |
Setup distance metrics for streaming search.
Add range checks when converting to internal distance threshold.
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/vespa/searchlib/tensor/angular_distance.cpp | 7 | ||||
-rw-r--r-- | searchlib/src/vespa/searchlib/tensor/geo_degrees_distance.cpp | 8 |
2 files changed, 15 insertions, 0 deletions
diff --git a/searchlib/src/vespa/searchlib/tensor/angular_distance.cpp b/searchlib/src/vespa/searchlib/tensor/angular_distance.cpp index ab8f2b30df9..ec30236154a 100644 --- a/searchlib/src/vespa/searchlib/tensor/angular_distance.cpp +++ b/searchlib/src/vespa/searchlib/tensor/angular_distance.cpp @@ -2,6 +2,7 @@ #include "angular_distance.h" #include "temporary_vector_store.h" +#include <numbers> using vespalib::typify_invoke; using vespalib::eval::TypifyCellType; @@ -72,6 +73,12 @@ public: return distance; } double convert_threshold(double threshold) const override { + if (threshold < 0.0) { + return 0.0; + } + if (threshold > std::numbers::pi) { + return 2.0; + } double cosine_similarity = cos(threshold); return 1.0 - cosine_similarity; } diff --git a/searchlib/src/vespa/searchlib/tensor/geo_degrees_distance.cpp b/searchlib/src/vespa/searchlib/tensor/geo_degrees_distance.cpp index 0212830efb6..628a550cf8c 100644 --- a/searchlib/src/vespa/searchlib/tensor/geo_degrees_distance.cpp +++ b/searchlib/src/vespa/searchlib/tensor/geo_degrees_distance.cpp @@ -2,6 +2,7 @@ #include "geo_degrees_distance.h" #include "temporary_vector_store.h" +#include <numbers> using vespalib::typify_invoke; using vespalib::eval::TypifyCellType; @@ -56,6 +57,13 @@ public: return hav_central_angle; } double convert_threshold(double threshold) const override { + if (threshold < 0.0) { + return 0.0; + } + constexpr double max_threshold = std::numbers::pi * earth_mean_radius; + if (threshold > max_threshold) { + threshold = max_threshold; + } double half_angle = threshold / (2 * earth_mean_radius); double rt_hav = sin(half_angle); return rt_hav * rt_hav; |