summaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/tensor/imported_tensor_attribute_vector_read_guard.h
blob: d0f09da928129a664c0a40dccd3333e44522eedd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/searchlib/attribute/imported_attribute_vector_read_guard.h>
#include "i_tensor_attribute.h"

namespace search::attribute {
class ImportedAttributeVector;
}

namespace search::tensor {

/**
 * Short lived attribute vector for imported tensor attributes.
 *
 * Extra information for direct lid to target lid mapping with
 * boundary check is setup during construction.
 */
class ImportedTensorAttributeVectorReadGuard : public attribute::ImportedAttributeVectorReadGuard,
                                               public ITensorAttribute
{
    using ReferenceAttribute = attribute::ReferenceAttribute;
    using BitVectorSearchCache = attribute::BitVectorSearchCache;
    const ITensorAttribute &_target_tensor_attribute;
public:
    ImportedTensorAttributeVectorReadGuard(const attribute::ImportedAttributeVector &imported_attribute,
                                           bool stableEnumGuard);
    ~ImportedTensorAttributeVectorReadGuard();

    const ITensorAttribute *asTensorAttribute() const override;

    std::unique_ptr<vespalib::eval::Value> getTensor(uint32_t docId) const override;
    std::unique_ptr<vespalib::eval::Value> getEmptyTensor() const override;
    vespalib::eval::TypedCells extract_cells_ref(uint32_t docid) const override;
    const vespalib::eval::Value& get_tensor_ref(uint32_t docid) const override;
    bool supports_extract_cells_ref() const override { return _target_tensor_attribute.supports_extract_cells_ref(); }
    bool supports_get_tensor_ref() const override { return _target_tensor_attribute.supports_get_tensor_ref(); }
    DistanceMetric distance_metric() const override { return _target_tensor_attribute.distance_metric(); }
    uint32_t get_num_docs() const override { return getNumDocs(); }

    const vespalib::eval::ValueType &getTensorType() const override;
    void get_state(const vespalib::slime::Inserter& inserter) const override;
};

}