diff options
Diffstat (limited to 'searchlib')
4 files changed, 29 insertions, 2 deletions
diff --git a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp index 8cda62682d0..f4010857c76 100644 --- a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.cpp @@ -76,6 +76,17 @@ DirectTensorAttribute::setTensor(DocId lid, const vespalib::eval::Value &tensor) set_tensor(lid, FastValueBuilderFactory::get().copy(tensor)); } +void +DirectTensorAttribute::update_tensor(DocId docId, + const document::TensorUpdate &update, + const vespalib::eval::Value &old_tensor) +{ + auto new_value = update.apply_to(old_tensor, FastValueBuilderFactory::get()); + if (new_value) { + set_tensor(docId, std::move(new_value)); + } +} + std::unique_ptr<vespalib::eval::Value> DirectTensorAttribute::getTensor(DocId docId) const { diff --git a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h index a49b3c751d9..a87526342ef 100644 --- a/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h +++ b/searchlib/src/vespa/searchlib/tensor/direct_tensor_attribute.h @@ -17,6 +17,9 @@ public: DirectTensorAttribute(vespalib::stringref baseFileName, const Config &cfg); virtual ~DirectTensorAttribute(); virtual void setTensor(DocId docId, const vespalib::eval::Value &tensor) override; + void update_tensor(DocId docId, + const document::TensorUpdate &update, + const vespalib::eval::Value &old_tensor) override; virtual std::unique_ptr<vespalib::eval::Value> getTensor(DocId docId) const override; virtual bool onLoad() override; virtual std::unique_ptr<AttributeSaver> onInitSave(vespalib::stringref fileName) override; diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp index e0b21290284..f5de1de640f 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp +++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.cpp @@ -13,6 +13,7 @@ #include <vespa/eval/eval/value.h> using document::TensorDataType; +using document::TensorUpdate; using document::WrongTensorTypeException; using vespalib::eval::FastValueBuilderFactory; using vespalib::eval::TensorSpec; @@ -250,6 +251,15 @@ TensorAttribute::getRefCopy() const return RefCopyVector(&_refVector[0], &_refVector[0] + size); } +void +TensorAttribute::update_tensor(DocId docId, + const document::TensorUpdate &update, + const vespalib::eval::Value &old_tensor) +{ + auto new_value = update.apply_to(old_tensor, FastValueBuilderFactory::get()); + setTensor(docId, *new_value); +} + std::unique_ptr<PrepareResult> TensorAttribute::prepare_set_tensor(DocId docid, const vespalib::eval::Value& tensor) const { diff --git a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h index 7abfe66a2e4..adb9e7bca8c 100644 --- a/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h +++ b/searchlib/src/vespa/searchlib/tensor/tensor_attribute.h @@ -7,8 +7,9 @@ #include "tensor_store.h" #include <vespa/searchlib/attribute/not_implemented_attribute.h> #include <vespa/vespalib/util/rcuvector.h> +#include <vespa/document/update/tensor_update.h> -namespace vespalib::eval { struct Value; } +namespace vespalib::eval { struct Value; struct ValueBuilderFactory; } namespace search::tensor { @@ -58,7 +59,9 @@ public: uint32_t getVersion() const override; RefCopyVector getRefCopy() const; virtual void setTensor(DocId docId, const vespalib::eval::Value &tensor) = 0; - + virtual void update_tensor(DocId docId, + const document::TensorUpdate &update, + const vespalib::eval::Value &oldTensor); /** * Performs the prepare step in a two-phase operation to set a tensor for a document. * |