Faiss
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
/data/users/hoss/faiss/IndexBinaryHNSW.h
1 /**
2  * Copyright (c) Facebook, Inc. and its affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 // -*- c++ -*-
9 
10 #pragma once
11 
12 #include "HNSW.h"
13 #include "IndexBinaryFlat.h"
14 #include "utils.h"
15 
16 
17 namespace faiss {
18 
19 
20 /** The HNSW index is a normal random-access index with a HNSW
21  * link structure built on top */
22 
24  typedef HNSW::storage_idx_t storage_idx_t;
25 
26  // the link strcuture
27  HNSW hnsw;
28 
29  // the sequential storage
30  bool own_fields;
31  IndexBinary *storage;
32 
33  explicit IndexBinaryHNSW();
34  explicit IndexBinaryHNSW(int d, int M = 32);
35  explicit IndexBinaryHNSW(IndexBinary *storage, int M = 32);
36 
37  ~IndexBinaryHNSW() override;
38 
39  DistanceComputer *get_distance_computer() const;
40 
41  void add(idx_t n, const uint8_t *x) override;
42 
43  /// Trains the storage if needed
44  void train(idx_t n, const uint8_t* x) override;
45 
46  /// entry point for search
47  void search(idx_t n, const uint8_t *x, idx_t k,
48  int32_t *distances, idx_t *labels) const override;
49 
50  void reconstruct(idx_t key, uint8_t* recons) const override;
51 
52  void reset() override;
53 };
54 
55 
56 } // namespace faiss
void add(idx_t n, const uint8_t *x) override
Index::idx_t idx_t
all indices are this type
Definition: IndexBinary.h:37
int d
vector dimension
Definition: IndexBinary.h:41
void reconstruct(idx_t key, uint8_t *recons) const override
void train(idx_t n, const uint8_t *x) override
Trains the storage if needed.
void search(idx_t n, const uint8_t *x, idx_t k, int32_t *distances, idx_t *labels) const override
entry point for search
int storage_idx_t
internal storage of vectors (32 bits: this is expensive)
Definition: HNSW.h:48
void reset() override
Removes all elements from the database.