/root/doris/contrib/faiss/faiss/IndexBinaryFlat.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) Meta Platforms, Inc. and 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_BINARY_FLAT_H |
11 | | #define INDEX_BINARY_FLAT_H |
12 | | |
13 | | #include <vector> |
14 | | |
15 | | #include <faiss/IndexBinary.h> |
16 | | |
17 | | #include <faiss/impl/maybe_owned_vector.h> |
18 | | #include <faiss/utils/approx_topk/mode.h> |
19 | | |
20 | | namespace faiss { |
21 | | |
22 | | /** Index that stores the full vectors and performs exhaustive search. */ |
23 | | struct IndexBinaryFlat : IndexBinary { |
24 | | /// database vectors, size ntotal * d / 8 |
25 | | MaybeOwnedVector<uint8_t> xb; |
26 | | |
27 | | /** Select between using a heap or counting to select the k smallest values |
28 | | * when scanning inverted lists. |
29 | | */ |
30 | | bool use_heap = true; |
31 | | |
32 | | size_t query_batch_size = 32; |
33 | | |
34 | | ApproxTopK_mode_t approx_topk_mode = ApproxTopK_mode_t::EXACT_TOPK; |
35 | | |
36 | | explicit IndexBinaryFlat(idx_t d); |
37 | | |
38 | | void add(idx_t n, const uint8_t* x) override; |
39 | | |
40 | | void reset() override; |
41 | | |
42 | | void search( |
43 | | idx_t n, |
44 | | const uint8_t* x, |
45 | | idx_t k, |
46 | | int32_t* distances, |
47 | | idx_t* labels, |
48 | | const SearchParameters* params = nullptr) const override; |
49 | | |
50 | | void range_search( |
51 | | idx_t n, |
52 | | const uint8_t* x, |
53 | | int radius, |
54 | | RangeSearchResult* result, |
55 | | const SearchParameters* params = nullptr) const override; |
56 | | |
57 | | void reconstruct(idx_t key, uint8_t* recons) const override; |
58 | | |
59 | | /** Remove some ids. Note that because of the indexing structure, |
60 | | * the semantics of this operation are different from the usual ones: |
61 | | * the new ids are shifted. */ |
62 | | size_t remove_ids(const IDSelector& sel) override; |
63 | | |
64 | 0 | IndexBinaryFlat() {} |
65 | | }; |
66 | | |
67 | | } // namespace faiss |
68 | | |
69 | | #endif // INDEX_BINARY_FLAT_H |