Debian Codegraph @

c_api/MetaIndexes_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 METAINDEXES_C_H
11 #define METAINDEXES_C_H
12
13 #include "Index_c.h"
14 #include "faiss_c.h"
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 /** Index that translates search results to ids */
21 FAISS_DECLARE_CLASS_INHERITED(IndexIDMap, Index)
22
23 FAISS_DECLARE_GETTER_SETTER(IndexIDMap, int, own_fields)
24
25 int faiss_IndexIDMap_new(FaissIndexIDMap** p_index, FaissIndex* index);
26
27 /** attempt a dynamic cast to a IDMap, thus checking
28 * check whether the underlying index type is `IndexIDMap`.
29 *
30 * @param index opaque pointer to index object
31 * @return the same pointer if the index is a IDMap index, NULL otherwise
32 */
33 FAISS_DECLARE_INDEX_DOWNCAST(IndexIDMap)
34
35 /** get a pointer to the index map's internal ID vector (the `id_map` field).
36 * The outputs of this function become invalid after any operation that can
37 * modify the index.
38 *
39 * @param index opaque pointer to index object
40 * @param p_id_map output, the pointer to the beginning of `id_map`.
41 * @param p_size output, the current length of `id_map`.
42 */
43 void faiss_IndexIDMap_id_map(
44 FaissIndexIDMap* index,
45 idx_t** p_id_map,
46 size_t* p_size);
47
48 /** get a pointer to the sub-index (the `index` field).
49 * The outputs of this function become invalid after any operation that can
50 * modify the index.
51 *
52 * @param index opaque pointer to index object
53 */
54 FaissIndex* faiss_IndexIDMap_sub_index(FaissIndexIDMap* index);
55
56 /** same as IndexIDMap but also provides an efficient reconstruction
57 implementation via a 2-way index */
58 FAISS_DECLARE_CLASS_INHERITED(IndexIDMap2, Index)
59
60 FAISS_DECLARE_GETTER_SETTER(IndexIDMap2, int, own_fields)
61
62 int faiss_IndexIDMap2_new(FaissIndexIDMap2** p_index, FaissIndex* index);
63
64 /// make the rev_map from scratch
65 int faiss_IndexIDMap2_construct_rev_map(FaissIndexIDMap2* index);
66
67 /** attempt a dynamic cast to a IDMap2, thus checking
68 * check whether the underlying index type is `IndexIDMap`.
69 *
70 * @param index opaque pointer to index object
71 * @return the same pointer if the index is a IDMap2 index, NULL otherwise
72 */
73 FAISS_DECLARE_INDEX_DOWNCAST(IndexIDMap2)
74
75 /** get a pointer to the index map's internal ID vector (the `id_map` field).
76 * The outputs of this function become invalid after any operation that can
77 * modify the index.
78 *
79 * @param index opaque pointer to index object
80 * @param p_id_map output, the pointer to the beginning of `id_map`.
81 * @param p_size output, the current length of `id_map`.
82 */
83 void faiss_IndexIDMap2_id_map(
84 FaissIndexIDMap2* index,
85 idx_t** p_id_map,
86 size_t* p_size);
87
88 /** get a pointer to the sub-index (the `index` field).
89 * The outputs of this function become invalid after any operation that can
90 * modify the index.
91 *
92 * @param index opaque pointer to index object
93 */
94 FaissIndex* faiss_IndexIDMap2_sub_index(FaissIndexIDMap2* index);
95
96 #ifdef __cplusplus
97 }
98 #endif
99 #endif