faiss 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/ext/faiss/extconf.rb +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +36 -33
- data/vendor/faiss/faiss/AutoTune.h +6 -3
- data/vendor/faiss/faiss/Clustering.cpp +16 -12
- data/vendor/faiss/faiss/Index.cpp +3 -4
- data/vendor/faiss/faiss/Index.h +3 -3
- data/vendor/faiss/faiss/IndexBinary.cpp +3 -4
- data/vendor/faiss/faiss/IndexBinary.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -12
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +1 -2
- data/vendor/faiss/faiss/IndexFlat.cpp +0 -148
- data/vendor/faiss/faiss/IndexFlat.h +0 -51
- data/vendor/faiss/faiss/IndexHNSW.cpp +4 -5
- data/vendor/faiss/faiss/IndexIVF.cpp +118 -31
- data/vendor/faiss/faiss/IndexIVF.h +22 -15
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +3 -3
- data/vendor/faiss/faiss/IndexIVFFlat.h +2 -1
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +39 -15
- data/vendor/faiss/faiss/IndexIVFPQ.h +25 -9
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1116 -0
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +166 -0
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +8 -9
- data/vendor/faiss/faiss/IndexIVFPQR.h +2 -1
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +1 -2
- data/vendor/faiss/faiss/IndexPQ.cpp +34 -18
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +536 -0
- data/vendor/faiss/faiss/IndexPQFastScan.h +111 -0
- data/vendor/faiss/faiss/IndexPreTransform.cpp +47 -0
- data/vendor/faiss/faiss/IndexPreTransform.h +2 -0
- data/vendor/faiss/faiss/IndexRefine.cpp +256 -0
- data/vendor/faiss/faiss/IndexRefine.h +73 -0
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuDistance.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndex.h +16 -9
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +8 -1
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -11
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +19 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +28 -2
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +24 -14
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +29 -2
- data/vendor/faiss/faiss/gpu/GpuResources.h +4 -0
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +60 -27
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +28 -6
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +547 -0
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +51 -0
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +3 -3
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +3 -2
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +274 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +7 -2
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +5 -1
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +231 -0
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +33 -0
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +1 -0
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +6 -0
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +5 -6
- data/vendor/faiss/faiss/gpu/utils/Timer.h +2 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +5 -4
- data/vendor/faiss/faiss/impl/HNSW.cpp +2 -4
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +4 -4
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +22 -12
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +2 -0
- data/vendor/faiss/faiss/impl/ResultHandler.h +452 -0
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +29 -19
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +6 -0
- data/vendor/faiss/faiss/impl/index_read.cpp +64 -96
- data/vendor/faiss/faiss/impl/index_write.cpp +34 -25
- data/vendor/faiss/faiss/impl/io.cpp +33 -2
- data/vendor/faiss/faiss/impl/io.h +7 -2
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +1 -15
- data/vendor/faiss/faiss/impl/platform_macros.h +44 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +272 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +169 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +180 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +354 -0
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +559 -0
- data/vendor/faiss/faiss/index_factory.cpp +112 -7
- data/vendor/faiss/faiss/index_io.h +1 -48
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +151 -0
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +76 -0
- data/vendor/faiss/faiss/{DirectMap.cpp → invlists/DirectMap.cpp} +1 -1
- data/vendor/faiss/faiss/{DirectMap.h → invlists/DirectMap.h} +1 -1
- data/vendor/faiss/faiss/{InvertedLists.cpp → invlists/InvertedLists.cpp} +72 -1
- data/vendor/faiss/faiss/{InvertedLists.h → invlists/InvertedLists.h} +32 -1
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +107 -0
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +63 -0
- data/vendor/faiss/faiss/{OnDiskInvertedLists.cpp → invlists/OnDiskInvertedLists.cpp} +21 -6
- data/vendor/faiss/faiss/{OnDiskInvertedLists.h → invlists/OnDiskInvertedLists.h} +5 -2
- data/vendor/faiss/faiss/python/python_callbacks.h +8 -1
- data/vendor/faiss/faiss/utils/AlignedTable.h +141 -0
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -4
- data/vendor/faiss/faiss/utils/Heap.h +61 -50
- data/vendor/faiss/faiss/utils/distances.cpp +164 -319
- data/vendor/faiss/faiss/utils/distances.h +28 -20
- data/vendor/faiss/faiss/utils/distances_simd.cpp +277 -49
- data/vendor/faiss/faiss/utils/extra_distances.cpp +1 -2
- data/vendor/faiss/faiss/utils/hamming-inl.h +4 -4
- data/vendor/faiss/faiss/utils/hamming.cpp +3 -6
- data/vendor/faiss/faiss/utils/hamming.h +2 -7
- data/vendor/faiss/faiss/utils/ordered_key_value.h +98 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +1256 -0
- data/vendor/faiss/faiss/utils/partitioning.h +69 -0
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +277 -0
- data/vendor/faiss/faiss/utils/quantize_lut.h +80 -0
- data/vendor/faiss/faiss/utils/simdlib.h +31 -0
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +461 -0
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +589 -0
- metadata +43 -141
- data/vendor/faiss/benchs/bench_6bit_codec.cpp +0 -80
- data/vendor/faiss/c_api/AutoTune_c.cpp +0 -83
- data/vendor/faiss/c_api/AutoTune_c.h +0 -66
- data/vendor/faiss/c_api/Clustering_c.cpp +0 -145
- data/vendor/faiss/c_api/Clustering_c.h +0 -123
- data/vendor/faiss/c_api/IndexFlat_c.cpp +0 -140
- data/vendor/faiss/c_api/IndexFlat_c.h +0 -115
- data/vendor/faiss/c_api/IndexIVFFlat_c.cpp +0 -64
- data/vendor/faiss/c_api/IndexIVFFlat_c.h +0 -58
- data/vendor/faiss/c_api/IndexIVF_c.cpp +0 -99
- data/vendor/faiss/c_api/IndexIVF_c.h +0 -142
- data/vendor/faiss/c_api/IndexLSH_c.cpp +0 -37
- data/vendor/faiss/c_api/IndexLSH_c.h +0 -40
- data/vendor/faiss/c_api/IndexPreTransform_c.cpp +0 -21
- data/vendor/faiss/c_api/IndexPreTransform_c.h +0 -32
- data/vendor/faiss/c_api/IndexShards_c.cpp +0 -38
- data/vendor/faiss/c_api/IndexShards_c.h +0 -39
- data/vendor/faiss/c_api/Index_c.cpp +0 -105
- data/vendor/faiss/c_api/Index_c.h +0 -183
- data/vendor/faiss/c_api/MetaIndexes_c.cpp +0 -49
- data/vendor/faiss/c_api/MetaIndexes_c.h +0 -49
- data/vendor/faiss/c_api/clone_index_c.cpp +0 -23
- data/vendor/faiss/c_api/clone_index_c.h +0 -32
- data/vendor/faiss/c_api/error_c.h +0 -42
- data/vendor/faiss/c_api/error_impl.cpp +0 -27
- data/vendor/faiss/c_api/error_impl.h +0 -16
- data/vendor/faiss/c_api/faiss_c.h +0 -58
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.cpp +0 -98
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.h +0 -56
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.cpp +0 -52
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.h +0 -68
- data/vendor/faiss/c_api/gpu/GpuIndex_c.cpp +0 -17
- data/vendor/faiss/c_api/gpu/GpuIndex_c.h +0 -30
- data/vendor/faiss/c_api/gpu/GpuIndicesOptions_c.h +0 -38
- data/vendor/faiss/c_api/gpu/GpuResources_c.cpp +0 -86
- data/vendor/faiss/c_api/gpu/GpuResources_c.h +0 -66
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.cpp +0 -54
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.h +0 -53
- data/vendor/faiss/c_api/gpu/macros_impl.h +0 -42
- data/vendor/faiss/c_api/impl/AuxIndexStructures_c.cpp +0 -220
- data/vendor/faiss/c_api/impl/AuxIndexStructures_c.h +0 -149
- data/vendor/faiss/c_api/index_factory_c.cpp +0 -26
- data/vendor/faiss/c_api/index_factory_c.h +0 -30
- data/vendor/faiss/c_api/index_io_c.cpp +0 -42
- data/vendor/faiss/c_api/index_io_c.h +0 -50
- data/vendor/faiss/c_api/macros_impl.h +0 -110
- data/vendor/faiss/demos/demo_imi_flat.cpp +0 -154
- data/vendor/faiss/demos/demo_imi_pq.cpp +0 -203
- data/vendor/faiss/demos/demo_ivfpq_indexing.cpp +0 -151
- data/vendor/faiss/demos/demo_sift1M.cpp +0 -252
- data/vendor/faiss/demos/demo_weighted_kmeans.cpp +0 -185
- data/vendor/faiss/misc/test_blas.cpp +0 -87
- data/vendor/faiss/tests/test_binary_flat.cpp +0 -62
- data/vendor/faiss/tests/test_dealloc_invlists.cpp +0 -188
- data/vendor/faiss/tests/test_ivfpq_codec.cpp +0 -70
- data/vendor/faiss/tests/test_ivfpq_indexing.cpp +0 -100
- data/vendor/faiss/tests/test_lowlevel_ivf.cpp +0 -573
- data/vendor/faiss/tests/test_merge.cpp +0 -260
- data/vendor/faiss/tests/test_omp_threads.cpp +0 -14
- data/vendor/faiss/tests/test_ondisk_ivf.cpp +0 -225
- data/vendor/faiss/tests/test_pairs_decoding.cpp +0 -193
- data/vendor/faiss/tests/test_params_override.cpp +0 -236
- data/vendor/faiss/tests/test_pq_encoding.cpp +0 -98
- data/vendor/faiss/tests/test_sliding_ivf.cpp +0 -246
- data/vendor/faiss/tests/test_threaded_index.cpp +0 -253
- data/vendor/faiss/tests/test_transfer_invlists.cpp +0 -159
- data/vendor/faiss/tutorial/cpp/1-Flat.cpp +0 -104
- data/vendor/faiss/tutorial/cpp/2-IVFFlat.cpp +0 -85
- data/vendor/faiss/tutorial/cpp/3-IVFPQ.cpp +0 -98
- data/vendor/faiss/tutorial/cpp/4-GPU.cpp +0 -122
- data/vendor/faiss/tutorial/cpp/5-Multiple-GPUs.cpp +0 -104
@@ -1,115 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
// Copyright 2004-present Facebook. All Rights Reserved
|
9
|
-
// -*- c -*-
|
10
|
-
|
11
|
-
#ifndef FAISS_INDEX_FLAT_C_H
|
12
|
-
#define FAISS_INDEX_FLAT_C_H
|
13
|
-
|
14
|
-
#include "Index_c.h"
|
15
|
-
#include "faiss_c.h"
|
16
|
-
|
17
|
-
#ifdef __cplusplus
|
18
|
-
extern "C" {
|
19
|
-
#endif
|
20
|
-
|
21
|
-
// forward declaration
|
22
|
-
typedef enum FaissMetricType FaissMetricType;
|
23
|
-
|
24
|
-
/** Opaque type for IndexFlat */
|
25
|
-
FAISS_DECLARE_CLASS_INHERITED(IndexFlat, Index)
|
26
|
-
|
27
|
-
int faiss_IndexFlat_new(FaissIndexFlat** p_index);
|
28
|
-
|
29
|
-
int faiss_IndexFlat_new_with(FaissIndexFlat** p_index, idx_t d, FaissMetricType metric);
|
30
|
-
|
31
|
-
/** get a pointer to the index's internal data (the `xb` field). The outputs
|
32
|
-
* become invalid after any data addition or removal operation.
|
33
|
-
*
|
34
|
-
* @param index opaque pointer to index object
|
35
|
-
* @param p_xb output, the pointer to the beginning of `xb`.
|
36
|
-
* @param p_size output, the current size of `sb` in number of float values.
|
37
|
-
*/
|
38
|
-
void faiss_IndexFlat_xb(FaissIndexFlat* index, float** p_xb, size_t* p_size);
|
39
|
-
|
40
|
-
/** attempt a dynamic cast to a flat index, thus checking
|
41
|
-
* check whether the underlying index type is `IndexFlat`.
|
42
|
-
*
|
43
|
-
* @param index opaque pointer to index object
|
44
|
-
* @return the same pointer if the index is a flat index, NULL otherwise
|
45
|
-
*/
|
46
|
-
FAISS_DECLARE_INDEX_DOWNCAST(IndexFlat)
|
47
|
-
|
48
|
-
FAISS_DECLARE_DESTRUCTOR(IndexFlat)
|
49
|
-
|
50
|
-
/** compute distance with a subset of vectors
|
51
|
-
*
|
52
|
-
* @param index opaque pointer to index object
|
53
|
-
* @param x query vectors, size n * d
|
54
|
-
* @param labels indices of the vectors that should be compared
|
55
|
-
* for each query vector, size n * k
|
56
|
-
* @param distances
|
57
|
-
* corresponding output distances, size n * k
|
58
|
-
*/
|
59
|
-
int faiss_IndexFlat_compute_distance_subset(
|
60
|
-
FaissIndex *index,
|
61
|
-
idx_t n,
|
62
|
-
const float *x,
|
63
|
-
idx_t k,
|
64
|
-
float *distances,
|
65
|
-
const idx_t *labels);
|
66
|
-
|
67
|
-
/** Opaque type for IndexFlatIP */
|
68
|
-
FAISS_DECLARE_CLASS_INHERITED(IndexFlatIP, Index)
|
69
|
-
|
70
|
-
int faiss_IndexFlatIP_new(FaissIndexFlatIP** p_index);
|
71
|
-
|
72
|
-
int faiss_IndexFlatIP_new_with(FaissIndexFlatIP** p_index, idx_t d);
|
73
|
-
|
74
|
-
/** Opaque type for IndexFlatL2 */
|
75
|
-
FAISS_DECLARE_CLASS_INHERITED(IndexFlatL2, Index)
|
76
|
-
|
77
|
-
int faiss_IndexFlatL2_new(FaissIndexFlatL2** p_index);
|
78
|
-
|
79
|
-
int faiss_IndexFlatL2_new_with(FaissIndexFlatL2** p_index, idx_t d);
|
80
|
-
|
81
|
-
/** Opaque type for IndexFlatL2BaseShift
|
82
|
-
*
|
83
|
-
* same as an IndexFlatL2 but a value is subtracted from each distance
|
84
|
-
*/
|
85
|
-
FAISS_DECLARE_CLASS_INHERITED(IndexFlatL2BaseShift, Index)
|
86
|
-
|
87
|
-
int faiss_IndexFlatL2BaseShift_new(FaissIndexFlatL2BaseShift** p_index, idx_t d, size_t nshift, const float *shift);
|
88
|
-
|
89
|
-
/** Opaque type for IndexRefineFlat
|
90
|
-
*
|
91
|
-
* Index that queries in a base_index (a fast one) and refines the
|
92
|
-
* results with an exact search, hopefully improving the results.
|
93
|
-
*/
|
94
|
-
FAISS_DECLARE_CLASS_INHERITED(IndexRefineFlat, Index)
|
95
|
-
|
96
|
-
int faiss_IndexRefineFlat_new(FaissIndexRefineFlat** p_index, FaissIndex* base_index);
|
97
|
-
|
98
|
-
FAISS_DECLARE_DESTRUCTOR(IndexRefineFlat)
|
99
|
-
|
100
|
-
/** Opaque type for IndexFlat1D
|
101
|
-
*
|
102
|
-
* optimized version for 1D "vectors"
|
103
|
-
*/
|
104
|
-
FAISS_DECLARE_CLASS_INHERITED(IndexFlat1D, Index)
|
105
|
-
|
106
|
-
int faiss_IndexFlat1D_new(FaissIndexFlat1D** p_index);
|
107
|
-
int faiss_IndexFlat1D_new_with(FaissIndexFlat1D** p_index, int continuous_update);
|
108
|
-
|
109
|
-
int faiss_IndexFlat1D_update_permutation(FaissIndexFlat1D* index);
|
110
|
-
|
111
|
-
#ifdef __cplusplus
|
112
|
-
}
|
113
|
-
#endif
|
114
|
-
|
115
|
-
#endif
|
@@ -1,64 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
// Copyright 2004-present Facebook. All Rights Reserved.
|
9
|
-
// -*- c++ -*-
|
10
|
-
|
11
|
-
#include "Index_c.h"
|
12
|
-
#include "Clustering_c.h"
|
13
|
-
#include "IndexIVFFlat_c.h"
|
14
|
-
#include "IndexIVFFlat.h"
|
15
|
-
#include "macros_impl.h"
|
16
|
-
|
17
|
-
using faiss::Index;
|
18
|
-
using faiss::IndexIVFFlat;
|
19
|
-
using faiss::MetricType;
|
20
|
-
|
21
|
-
DEFINE_DESTRUCTOR(IndexIVFFlat)
|
22
|
-
DEFINE_INDEX_DOWNCAST(IndexIVFFlat)
|
23
|
-
|
24
|
-
int faiss_IndexIVFFlat_new(FaissIndexIVFFlat** p_index) {
|
25
|
-
try {
|
26
|
-
*p_index = reinterpret_cast<FaissIndexIVFFlat*>(new IndexIVFFlat());
|
27
|
-
} CATCH_AND_HANDLE
|
28
|
-
}
|
29
|
-
|
30
|
-
int faiss_IndexIVFFlat_new_with(FaissIndexIVFFlat** p_index,
|
31
|
-
FaissIndex* quantizer, size_t d, size_t nlist)
|
32
|
-
{
|
33
|
-
try {
|
34
|
-
auto q = reinterpret_cast<Index*>(quantizer);
|
35
|
-
*p_index = reinterpret_cast<FaissIndexIVFFlat*>(new IndexIVFFlat(q, d, nlist));
|
36
|
-
} CATCH_AND_HANDLE
|
37
|
-
}
|
38
|
-
|
39
|
-
int faiss_IndexIVFFlat_new_with_metric(
|
40
|
-
FaissIndexIVFFlat** p_index, FaissIndex* quantizer, size_t d, size_t nlist,
|
41
|
-
FaissMetricType metric)
|
42
|
-
{
|
43
|
-
try {
|
44
|
-
auto q = reinterpret_cast<Index*>(quantizer);
|
45
|
-
auto m = static_cast<MetricType>(metric);
|
46
|
-
*p_index = reinterpret_cast<FaissIndexIVFFlat*>(new IndexIVFFlat(q, d, nlist, m));
|
47
|
-
} CATCH_AND_HANDLE
|
48
|
-
}
|
49
|
-
|
50
|
-
int faiss_IndexIVFFlat_add_core(FaissIndexIVFFlat* index, idx_t n,
|
51
|
-
const float * x, const idx_t *xids, const int64_t *precomputed_idx)
|
52
|
-
{
|
53
|
-
try {
|
54
|
-
reinterpret_cast<IndexIVFFlat*>(index)->add_core(n, x, xids, precomputed_idx);
|
55
|
-
} CATCH_AND_HANDLE
|
56
|
-
}
|
57
|
-
|
58
|
-
int faiss_IndexIVFFlat_update_vectors(FaissIndexIVFFlat* index, int nv,
|
59
|
-
idx_t *idx, const float *v)
|
60
|
-
{
|
61
|
-
try {
|
62
|
-
reinterpret_cast<IndexIVFFlat*>(index)->update_vectors(nv, idx, v);
|
63
|
-
} CATCH_AND_HANDLE
|
64
|
-
}
|
@@ -1,58 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
// Copyright 2004-present Facebook. All Rights Reserved.
|
9
|
-
// -*- c -*-
|
10
|
-
|
11
|
-
#ifndef FAISS_INDEX_IVF_FLAT_C_H
|
12
|
-
#define FAISS_INDEX_IVF_FLAT_C_H
|
13
|
-
|
14
|
-
#include "faiss_c.h"
|
15
|
-
#include "Index_c.h"
|
16
|
-
#include "Clustering_c.h"
|
17
|
-
|
18
|
-
#ifdef __cplusplus
|
19
|
-
extern "C" {
|
20
|
-
#endif
|
21
|
-
|
22
|
-
/** Inverted file with stored vectors. Here the inverted file
|
23
|
-
* pre-selects the vectors to be searched, but they are not otherwise
|
24
|
-
* encoded, the code array just contains the raw float entries.
|
25
|
-
*/
|
26
|
-
FAISS_DECLARE_CLASS(IndexIVFFlat)
|
27
|
-
FAISS_DECLARE_DESTRUCTOR(IndexIVFFlat)
|
28
|
-
FAISS_DECLARE_INDEX_DOWNCAST(IndexIVFFlat)
|
29
|
-
|
30
|
-
int faiss_IndexIVFFlat_new(FaissIndexIVFFlat** p_index);
|
31
|
-
|
32
|
-
int faiss_IndexIVFFlat_new_with(FaissIndexIVFFlat** p_index,
|
33
|
-
FaissIndex* quantizer, size_t d, size_t nlist);
|
34
|
-
|
35
|
-
int faiss_IndexIVFFlat_new_with_metric(
|
36
|
-
FaissIndexIVFFlat** p_index, FaissIndex* quantizer, size_t d, size_t nlist,
|
37
|
-
FaissMetricType metric);
|
38
|
-
|
39
|
-
int faiss_IndexIVFFlat_add_core(FaissIndexIVFFlat* index, idx_t n,
|
40
|
-
const float * x, const idx_t *xids, const int64_t *precomputed_idx);
|
41
|
-
|
42
|
-
/** Update a subset of vectors.
|
43
|
-
*
|
44
|
-
* The index must have a direct_map
|
45
|
-
*
|
46
|
-
* @param nv nb of vectors to update
|
47
|
-
* @param idx vector indices to update, size nv
|
48
|
-
* @param v vectors of new values, size nv*d
|
49
|
-
*/
|
50
|
-
int faiss_IndexIVFFlat_update_vectors(FaissIndexIVFFlat* index, int nv,
|
51
|
-
idx_t *idx, const float *v);
|
52
|
-
|
53
|
-
#ifdef __cplusplus
|
54
|
-
}
|
55
|
-
#endif
|
56
|
-
|
57
|
-
|
58
|
-
#endif
|
@@ -1,99 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
// Copyright 2004-present Facebook. All Rights Reserved.
|
9
|
-
// -*- c++ -*-
|
10
|
-
|
11
|
-
#include "Index_c.h"
|
12
|
-
#include "Clustering_c.h"
|
13
|
-
#include "IndexIVF_c.h"
|
14
|
-
#include "IndexIVF.h"
|
15
|
-
#include "macros_impl.h"
|
16
|
-
|
17
|
-
using faiss::IndexIVF;
|
18
|
-
using faiss::IndexIVFStats;
|
19
|
-
|
20
|
-
DEFINE_DESTRUCTOR(IndexIVF)
|
21
|
-
DEFINE_INDEX_DOWNCAST(IndexIVF)
|
22
|
-
|
23
|
-
/// number of possible key values
|
24
|
-
DEFINE_GETTER(IndexIVF, size_t, nlist)
|
25
|
-
/// number of probes at query time
|
26
|
-
DEFINE_GETTER(IndexIVF, size_t, nprobe)
|
27
|
-
/// quantizer that maps vectors to inverted lists
|
28
|
-
DEFINE_GETTER_PERMISSIVE(IndexIVF, FaissIndex*, quantizer)
|
29
|
-
|
30
|
-
/**
|
31
|
-
* = 0: use the quantizer as index in a kmeans training
|
32
|
-
* = 1: just pass on the training set to the train() of the quantizer
|
33
|
-
* = 2: kmeans training on a flat index + add the centroids to the quantizer
|
34
|
-
*/
|
35
|
-
DEFINE_GETTER(IndexIVF, char, quantizer_trains_alone)
|
36
|
-
|
37
|
-
/// whether object owns the quantizer
|
38
|
-
DEFINE_GETTER(IndexIVF, int, own_fields)
|
39
|
-
|
40
|
-
using faiss::IndexIVF;
|
41
|
-
|
42
|
-
int faiss_IndexIVF_merge_from(
|
43
|
-
FaissIndexIVF* index, FaissIndexIVF* other, idx_t add_id) {
|
44
|
-
try {
|
45
|
-
reinterpret_cast<IndexIVF*>(index)->merge_from(
|
46
|
-
*reinterpret_cast<IndexIVF*>(other), add_id);
|
47
|
-
} CATCH_AND_HANDLE
|
48
|
-
}
|
49
|
-
|
50
|
-
int faiss_IndexIVF_copy_subset_to(
|
51
|
-
const FaissIndexIVF* index, FaissIndexIVF* other, int subset_type, idx_t a1,
|
52
|
-
idx_t a2) {
|
53
|
-
try {
|
54
|
-
reinterpret_cast<const IndexIVF*>(index)->copy_subset_to(
|
55
|
-
*reinterpret_cast<IndexIVF*>(other), subset_type, a1, a2);
|
56
|
-
} CATCH_AND_HANDLE
|
57
|
-
}
|
58
|
-
|
59
|
-
int faiss_IndexIVF_search_preassigned (const FaissIndexIVF* index,
|
60
|
-
idx_t n, const float *x, idx_t k, const idx_t *assign,
|
61
|
-
const float *centroid_dis, float *distances, idx_t *labels,
|
62
|
-
int store_pairs) {
|
63
|
-
try {
|
64
|
-
reinterpret_cast<const IndexIVF*>(index)->search_preassigned(
|
65
|
-
n, x, k, assign, centroid_dis, distances, labels, store_pairs);
|
66
|
-
} CATCH_AND_HANDLE
|
67
|
-
}
|
68
|
-
|
69
|
-
size_t faiss_IndexIVF_get_list_size(const FaissIndexIVF* index, size_t list_no) {
|
70
|
-
return reinterpret_cast<const IndexIVF*>(index)->get_list_size(list_no);
|
71
|
-
}
|
72
|
-
|
73
|
-
int faiss_IndexIVF_make_direct_map(FaissIndexIVF* index,
|
74
|
-
int new_maintain_direct_map) {
|
75
|
-
try {
|
76
|
-
reinterpret_cast<IndexIVF*>(index)->make_direct_map(
|
77
|
-
static_cast<bool>(new_maintain_direct_map));
|
78
|
-
} CATCH_AND_HANDLE
|
79
|
-
}
|
80
|
-
|
81
|
-
double faiss_IndexIVF_imbalance_factor (const FaissIndexIVF* index) {
|
82
|
-
return reinterpret_cast<const IndexIVF*>(index)->invlists->imbalance_factor();
|
83
|
-
}
|
84
|
-
|
85
|
-
/// display some stats about the inverted lists
|
86
|
-
void faiss_IndexIVF_print_stats (const FaissIndexIVF* index) {
|
87
|
-
reinterpret_cast<const IndexIVF*>(index)->invlists->print_stats();
|
88
|
-
}
|
89
|
-
|
90
|
-
/// get inverted lists ids
|
91
|
-
void faiss_IndexIVF_invlists_get_ids (const FaissIndexIVF* index, size_t list_no, idx_t* invlist) {
|
92
|
-
const idx_t* list = reinterpret_cast<const IndexIVF*>(index)->invlists->get_ids(list_no);
|
93
|
-
size_t list_size = reinterpret_cast<const IndexIVF*>(index)->get_list_size(list_no);
|
94
|
-
memcpy(invlist, list, list_size*sizeof(idx_t));
|
95
|
-
}
|
96
|
-
|
97
|
-
void faiss_IndexIVFStats_reset(FaissIndexIVFStats* stats) {
|
98
|
-
reinterpret_cast<IndexIVFStats*>(stats)->reset();
|
99
|
-
}
|
@@ -1,142 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its 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
|
-
// Copyright 2004-present Facebook. All Rights Reserved.
|
9
|
-
// -*- c -*-
|
10
|
-
|
11
|
-
#ifndef FAISS_INDEX_IVF_C_H
|
12
|
-
#define FAISS_INDEX_IVF_C_H
|
13
|
-
|
14
|
-
#include "faiss_c.h"
|
15
|
-
#include "Index_c.h"
|
16
|
-
#include "Clustering_c.h"
|
17
|
-
|
18
|
-
#ifdef __cplusplus
|
19
|
-
extern "C" {
|
20
|
-
#endif
|
21
|
-
|
22
|
-
/** Index based on a inverted file (IVF)
|
23
|
-
*
|
24
|
-
* In the inverted file, the quantizer (an Index instance) provides a
|
25
|
-
* quantization index for each vector to be added. The quantization
|
26
|
-
* index maps to a list (aka inverted list or posting list), where the
|
27
|
-
* id of the vector is then stored.
|
28
|
-
*
|
29
|
-
* At search time, the vector to be searched is also quantized, and
|
30
|
-
* only the list corresponding to the quantization index is
|
31
|
-
* searched. This speeds up the search by making it
|
32
|
-
* non-exhaustive. This can be relaxed using multi-probe search: a few
|
33
|
-
* (nprobe) quantization indices are selected and several inverted
|
34
|
-
* lists are visited.
|
35
|
-
*
|
36
|
-
* Sub-classes implement a post-filtering of the index that refines
|
37
|
-
* the distance estimation from the query to databse vectors.
|
38
|
-
*/
|
39
|
-
FAISS_DECLARE_CLASS_INHERITED(IndexIVF, Index)
|
40
|
-
FAISS_DECLARE_DESTRUCTOR(IndexIVF)
|
41
|
-
FAISS_DECLARE_INDEX_DOWNCAST(IndexIVF)
|
42
|
-
|
43
|
-
/// number of possible key values
|
44
|
-
FAISS_DECLARE_GETTER(IndexIVF, size_t, nlist)
|
45
|
-
/// number of probes at query time
|
46
|
-
FAISS_DECLARE_GETTER(IndexIVF, size_t, nprobe)
|
47
|
-
/// quantizer that maps vectors to inverted lists
|
48
|
-
FAISS_DECLARE_GETTER(IndexIVF, FaissIndex*, quantizer)
|
49
|
-
/**
|
50
|
-
* = 0: use the quantizer as index in a kmeans training
|
51
|
-
* = 1: just pass on the training set to the train() of the quantizer
|
52
|
-
* = 2: kmeans training on a flat index + add the centroids to the quantizer
|
53
|
-
*/
|
54
|
-
FAISS_DECLARE_GETTER(IndexIVF, char, quantizer_trains_alone)
|
55
|
-
|
56
|
-
/// whether object owns the quantizer
|
57
|
-
FAISS_DECLARE_GETTER(IndexIVF, int, own_fields)
|
58
|
-
|
59
|
-
/** moves the entries from another dataset to self. On output,
|
60
|
-
* other is empty. add_id is added to all moved ids (for
|
61
|
-
* sequential ids, this would be this->ntotal */
|
62
|
-
int faiss_IndexIVF_merge_from(
|
63
|
-
FaissIndexIVF* index, FaissIndexIVF* other, idx_t add_id);
|
64
|
-
|
65
|
-
/** copy a subset of the entries index to the other index
|
66
|
-
*
|
67
|
-
* if subset_type == 0: copies ids in [a1, a2)
|
68
|
-
* if subset_type == 1: copies ids if id % a1 == a2
|
69
|
-
* if subset_type == 2: copies inverted lists such that a1
|
70
|
-
* elements are left before and a2 elements are after
|
71
|
-
*/
|
72
|
-
int faiss_IndexIVF_copy_subset_to(
|
73
|
-
const FaissIndexIVF* index, FaissIndexIVF* other, int subset_type, idx_t a1,
|
74
|
-
idx_t a2);
|
75
|
-
|
76
|
-
/** search a set of vectors, that are pre-quantized by the IVF
|
77
|
-
* quantizer. Fill in the corresponding heaps with the query
|
78
|
-
* results. search() calls this.
|
79
|
-
*
|
80
|
-
* @param n nb of vectors to query
|
81
|
-
* @param x query vectors, size nx * d
|
82
|
-
* @param assign coarse quantization indices, size nx * nprobe
|
83
|
-
* @param centroid_dis
|
84
|
-
* distances to coarse centroids, size nx * nprobe
|
85
|
-
* @param distance
|
86
|
-
* output distances, size n * k
|
87
|
-
* @param labels output labels, size n * k
|
88
|
-
* @param store_pairs store inv list index + inv list offset
|
89
|
-
* instead in upper/lower 32 bit of result,
|
90
|
-
* instead of ids (used for reranking).
|
91
|
-
*/
|
92
|
-
int faiss_IndexIVF_search_preassigned (const FaissIndexIVF* index,
|
93
|
-
idx_t n, const float *x, idx_t k, const idx_t *assign,
|
94
|
-
const float *centroid_dis, float *distances, idx_t *labels,
|
95
|
-
int store_pairs);
|
96
|
-
|
97
|
-
size_t faiss_IndexIVF_get_list_size(const FaissIndexIVF* index,
|
98
|
-
size_t list_no);
|
99
|
-
|
100
|
-
/** intialize a direct map
|
101
|
-
*
|
102
|
-
* @param new_maintain_direct_map if true, create a direct map,
|
103
|
-
* else clear it
|
104
|
-
*/
|
105
|
-
int faiss_IndexIVF_make_direct_map(FaissIndexIVF* index,
|
106
|
-
int new_maintain_direct_map);
|
107
|
-
|
108
|
-
/** Check the inverted lists' imbalance factor.
|
109
|
-
*
|
110
|
-
* 1= perfectly balanced, >1: imbalanced
|
111
|
-
*/
|
112
|
-
double faiss_IndexIVF_imbalance_factor (const FaissIndexIVF* index);
|
113
|
-
|
114
|
-
/// display some stats about the inverted lists of the index
|
115
|
-
void faiss_IndexIVF_print_stats (const FaissIndexIVF* index);
|
116
|
-
|
117
|
-
/// Get the IDs in an inverted list. IDs are written to `invlist`, which must be large enough
|
118
|
-
//// to accommodate the full list.
|
119
|
-
///
|
120
|
-
/// @param list_no the list ID
|
121
|
-
/// @param invlist output pointer to a slice of memory, at least as long as the list's size
|
122
|
-
/// @see faiss_IndexIVF_get_list_size(size_t)
|
123
|
-
void faiss_IndexIVF_invlists_get_ids (const FaissIndexIVF* index, size_t list_no, idx_t* invlist);
|
124
|
-
|
125
|
-
typedef struct FaissIndexIVFStats {
|
126
|
-
size_t nq; // nb of queries run
|
127
|
-
size_t nlist; // nb of inverted lists scanned
|
128
|
-
size_t ndis; // nb of distancs computed
|
129
|
-
} FaissIndexIVFStats;
|
130
|
-
|
131
|
-
void faiss_IndexIVFStats_reset(FaissIndexIVFStats* stats);
|
132
|
-
|
133
|
-
inline void faiss_IndexIVFStats_init(FaissIndexIVFStats* stats) {
|
134
|
-
faiss_IndexIVFStats_reset(stats);
|
135
|
-
}
|
136
|
-
|
137
|
-
#ifdef __cplusplus
|
138
|
-
}
|
139
|
-
#endif
|
140
|
-
|
141
|
-
|
142
|
-
#endif
|