1 module faiss.index_ivf_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 /** Inverted file with stored vectors. Here the inverted file
19  * pre-selects the vectors to be searched, but they are not otherwise
20  * encoded, the code array just contains the raw float entries.
21  */
22 
23 /// number of possible key values
24 
25 /// number of probes at query time
26 
27 /// quantizer that maps vectors to inverted lists
28 
29 /**
30  * = 0: use the quantizer as index in a kmeans training
31  * = 1: just pass on the training set to the train() of the quantizer
32  * = 2: kmeans training on a flat index + add the centroids to the quantizer
33  */
34 
35 struct FaissIndex_H;
36 alias FaissIndexIVFFlat = FaissIndex_H;
37 void faiss_IndexIVFFlat_free (FaissIndexIVFFlat* obj);
38 FaissIndexIVFFlat* faiss_IndexIVFFlat_cast (FaissIndex*);
39 size_t faiss_IndexIVFFlat_nlist (const(FaissIndexIVFFlat)*);
40 size_t faiss_IndexIVFFlat_nprobe (const(FaissIndexIVFFlat)*);
41 void faiss_IndexIVFFlat_set_nprobe (FaissIndexIVFFlat*, size_t);
42 FaissIndex* faiss_IndexIVFFlat_quantizer (const(FaissIndexIVFFlat)*);
43 char faiss_IndexIVFFlat_quantizer_trains_alone (const(FaissIndexIVFFlat)*); /// whether object owns the quantizer
44 int faiss_IndexIVFFlat_own_fields (const(FaissIndexIVFFlat)*);
45 void faiss_IndexIVFFlat_set_own_fields (FaissIndexIVFFlat*, int);
46 
47 int faiss_IndexIVFFlat_new (FaissIndexIVFFlat** p_index);
48 
49 int faiss_IndexIVFFlat_new_with (
50     FaissIndexIVFFlat** p_index,
51     FaissIndex* quantizer,
52     size_t d,
53     size_t nlist);
54 
55 int faiss_IndexIVFFlat_new_with_metric (
56     FaissIndexIVFFlat** p_index,
57     FaissIndex* quantizer,
58     size_t d,
59     size_t nlist,
60     FaissMetricType metric);
61 
62 int faiss_IndexIVFFlat_add_core (
63     FaissIndexIVFFlat* index,
64     idx_t n,
65     const(float)* x,
66     const(idx_t)* xids,
67     const(long)* precomputed_idx);
68 
69 /** Update a subset of vectors.
70  *
71  * The index must have a direct_map
72  *
73  * @param nv     nb of vectors to update
74  * @param idx    vector indices to update, size nv
75  * @param v      vectors of new values, size nv*d
76  */
77 int faiss_IndexIVFFlat_update_vectors (
78     FaissIndexIVFFlat* index,
79     int nv,
80     idx_t* idx,
81     const(float)* v);
82