Debian Codegraph @

c_api/IndexBinaryIVF_c.h

raw
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 FAISS_INDEX_BINARY_IVF_C_H
11 #define FAISS_INDEX_BINARY_IVF_C_H
12
13 #include "IndexBinary_c.h"
14 #include "IndexIVF_c.h"
15 #include "faiss_c.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 /** Index based on a inverted file (IVF)
22 *
23 * In the inverted file, the quantizer (an IndexBinary instance) provides a
24 * quantization index for each vector to be added. The quantization
25 * index maps to a list (aka inverted list or posting list), where the
26 * id of the vector is stored.
27 *
28 * Otherwise the object is similar to the IndexIVF
29 */
30 FAISS_DECLARE_CLASS_INHERITED(IndexBinaryIVF, IndexBinary)
31 FAISS_DECLARE_DESTRUCTOR(IndexBinaryIVF)
32 FAISS_DECLARE_INDEX_BINARY_DOWNCAST(IndexBinaryIVF)
33
34 /// number of possible key values
35 FAISS_DECLARE_GETTER(IndexBinaryIVF, size_t, nlist)
36 /// number of probes at query time
37 FAISS_DECLARE_GETTER_SETTER(IndexBinaryIVF, size_t, nprobe)
38 /// quantizer that maps vectors to inverted lists
39 FAISS_DECLARE_GETTER(IndexBinaryIVF, FaissIndexBinary*, quantizer)
40
41 /// whether object owns the quantizer
42 FAISS_DECLARE_GETTER_SETTER(IndexBinaryIVF, int, own_fields)
43
44 /// max nb of codes to visit to do a query
45 FAISS_DECLARE_GETTER_SETTER(IndexBinaryIVF, size_t, max_codes)
46
47 /** Select between using a heap or counting to select the k smallest values
48 * when scanning inverted lists.
49 */
50 FAISS_DECLARE_GETTER_SETTER(IndexBinaryIVF, int, use_heap)
51
52 /// collect computations per batch
53 FAISS_DECLARE_GETTER_SETTER(IndexBinaryIVF, int, per_invlist_search)
54
55 /** moves the entries from another dataset to self. On output,
56 * other is empty. add_id is added to all moved ids (for
57 * sequential ids, this would be this->ntotal */
58 int faiss_IndexBinaryIVF_merge_from(
59 FaissIndexBinaryIVF* index,
60 FaissIndexBinaryIVF* other,
61 idx_t add_id);
62
63 /** Search a set of vectors, that are pre-quantized by the IVF
64 * quantizer. Fill in the corresponding heaps with the query
65 * results. search() calls this.
66 *
67 * @param n nb of vectors to query
68 * @param x query vectors, size nx * d
69 * @param assign coarse quantization indices, size nx * nprobe
70 * @param centroid_dis
71 * distances to coarse centroids, size nx * nprobe
72 * @param distance
73 * output distances, size n * k
74 * @param labels output labels, size n * k
75 * @param store_pairs store inv list index + inv list offset
76 * instead in upper/lower 32 bit of result,
77 * instead of ids (used for reranking).
78 * @param params used to override the object's search parameters
79 */
80 int faiss_IndexBinaryIVF_search_preassigned(
81 const FaissIndexBinaryIVF* index,
82 idx_t n,
83 const uint8_t* x,
84 idx_t k,
85 const idx_t* cidx,
86 const int32_t* cdis,
87 int32_t* dis,
88 idx_t* idx,
89 int store_pairs,
90 const FaissSearchParametersIVF* params);
91
92 size_t faiss_IndexBinaryIVF_get_list_size(
93 const FaissIndexBinaryIVF* index,
94 size_t list_no);
95
96 /** initialize a direct map
97 *
98 * @param new_maintain_direct_map if true, create a direct map,
99 * else clear it
100 */
101 int faiss_IndexBinaryIVF_make_direct_map(
102 FaissIndexBinaryIVF* index,
103 int new_maintain_direct_map);
104
105 /** Check the inverted lists' imbalance factor.
106 *
107 * 1= perfectly balanced, >1: imbalanced
108 */
109 double faiss_IndexBinaryIVF_imbalance_factor(const FaissIndexBinaryIVF* index);
110
111 /// display some stats about the inverted lists of the index
112 void faiss_IndexBinaryIVF_print_stats(const FaissIndexBinaryIVF* index);
113
114 #ifdef __cplusplus
115 }
116 #endif
117
118 #endif