1 module faiss.meta_indexes;
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 /** Index that translates search results to ids */
19 
20 /** attempt a dynamic cast to a IDMap, thus checking
21  * check whether the underlying index type is `IndexIDMap`.
22  *
23  * @param index opaque pointer to index object
24  * @return the same pointer if the index is a IDMap index, NULL otherwise
25  */
26 
27 /** get a pointer to the index map's internal ID vector (the `id_map` field).
28  * The outputs of this function become invalid after any operation that can
29  * modify the index.
30  *
31  * @param index   opaque pointer to index object
32  * @param p_id_map    output, the pointer to the beginning of `id_map`.
33  * @param p_size  output, the current length of `id_map`.
34  */
35 struct FaissIndex_H;
36 alias FaissIndexIDMap = FaissIndex_H;
37 int faiss_IndexIDMap_own_fields (const(FaissIndexIDMap)*);
38 void faiss_IndexIDMap_set_own_fields (FaissIndexIDMap*, int);
39 int faiss_IndexIDMap_new (FaissIndexIDMap** p_index, FaissIndex* index);
40 FaissIndexIDMap* faiss_IndexIDMap_cast (FaissIndex*);
41 void faiss_IndexIDMap_id_map (
42     FaissIndexIDMap* index,
43     idx_t** p_id_map,
44     size_t* p_size);
45 
46 /** get a pointer to the sub-index (the `index` field).
47  * The outputs of this function become invalid after any operation that can
48  * modify the index.
49  *
50  * @param index   opaque pointer to index object
51  */
52 FaissIndex* faiss_IndexIDMap_sub_index (FaissIndexIDMap* index);
53 
54 /** same as IndexIDMap but also provides an efficient reconstruction
55     implementation via a 2-way index */
56 alias FaissIndexIDMap2 = FaissIndex_H;
57 
58 int faiss_IndexIDMap2_own_fields (const(FaissIndexIDMap2)*);
59 void faiss_IndexIDMap2_set_own_fields (FaissIndexIDMap2*, int);
60 
61 int faiss_IndexIDMap2_new (FaissIndexIDMap2** p_index, FaissIndex* index);
62 
63 /// make the rev_map from scratch
64 int faiss_IndexIDMap2_construct_rev_map (FaissIndexIDMap2* index);
65 
66 /** attempt a dynamic cast to a IDMap2, thus checking
67  * check whether the underlying index type is `IndexIDMap`.
68  *
69  * @param index opaque pointer to index object
70  * @return the same pointer if the index is a IDMap2 index, NULL otherwise
71  */
72 FaissIndexIDMap2* faiss_IndexIDMap2_cast (FaissIndex*);
73 
74 /** get a pointer to the index map's internal ID vector (the `id_map` field).
75  * The outputs of this function become invalid after any operation that can
76  * modify the index.
77  *
78  * @param index   opaque pointer to index object
79  * @param p_id_map    output, the pointer to the beginning of `id_map`.
80  * @param p_size  output, the current length of `id_map`.
81  */
82 void faiss_IndexIDMap2_id_map (
83     FaissIndexIDMap2* index,
84     idx_t** p_id_map,
85     size_t* p_size);
86 
87 /** get a pointer to the sub-index (the `index` field).
88  * The outputs of this function become invalid after any operation that can
89  * modify the index.
90  *
91  * @param index   opaque pointer to index object
92  */
93 FaissIndex* faiss_IndexIDMap2_sub_index (FaissIndexIDMap2* index);
94