Debian Codegraph @

c_api/IndexFlat_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_FLAT_C_H
11 #define FAISS_INDEX_FLAT_C_H
12
13 #include "Index_c.h"
14 #include "faiss_c.h"
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 // forward declaration
21 typedef enum FaissMetricType FaissMetricType;
22
23 /** Opaque type for IndexFlat */
24 FAISS_DECLARE_CLASS_INHERITED(IndexFlat, Index)
25
26 int faiss_IndexFlat_new(FaissIndexFlat** p_index);
27
28 int faiss_IndexFlat_new_with(
29 FaissIndexFlat** p_index,
30 idx_t d,
31 FaissMetricType metric);
32
33 /** get a pointer to the index's internal data (the `xb` field). The outputs
34 * become invalid after any data addition or removal operation.
35 *
36 * @param index opaque pointer to index object
37 * @param p_xb output, the pointer to the beginning of `xb`.
38 * @param p_size output, the current size of `xb` in number of float values.
39 */
40 void faiss_IndexFlat_xb(FaissIndexFlat* index, float** p_xb, size_t* p_size);
41
42 /** attempt a dynamic cast to a flat index, thus checking
43 * check whether the underlying index type is `IndexFlat`.
44 *
45 * @param index opaque pointer to index object
46 * @return the same pointer if the index is a flat index, NULL otherwise
47 */
48 FAISS_DECLARE_INDEX_DOWNCAST(IndexFlat)
49
50 FAISS_DECLARE_DESTRUCTOR(IndexFlat)
51
52 /** compute distance with a subset of vectors
53 *
54 * @param index opaque pointer to index object
55 * @param x query vectors, size n * d
56 * @param labels indices of the vectors that should be compared
57 * for each query vector, size n * k
58 * @param distances
59 * corresponding output distances, size n * k
60 */
61 int faiss_IndexFlat_compute_distance_subset(
62 FaissIndex* index,
63 idx_t n,
64 const float* x,
65 idx_t k,
66 float* distances,
67 const idx_t* labels);
68
69 /** Opaque type for IndexFlatIP */
70 FAISS_DECLARE_CLASS_INHERITED(IndexFlatIP, Index)
71
72 FAISS_DECLARE_INDEX_DOWNCAST(IndexFlatIP)
73 FAISS_DECLARE_DESTRUCTOR(IndexFlatIP)
74
75 int faiss_IndexFlatIP_new(FaissIndexFlatIP** p_index);
76
77 int faiss_IndexFlatIP_new_with(FaissIndexFlatIP** p_index, idx_t d);
78
79 /** Opaque type for IndexFlatL2 */
80 FAISS_DECLARE_CLASS_INHERITED(IndexFlatL2, Index)
81
82 FAISS_DECLARE_INDEX_DOWNCAST(IndexFlatL2)
83 FAISS_DECLARE_DESTRUCTOR(IndexFlatL2)
84
85 int faiss_IndexFlatL2_new(FaissIndexFlatL2** p_index);
86
87 int faiss_IndexFlatL2_new_with(FaissIndexFlatL2** p_index, idx_t d);
88
89 /** Opaque type for IndexRefineFlat
90 *
91 * Index that queries in a base_index (a fast one) and refines the
92 * results with an exact search, hopefully improving the results.
93 */
94 FAISS_DECLARE_CLASS_INHERITED(IndexRefineFlat, Index)
95
96 int faiss_IndexRefineFlat_new(
97 FaissIndexRefineFlat** p_index,
98 FaissIndex* base_index);
99
100 FAISS_DECLARE_DESTRUCTOR(IndexRefineFlat)
101 FAISS_DECLARE_INDEX_DOWNCAST(IndexRefineFlat)
102
103 FAISS_DECLARE_GETTER_SETTER(IndexRefineFlat, int, own_fields)
104
105 /// factor between k requested in search and the k requested from
106 /// the base_index (should be >= 1)
107 FAISS_DECLARE_GETTER_SETTER(IndexRefineFlat, float, k_factor)
108
109 /** Opaque type for IndexFlat1D
110 *
111 * optimized version for 1D "vectors"
112 */
113 FAISS_DECLARE_CLASS_INHERITED(IndexFlat1D, Index)
114
115 FAISS_DECLARE_INDEX_DOWNCAST(IndexFlat1D)
116 FAISS_DECLARE_DESTRUCTOR(IndexFlat1D)
117
118 int faiss_IndexFlat1D_new(FaissIndexFlat1D** p_index);
119 int faiss_IndexFlat1D_new_with(
120 FaissIndexFlat1D** p_index,
121 int continuous_update);
122
123 int faiss_IndexFlat1D_update_permutation(FaissIndexFlat1D* index);
124
125 #ifdef __cplusplus
126 }
127 #endif
128
129 #endif