diff options
Diffstat (limited to 'searchlib')
8 files changed, 36 insertions, 30 deletions
diff --git a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp index 72b2f1e320a..b6953ec5dca 100644 --- a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp +++ b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp @@ -1044,8 +1044,13 @@ TEST_F("Nearest neighbor index type is added to attribute file header", DenseTen template <typename ParentT> class NearestNeighborBlueprintFixtureBase : public ParentT { +private: + std::unique_ptr<Value> _query_tensor; + public: - NearestNeighborBlueprintFixtureBase() { + NearestNeighborBlueprintFixtureBase() + : _query_tensor() + { this->set_tensor(1, vec_2d(1, 1)); this->set_tensor(2, vec_2d(2, 2)); this->set_tensor(3, vec_2d(3, 3)); @@ -1058,8 +1063,9 @@ public: this->set_tensor(10, vec_2d(0, 0)); } - std::unique_ptr<Value> createDenseTensor(const TensorSpec &spec) { - return SimpleValue::from_spec(spec); + const Value& create_query_tensor(const TensorSpec& spec) { + _query_tensor = SimpleValue::from_spec(spec); + return *_query_tensor; } std::unique_ptr<NearestNeighborBlueprint> make_blueprint(bool approximate = true, double global_filter_lower_limit = 0.05) { @@ -1067,7 +1073,7 @@ public: auto bp = std::make_unique<NearestNeighborBlueprint>( field, this->as_dense_tensor(), - createDenseTensor(vec_2d(17, 42)), + create_query_tensor(vec_2d(17, 42)), 3, approximate, 5, 100100.25, global_filter_lower_limit, 1.0); diff --git a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp index 4ec6c4f6565..d9db50ae816 100644 --- a/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp +++ b/searchlib/src/vespa/searchlib/attribute/attribute_blueprint_factory.cpp @@ -769,8 +769,8 @@ public: return fail_nearest_neighbor_term(n, make_string("Attribute tensor type (%s) is not a dense tensor of order 1", ta_type.to_spec().c_str())); } - auto query_tensor = getRequestContext().get_query_tensor(n.get_query_tensor_name()); - if (query_tensor.get() == nullptr) { + const auto* query_tensor = getRequestContext().get_query_tensor(n.get_query_tensor_name()); + if (query_tensor == nullptr) { return fail_nearest_neighbor_term(n, "Query tensor was not found in request context"); } const auto & qt_type = query_tensor->type(); @@ -787,7 +787,7 @@ public: ta_type.to_spec().c_str())); } setResult(std::make_unique<queryeval::NearestNeighborBlueprint>(_field, *tensor_attr, - std::move(query_tensor), + *query_tensor, n.get_target_num_hits(), n.get_allow_approximate(), n.get_explore_additional_hits(), diff --git a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h index a492f055cdb..4d7e092a812 100644 --- a/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h +++ b/searchlib/src/vespa/searchlib/queryeval/fake_requestcontext.h @@ -34,15 +34,15 @@ public: ? _attributeContext->getAttribute(name) : nullptr; } - vespalib::eval::Value::UP get_query_tensor(const vespalib::string& tensor_name) const override { + vespalib::eval::Value* get_query_tensor(const vespalib::string& tensor_name) const override { if (_query_tensor && (tensor_name == _query_tensor_name)) { - return vespalib::eval::value_from_spec(*_query_tensor, vespalib::eval::FastValueBuilderFactory::get()); + return _query_tensor.get(); } - return {}; + return nullptr; } void set_query_tensor(const vespalib::string& name, const vespalib::eval::TensorSpec& tensor_spec) { _query_tensor_name = name; - _query_tensor = std::make_unique<vespalib::eval::TensorSpec>(tensor_spec); + _query_tensor = vespalib::eval::value_from_spec(tensor_spec, vespalib::eval::FastValueBuilderFactory::get()); } const search::attribute::AttributeBlueprintParams& get_attribute_blueprint_params() const override; @@ -52,7 +52,7 @@ private: const vespalib::Doom _doom; attribute::IAttributeContext *_attributeContext; vespalib::string _query_tensor_name; - std::unique_ptr<vespalib::eval::TensorSpec> _query_tensor; + std::unique_ptr<vespalib::eval::Value> _query_tensor; search::attribute::AttributeBlueprintParams _attribute_blueprint_params; }; diff --git a/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h b/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h index 376906c8e8f..5aa5db081ab 100644 --- a/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h +++ b/searchlib/src/vespa/searchlib/queryeval/irequestcontext.h @@ -36,7 +36,7 @@ public: * Returns the tensor of the given name that was passed with the query. * Returns nullptr if the tensor is not found or if it is not a tensor. */ - virtual std::unique_ptr<vespalib::eval::Value> get_query_tensor(const vespalib::string& tensor_name) const = 0; + virtual const vespalib::eval::Value* get_query_tensor(const vespalib::string& tensor_name) const = 0; virtual const search::attribute::AttributeBlueprintParams& get_attribute_blueprint_params() const = 0; }; diff --git a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp index 8aa806b01cd..a36a0006c76 100644 --- a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp +++ b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.cpp @@ -35,7 +35,7 @@ to_string(NearestNeighborBlueprint::Algorithm algorithm) NearestNeighborBlueprint::NearestNeighborBlueprint(const queryeval::FieldSpec& field, const tensor::ITensorAttribute& attr_tensor, - std::unique_ptr<Value> query_tensor, + const Value& query_tensor, uint32_t target_hits, bool approximate, uint32_t explore_additional_hits, @@ -44,7 +44,7 @@ NearestNeighborBlueprint::NearestNeighborBlueprint(const queryeval::FieldSpec& f double global_filter_upper_limit) : ComplexLeafBlueprint(field), _attr_tensor(attr_tensor), - _distance_calc(_attr_tensor, std::move(query_tensor)), + _distance_calc(_attr_tensor, query_tensor), _query_tensor(_distance_calc.query_tensor()), _target_hits(target_hits), _adjusted_target_hits(target_hits), diff --git a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.h b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.h index 3be7d7fd01f..9948cce1407 100644 --- a/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.h +++ b/searchlib/src/vespa/searchlib/queryeval/nearest_neighbor_blueprint.h @@ -50,7 +50,7 @@ private: public: NearestNeighborBlueprint(const queryeval::FieldSpec& field, const tensor::ITensorAttribute& attr_tensor, - std::unique_ptr<vespalib::eval::Value> query_tensor, + const vespalib::eval::Value& query_tensor, uint32_t target_hits, bool approximate, uint32_t explore_additional_hits, double distance_threshold, double global_filter_lower_limit, diff --git a/searchlib/src/vespa/searchlib/tensor/distance_calculator.cpp b/searchlib/src/vespa/searchlib/tensor/distance_calculator.cpp index c53d50bc9ff..adfa5b7ee4a 100644 --- a/searchlib/src/vespa/searchlib/tensor/distance_calculator.cpp +++ b/searchlib/src/vespa/searchlib/tensor/distance_calculator.cpp @@ -15,9 +15,9 @@ namespace { template<typename LCT, typename RCT> std::unique_ptr<Value> -convert_cells(const ValueType& new_type, std::unique_ptr<Value> old_value) +convert_cells(const ValueType& new_type, const Value& old_value) { - auto old_cells = old_value->cells().typify<LCT>(); + auto old_cells = old_value.cells().typify<LCT>(); auto builder = FastValueBuilderFactory::get().create_value_builder<RCT>(new_type); auto new_cells = builder->add_subspace(); assert(old_cells.size() == new_cells.size()); @@ -32,13 +32,13 @@ convert_cells(const ValueType& new_type, std::unique_ptr<Value> old_value) struct ConvertCellsSelector { template <typename LCT, typename RCT> - static auto invoke(const ValueType& new_type, std::unique_ptr<Value> old_value) { - return convert_cells<LCT, RCT>(new_type, std::move(old_value)); + static auto invoke(const ValueType& new_type, const Value& old_value) { + return convert_cells<LCT, RCT>(new_type, old_value); } - auto operator() (CellType from, CellType to, std::unique_ptr<Value> old_value) const { + auto operator() (CellType from, CellType to, const Value& old_value) const { using MyTypify = vespalib::eval::TypifyCellType; - ValueType new_type = old_value->type().cell_cast(to); - return vespalib::typify_invoke<2,MyTypify,ConvertCellsSelector>(from, to, new_type, std::move(old_value)); + ValueType new_type = old_value.type().cell_cast(to); + return vespalib::typify_invoke<2,MyTypify,ConvertCellsSelector>(from, to, new_type, old_value); } }; @@ -47,10 +47,10 @@ struct ConvertCellsSelector namespace search::tensor { DistanceCalculator::DistanceCalculator(const tensor::ITensorAttribute& attr_tensor, - std::unique_ptr<vespalib::eval::Value> query_tensor_in) + const vespalib::eval::Value& query_tensor_in) : _attr_tensor(attr_tensor), - _query_tensor_uptr(std::move(query_tensor_in)), - _query_tensor(), + _query_tensor_uptr(), + _query_tensor(&query_tensor_in), _query_tensor_cells(), _dist_fun_uptr(make_distance_function(_attr_tensor.distance_metric(), _attr_tensor.getTensorType().cell_type())), @@ -62,13 +62,13 @@ DistanceCalculator::DistanceCalculator(const tensor::ITensorAttribute& attr_tens _dist_fun = nns_index->distance_function(); assert(_dist_fun); } - auto query_ct = _query_tensor_uptr->cells().type; + auto query_ct = _query_tensor->cells().type; CellType required_ct = _dist_fun->expected_cell_type(); if (query_ct != required_ct) { ConvertCellsSelector converter; - _query_tensor_uptr = converter(query_ct, required_ct, std::move(_query_tensor_uptr)); + _query_tensor_uptr = converter(query_ct, required_ct, *_query_tensor); + _query_tensor = _query_tensor_uptr.get(); } - _query_tensor = _query_tensor_uptr.get(); _query_tensor_cells = _query_tensor->cells(); } diff --git a/searchlib/src/vespa/searchlib/tensor/distance_calculator.h b/searchlib/src/vespa/searchlib/tensor/distance_calculator.h index eeb66887598..f1cc7feb9df 100644 --- a/searchlib/src/vespa/searchlib/tensor/distance_calculator.h +++ b/searchlib/src/vespa/searchlib/tensor/distance_calculator.h @@ -25,7 +25,7 @@ private: public: DistanceCalculator(const tensor::ITensorAttribute& attr_tensor, - std::unique_ptr<vespalib::eval::Value> query_tensor_in); + const vespalib::eval::Value& query_tensor_in); /** * Only used by unit tests where ownership of query tensor and distance function is handled outside. |