From 51b7faca536b70351980b939850d49d15050f580 Mon Sep 17 00:00:00 2001 From: Tor Egge Date: Mon, 8 May 2023 16:23:32 +0200 Subject: Move ranking config to configdefinitions module. --- configdefinitions/src/vespa/CMakeLists.txt | 6 ++ configdefinitions/src/vespa/onnx-models.def | 15 +++++ configdefinitions/src/vespa/ranking-constants.def | 6 ++ .../src/vespa/ranking-expressions.def | 5 ++ .../src/apps/tests/persistenceconformance_test.cpp | 6 +- .../src/apps/verify_ranksetup/verify_ranksetup.cpp | 16 +++--- .../documentdb/configurer/configurer_test.cpp | 3 +- .../documentdbconfig/documentdbconfig_test.cpp | 6 +- .../fileconfigmanager/fileconfigmanager_test.cpp | 6 +- .../constant_value_repo_test.cpp | 4 +- .../index_environment/index_environment_test.cpp | 9 ++- .../src/tests/proton/matching/matching_test.cpp | 4 +- .../proton_config_fetcher_test.cpp | 20 +++---- .../proton_configurer/proton_configurer_test.cpp | 6 +- .../src/vespa/searchcore/bmcluster/bm_node.cpp | 6 +- .../src/vespa/searchcore/config/CMakeLists.txt | 6 -- .../src/vespa/searchcore/config/onnx-models.def | 15 ----- .../vespa/searchcore/config/ranking-constants.def | 6 -- .../searchcore/config/ranking-expressions.def | 5 -- .../searchcore/proton/matching/CMakeLists.txt | 4 -- .../proton/matching/i_ranking_assets_repo.h | 21 ------- .../searchcore/proton/matching/indexenvironment.h | 18 +++--- .../vespa/searchcore/proton/matching/matcher.cpp | 2 +- .../src/vespa/searchcore/proton/matching/matcher.h | 6 +- .../searchcore/proton/matching/onnx_models.cpp | 49 ---------------- .../vespa/searchcore/proton/matching/onnx_models.h | 42 -------------- .../proton/matching/ranking_assets_repo.cpp | 43 -------------- .../proton/matching/ranking_assets_repo.h | 39 ------------- .../proton/matching/ranking_constants.cpp | 59 -------------------- .../searchcore/proton/matching/ranking_constants.h | 49 ---------------- .../proton/matching/ranking_expressions.cpp | 65 ---------------------- .../proton/matching/ranking_expressions.h | 37 ------------ .../searchcore/proton/server/documentdbconfig.cpp | 4 +- .../searchcore/proton/server/documentdbconfig.h | 12 ++-- .../proton/server/documentdbconfigmanager.cpp | 30 +++++----- .../vespa/searchcore/proton/server/matchers.cpp | 10 ++-- .../src/vespa/searchcore/proton/server/matchers.h | 14 ++--- .../server/searchable_doc_subdb_configurer.cpp | 10 ++-- .../server/searchable_doc_subdb_configurer.h | 9 +-- .../proton/test/documentdb_config_builder.cpp | 6 +- searchlib/src/vespa/searchlib/fef/CMakeLists.txt | 4 ++ .../vespa/searchlib/fef/i_ranking_assets_repo.h | 22 ++++++++ searchlib/src/vespa/searchlib/fef/onnx_model.h | 2 +- searchlib/src/vespa/searchlib/fef/onnx_models.cpp | 49 ++++++++++++++++ searchlib/src/vespa/searchlib/fef/onnx_models.h | 42 ++++++++++++++ .../vespa/searchlib/fef/ranking_assets_repo.cpp | 43 ++++++++++++++ .../src/vespa/searchlib/fef/ranking_assets_repo.h | 39 +++++++++++++ .../src/vespa/searchlib/fef/ranking_constants.cpp | 59 ++++++++++++++++++++ .../src/vespa/searchlib/fef/ranking_constants.h | 49 ++++++++++++++++ .../vespa/searchlib/fef/ranking_expressions.cpp | 65 ++++++++++++++++++++++ .../src/vespa/searchlib/fef/ranking_expressions.h | 37 ++++++++++++ 51 files changed, 547 insertions(+), 543 deletions(-) create mode 100644 configdefinitions/src/vespa/onnx-models.def create mode 100644 configdefinitions/src/vespa/ranking-constants.def create mode 100644 configdefinitions/src/vespa/ranking-expressions.def delete mode 100644 searchcore/src/vespa/searchcore/config/onnx-models.def delete mode 100644 searchcore/src/vespa/searchcore/config/ranking-constants.def delete mode 100644 searchcore/src/vespa/searchcore/config/ranking-expressions.def delete mode 100644 searchcore/src/vespa/searchcore/proton/matching/i_ranking_assets_repo.h delete mode 100644 searchcore/src/vespa/searchcore/proton/matching/onnx_models.cpp delete mode 100644 searchcore/src/vespa/searchcore/proton/matching/onnx_models.h delete mode 100644 searchcore/src/vespa/searchcore/proton/matching/ranking_assets_repo.cpp delete mode 100644 searchcore/src/vespa/searchcore/proton/matching/ranking_assets_repo.h delete mode 100644 searchcore/src/vespa/searchcore/proton/matching/ranking_constants.cpp delete mode 100644 searchcore/src/vespa/searchcore/proton/matching/ranking_constants.h delete mode 100644 searchcore/src/vespa/searchcore/proton/matching/ranking_expressions.cpp delete mode 100644 searchcore/src/vespa/searchcore/proton/matching/ranking_expressions.h create mode 100644 searchlib/src/vespa/searchlib/fef/i_ranking_assets_repo.h create mode 100644 searchlib/src/vespa/searchlib/fef/onnx_models.cpp create mode 100644 searchlib/src/vespa/searchlib/fef/onnx_models.h create mode 100644 searchlib/src/vespa/searchlib/fef/ranking_assets_repo.cpp create mode 100644 searchlib/src/vespa/searchlib/fef/ranking_assets_repo.h create mode 100644 searchlib/src/vespa/searchlib/fef/ranking_constants.cpp create mode 100644 searchlib/src/vespa/searchlib/fef/ranking_constants.h create mode 100644 searchlib/src/vespa/searchlib/fef/ranking_expressions.cpp create mode 100644 searchlib/src/vespa/searchlib/fef/ranking_expressions.h diff --git a/configdefinitions/src/vespa/CMakeLists.txt b/configdefinitions/src/vespa/CMakeLists.txt index 2894c8c38b1..4512348b887 100644 --- a/configdefinitions/src/vespa/CMakeLists.txt +++ b/configdefinitions/src/vespa/CMakeLists.txt @@ -74,3 +74,9 @@ vespa_generate_config(configdefinitions all-clusters-bucket-spaces.def) install_config_definition(all-clusters-bucket-spaces.def vespa.config.content.all-clusters-bucket-spaces.def) vespa_generate_config(configdefinitions stateserver.def) install_config_definition(stateserver.def vespa.config.core.stateserver.def) +vespa_generate_config(configdefinitions ranking-constants.def) +install_config_definition(ranking-constants.def vespa.config.search.core.ranking-constants.def) +vespa_generate_config(configdefinitions ranking-expressions.def) +install_config_definition(ranking-expressions.def vespa.config.search.core.ranking-expressions.def) +vespa_generate_config(configdefinitions onnx-models.def) +install_config_definition(onnx-models.def vespa.config.search.core.onnx-models.def) diff --git a/configdefinitions/src/vespa/onnx-models.def b/configdefinitions/src/vespa/onnx-models.def new file mode 100644 index 00000000000..b8f5d319075 --- /dev/null +++ b/configdefinitions/src/vespa/onnx-models.def @@ -0,0 +1,15 @@ +# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +namespace=vespa.config.search.core + +model[].name string +model[].fileref file +model[].input[].name string +model[].input[].source string +model[].output[].name string +model[].output[].as string +model[].dry_run_on_setup bool default=false +model[].stateless_execution_mode string default="" +model[].stateless_interop_threads int default=-1 +model[].stateless_intraop_threads int default=-1 +model[].gpu_device int default=-1 +model[].gpu_device_required bool default=false diff --git a/configdefinitions/src/vespa/ranking-constants.def b/configdefinitions/src/vespa/ranking-constants.def new file mode 100644 index 00000000000..26dfa564a85 --- /dev/null +++ b/configdefinitions/src/vespa/ranking-constants.def @@ -0,0 +1,6 @@ +# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +namespace=vespa.config.search.core + +constant[].name string +constant[].fileref file +constant[].type string diff --git a/configdefinitions/src/vespa/ranking-expressions.def b/configdefinitions/src/vespa/ranking-expressions.def new file mode 100644 index 00000000000..a9401a4bccb --- /dev/null +++ b/configdefinitions/src/vespa/ranking-expressions.def @@ -0,0 +1,5 @@ +# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +namespace=vespa.config.search.core + +expression[].name string +expression[].fileref file diff --git a/searchcore/src/apps/tests/persistenceconformance_test.cpp b/searchcore/src/apps/tests/persistenceconformance_test.cpp index 0462c385e62..bbac0f9268f 100644 --- a/searchcore/src/apps/tests/persistenceconformance_test.cpp +++ b/searchcore/src/apps/tests/persistenceconformance_test.cpp @@ -125,9 +125,9 @@ public: return std::make_shared( 1, std::make_shared(), - std::make_shared(), - std::make_shared(), - std::make_shared(), + std::make_shared(), + std::make_shared(), + std::make_shared(), indexschema, attributes, summary, diff --git a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp index deba3925eb1..d80604919de 100644 --- a/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp +++ b/searchcore/src/apps/verify_ranksetup/verify_ranksetup.cpp @@ -4,7 +4,10 @@ #include "config-verify-ranksetup.h" #include #include +#include #include +#include +#include #include #include #include @@ -13,14 +16,11 @@ #include #include #include -#include -#include -#include #include -#include -#include #include #include +#include +#include #include #include #include @@ -33,9 +33,9 @@ using config::ConfigRuntimeException; using config::ConfigSubscriber; using config::IConfigContext; using config::InvalidConfigException; -using proton::matching::IRankingAssetsRepo; -using proton::matching::RankingExpressions; -using proton::matching::OnnxModels; +using search::fef::IRankingAssetsRepo; +using search::fef::OnnxModels; +using search::fef::RankingExpressions; using vespa::config::search::AttributesConfig; using vespa::config::search::IndexschemaConfig; using vespa::config::search::RankProfilesConfig; diff --git a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp index e0307777c4c..4af98801e92 100644 --- a/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp +++ b/searchcore/src/tests/proton/documentdb/configurer/configurer_test.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -35,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -58,6 +58,7 @@ using namespace vespalib; using proton::matching::SessionManager; using search::SerialNum; +using search::fef::RankingAssetsRepo; using searchcorespi::IndexSearchable; using searchcorespi::index::IThreadingService; using proton::test::MockGidToLidChangeHandler; diff --git a/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp b/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp index c7e060a9269..5e80091aec5 100644 --- a/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp +++ b/searchcore/src/tests/proton/documentdb/documentdbconfig/documentdbconfig_test.cpp @@ -16,9 +16,9 @@ using namespace proton; using namespace search::index; using namespace search; using namespace vespa::config::search; -using proton::matching::RankingConstants; -using proton::matching::RankingExpressions; -using proton::matching::OnnxModels; +using search::fef::OnnxModels; +using search::fef::RankingConstants; +using search::fef::RankingExpressions; using std::make_shared; using std::shared_ptr; using document::config_builder::DocumenttypesConfigBuilderHelper; diff --git a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp index 99915a1b50f..db2675a7779 100644 --- a/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp +++ b/searchcore/src/tests/proton/documentdb/fileconfigmanager/fileconfigmanager_test.cpp @@ -30,9 +30,9 @@ using namespace vespa::config::search::core; using namespace vespa::config::search; using namespace std::chrono_literals; using vespa::config::content::core::BucketspacesConfig; -using proton::matching::RankingConstants; -using proton::matching::RankingExpressions; -using proton::matching::OnnxModels; +using search::fef::OnnxModels; +using search::fef::RankingConstants; +using search::fef::RankingExpressions; using DBCM = DocumentDBConfigHelper; using DocumenttypesConfigSP = DocumentDBConfig::DocumenttypesConfigSP; diff --git a/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp b/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp index 39b06906a91..611a1c9b54c 100644 --- a/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp +++ b/searchcore/src/tests/proton/matching/constant_value_repo/constant_value_repo_test.cpp @@ -2,10 +2,10 @@ #include -#include #include +#include -using namespace proton::matching; +using namespace search::fef; using namespace vespalib::eval; class DoubleConstantValue : public ConstantValue { diff --git a/searchcore/src/tests/proton/matching/index_environment/index_environment_test.cpp b/searchcore/src/tests/proton/matching/index_environment/index_environment_test.cpp index 60c60f0a37e..f2e3aa4f1dd 100644 --- a/searchcore/src/tests/proton/matching/index_environment/index_environment_test.cpp +++ b/searchcore/src/tests/proton/matching/index_environment/index_environment_test.cpp @@ -3,14 +3,17 @@ #include #include -#include -#include +#include +#include using namespace proton::matching; using search::fef::FieldInfo; using search::fef::FieldType; -using search::fef::Properties; +using search::fef::IRankingAssetsRepo; using search::fef::OnnxModel; +using search::fef::OnnxModels; +using search::fef::Properties; +using search::fef::RankingExpressions; using search::index::Schema; using search::index::schema::CollectionType; using search::index::schema::DataType; diff --git a/searchcore/src/tests/proton/matching/matching_test.cpp b/searchcore/src/tests/proton/matching/matching_test.cpp index 4ad386afa3f..d5241f7d65b 100644 --- a/searchcore/src/tests/proton/matching/matching_test.cpp +++ b/searchcore/src/tests/proton/matching/matching_test.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -20,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -110,7 +110,7 @@ vespalib::string make_same_element_stack_dump(const vespalib::string &a1_term, c const uint32_t NUM_DOCS = 1000; -struct EmptyRankingAssetsRepo : public proton::matching::IRankingAssetsRepo { +struct EmptyRankingAssetsRepo : public search::fef::IRankingAssetsRepo { vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &) const override { return {}; } diff --git a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp index 13371521718..caedd363481 100644 --- a/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp +++ b/searchcore/src/tests/proton/proton_config_fetcher/proton_config_fetcher_test.cpp @@ -1,5 +1,15 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -10,9 +20,6 @@ #include #include #include -#include -#include -#include #include #include #include @@ -20,13 +27,6 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include #include #include diff --git a/searchcore/src/tests/proton/proton_configurer/proton_configurer_test.cpp b/searchcore/src/tests/proton/proton_configurer/proton_configurer_test.cpp index 51008e4cbee..d8dafd1c39e 100644 --- a/searchcore/src/tests/proton/proton_configurer/proton_configurer_test.cpp +++ b/searchcore/src/tests/proton/proton_configurer/proton_configurer_test.cpp @@ -40,9 +40,9 @@ using document::DocumentTypeRepo; using search::TuneFileDocumentDB; using std::map; using search::index::Schema; -using proton::matching::RankingConstants; -using proton::matching::RankingExpressions; -using proton::matching::OnnxModels; +using search::fef::OnnxModels; +using search::fef::RankingConstants; +using search::fef::RankingExpressions; struct DBConfigFixture { using UP = std::unique_ptr; diff --git a/searchcore/src/vespa/searchcore/bmcluster/bm_node.cpp b/searchcore/src/vespa/searchcore/bmcluster/bm_node.cpp index aebfe23aa6f..9d86b2d28e1 100644 --- a/searchcore/src/vespa/searchcore/bmcluster/bm_node.cpp +++ b/searchcore/src/vespa/searchcore/bmcluster/bm_node.cpp @@ -180,9 +180,9 @@ std::shared_ptr make_document_db_config(std::shared_ptr( 1, std::make_shared(), - std::make_shared(), - std::make_shared(), - std::make_shared(), + std::make_shared(), + std::make_shared(), + std::make_shared(), indexschema, attributes, summary, diff --git a/searchcore/src/vespa/searchcore/config/CMakeLists.txt b/searchcore/src/vespa/searchcore/config/CMakeLists.txt index 7069521ba6e..978969bbf27 100644 --- a/searchcore/src/vespa/searchcore/config/CMakeLists.txt +++ b/searchcore/src/vespa/searchcore/config/CMakeLists.txt @@ -5,10 +5,4 @@ vespa_add_library(searchcore_fconfig STATIC ) vespa_generate_config(searchcore_fconfig proton.def) install_config_definition(proton.def vespa.config.search.core.proton.def) -vespa_generate_config(searchcore_fconfig ranking-constants.def) -install_config_definition(ranking-constants.def vespa.config.search.core.ranking-constants.def) -vespa_generate_config(searchcore_fconfig ranking-expressions.def) -install_config_definition(ranking-expressions.def vespa.config.search.core.ranking-expressions.def) -vespa_generate_config(searchcore_fconfig onnx-models.def) -install_config_definition(onnx-models.def vespa.config.search.core.onnx-models.def) vespa_generate_config(searchcore_fconfig hwinfo.def) diff --git a/searchcore/src/vespa/searchcore/config/onnx-models.def b/searchcore/src/vespa/searchcore/config/onnx-models.def deleted file mode 100644 index b8f5d319075..00000000000 --- a/searchcore/src/vespa/searchcore/config/onnx-models.def +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -namespace=vespa.config.search.core - -model[].name string -model[].fileref file -model[].input[].name string -model[].input[].source string -model[].output[].name string -model[].output[].as string -model[].dry_run_on_setup bool default=false -model[].stateless_execution_mode string default="" -model[].stateless_interop_threads int default=-1 -model[].stateless_intraop_threads int default=-1 -model[].gpu_device int default=-1 -model[].gpu_device_required bool default=false diff --git a/searchcore/src/vespa/searchcore/config/ranking-constants.def b/searchcore/src/vespa/searchcore/config/ranking-constants.def deleted file mode 100644 index 26dfa564a85..00000000000 --- a/searchcore/src/vespa/searchcore/config/ranking-constants.def +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -namespace=vespa.config.search.core - -constant[].name string -constant[].fileref file -constant[].type string diff --git a/searchcore/src/vespa/searchcore/config/ranking-expressions.def b/searchcore/src/vespa/searchcore/config/ranking-expressions.def deleted file mode 100644 index a9401a4bccb..00000000000 --- a/searchcore/src/vespa/searchcore/config/ranking-expressions.def +++ /dev/null @@ -1,5 +0,0 @@ -# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -namespace=vespa.config.search.core - -expression[].name string -expression[].fileref file diff --git a/searchcore/src/vespa/searchcore/proton/matching/CMakeLists.txt b/searchcore/src/vespa/searchcore/proton/matching/CMakeLists.txt index 9a536a0d172..7960d1d51b5 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/CMakeLists.txt +++ b/searchcore/src/vespa/searchcore/proton/matching/CMakeLists.txt @@ -3,7 +3,6 @@ vespa_add_library(searchcore_matching STATIC SOURCES attribute_limiter.cpp blueprintbuilder.cpp - ranking_assets_repo.cpp docid_range_scheduler.cpp docsum_matcher.cpp document_scorer.cpp @@ -21,15 +20,12 @@ vespa_add_library(searchcore_matching STATIC match_tools.cpp matcher.cpp matching_stats.cpp - onnx_models.cpp partial_result.cpp query.cpp queryenvironment.cpp querylimiter.cpp querynodes.cpp rangequerylocator.cpp - ranking_constants.cpp - ranking_expressions.cpp requestcontext.cpp resolveviewvisitor.cpp result_processor.cpp diff --git a/searchcore/src/vespa/searchcore/proton/matching/i_ranking_assets_repo.h b/searchcore/src/vespa/searchcore/proton/matching/i_ranking_assets_repo.h deleted file mode 100644 index d96423bf25c..00000000000 --- a/searchcore/src/vespa/searchcore/proton/matching/i_ranking_assets_repo.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include - -namespace search::fef { class OnnxModel; } -namespace proton::matching { - -/** - * Interface for retrieving named constants, expressions and models from ranking. - * Empty strings or nullptrs indicates nothing found. - */ -struct IRankingAssetsRepo { - virtual vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &name) const = 0; - virtual vespalib::string getExpression(const vespalib::string &name) const = 0; - virtual const search::fef::OnnxModel *getOnnxModel(const vespalib::string &name) const = 0; - virtual ~IRankingAssetsRepo() = default; -}; - -} diff --git a/searchcore/src/vespa/searchcore/proton/matching/indexenvironment.h b/searchcore/src/vespa/searchcore/proton/matching/indexenvironment.h index 8f8ac516ab8..1fa6c7c3917 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/indexenvironment.h +++ b/searchcore/src/vespa/searchcore/proton/matching/indexenvironment.h @@ -2,7 +2,7 @@ #pragma once -#include "i_ranking_assets_repo.h" +#include #include #include #include @@ -19,13 +19,13 @@ class IndexEnvironment : public search::fef::IIndexEnvironment { private: using FieldNameMap = vespalib::hash_map; - search::fef::TableManager _tableManager; - search::fef::Properties _properties; - FieldNameMap _fieldNames; - std::vector _fields; - mutable FeatureMotivation _motivation; - const IRankingAssetsRepo &_rankingAssetsRepo; - uint32_t _distributionKey; + search::fef::TableManager _tableManager; + search::fef::Properties _properties; + FieldNameMap _fieldNames; + std::vector _fields; + mutable FeatureMotivation _motivation; + const search::fef::IRankingAssetsRepo& _rankingAssetsRepo; + uint32_t _distributionKey; /** @@ -50,7 +50,7 @@ public: IndexEnvironment(uint32_t distributionKey, const search::index::Schema &schema, search::fef::Properties props, - const IRankingAssetsRepo &constantValueRepo); + const search::fef::IRankingAssetsRepo& constantValueRepo); ~IndexEnvironment() override; diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp index b393558638d..657f3d11e76 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp +++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.cpp @@ -103,7 +103,7 @@ handleGroupingSession(SessionManager &sessionMgr, GroupingContext & groupingCont } // namespace proton::matching:: Matcher::Matcher(const search::index::Schema &schema, Properties props, const vespalib::Clock &clock, - QueryLimiter &queryLimiter, const IRankingAssetsRepo &rankingAssetsRepo, uint32_t distributionKey) + QueryLimiter &queryLimiter, const search::fef::IRankingAssetsRepo &rankingAssetsRepo, uint32_t distributionKey) : _indexEnv(distributionKey, schema, std::move(props), rankingAssetsRepo), _blueprintFactory(), _rankSetup(), diff --git a/searchcore/src/vespa/searchcore/proton/matching/matcher.h b/searchcore/src/vespa/searchcore/proton/matching/matcher.h index 6507ffca2eb..198334e4021 100644 --- a/searchcore/src/vespa/searchcore/proton/matching/matcher.h +++ b/searchcore/src/vespa/searchcore/proton/matching/matcher.h @@ -2,7 +2,6 @@ #pragma once -#include "i_ranking_assets_repo.h" #include "docsum_matcher.h" #include "indexenvironment.h" #include "matching_stats.h" @@ -10,10 +9,11 @@ #include "search_session.h" #include "viewresolver.h" #include -#include #include #include #include +#include +#include #include #include #include @@ -86,7 +86,7 @@ public: **/ Matcher(const search::index::Schema &schema, Properties props, const vespalib::Clock &clock, QueryLimiter &queryLimiter, - const IRankingAssetsRepo &rankingAssetsRepo, uint32_t distributionKey); + const search::fef::IRankingAssetsRepo &rankingAssetsRepo, uint32_t distributionKey); const search::fef::IIndexEnvironment &get_index_env() const { return _indexEnv; } diff --git a/searchcore/src/vespa/searchcore/proton/matching/onnx_models.cpp b/searchcore/src/vespa/searchcore/proton/matching/onnx_models.cpp deleted file mode 100644 index 399e4ab0ad0..00000000000 --- a/searchcore/src/vespa/searchcore/proton/matching/onnx_models.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "onnx_models.h" -#include - -namespace proton::matching { - -OnnxModels::OnnxModels() = default; -OnnxModels::OnnxModels(OnnxModels &&) noexcept = default; -OnnxModels::~OnnxModels() = default; - -OnnxModels::OnnxModels(Vector models) - : _models() -{ - for (auto &model: models) { - _models.emplace(model.name(), std::move(model)); - } -} - -bool -OnnxModels::operator==(const OnnxModels &rhs) const -{ - return (_models == rhs._models); -} - -const OnnxModels::Model * -OnnxModels::getModel(const vespalib::string &name) const -{ - auto itr = _models.find(name); - if (itr != _models.end()) { - return &itr->second; - } - return nullptr; -} - -void -OnnxModels::configure(const ModelConfig &config, Model &model) -{ - assert(config.name == model.name()); - for (const auto &input: config.input) { - model.input_feature(input.name, input.source); - } - for (const auto &output: config.output) { - model.output_name(output.name, output.as); - } - model.dry_run_on_setup(config.dryRunOnSetup); -} - -} diff --git a/searchcore/src/vespa/searchcore/proton/matching/onnx_models.h b/searchcore/src/vespa/searchcore/proton/matching/onnx_models.h deleted file mode 100644 index 4a8bdbca3d9..00000000000 --- a/searchcore/src/vespa/searchcore/proton/matching/onnx_models.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include -#include -#include -#include -#include - -namespace proton::matching { - -/** - * Class representing a set of configured onnx models, with full path - * for where the models are stored on disk. - */ -class OnnxModels { -public: - using ModelConfig = vespa::config::search::core::OnnxModelsConfig::Model; - using Model = search::fef::OnnxModel; - using Vector = std::vector; - -private: - using Map = std::map; - Map _models; - -public: - using SP = std::shared_ptr; - OnnxModels(); - OnnxModels(Vector models); - OnnxModels(OnnxModels &&) noexcept; - OnnxModels & operator=(OnnxModels &&) = delete; - OnnxModels(const OnnxModels &) = delete; - OnnxModels & operator =(const OnnxModels &) = delete; - ~OnnxModels(); - bool operator==(const OnnxModels &rhs) const; - [[nodiscard]] const Model *getModel(const vespalib::string &name) const; - [[nodiscard]] size_t size() const { return _models.size(); } - static void configure(const ModelConfig &config, Model &model); -}; - -} diff --git a/searchcore/src/vespa/searchcore/proton/matching/ranking_assets_repo.cpp b/searchcore/src/vespa/searchcore/proton/matching/ranking_assets_repo.cpp deleted file mode 100644 index cfe7f836e42..00000000000 --- a/searchcore/src/vespa/searchcore/proton/matching/ranking_assets_repo.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "ranking_assets_repo.h" - -using vespalib::eval::ConstantValue; - -namespace proton::matching { - -RankingAssetsRepo::RankingAssetsRepo(const ConstantValueFactory &factory, - std::shared_ptr constants, - std::shared_ptr expressions, - std::shared_ptr models) - : _factory(factory), - _constants(std::move(constants)), - _rankingExpressions(std::move(expressions)), - _onnxModels(std::move(models)) -{ -} - -RankingAssetsRepo::~RankingAssetsRepo() = default; - -ConstantValue::UP -RankingAssetsRepo::getConstant(const vespalib::string &name) const -{ - if ( ! _constants) return {}; - const RankingConstants::Constant *constant = _constants->getConstant(name); - if (constant != nullptr) { - return _factory.create(constant->filePath, constant->type); - } - return {}; -} - -vespalib::string -RankingAssetsRepo::getExpression(const vespalib::string &name) const { - return _rankingExpressions ? _rankingExpressions->loadExpression(name) : ""; -} - -const search::fef::OnnxModel * -RankingAssetsRepo::getOnnxModel(const vespalib::string &name) const { - return _onnxModels ? _onnxModels->getModel(name) : nullptr; -} - -} diff --git a/searchcore/src/vespa/searchcore/proton/matching/ranking_assets_repo.h b/searchcore/src/vespa/searchcore/proton/matching/ranking_assets_repo.h deleted file mode 100644 index 3e502d2ef69..00000000000 --- a/searchcore/src/vespa/searchcore/proton/matching/ranking_assets_repo.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include "i_ranking_assets_repo.h" -#include "ranking_constants.h" -#include "onnx_models.h" -#include "ranking_expressions.h" -#include - -namespace proton::matching { - -/** - * Class that provides access to a configured set of rank constant values. - * - * This class maps symbolic names to assets used while setting up rank features blueprints. - * A factory is used to instantiate constant values. - */ -class RankingAssetsRepo : public IRankingAssetsRepo { -private: - using ConstantValueFactory = vespalib::eval::ConstantValueFactory; - - const ConstantValueFactory &_factory; - const std::shared_ptr _constants; - const std::shared_ptr _rankingExpressions; - const std::shared_ptr _onnxModels; - -public: - RankingAssetsRepo(const ConstantValueFactory &factory, - std::shared_ptr constants, - std::shared_ptr expressions, - std::shared_ptr models); - ~RankingAssetsRepo() override; - vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &name) const override; - vespalib::string getExpression(const vespalib::string &name) const override; - const search::fef::OnnxModel *getOnnxModel(const vespalib::string &name) const override; -}; - -} diff --git a/searchcore/src/vespa/searchcore/proton/matching/ranking_constants.cpp b/searchcore/src/vespa/searchcore/proton/matching/ranking_constants.cpp deleted file mode 100644 index 02f705ba4ea..00000000000 --- a/searchcore/src/vespa/searchcore/proton/matching/ranking_constants.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "ranking_constants.h" - -namespace proton::matching { - -RankingConstants::Constant::Constant(const vespalib::string &name_in, - const vespalib::string &type_in, - const vespalib::string &filePath_in) - : name(name_in), - type(type_in), - filePath(filePath_in) -{ -} - -RankingConstants::Constant::~Constant() = default; - -bool -RankingConstants::Constant::operator==(const Constant &rhs) const -{ - return (name == rhs.name) && - (type == rhs.type) && - (filePath == rhs.filePath); -} - -RankingConstants::RankingConstants() - : _constants() -{ -} - -RankingConstants::~RankingConstants() = default; -RankingConstants::RankingConstants(RankingConstants &&) noexcept = default; - -RankingConstants::RankingConstants(const Vector &constants) - : _constants() -{ - for (const auto &constant : constants) { - _constants.insert(std::make_pair(constant.name, constant)); - } -} - -bool -RankingConstants::operator==(const RankingConstants &rhs) const -{ - return _constants == rhs._constants; -} - -const RankingConstants::Constant * -RankingConstants::getConstant(const vespalib::string &name) const -{ - auto itr = _constants.find(name); - if (itr != _constants.end()) { - return &itr->second; - } - return nullptr; -} - -} - diff --git a/searchcore/src/vespa/searchcore/proton/matching/ranking_constants.h b/searchcore/src/vespa/searchcore/proton/matching/ranking_constants.h deleted file mode 100644 index c527c6e5571..00000000000 --- a/searchcore/src/vespa/searchcore/proton/matching/ranking_constants.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include -#include -#include -#include - -namespace proton::matching { - -/** - * Class representing a set of configured ranking constants, with name, type and file path (where constant is stored). - */ -class RankingConstants { -public: - struct Constant { - vespalib::string name; - vespalib::string type; - vespalib::string filePath; - - Constant(const vespalib::string &name_in, - const vespalib::string &type_in, - const vespalib::string &filePath_in); - ~Constant(); - bool operator==(const Constant &rhs) const; - }; - - using Vector = std::vector; - -private: - using Map = std::map; - Map _constants; - -public: - using SP = std::shared_ptr; - RankingConstants(); - RankingConstants(RankingConstants &&) noexcept; - RankingConstants & operator =(RankingConstants &&) = delete; - RankingConstants(const RankingConstants &) = delete; - RankingConstants & operator =(const RankingConstants &) = delete; - explicit RankingConstants(const Vector &constants); - ~RankingConstants(); - bool operator==(const RankingConstants &rhs) const; - const Constant *getConstant(const vespalib::string &name) const; - size_t size() const { return _constants.size(); } -}; - -} diff --git a/searchcore/src/vespa/searchcore/proton/matching/ranking_expressions.cpp b/searchcore/src/vespa/searchcore/proton/matching/ranking_expressions.cpp deleted file mode 100644 index 98b1e3ea653..00000000000 --- a/searchcore/src/vespa/searchcore/proton/matching/ranking_expressions.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#include "ranking_expressions.h" -#include -#include -#include - -#include -LOG_SETUP(".proton.matching.ranking_expressions"); - -namespace proton::matching { - -namespace { - -vespalib::string extract_data(vespalib::Input &input) { - vespalib::string result; - for (auto chunk = input.obtain(); chunk.size > 0; chunk = input.obtain()) { - result.append(vespalib::stringref(chunk.data, chunk.size)); - input.evict(chunk.size); - } - return result; -} - -} // unnamed - -RankingExpressions::RankingExpressions() = default; -RankingExpressions::RankingExpressions(RankingExpressions &&rhs) noexcept = default; -RankingExpressions::~RankingExpressions() = default; - -RankingExpressions & -RankingExpressions::add(const vespalib::string &name, const vespalib::string &path) -{ - _expressions.insert_or_assign(name, path); - return *this; -} - -vespalib::string -RankingExpressions::loadExpression(const vespalib::string &name) const -{ - auto pos = _expressions.find(name); - if (pos == _expressions.end()) { - LOG(warning, "no such ranking expression: '%s'", name.c_str()); - return {}; - } - auto path = pos->second; - vespalib::MappedFileInput file(path); - if (!file.valid()) { - LOG(warning, "rankexpression: %s -> could not read file: %s", name.c_str(), path.c_str()); - return {}; - } - if (ends_with(path, ".lz4")) { - size_t buffer_size = 64_Ki; - vespalib::Lz4InputDecoder lz4_decoder(file, buffer_size); - auto result = extract_data(lz4_decoder); - if (lz4_decoder.failed()) { - LOG(warning, "file contains lz4 errors (%s): %s", - lz4_decoder.reason().c_str(), path.c_str()); - return {}; - } - return result; - } - return extract_data(file); -} - -} diff --git a/searchcore/src/vespa/searchcore/proton/matching/ranking_expressions.h b/searchcore/src/vespa/searchcore/proton/matching/ranking_expressions.h deleted file mode 100644 index c228f2b92ca..00000000000 --- a/searchcore/src/vespa/searchcore/proton/matching/ranking_expressions.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -#pragma once - -#include -#include -#include - -namespace proton::matching { - -/** - * Class representing a collection of named ranking expressions - * obtained through file-distribution. - */ -class RankingExpressions -{ -private: - // expression name -> full_path of expression file - std::map _expressions; - -public: - using SP = std::shared_ptr; - RankingExpressions(); - RankingExpressions(RankingExpressions &&rhs) noexcept; - RankingExpressions & operator=(RankingExpressions &&rhs) = delete; - RankingExpressions(const RankingExpressions &rhs) = delete; - RankingExpressions & operator=(const RankingExpressions &rhs) = delete; - ~RankingExpressions(); - bool operator==(const RankingExpressions &rhs) const { - return _expressions == rhs._expressions; - } - size_t size() const { return _expressions.size(); } - RankingExpressions &add(const vespalib::string &name, const vespalib::string &path); - vespalib::string loadExpression(const vespalib::string &name) const; -}; - -} diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.cpp index afb61101853..00d9c194b9e 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.cpp @@ -4,15 +4,15 @@ #include "threading_service_config.h" #include #include +#include #include +#include #include #include #include #include #include #include -#include -#include #include #include #include diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.h b/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.h index ed1e8fc7516..11f23cf0b66 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.h +++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfig.h @@ -5,11 +5,11 @@ #include "document_db_maintenance_config.h" #include "threading_service_config.h" #include -#include -#include -#include #include #include +#include +#include +#include #include #include @@ -98,9 +98,9 @@ public: using AttributesConfigSP = std::shared_ptr; using RankProfilesConfig = const vespa::config::search::internal::InternalRankProfilesType; using RankProfilesConfigSP = std::shared_ptr; - using RankingConstants = matching::RankingConstants; - using RankingExpressions = matching::RankingExpressions; - using OnnxModels = matching::OnnxModels; + using RankingConstants = search::fef::RankingConstants; + using RankingExpressions = search::fef::RankingExpressions; + using OnnxModels = search::fef::OnnxModels; using SummaryConfig = const vespa::config::search::internal::InternalSummaryType; using SummaryConfigSP = std::shared_ptr; using JuniperrcConfig = const vespa::config::search::summary::internal::InternalJuniperrcType; diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp index 2c75f00a672..96f6c87890d 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdbconfigmanager.cpp @@ -3,22 +3,22 @@ #include "documentdbconfigmanager.h" #include "bootstrapconfig.h" #include "threading_service_config.h" -#include -#include -#include -#include -#include -#include +#include #include +#include +#include #include +#include +#include +#include +#include #include #include #include #include -#include -#include -#include #include +#include +#include #include #include #include @@ -38,11 +38,11 @@ using namespace vespa::config::search; using document::DocumentTypeRepo; using search::TuneFileDocumentDB; +using search::fef::OnnxModels; +using search::fef::RankingConstants; +using search::fef::RankingExpressions; using search::index::Schema; using search::index::SchemaBuilder; -using proton::matching::RankingConstants; -using proton::matching::RankingExpressions; -using proton::matching::OnnxModels; using vespalib::compression::CompressionConfig; using search::LogDocumentStore; using search::LogDataStore; @@ -275,9 +275,9 @@ DocumentDBConfigManager::update(FNET_Transport & transport, const ConfigSnapshot DocumentDBConfig::SP current = _pendingConfigSnapshot; RankProfilesConfigSP newRankProfilesConfig; - matching::RankingConstants::SP newRankingConstants; - matching::RankingExpressions::SP newRankingExpressions; - matching::OnnxModels::SP newOnnxModels; + search::fef::RankingConstants::SP newRankingConstants; + search::fef::RankingExpressions::SP newRankingExpressions; + search::fef::OnnxModels::SP newOnnxModels; IndexschemaConfigSP newIndexschemaConfig; MaintenanceConfigSP oldMaintenanceConfig; MaintenanceConfigSP newMaintenanceConfig; diff --git a/searchcore/src/vespa/searchcore/proton/server/matchers.cpp b/searchcore/src/vespa/searchcore/proton/server/matchers.cpp index 0586451ec98..969e4b9cbdf 100644 --- a/searchcore/src/vespa/searchcore/proton/server/matchers.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/matchers.cpp @@ -2,23 +2,23 @@ #include "matchers.h" #include -#include -#include +#include +#include #include #include #include namespace proton { -using matching::RankingExpressions; -using matching::OnnxModels; +using search::fef::OnnxModels; +using search::fef::RankingExpressions; using matching::Matcher; using matching::MatchingStats; using namespace vespalib::make_string_short; Matchers::Matchers(const vespalib::Clock &clock, matching::QueryLimiter &queryLimiter, - const matching::RankingAssetsRepo &rankingAssetsRepo) + const search::fef::RankingAssetsRepo &rankingAssetsRepo) : _rpmap(), _ranking_assets_repo(rankingAssetsRepo), _fallback(std::make_shared(search::index::Schema(), search::fef::Properties(), clock, queryLimiter, diff --git a/searchcore/src/vespa/searchcore/proton/server/matchers.h b/searchcore/src/vespa/searchcore/proton/server/matchers.h index 94a84faa7d6..81de92a406a 100644 --- a/searchcore/src/vespa/searchcore/proton/server/matchers.h +++ b/searchcore/src/vespa/searchcore/proton/server/matchers.h @@ -3,7 +3,7 @@ #pragma once #include -#include +#include #include namespace vespalib { class Clock; } @@ -18,15 +18,15 @@ namespace matching { class Matchers { private: using Map = vespalib::hash_map>; - Map _rpmap; - const matching::RankingAssetsRepo _ranking_assets_repo; - std::shared_ptr _fallback; - std::shared_ptr _default; + Map _rpmap; + const search::fef::RankingAssetsRepo _ranking_assets_repo; + std::shared_ptr _fallback; + std::shared_ptr _default; public: using SP = std::shared_ptr; Matchers(const vespalib::Clock &clock, matching::QueryLimiter &queryLimiter, - const matching::RankingAssetsRepo &rankingAssetsRepo); + const search::fef::RankingAssetsRepo &rankingAssetsRepo); Matchers(const Matchers &) = delete; Matchers & operator =(const Matchers &) = delete; ~Matchers(); @@ -34,7 +34,7 @@ public: matching::MatchingStats getStats() const; matching::MatchingStats getStats(const vespalib::string &name) const; std::shared_ptr lookup(const vespalib::string &name) const; - const matching::RankingAssetsRepo& get_ranking_assets_repo() const noexcept { return _ranking_assets_repo; } + const search::fef::RankingAssetsRepo& get_ranking_assets_repo() const noexcept { return _ranking_assets_repo; } }; } // namespace proton diff --git a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp index 8fefa53bba4..d2d7ab1ea84 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.cpp @@ -28,8 +28,6 @@ using vespa::config::search::RankProfilesConfig; namespace proton { using matching::Matcher; -using matching::RankingExpressions; -using matching::OnnxModels; using ARIConfig = AttributeReprocessingInitializer::Config; @@ -117,10 +115,10 @@ SearchableDocSubDBConfigurer::createMatchers(const DocumentDBConfig& new_config_ { auto& schema = new_config_snapshot.getSchemaSP(); auto& cfg = new_config_snapshot.getRankProfilesConfig(); - matching::RankingAssetsRepo ranking_assets_repo_source(_constant_value_factory, - new_config_snapshot.getRankingConstantsSP(), - new_config_snapshot.getRankingExpressionsSP(), - new_config_snapshot.getOnnxModelsSP()); + search::fef::RankingAssetsRepo ranking_assets_repo_source(_constant_value_factory, + new_config_snapshot.getRankingConstantsSP(), + new_config_snapshot.getRankingExpressionsSP(), + new_config_snapshot.getOnnxModelsSP()); auto newMatchers = std::make_shared(_clock, _queryLimiter, ranking_assets_repo_source); auto& ranking_assets_repo = newMatchers->get_ranking_assets_repo(); for (const auto &profile : cfg.rankprofile) { diff --git a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h index 5c57afe6d63..db86321b9f3 100644 --- a/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h +++ b/searchcore/src/vespa/searchcore/proton/server/searchable_doc_subdb_configurer.h @@ -5,16 +5,17 @@ #include #include -namespace searchcorespi { class IndexSearchable; } - -namespace proton::matching { +namespace search::fef { class RankingExpressions; class OnnxModels; -class QueryLimiter; } +namespace searchcorespi { class IndexSearchable; } + +namespace proton::matching { class QueryLimiter; } + namespace vespalib::eval { struct ConstantValueFactory; } namespace vespalib { class Clock; } diff --git a/searchcore/src/vespa/searchcore/proton/test/documentdb_config_builder.cpp b/searchcore/src/vespa/searchcore/proton/test/documentdb_config_builder.cpp index afaf62d043c..93c5b734a35 100644 --- a/searchcore/src/vespa/searchcore/proton/test/documentdb_config_builder.cpp +++ b/searchcore/src/vespa/searchcore/proton/test/documentdb_config_builder.cpp @@ -31,9 +31,9 @@ DocumentDBConfigBuilder::DocumentDBConfigBuilder(int64_t generation, const vespalib::string &docTypeName) : _generation(generation), _rankProfiles(std::make_shared()), - _rankingConstants(std::make_shared()), - _rankingExpressions(std::make_shared()), - _onnxModels(std::make_shared()), + _rankingConstants(std::make_shared()), + _rankingExpressions(std::make_shared()), + _onnxModels(std::make_shared()), _indexschema(std::make_shared()), _attributes(std::make_shared()), _summary(std::make_shared()), diff --git a/searchlib/src/vespa/searchlib/fef/CMakeLists.txt b/searchlib/src/vespa/searchlib/fef/CMakeLists.txt index 398cc0518f8..2ea9349861b 100644 --- a/searchlib/src/vespa/searchlib/fef/CMakeLists.txt +++ b/searchlib/src/vespa/searchlib/fef/CMakeLists.txt @@ -20,6 +20,7 @@ vespa_add_library(searchlib_fef OBJECT matchdatalayout.cpp objectstore.cpp onnx_model.cpp + onnx_models.cpp parameter.cpp parameterdescriptions.cpp parametervalidator.cpp @@ -29,6 +30,9 @@ vespa_add_library(searchlib_fef OBJECT query_value.cpp queryproperties.cpp rank_program.cpp + ranking_assets_repo.cpp + ranking_constants.cpp + ranking_expressions.cpp ranksetup.cpp simpletermdata.cpp simpletermfielddata.cpp diff --git a/searchlib/src/vespa/searchlib/fef/i_ranking_assets_repo.h b/searchlib/src/vespa/searchlib/fef/i_ranking_assets_repo.h new file mode 100644 index 00000000000..e3c1ed0d821 --- /dev/null +++ b/searchlib/src/vespa/searchlib/fef/i_ranking_assets_repo.h @@ -0,0 +1,22 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include + +namespace search::fef { + +class OnnxModel; + +/** + * Interface for retrieving named constants, expressions and models from ranking. + * Empty strings or nullptrs indicates nothing found. + */ +struct IRankingAssetsRepo { + virtual vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &name) const = 0; + virtual vespalib::string getExpression(const vespalib::string &name) const = 0; + virtual const search::fef::OnnxModel *getOnnxModel(const vespalib::string &name) const = 0; + virtual ~IRankingAssetsRepo() = default; +}; + +} diff --git a/searchlib/src/vespa/searchlib/fef/onnx_model.h b/searchlib/src/vespa/searchlib/fef/onnx_model.h index 62d12b8bcd1..345388573de 100644 --- a/searchlib/src/vespa/searchlib/fef/onnx_model.h +++ b/searchlib/src/vespa/searchlib/fef/onnx_model.h @@ -11,7 +11,7 @@ namespace search::fef { /** * Class containing configuration for a single onnx model setup. This * class is used both by the IIndexEnvironment api as well as the - * OnnxModels config adapter in the search core (matching component). + * OnnxModels config adapter. **/ class OnnxModel { private: diff --git a/searchlib/src/vespa/searchlib/fef/onnx_models.cpp b/searchlib/src/vespa/searchlib/fef/onnx_models.cpp new file mode 100644 index 00000000000..15092b604cc --- /dev/null +++ b/searchlib/src/vespa/searchlib/fef/onnx_models.cpp @@ -0,0 +1,49 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "onnx_models.h" +#include + +namespace search::fef { + +OnnxModels::OnnxModels() = default; +OnnxModels::OnnxModels(OnnxModels &&) noexcept = default; +OnnxModels::~OnnxModels() = default; + +OnnxModels::OnnxModels(Vector models) + : _models() +{ + for (auto &model: models) { + _models.emplace(model.name(), std::move(model)); + } +} + +bool +OnnxModels::operator==(const OnnxModels &rhs) const +{ + return (_models == rhs._models); +} + +const OnnxModels::Model * +OnnxModels::getModel(const vespalib::string &name) const +{ + auto itr = _models.find(name); + if (itr != _models.end()) { + return &itr->second; + } + return nullptr; +} + +void +OnnxModels::configure(const ModelConfig &config, Model &model) +{ + assert(config.name == model.name()); + for (const auto &input: config.input) { + model.input_feature(input.name, input.source); + } + for (const auto &output: config.output) { + model.output_name(output.name, output.as); + } + model.dry_run_on_setup(config.dryRunOnSetup); +} + +} diff --git a/searchlib/src/vespa/searchlib/fef/onnx_models.h b/searchlib/src/vespa/searchlib/fef/onnx_models.h new file mode 100644 index 00000000000..c6c4a2b3fe9 --- /dev/null +++ b/searchlib/src/vespa/searchlib/fef/onnx_models.h @@ -0,0 +1,42 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "onnx_model.h" +#include +#include +#include +#include + +namespace search::fef { + +/** + * Class representing a set of configured onnx models, with full path + * for where the models are stored on disk. + */ +class OnnxModels { +public: + using ModelConfig = vespa::config::search::core::OnnxModelsConfig::Model; + using Model = OnnxModel; + using Vector = std::vector; + +private: + using Map = std::map; + Map _models; + +public: + using SP = std::shared_ptr; + OnnxModels(); + OnnxModels(Vector models); + OnnxModels(OnnxModels &&) noexcept; + OnnxModels & operator=(OnnxModels &&) = delete; + OnnxModels(const OnnxModels &) = delete; + OnnxModels & operator =(const OnnxModels &) = delete; + ~OnnxModels(); + bool operator==(const OnnxModels &rhs) const; + [[nodiscard]] const Model *getModel(const vespalib::string &name) const; + [[nodiscard]] size_t size() const { return _models.size(); } + static void configure(const ModelConfig &config, Model &model); +}; + +} diff --git a/searchlib/src/vespa/searchlib/fef/ranking_assets_repo.cpp b/searchlib/src/vespa/searchlib/fef/ranking_assets_repo.cpp new file mode 100644 index 00000000000..6b5629ff91c --- /dev/null +++ b/searchlib/src/vespa/searchlib/fef/ranking_assets_repo.cpp @@ -0,0 +1,43 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "ranking_assets_repo.h" + +using vespalib::eval::ConstantValue; + +namespace search::fef { + +RankingAssetsRepo::RankingAssetsRepo(const ConstantValueFactory &factory, + std::shared_ptr constants, + std::shared_ptr expressions, + std::shared_ptr models) + : _factory(factory), + _constants(std::move(constants)), + _rankingExpressions(std::move(expressions)), + _onnxModels(std::move(models)) +{ +} + +RankingAssetsRepo::~RankingAssetsRepo() = default; + +ConstantValue::UP +RankingAssetsRepo::getConstant(const vespalib::string &name) const +{ + if ( ! _constants) return {}; + const RankingConstants::Constant *constant = _constants->getConstant(name); + if (constant != nullptr) { + return _factory.create(constant->filePath, constant->type); + } + return {}; +} + +vespalib::string +RankingAssetsRepo::getExpression(const vespalib::string &name) const { + return _rankingExpressions ? _rankingExpressions->loadExpression(name) : ""; +} + +const OnnxModel * +RankingAssetsRepo::getOnnxModel(const vespalib::string &name) const { + return _onnxModels ? _onnxModels->getModel(name) : nullptr; +} + +} diff --git a/searchlib/src/vespa/searchlib/fef/ranking_assets_repo.h b/searchlib/src/vespa/searchlib/fef/ranking_assets_repo.h new file mode 100644 index 00000000000..4e613f4bffb --- /dev/null +++ b/searchlib/src/vespa/searchlib/fef/ranking_assets_repo.h @@ -0,0 +1,39 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "i_ranking_assets_repo.h" +#include "ranking_constants.h" +#include "onnx_models.h" +#include "ranking_expressions.h" +#include + +namespace search::fef { + +/** + * Class that provides access to a configured set of rank constant values. + * + * This class maps symbolic names to assets used while setting up rank features blueprints. + * A factory is used to instantiate constant values. + */ +class RankingAssetsRepo : public IRankingAssetsRepo { +private: + using ConstantValueFactory = vespalib::eval::ConstantValueFactory; + + const ConstantValueFactory &_factory; + const std::shared_ptr _constants; + const std::shared_ptr _rankingExpressions; + const std::shared_ptr _onnxModels; + +public: + RankingAssetsRepo(const ConstantValueFactory &factory, + std::shared_ptr constants, + std::shared_ptr expressions, + std::shared_ptr models); + ~RankingAssetsRepo() override; + vespalib::eval::ConstantValue::UP getConstant(const vespalib::string &name) const override; + vespalib::string getExpression(const vespalib::string &name) const override; + const OnnxModel *getOnnxModel(const vespalib::string &name) const override; +}; + +} diff --git a/searchlib/src/vespa/searchlib/fef/ranking_constants.cpp b/searchlib/src/vespa/searchlib/fef/ranking_constants.cpp new file mode 100644 index 00000000000..1d0df1b8d94 --- /dev/null +++ b/searchlib/src/vespa/searchlib/fef/ranking_constants.cpp @@ -0,0 +1,59 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "ranking_constants.h" + +namespace search::fef { + +RankingConstants::Constant::Constant(const vespalib::string &name_in, + const vespalib::string &type_in, + const vespalib::string &filePath_in) + : name(name_in), + type(type_in), + filePath(filePath_in) +{ +} + +RankingConstants::Constant::~Constant() = default; + +bool +RankingConstants::Constant::operator==(const Constant &rhs) const +{ + return (name == rhs.name) && + (type == rhs.type) && + (filePath == rhs.filePath); +} + +RankingConstants::RankingConstants() + : _constants() +{ +} + +RankingConstants::~RankingConstants() = default; +RankingConstants::RankingConstants(RankingConstants &&) noexcept = default; + +RankingConstants::RankingConstants(const Vector &constants) + : _constants() +{ + for (const auto &constant : constants) { + _constants.insert(std::make_pair(constant.name, constant)); + } +} + +bool +RankingConstants::operator==(const RankingConstants &rhs) const +{ + return _constants == rhs._constants; +} + +const RankingConstants::Constant * +RankingConstants::getConstant(const vespalib::string &name) const +{ + auto itr = _constants.find(name); + if (itr != _constants.end()) { + return &itr->second; + } + return nullptr; +} + +} + diff --git a/searchlib/src/vespa/searchlib/fef/ranking_constants.h b/searchlib/src/vespa/searchlib/fef/ranking_constants.h new file mode 100644 index 00000000000..56c124986ba --- /dev/null +++ b/searchlib/src/vespa/searchlib/fef/ranking_constants.h @@ -0,0 +1,49 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include +#include +#include +#include + +namespace search::fef { + +/** + * Class representing a set of configured ranking constants, with name, type and file path (where constant is stored). + */ +class RankingConstants { +public: + struct Constant { + vespalib::string name; + vespalib::string type; + vespalib::string filePath; + + Constant(const vespalib::string &name_in, + const vespalib::string &type_in, + const vespalib::string &filePath_in); + ~Constant(); + bool operator==(const Constant &rhs) const; + }; + + using Vector = std::vector; + +private: + using Map = std::map; + Map _constants; + +public: + using SP = std::shared_ptr; + RankingConstants(); + RankingConstants(RankingConstants &&) noexcept; + RankingConstants & operator =(RankingConstants &&) = delete; + RankingConstants(const RankingConstants &) = delete; + RankingConstants & operator =(const RankingConstants &) = delete; + explicit RankingConstants(const Vector &constants); + ~RankingConstants(); + bool operator==(const RankingConstants &rhs) const; + const Constant *getConstant(const vespalib::string &name) const; + size_t size() const { return _constants.size(); } +}; + +} diff --git a/searchlib/src/vespa/searchlib/fef/ranking_expressions.cpp b/searchlib/src/vespa/searchlib/fef/ranking_expressions.cpp new file mode 100644 index 00000000000..2b293ea7d3f --- /dev/null +++ b/searchlib/src/vespa/searchlib/fef/ranking_expressions.cpp @@ -0,0 +1,65 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "ranking_expressions.h" +#include +#include +#include + +#include +LOG_SETUP(".fef.ranking_expressions"); + +namespace search::fef { + +namespace { + +vespalib::string extract_data(vespalib::Input &input) { + vespalib::string result; + for (auto chunk = input.obtain(); chunk.size > 0; chunk = input.obtain()) { + result.append(vespalib::stringref(chunk.data, chunk.size)); + input.evict(chunk.size); + } + return result; +} + +} // unnamed + +RankingExpressions::RankingExpressions() = default; +RankingExpressions::RankingExpressions(RankingExpressions &&rhs) noexcept = default; +RankingExpressions::~RankingExpressions() = default; + +RankingExpressions & +RankingExpressions::add(const vespalib::string &name, const vespalib::string &path) +{ + _expressions.insert_or_assign(name, path); + return *this; +} + +vespalib::string +RankingExpressions::loadExpression(const vespalib::string &name) const +{ + auto pos = _expressions.find(name); + if (pos == _expressions.end()) { + LOG(warning, "no such ranking expression: '%s'", name.c_str()); + return {}; + } + auto path = pos->second; + vespalib::MappedFileInput file(path); + if (!file.valid()) { + LOG(warning, "rankexpression: %s -> could not read file: %s", name.c_str(), path.c_str()); + return {}; + } + if (ends_with(path, ".lz4")) { + size_t buffer_size = 64_Ki; + vespalib::Lz4InputDecoder lz4_decoder(file, buffer_size); + auto result = extract_data(lz4_decoder); + if (lz4_decoder.failed()) { + LOG(warning, "file contains lz4 errors (%s): %s", + lz4_decoder.reason().c_str(), path.c_str()); + return {}; + } + return result; + } + return extract_data(file); +} + +} diff --git a/searchlib/src/vespa/searchlib/fef/ranking_expressions.h b/searchlib/src/vespa/searchlib/fef/ranking_expressions.h new file mode 100644 index 00000000000..317015938e6 --- /dev/null +++ b/searchlib/src/vespa/searchlib/fef/ranking_expressions.h @@ -0,0 +1,37 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include +#include +#include + +namespace search::fef { + +/** + * Class representing a collection of named ranking expressions + * obtained through file-distribution. + */ +class RankingExpressions +{ +private: + // expression name -> full_path of expression file + std::map _expressions; + +public: + using SP = std::shared_ptr; + RankingExpressions(); + RankingExpressions(RankingExpressions &&rhs) noexcept; + RankingExpressions & operator=(RankingExpressions &&rhs) = delete; + RankingExpressions(const RankingExpressions &rhs) = delete; + RankingExpressions & operator=(const RankingExpressions &rhs) = delete; + ~RankingExpressions(); + bool operator==(const RankingExpressions &rhs) const { + return _expressions == rhs._expressions; + } + size_t size() const { return _expressions.size(); } + RankingExpressions &add(const vespalib::string &name, const vespalib::string &path); + vespalib::string loadExpression(const vespalib::string &name) const; +}; + +} -- cgit v1.2.3