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,37 +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 "IndexLSH_c.h"
|
12
|
-
#include "IndexLSH.h"
|
13
|
-
#include "macros_impl.h"
|
14
|
-
|
15
|
-
using faiss::Index;
|
16
|
-
using faiss::IndexLSH;
|
17
|
-
|
18
|
-
DEFINE_DESTRUCTOR(IndexLSH)
|
19
|
-
DEFINE_INDEX_DOWNCAST(IndexLSH)
|
20
|
-
|
21
|
-
DEFINE_GETTER(IndexLSH, int, nbits)
|
22
|
-
DEFINE_GETTER(IndexLSH, int, bytes_per_vec)
|
23
|
-
DEFINE_GETTER_PERMISSIVE(IndexLSH, int, rotate_data)
|
24
|
-
DEFINE_GETTER_PERMISSIVE(IndexLSH, int, train_thresholds)
|
25
|
-
|
26
|
-
int faiss_IndexLSH_new(FaissIndexLSH** p_index, idx_t d, int nbits) {
|
27
|
-
try {
|
28
|
-
*p_index = reinterpret_cast<FaissIndexLSH*>(new IndexLSH(d, nbits));
|
29
|
-
} CATCH_AND_HANDLE
|
30
|
-
}
|
31
|
-
|
32
|
-
int faiss_IndexLSH_new_with_options(FaissIndexLSH** p_index, idx_t d, int nbits, int rotate_data, int train_thresholds) {
|
33
|
-
try {
|
34
|
-
*p_index = reinterpret_cast<FaissIndexLSH*>(
|
35
|
-
new IndexLSH(d, nbits, static_cast<bool>(rotate_data), static_cast<bool>(train_thresholds)));
|
36
|
-
} CATCH_AND_HANDLE
|
37
|
-
}
|
@@ -1,40 +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 INDEX_LSH_C_H
|
12
|
-
#define INDEX_LSH_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
|
-
/** The sign of each vector component is put in a binary signature */
|
23
|
-
FAISS_DECLARE_CLASS_INHERITED(IndexLSH, Index)
|
24
|
-
FAISS_DECLARE_DESTRUCTOR(IndexLSH)
|
25
|
-
FAISS_DECLARE_INDEX_DOWNCAST(IndexLSH)
|
26
|
-
|
27
|
-
FAISS_DECLARE_GETTER(IndexLSH, int, nbits)
|
28
|
-
FAISS_DECLARE_GETTER(IndexLSH, int, bytes_per_vec)
|
29
|
-
FAISS_DECLARE_GETTER(IndexLSH, int, rotate_data)
|
30
|
-
FAISS_DECLARE_GETTER(IndexLSH, int, train_thresholds)
|
31
|
-
|
32
|
-
int faiss_IndexLSH_new(FaissIndexLSH** p_index, idx_t d, int nbits);
|
33
|
-
|
34
|
-
int faiss_IndexLSH_new_with_options(FaissIndexLSH** p_index, idx_t d, int nbits, int rotate_data, int train_thresholds);
|
35
|
-
|
36
|
-
#ifdef __cplusplus
|
37
|
-
}
|
38
|
-
#endif
|
39
|
-
|
40
|
-
#endif
|
@@ -1,21 +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 "IndexPreTransform_c.h"
|
12
|
-
#include "IndexPreTransform.h"
|
13
|
-
#include "macros_impl.h"
|
14
|
-
|
15
|
-
using faiss::Index;
|
16
|
-
using faiss::IndexPreTransform;
|
17
|
-
|
18
|
-
DEFINE_DESTRUCTOR(IndexPreTransform)
|
19
|
-
DEFINE_INDEX_DOWNCAST(IndexPreTransform)
|
20
|
-
|
21
|
-
DEFINE_GETTER_PERMISSIVE(IndexPreTransform, FaissIndex*, index)
|
@@ -1,32 +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_PRETRANSFORM_C_H
|
12
|
-
#define FAISS_INDEX_PRETRANSFORM_C_H
|
13
|
-
|
14
|
-
#include "faiss_c.h"
|
15
|
-
#include "Index_c.h"
|
16
|
-
|
17
|
-
#ifdef __cplusplus
|
18
|
-
extern "C" {
|
19
|
-
#endif
|
20
|
-
|
21
|
-
FAISS_DECLARE_CLASS(IndexPreTransform)
|
22
|
-
FAISS_DECLARE_DESTRUCTOR(IndexPreTransform)
|
23
|
-
FAISS_DECLARE_INDEX_DOWNCAST(IndexPreTransform)
|
24
|
-
|
25
|
-
FAISS_DECLARE_GETTER(IndexPreTransform, FaissIndex*, index)
|
26
|
-
|
27
|
-
#ifdef __cplusplus
|
28
|
-
}
|
29
|
-
#endif
|
30
|
-
|
31
|
-
|
32
|
-
#endif
|
@@ -1,38 +0,0 @@
|
|
1
|
-
#include "IndexShards_c.h"
|
2
|
-
#include "IndexShards.h"
|
3
|
-
#include "macros_impl.h"
|
4
|
-
|
5
|
-
using faiss::Index;
|
6
|
-
using faiss::IndexShards;
|
7
|
-
|
8
|
-
DEFINE_GETTER(IndexShards, int, own_fields)
|
9
|
-
DEFINE_SETTER(IndexShards, int, own_fields)
|
10
|
-
|
11
|
-
DEFINE_GETTER(IndexShards, int, successive_ids)
|
12
|
-
DEFINE_SETTER(IndexShards, int, successive_ids)
|
13
|
-
|
14
|
-
int faiss_IndexShards_new(FaissIndexShards** p_index, idx_t d) {
|
15
|
-
try {
|
16
|
-
auto out = new IndexShards(d);
|
17
|
-
*p_index = reinterpret_cast<FaissIndexShards*>(out);
|
18
|
-
} CATCH_AND_HANDLE
|
19
|
-
}
|
20
|
-
|
21
|
-
int faiss_IndexShards_new_with_options(FaissIndexShards** p_index, idx_t d, int threaded, int successive_ids) {
|
22
|
-
try {
|
23
|
-
auto out = new IndexShards(d, static_cast<bool>(threaded), static_cast<bool>(successive_ids));
|
24
|
-
*p_index = reinterpret_cast<FaissIndexShards*>(out);
|
25
|
-
} CATCH_AND_HANDLE
|
26
|
-
}
|
27
|
-
|
28
|
-
int faiss_IndexShards_add_shard(FaissIndexShards* index, FaissIndex* shard) {
|
29
|
-
try {
|
30
|
-
reinterpret_cast<IndexShards*>(index)->add_shard(
|
31
|
-
reinterpret_cast<Index*>(shard));
|
32
|
-
} CATCH_AND_HANDLE
|
33
|
-
}
|
34
|
-
|
35
|
-
FaissIndex* faiss_IndexShards_at(FaissIndexShards* index, int i) {
|
36
|
-
auto shard = reinterpret_cast<IndexShards*>(index)->at(i);
|
37
|
-
return reinterpret_cast<FaissIndex*>(shard);
|
38
|
-
}
|
@@ -1,39 +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 INDEXSHARDS_C_H
|
12
|
-
#define INDEXSHARDS_C_H
|
13
|
-
|
14
|
-
#include "faiss_c.h"
|
15
|
-
#include "Index_c.h"
|
16
|
-
|
17
|
-
#ifdef __cplusplus
|
18
|
-
extern "C" {
|
19
|
-
#endif
|
20
|
-
|
21
|
-
/** Index that concatenates the results from several sub-indexes
|
22
|
-
*/
|
23
|
-
FAISS_DECLARE_CLASS_INHERITED(IndexShards, Index)
|
24
|
-
|
25
|
-
FAISS_DECLARE_GETTER_SETTER(IndexShards, int, own_fields)
|
26
|
-
FAISS_DECLARE_GETTER_SETTER(IndexShards, int, successive_ids)
|
27
|
-
|
28
|
-
int faiss_IndexShards_new(FaissIndexShards** p_index, idx_t d);
|
29
|
-
|
30
|
-
int faiss_IndexShards_new_with_options(FaissIndexShards** p_index, idx_t d, int threaded, int successive_ids);
|
31
|
-
|
32
|
-
int faiss_IndexShards_add_shard(FaissIndexShards* index, FaissIndex* shard);
|
33
|
-
|
34
|
-
FaissIndex* faiss_IndexShards_at(FaissIndexShards* index, int i);
|
35
|
-
|
36
|
-
#ifdef __cplusplus
|
37
|
-
}
|
38
|
-
#endif
|
39
|
-
#endif
|
@@ -1,105 +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 "Index.h"
|
13
|
-
#include "macros_impl.h"
|
14
|
-
|
15
|
-
extern "C" {
|
16
|
-
|
17
|
-
DEFINE_DESTRUCTOR(Index)
|
18
|
-
|
19
|
-
DEFINE_GETTER(Index, int, d)
|
20
|
-
|
21
|
-
DEFINE_GETTER(Index, int, is_trained)
|
22
|
-
|
23
|
-
DEFINE_GETTER(Index, idx_t, ntotal)
|
24
|
-
|
25
|
-
DEFINE_GETTER(Index, FaissMetricType, metric_type)
|
26
|
-
|
27
|
-
int faiss_Index_train(FaissIndex* index, idx_t n, const float* x) {
|
28
|
-
try {
|
29
|
-
reinterpret_cast<faiss::Index*>(index)->train(n, x);
|
30
|
-
} CATCH_AND_HANDLE
|
31
|
-
}
|
32
|
-
|
33
|
-
int faiss_Index_add(FaissIndex* index, idx_t n, const float* x) {
|
34
|
-
try {
|
35
|
-
reinterpret_cast<faiss::Index*>(index)->add(n, x);
|
36
|
-
} CATCH_AND_HANDLE
|
37
|
-
}
|
38
|
-
|
39
|
-
int faiss_Index_add_with_ids(FaissIndex* index, idx_t n, const float* x, const idx_t* xids) {
|
40
|
-
try {
|
41
|
-
reinterpret_cast<faiss::Index*>(index)->add_with_ids(n, x, xids);
|
42
|
-
} CATCH_AND_HANDLE
|
43
|
-
}
|
44
|
-
|
45
|
-
int faiss_Index_search(const FaissIndex* index, idx_t n, const float* x, idx_t k,
|
46
|
-
float* distances, idx_t* labels) {
|
47
|
-
try {
|
48
|
-
reinterpret_cast<const faiss::Index*>(index)->search(n, x, k, distances, labels);
|
49
|
-
} CATCH_AND_HANDLE
|
50
|
-
}
|
51
|
-
|
52
|
-
int faiss_Index_range_search(const FaissIndex* index, idx_t n, const float* x, float radius,
|
53
|
-
FaissRangeSearchResult* result) {
|
54
|
-
try {
|
55
|
-
reinterpret_cast<const faiss::Index*>(index)->range_search(
|
56
|
-
n, x, radius, reinterpret_cast<faiss::RangeSearchResult*>(result));
|
57
|
-
} CATCH_AND_HANDLE
|
58
|
-
}
|
59
|
-
|
60
|
-
int faiss_Index_assign(FaissIndex* index, idx_t n, const float * x, idx_t * labels, idx_t k) {
|
61
|
-
try {
|
62
|
-
reinterpret_cast<faiss::Index*>(index)->assign(n, x, labels, k);
|
63
|
-
} CATCH_AND_HANDLE
|
64
|
-
}
|
65
|
-
|
66
|
-
int faiss_Index_reset(FaissIndex* index) {
|
67
|
-
try {
|
68
|
-
reinterpret_cast<faiss::Index*>(index)->reset();
|
69
|
-
} CATCH_AND_HANDLE
|
70
|
-
}
|
71
|
-
|
72
|
-
int faiss_Index_remove_ids(FaissIndex* index, const FaissIDSelector* sel, size_t* n_removed) {
|
73
|
-
try {
|
74
|
-
size_t n {reinterpret_cast<faiss::Index*>(index)->remove_ids(
|
75
|
-
*reinterpret_cast<const faiss::IDSelector*>(sel))};
|
76
|
-
if (n_removed) {
|
77
|
-
*n_removed = n;
|
78
|
-
}
|
79
|
-
} CATCH_AND_HANDLE
|
80
|
-
}
|
81
|
-
|
82
|
-
int faiss_Index_reconstruct(const FaissIndex* index, idx_t key, float* recons) {
|
83
|
-
try {
|
84
|
-
reinterpret_cast<const faiss::Index*>(index)->reconstruct(key, recons);
|
85
|
-
} CATCH_AND_HANDLE
|
86
|
-
}
|
87
|
-
|
88
|
-
int faiss_Index_reconstruct_n (const FaissIndex* index, idx_t i0, idx_t ni, float* recons) {
|
89
|
-
try {
|
90
|
-
reinterpret_cast<const faiss::Index*>(index)->reconstruct_n(i0, ni, recons);
|
91
|
-
} CATCH_AND_HANDLE
|
92
|
-
}
|
93
|
-
|
94
|
-
int faiss_Index_compute_residual(const FaissIndex* index, const float* x, float* residual, idx_t key) {
|
95
|
-
try {
|
96
|
-
reinterpret_cast<const faiss::Index*>(index)->compute_residual(x, residual, key);
|
97
|
-
} CATCH_AND_HANDLE
|
98
|
-
}
|
99
|
-
|
100
|
-
int faiss_Index_compute_residual_n(const FaissIndex* index, idx_t n, const float* x, float* residuals, const idx_t* keys) {
|
101
|
-
try {
|
102
|
-
reinterpret_cast<const faiss::Index *>(index)->compute_residual_n(n, x, residuals, keys);
|
103
|
-
} CATCH_AND_HANDLE
|
104
|
-
}
|
105
|
-
}
|
@@ -1,183 +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_C_H
|
12
|
-
#define FAISS_INDEX_C_H
|
13
|
-
|
14
|
-
#include <stddef.h>
|
15
|
-
#include "faiss_c.h"
|
16
|
-
|
17
|
-
#ifdef __cplusplus
|
18
|
-
extern "C" {
|
19
|
-
#endif
|
20
|
-
|
21
|
-
// forward declaration required here
|
22
|
-
FAISS_DECLARE_CLASS(RangeSearchResult)
|
23
|
-
|
24
|
-
//typedef struct FaissRangeSearchResult_H FaissRangeSearchResult;
|
25
|
-
typedef struct FaissIDSelector_H FaissIDSelector;
|
26
|
-
|
27
|
-
/// Some algorithms support both an inner product version and a L2 search version.
|
28
|
-
typedef enum FaissMetricType {
|
29
|
-
METRIC_INNER_PRODUCT = 0, ///< maximum inner product search
|
30
|
-
METRIC_L2 = 1, ///< squared L2 search
|
31
|
-
METRIC_L1, ///< L1 (aka cityblock)
|
32
|
-
METRIC_Linf, ///< infinity distance
|
33
|
-
METRIC_Lp, ///< L_p distance, p is given by metric_arg
|
34
|
-
|
35
|
-
/// some additional metrics defined in scipy.spatial.distance
|
36
|
-
METRIC_Canberra = 20,
|
37
|
-
METRIC_BrayCurtis,
|
38
|
-
METRIC_JensenShannon,
|
39
|
-
} FaissMetricType;
|
40
|
-
|
41
|
-
/// Opaque type for referencing to an index object
|
42
|
-
FAISS_DECLARE_CLASS(Index)
|
43
|
-
FAISS_DECLARE_DESTRUCTOR(Index)
|
44
|
-
|
45
|
-
/// Getter for d
|
46
|
-
FAISS_DECLARE_GETTER(Index, int, d)
|
47
|
-
|
48
|
-
/// Getter for is_trained
|
49
|
-
FAISS_DECLARE_GETTER(Index, int, is_trained)
|
50
|
-
|
51
|
-
/// Getter for ntotal
|
52
|
-
FAISS_DECLARE_GETTER(Index, idx_t, ntotal)
|
53
|
-
|
54
|
-
/// Getter for metric_type
|
55
|
-
FAISS_DECLARE_GETTER(Index, FaissMetricType, metric_type)
|
56
|
-
|
57
|
-
/** Perform training on a representative set of vectors
|
58
|
-
*
|
59
|
-
* @param index opaque pointer to index object
|
60
|
-
* @param n nb of training vectors
|
61
|
-
* @param x training vecors, size n * d
|
62
|
-
*/
|
63
|
-
int faiss_Index_train(FaissIndex* index, idx_t n, const float* x);
|
64
|
-
|
65
|
-
/** Add n vectors of dimension d to the index.
|
66
|
-
*
|
67
|
-
* Vectors are implicitly assigned labels ntotal .. ntotal + n - 1
|
68
|
-
* This function slices the input vectors in chuncks smaller than
|
69
|
-
* blocksize_add and calls add_core.
|
70
|
-
* @param index opaque pointer to index object
|
71
|
-
* @param x input matrix, size n * d
|
72
|
-
*/
|
73
|
-
int faiss_Index_add(FaissIndex* index, idx_t n, const float* x);
|
74
|
-
|
75
|
-
/** Same as add, but stores xids instead of sequential ids.
|
76
|
-
*
|
77
|
-
* The default implementation fails with an assertion, as it is
|
78
|
-
* not supported by all indexes.
|
79
|
-
*
|
80
|
-
* @param index opaque pointer to index object
|
81
|
-
* @param xids if non-null, ids to store for the vectors (size n)
|
82
|
-
*/
|
83
|
-
int faiss_Index_add_with_ids(FaissIndex* index, idx_t n, const float* x, const idx_t* xids);
|
84
|
-
|
85
|
-
/** query n vectors of dimension d to the index.
|
86
|
-
*
|
87
|
-
* return at most k vectors. If there are not enough results for a
|
88
|
-
* query, the result array is padded with -1s.
|
89
|
-
*
|
90
|
-
* @param index opaque pointer to index object
|
91
|
-
* @param x input vectors to search, size n * d
|
92
|
-
* @param labels output labels of the NNs, size n*k
|
93
|
-
* @param distances output pairwise distances, size n*k
|
94
|
-
*/
|
95
|
-
int faiss_Index_search(const FaissIndex* index, idx_t n, const float* x, idx_t k,
|
96
|
-
float* distances, idx_t* labels);
|
97
|
-
|
98
|
-
/** query n vectors of dimension d to the index.
|
99
|
-
*
|
100
|
-
* return all vectors with distance < radius. Note that many
|
101
|
-
* indexes do not implement the range_search (only the k-NN search
|
102
|
-
* is mandatory).
|
103
|
-
*
|
104
|
-
* @param index opaque pointer to index object
|
105
|
-
* @param x input vectors to search, size n * d
|
106
|
-
* @param radius search radius
|
107
|
-
* @param result result table
|
108
|
-
*/
|
109
|
-
int faiss_Index_range_search(const FaissIndex* index, idx_t n, const float* x,
|
110
|
-
float radius, FaissRangeSearchResult* result);
|
111
|
-
|
112
|
-
/** return the indexes of the k vectors closest to the query x.
|
113
|
-
*
|
114
|
-
* This function is identical as search but only return labels of neighbors.
|
115
|
-
* @param index opaque pointer to index object
|
116
|
-
* @param x input vectors to search, size n * d
|
117
|
-
* @param labels output labels of the NNs, size n*k
|
118
|
-
*/
|
119
|
-
int faiss_Index_assign(FaissIndex* index, idx_t n, const float * x, idx_t * labels, idx_t k);
|
120
|
-
|
121
|
-
/** removes all elements from the database.
|
122
|
-
* @param index opaque pointer to index object
|
123
|
-
*/
|
124
|
-
int faiss_Index_reset(FaissIndex* index);
|
125
|
-
|
126
|
-
/** removes IDs from the index. Not supported by all indexes
|
127
|
-
* @param index opaque pointer to index object
|
128
|
-
* @param nremove output for the number of IDs removed
|
129
|
-
*/
|
130
|
-
int faiss_Index_remove_ids(FaissIndex* index, const FaissIDSelector* sel, size_t* n_removed);
|
131
|
-
|
132
|
-
/** Reconstruct a stored vector (or an approximation if lossy coding)
|
133
|
-
*
|
134
|
-
* this function may not be defined for some indexes
|
135
|
-
* @param index opaque pointer to index object
|
136
|
-
* @param key id of the vector to reconstruct
|
137
|
-
* @param recons reconstucted vector (size d)
|
138
|
-
*/
|
139
|
-
int faiss_Index_reconstruct(const FaissIndex* index, idx_t key, float* recons);
|
140
|
-
|
141
|
-
/** Reconstruct vectors i0 to i0 + ni - 1
|
142
|
-
*
|
143
|
-
* this function may not be defined for some indexes
|
144
|
-
* @param index opaque pointer to index object
|
145
|
-
* @param recons reconstucted vector (size ni * d)
|
146
|
-
*/
|
147
|
-
int faiss_Index_reconstruct_n (const FaissIndex* index, idx_t i0, idx_t ni, float* recons);
|
148
|
-
|
149
|
-
/** Computes a residual vector after indexing encoding.
|
150
|
-
*
|
151
|
-
* The residual vector is the difference between a vector and the
|
152
|
-
* reconstruction that can be decoded from its representation in
|
153
|
-
* the index. The residual can be used for multiple-stage indexing
|
154
|
-
* methods, like IndexIVF's methods.
|
155
|
-
*
|
156
|
-
* @param index opaque pointer to index object
|
157
|
-
* @param x input vector, size d
|
158
|
-
* @param residual output residual vector, size d
|
159
|
-
* @param key encoded index, as returned by search and assign
|
160
|
-
*/
|
161
|
-
int faiss_Index_compute_residual(const FaissIndex* index, const float* x, float* residual, idx_t key);
|
162
|
-
|
163
|
-
/** Computes a residual vector after indexing encoding.
|
164
|
-
*
|
165
|
-
* The residual vector is the difference between a vector and the
|
166
|
-
* reconstruction that can be decoded from its representation in
|
167
|
-
* the index. The residual can be used for multiple-stage indexing
|
168
|
-
* methods, like IndexIVF's methods.
|
169
|
-
*
|
170
|
-
* @param index opaque pointer to index object
|
171
|
-
* @param n number of vectors
|
172
|
-
* @param x input vector, size (n x d)
|
173
|
-
* @param residuals output residual vectors, size (n x d)
|
174
|
-
* @param keys encoded index, as returned by search and assign
|
175
|
-
*/
|
176
|
-
int faiss_Index_compute_residual_n(const FaissIndex* index, idx_t n, const float* x, float* residuals, const idx_t* keys);
|
177
|
-
|
178
|
-
|
179
|
-
#ifdef __cplusplus
|
180
|
-
}
|
181
|
-
#endif
|
182
|
-
|
183
|
-
#endif
|