blob: 6d94b8c3423193d42bb0042195edf4a53ccd8302 (
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
47
48
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "nearest_neighbor_index_loader.h"
#include "hnsw_index_traits.h"
#include <vespa/vespalib/util/exceptions.h>
#include <cstdint>
#include <memory>
#include <vector>
class FastOS_FileInterface;
namespace search::tensor {
template <HnswIndexType type>
struct HnswGraph;
/**
* Implements loading of HNSW graph structure from binary format.
**/
template <typename ReaderType, HnswIndexType type>
class HnswIndexLoader : public NearestNeighborIndexLoader {
private:
using IdMapping = typename HnswIndexTraits<type>::IdMapping;
HnswGraph<type>& _graph;
std::unique_ptr<ReaderType> _reader;
uint32_t _entry_nodeid;
int32_t _entry_level;
uint32_t _num_nodes;
uint32_t _nodeid;
std::vector<uint32_t> _link_array;
bool _complete;
IdMapping& _id_mapping;
void init();
uint32_t next_int() {
return _reader->readHostOrder();
}
public:
HnswIndexLoader(HnswGraph<type>& graph, IdMapping& id_mapping, std::unique_ptr<ReaderType> reader);
virtual ~HnswIndexLoader();
bool load_next() override;
};
}
|