Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
IndexFlat_c.h
1 /**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD+Patents license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9 // Copyright 2004-present Facebook. All Rights Reserved
10 // -*- c -*-
11
12 #ifndef FAISS_INDEX_FLAT_C_H
13 #define FAISS_INDEX_FLAT_C_H
14
15 #include "Index_c.h"
16 #include "faiss_c.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 // forward declaration
23 typedef enum FaissMetricType FaissMetricType;
24
25 /** Opaque type for IndexFlat */
26 FAISS_DECLARE_CLASS_INHERITED(IndexFlat, Index)
27
28 int faiss_IndexFlat_new(FaissIndexFlat** p_index);
29
30 int faiss_IndexFlat_new_with(FaissIndexFlat** p_index, idx_t d, FaissMetricType metric);
31
32 /** get a pointer to the index's internal data (the `xb` field). The outputs
33 * become invalid after any data addition or removal operation.
34 *
35 * @param index opaque pointer to index object
36 * @param p_xb output, the pointer to the beginning of `xb`.
37 * @param p_size output, the current size of `sb` in number of float values.
38 */
39 void faiss_IndexFlat_xb(FaissIndexFlat* index, float** p_xb, size_t* p_size);
40
41 /** attempt a dynamic cast to a flat index, thus checking
42 * check whether the underlying index type is `IndexFlat`.
43 *
44 * @param index opaque pointer to index object
45 * @return the same pointer if the index is a flat index, NULL otherwise
46 */
47 FAISS_DECLARE_INDEX_DOWNCAST(IndexFlat)
48
49 FAISS_DECLARE_DESTRUCTOR(IndexFlat)
50
51 /** compute distance with a subset of vectors
52 *
53 * @param index opaque pointer to index object
54 * @param x query vectors, size n * d
55 * @param labels indices of the vectors that should be compared
56 * for each query vector, size n * k
57 * @param distances
58 * corresponding output distances, size n * k
59 */
60 int faiss_IndexFlat_compute_distance_subset(
61 FaissIndex *index,
62 idx_t n,
63 const float *x,
64 idx_t k,
65 float *distances,
66 const idx_t *labels);
67
68 /** Opaque type for IndexFlatIP */
69 FAISS_DECLARE_CLASS_INHERITED(IndexFlatIP, Index)
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 FAISS_DECLARE_CLASS_INHERITED(IndexFlatL2, Index)
77
78 int faiss_IndexFlatL2_new(FaissIndexFlatL2** p_index);
79
80 int faiss_IndexFlatL2_new_with(FaissIndexFlatL2** p_index, idx_t d);
81
82 /** Opaque type for IndexFlatL2BaseShift
83 *
84 * same as an IndexFlatL2 but a value is subtracted from each distance
85 */
86 FAISS_DECLARE_CLASS_INHERITED(IndexFlatL2BaseShift, Index)
87
88 int faiss_IndexFlatL2BaseShift_new(FaissIndexFlatL2BaseShift** p_index, idx_t d, size_t nshift, const float *shift);
89
90 /** Opaque type for IndexRefineFlat
91 *
92 * Index that queries in a base_index (a fast one) and refines the
93 * results with an exact search, hopefully improving the results.
94 */
95 FAISS_DECLARE_CLASS_INHERITED(IndexRefineFlat, Index)
96
97 int faiss_IndexRefineFlat_new(FaissIndexRefineFlat** p_index, FaissIndex* base_index);
98
99 FAISS_DECLARE_DESTRUCTOR(IndexRefineFlat)
100
101 /** Opaque type for IndexFlat1D
102 *
103 * optimized version for 1D "vectors"
104 */
105 FAISS_DECLARE_CLASS_INHERITED(IndexFlat1D, Index)
106
107 int faiss_IndexFlat1D_new(FaissIndexFlat1D** p_index);
108 int faiss_IndexFlat1D_new_with(FaissIndexFlat1D** p_index, int continuous_update);
109
110 int faiss_IndexFlat1D_update_permutation(FaissIndexFlat1D* index);
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif