// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once #include "fieldsearcher.h" #include #include #include #include #include #include namespace search::fef { class IQueryEnvironment; } namespace search::tensor { class TensorExtAttribute; } namespace vsm { /** * Class used to perform exact nearest neighbor search over the streamed values of a tensor field. * * The raw score from the distance calculation is stored in NearestNeighborQueryNode instances * searching this field. */ class NearestNeighborFieldSearcher : public FieldSearcher { private: class NodeAndCalc : search::streaming::NearestNeighborQueryNode::RawScoreCalculator { public: search::streaming::NearestNeighborQueryNode* node; std::unique_ptr calc; search::queryeval::NearestNeighborDistanceHeap heap; NodeAndCalc(search::streaming::NearestNeighborQueryNode* node_in, std::unique_ptr calc_in); double to_raw_score(double distance) override; }; search::attribute::DistanceMetric _metric; std::unique_ptr _attr; std::vector> _calcs; public: NearestNeighborFieldSearcher(FieldIdT fid, search::attribute::DistanceMetric metric); ~NearestNeighborFieldSearcher() override; std::unique_ptr duplicate() const override; void prepare(search::streaming::QueryTermList& qtl, const SharedSearcherBuf& buf, const vsm::FieldPathMapT& field_paths, search::fef::IQueryEnvironment& query_env) override; void onValue(const document::FieldValue& fv) override; static search::attribute::DistanceMetric distance_metric_from_string(vespalib::stringref value); }; }