1 module faiss.index_flat;
2 
3 import faiss.common;
4 import faiss.index;
5 
6 /**
7  * Copyright (c) Facebook, Inc. and its affiliates.
8  *
9  * This source code is licensed under the MIT license found in the
10  * LICENSE file in the root directory of this source tree.
11  */
12 
13 // Copyright 2004-present Facebook. All Rights Reserved
14 // -*- c -*-
15 
16 extern (C):
17 
18 // forward declaration
19 
20 /** Opaque type for IndexFlat */
21 
22 /** get a pointer to the index's internal data (the `xb` field). The outputs
23  * become invalid after any data addition or removal operation.
24  *
25  * @param index   opaque pointer to index object
26  * @param p_xb    output, the pointer to the beginning of `xb`.
27  * @param p_size  output, the current size of `sb` in number of float values.
28  */
29 
30 /** attempt a dynamic cast to a flat index, thus checking
31  * check whether the underlying index type is `IndexFlat`.
32  *
33  * @param index opaque pointer to index object
34  * @return the same pointer if the index is a flat index, NULL otherwise
35  */
36 struct FaissIndex_H;
37 alias FaissIndexFlat = FaissIndex_H;
38 int faiss_IndexFlat_new (FaissIndexFlat** p_index);
39 int faiss_IndexFlat_new_with (
40     FaissIndexFlat** p_index,
41     idx_t d,
42     FaissMetricType metric);
43 void faiss_IndexFlat_xb (FaissIndexFlat* index, float** p_xb, size_t* p_size);
44 FaissIndexFlat* faiss_IndexFlat_cast (FaissIndex*);
45 
46 void faiss_IndexFlat_free (FaissIndexFlat* obj);
47 
48 /** compute distance with a subset of vectors
49  *
50  * @param index   opaque pointer to index object
51  * @param x       query vectors, size n * d
52  * @param labels  indices of the vectors that should be compared
53  *                for each query vector, size n * k
54  * @param distances
55  *                corresponding output distances, size n * k
56  */
57 int faiss_IndexFlat_compute_distance_subset (
58     FaissIndex* index,
59     idx_t n,
60     const(float)* x,
61     idx_t k,
62     float* distances,
63     const(idx_t)* labels);
64 
65 /** Opaque type for IndexFlatIP */
66 alias FaissIndexFlatIP = FaissIndex_H;
67 
68 FaissIndexFlatIP* faiss_IndexFlatIP_cast (FaissIndex*);
69 void faiss_IndexFlatIP_free (FaissIndexFlatIP* obj);
70 
71 int faiss_IndexFlatIP_new (FaissIndexFlatIP** p_index);
72 
73 int faiss_IndexFlatIP_new_with (FaissIndexFlatIP** p_index, idx_t d);
74 
75 /** Opaque type for IndexFlatL2 */
76 alias FaissIndexFlatL2 = FaissIndex_H;
77 
78 FaissIndexFlatL2* faiss_IndexFlatL2_cast (FaissIndex*);
79 void faiss_IndexFlatL2_free (FaissIndexFlatL2* obj);
80 
81 int faiss_IndexFlatL2_new (FaissIndexFlatL2** p_index);
82 
83 int faiss_IndexFlatL2_new_with (FaissIndexFlatL2** p_index, idx_t d);
84 
85 /** Opaque type for IndexRefineFlat
86  *
87  * Index that queries in a base_index (a fast one) and refines the
88  * results with an exact search, hopefully improving the results.
89  */
90 alias FaissIndexRefineFlat = FaissIndex_H;
91 
92 int faiss_IndexRefineFlat_new (
93     FaissIndexRefineFlat** p_index,
94     FaissIndex* base_index);
95 
96 void faiss_IndexRefineFlat_free (FaissIndexRefineFlat* obj);
97 FaissIndexRefineFlat* faiss_IndexRefineFlat_cast (FaissIndex*);
98 
99 int faiss_IndexRefineFlat_own_fields (const(FaissIndexRefineFlat)*);
100 void faiss_IndexRefineFlat_set_own_fields (FaissIndexRefineFlat*, int);
101 
102 /// factor between k requested in search and the k requested from
103 /// the base_index (should be >= 1)
104 float faiss_IndexRefineFlat_k_factor (const(FaissIndexRefineFlat)*);
105 void faiss_IndexRefineFlat_set_k_factor (FaissIndexRefineFlat*, float);
106 
107 /** Opaque type for IndexFlat1D
108  *
109  * optimized version for 1D "vectors"
110  */
111 alias FaissIndexFlat1D = FaissIndex_H;
112 
113 FaissIndexFlat1D* faiss_IndexFlat1D_cast (FaissIndex*);
114 void faiss_IndexFlat1D_free (FaissIndexFlat1D* obj);
115 
116 int faiss_IndexFlat1D_new (FaissIndexFlat1D** p_index);
117 int faiss_IndexFlat1D_new_with (
118     FaissIndexFlat1D** p_index,
119     int continuous_update);
120 
121 int faiss_IndexFlat1D_update_permutation (FaissIndexFlat1D* index);
122