Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
/data/users/hoss/faiss/IndexLSH.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 #ifndef INDEX_LSH_H
11 #define INDEX_LSH_H
12
13 #include <vector>
14
15 #include "Index.h"
16 #include "VectorTransform.h"
17
18 namespace faiss {
19
20
21 /** The sign of each vector component is put in a binary signature */
22 struct IndexLSH:Index {
23 typedef unsigned char uint8_t;
24
25 int nbits; ///< nb of bits per vector
26 int bytes_per_vec; ///< nb of 8-bits per encoded vector
27 bool rotate_data; ///< whether to apply a random rotation to input
28 bool train_thresholds; ///< whether we train thresholds or use 0
29
30 RandomRotationMatrix rrot; ///< optional random rotation
31
32 std::vector <float> thresholds; ///< thresholds to compare with
33
34 /// encoded dataset
35 std::vector<uint8_t> codes;
36
37 IndexLSH (
38 idx_t d, int nbits,
39 bool rotate_data = true,
40 bool train_thresholds = false);
41
42 /** Preprocesses and resizes the input to the size required to
43 * binarize the data
44 *
45 * @param x input vectors, size n * d
46 * @return output vectors, size n * bits. May be the same pointer
47 * as x, otherwise it should be deleted by the caller
48 */
49 const float *apply_preprocess (idx_t n, const float *x) const;
50
51 void train(idx_t n, const float* x) override;
52
53 void add(idx_t n, const float* x) override;
54
55 void search(
56 idx_t n,
57 const float* x,
58 idx_t k,
59 float* distances,
60 idx_t* labels) const override;
61
62 void reset() override;
63
64 /// transfer the thresholds to a pre-processing stage (and unset
65 /// train_thresholds)
66 void transfer_thresholds (LinearTransform * vt);
67
68 ~IndexLSH() override {}
69
70 IndexLSH ();
71 };
72
73
74 }
75
76
77 #endif
faiss::RandomRotationMatrix
Randomly rotate a set of vectors.
Definition: VectorTransform.h:115
faiss::IndexLSH::bytes_per_vec
int bytes_per_vec
nb of 8-bits per encoded vector
Definition: IndexLSH.h:26
faiss::IndexLSH::thresholds
std::vector< float > thresholds
thresholds to compare with
Definition: IndexLSH.h:32
faiss::IndexLSH
Definition: IndexLSH.h:22
faiss::IndexLSH::train_thresholds
bool train_thresholds
whether we train thresholds or use 0
Definition: IndexLSH.h:28
faiss::IndexLSH::search
void search(idx_t n, const float *x, idx_t k, float *distances, idx_t *labels) const override
Definition: IndexLSH.cpp:128
faiss::Index::d
int d
vector dimension
Definition: Index.h:66
faiss::Index::idx_t
long idx_t
all indices are this type
Definition: Index.h:62
faiss::IndexLSH::rrot
RandomRotationMatrix rrot
optional random rotation
Definition: IndexLSH.h:30
faiss::IndexLSH::transfer_thresholds
void transfer_thresholds(LinearTransform *vt)
Definition: IndexLSH.cpp:160
faiss::LinearTransform
Definition: VectorTransform.h:75
faiss::IndexLSH::reset
void reset() override
removes all elements from the database.
Definition: IndexLSH.cpp:173
faiss::IndexLSH::add
void add(idx_t n, const float *x) override
Definition: IndexLSH.cpp:116
faiss::IndexLSH::train
void train(idx_t n, const float *x) override
Definition: IndexLSH.cpp:85
faiss::IndexLSH::nbits
int nbits
nb of bits per vector
Definition: IndexLSH.h:25
faiss::Index
Definition: Index.h:61
faiss::IndexLSH::apply_preprocess
const float * apply_preprocess(idx_t n, const float *x) const
Definition: IndexLSH.cpp:50
faiss::IndexLSH::rotate_data
bool rotate_data
whether to apply a random rotation to input
Definition: IndexLSH.h:27
faiss::IndexLSH::codes
std::vector< uint8_t > codes
encoded dataset
Definition: IndexLSH.h:35