aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/tensor/tensor_attribute_saver.h
blob: 56a41942f0f1a637b3239a3767c7bd469d954d90 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "tensor_attribute.h"
#include <vespa/searchlib/attribute/attributesaver.h>
#include <vespa/searchlib/attribute/save_utils.h>

namespace search { class BufferWriter; }

namespace search::tensor {

class TensorStore;
class NearestNeighborIndexSaver;

/**
 * Class for saving a tensor attribute.
 * Will also save the nearest neighbor index if existing.
 */
class TensorAttributeSaver : public AttributeSaver {
    using GenerationHandler = vespalib::GenerationHandler;
    using IndexSaverUP = std::unique_ptr<NearestNeighborIndexSaver>;

    attribute::EntryRefVector _refs;
    const TensorStore& _tensor_store;
    IndexSaverUP _index_saver;

    bool onSave(IAttributeSaveTarget &saveTarget) override;
    void save_dense_tensor_store(BufferWriter& writer, const DenseTensorStore& dense_tensor_store) const;
    void save_tensor_store(BufferWriter& writer) const;

public:
    TensorAttributeSaver(GenerationHandler::Guard &&guard,
                         const attribute::AttributeHeader &header,
                         attribute::EntryRefVector&& refs,
                         const TensorStore &tensor_store,
                         IndexSaverUP index_saver);

    ~TensorAttributeSaver() override;

    static vespalib::string index_file_suffix();
};

}