aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/tensor/dense_tensor_attribute.cpp
blob: fb74dd51fa3245169d814dc22b16e894b13ae1e2 (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 Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "dense_tensor_attribute.h"
#include <vespa/searchcommon/attribute/config.h>

namespace search::tensor {

DenseTensorAttribute::DenseTensorAttribute(vespalib::stringref baseFileName, const Config& cfg,
                                           const NearestNeighborIndexFactory& index_factory)
    : TensorAttribute(baseFileName, cfg, _denseTensorStore, index_factory),
      _denseTensorStore(cfg.tensorType(), get_memory_allocator())
{
}


DenseTensorAttribute::~DenseTensorAttribute()
{
    getGenerationHolder().reclaim_all();
    _tensorStore.reclaim_all_memory();
}

vespalib::eval::TypedCells
DenseTensorAttribute::extract_cells_ref(DocId docId) const
{
    EntryRef ref;
    if (docId < getCommittedDocIdLimit()) {
        ref = acquire_entry_ref(docId);
    }
    return _denseTensorStore.get_typed_cells(ref);
}

vespalib::eval::TypedCells
DenseTensorAttribute::get_vector(uint32_t docid, uint32_t subspace) const
{
    EntryRef ref = (subspace == 0) ? acquire_entry_ref(docid) : EntryRef();
    return _denseTensorStore.get_typed_cells(ref);
}

VectorBundle
DenseTensorAttribute::get_vectors(uint32_t docid) const
{
    EntryRef ref = acquire_entry_ref(docid);
    return _denseTensorStore.get_vectors(ref);
}

}