faiss 0.1.5 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +12 -0
- data/ext/faiss/ext.cpp +1 -1
- data/ext/faiss/extconf.rb +6 -2
- data/ext/faiss/index.cpp +114 -43
- data/ext/faiss/index_binary.cpp +24 -30
- data/ext/faiss/kmeans.cpp +20 -16
- data/ext/faiss/numo.hpp +867 -0
- data/ext/faiss/pca_matrix.cpp +13 -14
- data/ext/faiss/product_quantizer.cpp +23 -24
- data/ext/faiss/utils.cpp +10 -37
- data/ext/faiss/utils.h +2 -13
- data/lib/faiss.rb +0 -5
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +292 -291
- data/vendor/faiss/faiss/AutoTune.h +55 -56
- data/vendor/faiss/faiss/Clustering.cpp +334 -195
- data/vendor/faiss/faiss/Clustering.h +88 -35
- data/vendor/faiss/faiss/IVFlib.cpp +171 -195
- data/vendor/faiss/faiss/IVFlib.h +48 -51
- data/vendor/faiss/faiss/Index.cpp +85 -103
- data/vendor/faiss/faiss/Index.h +54 -48
- data/vendor/faiss/faiss/Index2Layer.cpp +139 -164
- data/vendor/faiss/faiss/Index2Layer.h +22 -22
- data/vendor/faiss/faiss/IndexBinary.cpp +45 -37
- data/vendor/faiss/faiss/IndexBinary.h +140 -132
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +73 -53
- data/vendor/faiss/faiss/IndexBinaryFlat.h +29 -24
- data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +46 -43
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +16 -15
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +215 -232
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +25 -24
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +182 -177
- data/vendor/faiss/faiss/IndexBinaryHash.h +41 -34
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +489 -461
- data/vendor/faiss/faiss/IndexBinaryIVF.h +97 -68
- data/vendor/faiss/faiss/IndexFlat.cpp +116 -147
- data/vendor/faiss/faiss/IndexFlat.h +35 -46
- data/vendor/faiss/faiss/IndexHNSW.cpp +372 -348
- data/vendor/faiss/faiss/IndexHNSW.h +57 -41
- data/vendor/faiss/faiss/IndexIVF.cpp +474 -454
- data/vendor/faiss/faiss/IndexIVF.h +146 -113
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +248 -250
- data/vendor/faiss/faiss/IndexIVFFlat.h +48 -51
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +457 -516
- data/vendor/faiss/faiss/IndexIVFPQ.h +74 -66
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +406 -372
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +82 -57
- data/vendor/faiss/faiss/IndexIVFPQR.cpp +104 -102
- data/vendor/faiss/faiss/IndexIVFPQR.h +33 -28
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +125 -133
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +19 -21
- data/vendor/faiss/faiss/IndexLSH.cpp +75 -96
- data/vendor/faiss/faiss/IndexLSH.h +21 -26
- data/vendor/faiss/faiss/IndexLattice.cpp +42 -56
- data/vendor/faiss/faiss/IndexLattice.h +11 -16
- data/vendor/faiss/faiss/IndexNNDescent.cpp +231 -0
- data/vendor/faiss/faiss/IndexNNDescent.h +72 -0
- data/vendor/faiss/faiss/IndexNSG.cpp +303 -0
- data/vendor/faiss/faiss/IndexNSG.h +85 -0
- data/vendor/faiss/faiss/IndexPQ.cpp +405 -464
- data/vendor/faiss/faiss/IndexPQ.h +64 -67
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +143 -170
- data/vendor/faiss/faiss/IndexPQFastScan.h +46 -32
- data/vendor/faiss/faiss/IndexPreTransform.cpp +120 -150
- data/vendor/faiss/faiss/IndexPreTransform.h +33 -36
- data/vendor/faiss/faiss/IndexRefine.cpp +115 -131
- data/vendor/faiss/faiss/IndexRefine.h +22 -23
- data/vendor/faiss/faiss/IndexReplicas.cpp +147 -153
- data/vendor/faiss/faiss/IndexReplicas.h +62 -56
- data/vendor/faiss/faiss/IndexResidual.cpp +291 -0
- data/vendor/faiss/faiss/IndexResidual.h +152 -0
- data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +120 -155
- data/vendor/faiss/faiss/IndexScalarQuantizer.h +41 -45
- data/vendor/faiss/faiss/IndexShards.cpp +256 -240
- data/vendor/faiss/faiss/IndexShards.h +85 -73
- data/vendor/faiss/faiss/MatrixStats.cpp +112 -97
- data/vendor/faiss/faiss/MatrixStats.h +7 -10
- data/vendor/faiss/faiss/MetaIndexes.cpp +135 -157
- data/vendor/faiss/faiss/MetaIndexes.h +40 -34
- data/vendor/faiss/faiss/MetricType.h +7 -7
- data/vendor/faiss/faiss/VectorTransform.cpp +652 -474
- data/vendor/faiss/faiss/VectorTransform.h +61 -89
- data/vendor/faiss/faiss/clone_index.cpp +77 -73
- data/vendor/faiss/faiss/clone_index.h +4 -9
- data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +33 -38
- data/vendor/faiss/faiss/gpu/GpuAutoTune.h +11 -9
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +197 -170
- data/vendor/faiss/faiss/gpu/GpuCloner.h +53 -35
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.cpp +12 -14
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +27 -25
- data/vendor/faiss/faiss/gpu/GpuDistance.h +116 -112
- data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +1 -2
- data/vendor/faiss/faiss/gpu/GpuIndex.h +134 -137
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +76 -73
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +173 -162
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +67 -64
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +89 -86
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +150 -141
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +101 -103
- data/vendor/faiss/faiss/gpu/GpuIndicesOptions.h +17 -16
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +116 -128
- data/vendor/faiss/faiss/gpu/GpuResources.h +182 -186
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +433 -422
- data/vendor/faiss/faiss/gpu/StandardGpuResources.h +131 -130
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +468 -456
- data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +25 -19
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +22 -20
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +9 -8
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +39 -44
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +16 -14
- data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +77 -71
- data/vendor/faiss/faiss/gpu/perf/PerfIVFPQAdd.cpp +109 -88
- data/vendor/faiss/faiss/gpu/perf/WriteIndex.cpp +75 -64
- data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +230 -215
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +80 -86
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +284 -277
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +416 -416
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +611 -517
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +166 -164
- data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +61 -53
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +274 -238
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +73 -57
- data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +47 -50
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +79 -72
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +140 -146
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.h +69 -71
- data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +21 -16
- data/vendor/faiss/faiss/gpu/utils/Timer.cpp +25 -29
- data/vendor/faiss/faiss/gpu/utils/Timer.h +30 -29
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +270 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +115 -0
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +90 -120
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +81 -65
- data/vendor/faiss/faiss/impl/FaissAssert.h +73 -58
- data/vendor/faiss/faiss/impl/FaissException.cpp +56 -48
- data/vendor/faiss/faiss/impl/FaissException.h +41 -29
- data/vendor/faiss/faiss/impl/HNSW.cpp +595 -611
- data/vendor/faiss/faiss/impl/HNSW.h +179 -200
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +672 -0
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +172 -0
- data/vendor/faiss/faiss/impl/NNDescent.cpp +487 -0
- data/vendor/faiss/faiss/impl/NNDescent.h +154 -0
- data/vendor/faiss/faiss/impl/NSG.cpp +682 -0
- data/vendor/faiss/faiss/impl/NSG.h +199 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +484 -454
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +52 -55
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +26 -47
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +469 -459
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +76 -87
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +448 -0
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +130 -0
- data/vendor/faiss/faiss/impl/ResultHandler.h +96 -132
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +648 -701
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +48 -46
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +129 -131
- data/vendor/faiss/faiss/impl/ThreadedIndex.h +61 -55
- data/vendor/faiss/faiss/impl/index_read.cpp +547 -479
- data/vendor/faiss/faiss/impl/index_write.cpp +497 -407
- data/vendor/faiss/faiss/impl/io.cpp +75 -94
- data/vendor/faiss/faiss/impl/io.h +31 -41
- data/vendor/faiss/faiss/impl/io_macros.h +40 -29
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +137 -186
- data/vendor/faiss/faiss/impl/lattice_Zn.h +40 -51
- data/vendor/faiss/faiss/impl/platform_macros.h +29 -8
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +77 -124
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +39 -48
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +41 -52
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +80 -117
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +109 -137
- data/vendor/faiss/faiss/index_factory.cpp +269 -218
- data/vendor/faiss/faiss/index_factory.h +6 -7
- data/vendor/faiss/faiss/index_io.h +23 -26
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +67 -75
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +22 -24
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +96 -112
- data/vendor/faiss/faiss/invlists/DirectMap.h +29 -33
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +307 -364
- data/vendor/faiss/faiss/invlists/InvertedLists.h +151 -151
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +29 -34
- data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +17 -18
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +257 -293
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +50 -45
- data/vendor/faiss/faiss/python/python_callbacks.cpp +23 -26
- data/vendor/faiss/faiss/python/python_callbacks.h +9 -16
- data/vendor/faiss/faiss/utils/AlignedTable.h +79 -44
- data/vendor/faiss/faiss/utils/Heap.cpp +40 -48
- data/vendor/faiss/faiss/utils/Heap.h +186 -209
- data/vendor/faiss/faiss/utils/WorkerThread.cpp +67 -76
- data/vendor/faiss/faiss/utils/WorkerThread.h +32 -33
- data/vendor/faiss/faiss/utils/distances.cpp +301 -310
- data/vendor/faiss/faiss/utils/distances.h +133 -118
- data/vendor/faiss/faiss/utils/distances_simd.cpp +456 -516
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +117 -0
- data/vendor/faiss/faiss/utils/extra_distances.cpp +113 -232
- data/vendor/faiss/faiss/utils/extra_distances.h +30 -29
- data/vendor/faiss/faiss/utils/hamming-inl.h +260 -209
- data/vendor/faiss/faiss/utils/hamming.cpp +375 -469
- data/vendor/faiss/faiss/utils/hamming.h +62 -85
- data/vendor/faiss/faiss/utils/ordered_key_value.h +16 -18
- data/vendor/faiss/faiss/utils/partitioning.cpp +393 -318
- data/vendor/faiss/faiss/utils/partitioning.h +26 -21
- data/vendor/faiss/faiss/utils/quantize_lut.cpp +78 -66
- data/vendor/faiss/faiss/utils/quantize_lut.h +22 -20
- data/vendor/faiss/faiss/utils/random.cpp +39 -63
- data/vendor/faiss/faiss/utils/random.h +13 -16
- data/vendor/faiss/faiss/utils/simdlib.h +4 -2
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +88 -85
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +226 -165
- data/vendor/faiss/faiss/utils/simdlib_neon.h +832 -0
- data/vendor/faiss/faiss/utils/utils.cpp +304 -287
- data/vendor/faiss/faiss/utils/utils.h +53 -48
- metadata +24 -10
- data/lib/faiss/index.rb +0 -20
- data/lib/faiss/index_binary.rb +0 -20
- data/lib/faiss/kmeans.rb +0 -15
- data/lib/faiss/pca_matrix.rb +0 -15
- data/lib/faiss/product_quantizer.rb +0 -22
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
#define FAISS_utils_h
|
|
18
18
|
|
|
19
19
|
#include <stdint.h>
|
|
20
|
+
#include <string>
|
|
20
21
|
|
|
21
22
|
#ifdef _MSC_VER
|
|
22
23
|
#define strtok_r strtok_s
|
|
@@ -24,29 +25,31 @@
|
|
|
24
25
|
|
|
25
26
|
#include <faiss/utils/Heap.h>
|
|
26
27
|
|
|
27
|
-
|
|
28
28
|
namespace faiss {
|
|
29
29
|
|
|
30
|
+
/****************************************************************************
|
|
31
|
+
* Get compile specific variables
|
|
32
|
+
***************************************************************************/
|
|
33
|
+
|
|
34
|
+
/// get compile options
|
|
35
|
+
std::string get_compile_options();
|
|
30
36
|
|
|
31
37
|
/**************************************************
|
|
32
38
|
* Get some stats about the system
|
|
33
|
-
**************************************************/
|
|
34
|
-
|
|
39
|
+
**************************************************/
|
|
35
40
|
|
|
36
41
|
/// ms elapsed since some arbitrary epoch
|
|
37
|
-
double getmillisecs
|
|
42
|
+
double getmillisecs();
|
|
38
43
|
|
|
39
44
|
/// get current RSS usage in kB
|
|
40
|
-
size_t get_mem_usage_kb
|
|
45
|
+
size_t get_mem_usage_kb();
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
uint64_t get_cycles ();
|
|
47
|
+
uint64_t get_cycles();
|
|
44
48
|
|
|
45
49
|
/***************************************************************************
|
|
46
50
|
* Misc matrix and vector manipulation functions
|
|
47
51
|
***************************************************************************/
|
|
48
52
|
|
|
49
|
-
|
|
50
53
|
/** compute c := a + bf * b for a, b and c tables
|
|
51
54
|
*
|
|
52
55
|
* @param n size of the tables
|
|
@@ -54,34 +57,37 @@ uint64_t get_cycles ();
|
|
|
54
57
|
* @param b size n
|
|
55
58
|
* @param c restult table, size n
|
|
56
59
|
*/
|
|
57
|
-
void fvec_madd
|
|
58
|
-
float bf, const float *b, float *c);
|
|
59
|
-
|
|
60
|
+
void fvec_madd(size_t n, const float* a, float bf, const float* b, float* c);
|
|
60
61
|
|
|
61
62
|
/** same as fvec_madd, also return index of the min of the result table
|
|
62
63
|
* @return index of the min of table c
|
|
63
64
|
*/
|
|
64
|
-
int fvec_madd_and_argmin
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
int fvec_madd_and_argmin(
|
|
66
|
+
size_t n,
|
|
67
|
+
const float* a,
|
|
68
|
+
float bf,
|
|
69
|
+
const float* b,
|
|
70
|
+
float* c);
|
|
67
71
|
|
|
68
72
|
/* perform a reflection (not an efficient implementation, just for test ) */
|
|
69
|
-
void reflection
|
|
70
|
-
|
|
73
|
+
void reflection(const float* u, float* x, size_t n, size_t d, size_t nu);
|
|
71
74
|
|
|
72
75
|
/** compute the Q of the QR decomposition for m > n
|
|
73
76
|
* @param a size n * m: input matrix and output Q
|
|
74
77
|
*/
|
|
75
|
-
void matrix_qr
|
|
78
|
+
void matrix_qr(int m, int n, float* a);
|
|
76
79
|
|
|
77
80
|
/** distances are supposed to be sorted. Sorts indices with same distance*/
|
|
78
|
-
void ranklist_handle_ties
|
|
81
|
+
void ranklist_handle_ties(int k, int64_t* idx, const float* dis);
|
|
79
82
|
|
|
80
83
|
/** count the number of comon elements between v1 and v2
|
|
81
84
|
* algorithm = sorting + bissection to avoid double-counting duplicates
|
|
82
85
|
*/
|
|
83
|
-
size_t ranklist_intersection_size
|
|
84
|
-
|
|
86
|
+
size_t ranklist_intersection_size(
|
|
87
|
+
size_t k1,
|
|
88
|
+
const int64_t* v1,
|
|
89
|
+
size_t k2,
|
|
90
|
+
const int64_t* v2);
|
|
85
91
|
|
|
86
92
|
/** merge a result table into another one
|
|
87
93
|
*
|
|
@@ -91,41 +97,38 @@ size_t ranklist_intersection_size (size_t k1, const int64_t *v1,
|
|
|
91
97
|
* @param translation add this value to all I1's indexes
|
|
92
98
|
* @return nb of values that were taken from the second table
|
|
93
99
|
*/
|
|
94
|
-
size_t merge_result_table_with
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
size_t merge_result_table_with(
|
|
101
|
+
size_t n,
|
|
102
|
+
size_t k,
|
|
103
|
+
int64_t* I0,
|
|
104
|
+
float* D0,
|
|
105
|
+
const int64_t* I1,
|
|
106
|
+
const float* D1,
|
|
107
|
+
bool keep_min = true,
|
|
108
|
+
int64_t translation = 0);
|
|
100
109
|
|
|
101
110
|
/// a balanced assignment has a IF of 1
|
|
102
|
-
double imbalance_factor
|
|
111
|
+
double imbalance_factor(int n, int k, const int64_t* assign);
|
|
103
112
|
|
|
104
113
|
/// same, takes a histogram as input
|
|
105
|
-
double imbalance_factor
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
void fvec_argsort (size_t n, const float *vals,
|
|
109
|
-
size_t *perm);
|
|
114
|
+
double imbalance_factor(int k, const int* hist);
|
|
110
115
|
|
|
111
|
-
void
|
|
112
|
-
size_t *perm);
|
|
116
|
+
void fvec_argsort(size_t n, const float* vals, size_t* perm);
|
|
113
117
|
|
|
118
|
+
void fvec_argsort_parallel(size_t n, const float* vals, size_t* perm);
|
|
114
119
|
|
|
115
120
|
/// compute histogram on v
|
|
116
|
-
int ivec_hist
|
|
121
|
+
int ivec_hist(size_t n, const int* v, int vmax, int* hist);
|
|
117
122
|
|
|
118
123
|
/** Compute histogram of bits on a code array
|
|
119
124
|
*
|
|
120
125
|
* @param codes size(n, nbits / 8)
|
|
121
126
|
* @param hist size(nbits): nb of 1s in the array of codes
|
|
122
127
|
*/
|
|
123
|
-
void bincode_hist(size_t n, size_t nbits, const uint8_t
|
|
124
|
-
|
|
128
|
+
void bincode_hist(size_t n, size_t nbits, const uint8_t* codes, int* hist);
|
|
125
129
|
|
|
126
130
|
/// compute a checksum on a table.
|
|
127
|
-
size_t ivec_checksum
|
|
128
|
-
|
|
131
|
+
size_t ivec_checksum(size_t n, const int* a);
|
|
129
132
|
|
|
130
133
|
/** random subsamples a set of vectors if there are too many of them
|
|
131
134
|
*
|
|
@@ -136,9 +139,13 @@ size_t ivec_checksum (size_t n, const int *a);
|
|
|
136
139
|
* @param seed random seed to use for sampling
|
|
137
140
|
* @return x or an array allocated with new [] with *n vectors
|
|
138
141
|
*/
|
|
139
|
-
const float
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
const float* fvecs_maybe_subsample(
|
|
143
|
+
size_t d,
|
|
144
|
+
size_t* n,
|
|
145
|
+
size_t nmax,
|
|
146
|
+
const float* x,
|
|
147
|
+
bool verbose = false,
|
|
148
|
+
int64_t seed = 1234);
|
|
142
149
|
|
|
143
150
|
/** Convert binary vector to +1/-1 valued float vector.
|
|
144
151
|
*
|
|
@@ -146,7 +153,7 @@ const float *fvecs_maybe_subsample (
|
|
|
146
153
|
* @param x_in input binary vector (uint8_t table of size d / 8)
|
|
147
154
|
* @param x_out output float vector (float table of size d)
|
|
148
155
|
*/
|
|
149
|
-
void binary_to_real(size_t d, const uint8_t
|
|
156
|
+
void binary_to_real(size_t d, const uint8_t* x_in, float* x_out);
|
|
150
157
|
|
|
151
158
|
/** Convert float vector to binary vector. Components > 0 are converted to 1,
|
|
152
159
|
* others to 0.
|
|
@@ -155,16 +162,14 @@ void binary_to_real(size_t d, const uint8_t *x_in, float *x_out);
|
|
|
155
162
|
* @param x_in input float vector (float table of size d)
|
|
156
163
|
* @param x_out output binary vector (uint8_t table of size d / 8)
|
|
157
164
|
*/
|
|
158
|
-
void real_to_binary(size_t d, const float
|
|
159
|
-
|
|
165
|
+
void real_to_binary(size_t d, const float* x_in, uint8_t* x_out);
|
|
160
166
|
|
|
161
167
|
/** A reasonable hashing function */
|
|
162
|
-
uint64_t hash_bytes
|
|
168
|
+
uint64_t hash_bytes(const uint8_t* bytes, int64_t n);
|
|
163
169
|
|
|
164
170
|
/** Whether OpenMP annotations were respected. */
|
|
165
171
|
bool check_openmp();
|
|
166
172
|
|
|
167
|
-
} //
|
|
168
|
-
|
|
173
|
+
} // namespace faiss
|
|
169
174
|
|
|
170
175
|
#endif /* FAISS_utils_h */
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: faiss
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrew Kane
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-06-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rice
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 4.0.2
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
26
|
+
version: 4.0.2
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: numo-narray
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -53,16 +53,12 @@ files:
|
|
|
53
53
|
- ext/faiss/index.cpp
|
|
54
54
|
- ext/faiss/index_binary.cpp
|
|
55
55
|
- ext/faiss/kmeans.cpp
|
|
56
|
+
- ext/faiss/numo.hpp
|
|
56
57
|
- ext/faiss/pca_matrix.cpp
|
|
57
58
|
- ext/faiss/product_quantizer.cpp
|
|
58
59
|
- ext/faiss/utils.cpp
|
|
59
60
|
- ext/faiss/utils.h
|
|
60
61
|
- lib/faiss.rb
|
|
61
|
-
- lib/faiss/index.rb
|
|
62
|
-
- lib/faiss/index_binary.rb
|
|
63
|
-
- lib/faiss/kmeans.rb
|
|
64
|
-
- lib/faiss/pca_matrix.rb
|
|
65
|
-
- lib/faiss/product_quantizer.rb
|
|
66
62
|
- lib/faiss/version.rb
|
|
67
63
|
- vendor/faiss/LICENSE
|
|
68
64
|
- vendor/faiss/faiss/AutoTune.cpp
|
|
@@ -107,6 +103,10 @@ files:
|
|
|
107
103
|
- vendor/faiss/faiss/IndexLSH.h
|
|
108
104
|
- vendor/faiss/faiss/IndexLattice.cpp
|
|
109
105
|
- vendor/faiss/faiss/IndexLattice.h
|
|
106
|
+
- vendor/faiss/faiss/IndexNNDescent.cpp
|
|
107
|
+
- vendor/faiss/faiss/IndexNNDescent.h
|
|
108
|
+
- vendor/faiss/faiss/IndexNSG.cpp
|
|
109
|
+
- vendor/faiss/faiss/IndexNSG.h
|
|
110
110
|
- vendor/faiss/faiss/IndexPQ.cpp
|
|
111
111
|
- vendor/faiss/faiss/IndexPQ.h
|
|
112
112
|
- vendor/faiss/faiss/IndexPQFastScan.cpp
|
|
@@ -117,6 +117,8 @@ files:
|
|
|
117
117
|
- vendor/faiss/faiss/IndexRefine.h
|
|
118
118
|
- vendor/faiss/faiss/IndexReplicas.cpp
|
|
119
119
|
- vendor/faiss/faiss/IndexReplicas.h
|
|
120
|
+
- vendor/faiss/faiss/IndexResidual.cpp
|
|
121
|
+
- vendor/faiss/faiss/IndexResidual.h
|
|
120
122
|
- vendor/faiss/faiss/IndexScalarQuantizer.cpp
|
|
121
123
|
- vendor/faiss/faiss/IndexScalarQuantizer.h
|
|
122
124
|
- vendor/faiss/faiss/IndexShards.cpp
|
|
@@ -175,6 +177,8 @@ files:
|
|
|
175
177
|
- vendor/faiss/faiss/gpu/utils/StaticUtils.h
|
|
176
178
|
- vendor/faiss/faiss/gpu/utils/Timer.cpp
|
|
177
179
|
- vendor/faiss/faiss/gpu/utils/Timer.h
|
|
180
|
+
- vendor/faiss/faiss/impl/AdditiveQuantizer.cpp
|
|
181
|
+
- vendor/faiss/faiss/impl/AdditiveQuantizer.h
|
|
178
182
|
- vendor/faiss/faiss/impl/AuxIndexStructures.cpp
|
|
179
183
|
- vendor/faiss/faiss/impl/AuxIndexStructures.h
|
|
180
184
|
- vendor/faiss/faiss/impl/FaissAssert.h
|
|
@@ -182,11 +186,19 @@ files:
|
|
|
182
186
|
- vendor/faiss/faiss/impl/FaissException.h
|
|
183
187
|
- vendor/faiss/faiss/impl/HNSW.cpp
|
|
184
188
|
- vendor/faiss/faiss/impl/HNSW.h
|
|
189
|
+
- vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp
|
|
190
|
+
- vendor/faiss/faiss/impl/LocalSearchQuantizer.h
|
|
191
|
+
- vendor/faiss/faiss/impl/NNDescent.cpp
|
|
192
|
+
- vendor/faiss/faiss/impl/NNDescent.h
|
|
193
|
+
- vendor/faiss/faiss/impl/NSG.cpp
|
|
194
|
+
- vendor/faiss/faiss/impl/NSG.h
|
|
185
195
|
- vendor/faiss/faiss/impl/PolysemousTraining.cpp
|
|
186
196
|
- vendor/faiss/faiss/impl/PolysemousTraining.h
|
|
187
197
|
- vendor/faiss/faiss/impl/ProductQuantizer-inl.h
|
|
188
198
|
- vendor/faiss/faiss/impl/ProductQuantizer.cpp
|
|
189
199
|
- vendor/faiss/faiss/impl/ProductQuantizer.h
|
|
200
|
+
- vendor/faiss/faiss/impl/ResidualQuantizer.cpp
|
|
201
|
+
- vendor/faiss/faiss/impl/ResidualQuantizer.h
|
|
190
202
|
- vendor/faiss/faiss/impl/ResultHandler.h
|
|
191
203
|
- vendor/faiss/faiss/impl/ScalarQuantizer.cpp
|
|
192
204
|
- vendor/faiss/faiss/impl/ScalarQuantizer.h
|
|
@@ -228,6 +240,7 @@ files:
|
|
|
228
240
|
- vendor/faiss/faiss/utils/distances.cpp
|
|
229
241
|
- vendor/faiss/faiss/utils/distances.h
|
|
230
242
|
- vendor/faiss/faiss/utils/distances_simd.cpp
|
|
243
|
+
- vendor/faiss/faiss/utils/extra_distances-inl.h
|
|
231
244
|
- vendor/faiss/faiss/utils/extra_distances.cpp
|
|
232
245
|
- vendor/faiss/faiss/utils/extra_distances.h
|
|
233
246
|
- vendor/faiss/faiss/utils/hamming-inl.h
|
|
@@ -243,6 +256,7 @@ files:
|
|
|
243
256
|
- vendor/faiss/faiss/utils/simdlib.h
|
|
244
257
|
- vendor/faiss/faiss/utils/simdlib_avx2.h
|
|
245
258
|
- vendor/faiss/faiss/utils/simdlib_emulated.h
|
|
259
|
+
- vendor/faiss/faiss/utils/simdlib_neon.h
|
|
246
260
|
- vendor/faiss/faiss/utils/utils.cpp
|
|
247
261
|
- vendor/faiss/faiss/utils/utils.h
|
|
248
262
|
homepage: https://github.com/ankane/faiss
|
|
@@ -257,7 +271,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
257
271
|
requirements:
|
|
258
272
|
- - ">="
|
|
259
273
|
- !ruby/object:Gem::Version
|
|
260
|
-
version: '2.
|
|
274
|
+
version: '2.6'
|
|
261
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
276
|
requirements:
|
|
263
277
|
- - ">="
|
data/lib/faiss/index.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
module Faiss
|
|
2
|
-
class Index
|
|
3
|
-
def train(objects)
|
|
4
|
-
objects = Numo::SFloat.cast(objects) unless objects.is_a?(Numo::SFloat)
|
|
5
|
-
_train(objects.shape[0], objects)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def add(objects)
|
|
9
|
-
objects = Numo::SFloat.cast(objects) unless objects.is_a?(Numo::SFloat)
|
|
10
|
-
_add(objects.shape[0], objects)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def search(objects, k)
|
|
14
|
-
objects = Numo::SFloat.cast(objects) unless objects.is_a?(Numo::SFloat)
|
|
15
|
-
n = objects.shape[0]
|
|
16
|
-
distances, labels = _search(n, objects, k)
|
|
17
|
-
[Numo::SFloat.from_binary(distances).reshape(n, k), Numo::Int64.from_binary(labels).reshape(n, k)]
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
data/lib/faiss/index_binary.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
module Faiss
|
|
2
|
-
class IndexBinary
|
|
3
|
-
def train(objects)
|
|
4
|
-
objects = Numo::UInt8.cast(objects) unless objects.is_a?(Numo::UInt8)
|
|
5
|
-
_train(objects.shape[0], objects)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def add(objects)
|
|
9
|
-
objects = Numo::UInt8.cast(objects) unless objects.is_a?(Numo::UInt8)
|
|
10
|
-
_add(objects.shape[0], objects)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def search(objects, k)
|
|
14
|
-
objects = Numo::UInt8.cast(objects) unless objects.is_a?(Numo::UInt8)
|
|
15
|
-
n = objects.shape[0]
|
|
16
|
-
distances, labels = _search(n, objects, k)
|
|
17
|
-
[Numo::UInt32.from_binary(distances).reshape(n, k), Numo::Int64.from_binary(labels).reshape(n, k)]
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
data/lib/faiss/kmeans.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module Faiss
|
|
2
|
-
class Kmeans
|
|
3
|
-
attr_reader :index
|
|
4
|
-
|
|
5
|
-
def train(objects)
|
|
6
|
-
objects = Numo::SFloat.cast(objects) unless objects.is_a?(Numo::SFloat)
|
|
7
|
-
@index = IndexFlatL2.new(d)
|
|
8
|
-
_train(objects.shape[0], objects, @index)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def centroids
|
|
12
|
-
Numo::SFloat.from_binary(_centroids).reshape(k, d)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
data/lib/faiss/pca_matrix.rb
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
module Faiss
|
|
2
|
-
class PCAMatrix
|
|
3
|
-
def train(objects)
|
|
4
|
-
objects = Numo::SFloat.cast(objects) unless objects.is_a?(Numo::SFloat)
|
|
5
|
-
_train(objects.shape[0], objects)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def apply(objects)
|
|
9
|
-
objects = Numo::SFloat.cast(objects) unless objects.is_a?(Numo::SFloat)
|
|
10
|
-
n = objects.shape[0]
|
|
11
|
-
res = _apply(n, objects)
|
|
12
|
-
Numo::SFloat.from_binary(res).reshape(n, d_out)
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module Faiss
|
|
2
|
-
class ProductQuantizer
|
|
3
|
-
def train(objects)
|
|
4
|
-
objects = Numo::SFloat.cast(objects) unless objects.is_a?(Numo::SFloat)
|
|
5
|
-
_train(objects.shape[0], objects)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def compute_codes(objects)
|
|
9
|
-
objects = Numo::SFloat.cast(objects) unless objects.is_a?(Numo::SFloat)
|
|
10
|
-
n = objects.shape[0]
|
|
11
|
-
res = _compute_codes(n, objects)
|
|
12
|
-
Numo::UInt8.from_binary(res).reshape(n, m)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def decode(objects)
|
|
16
|
-
objects = Numo::UInt8.cast(objects) unless objects.is_a?(Numo::UInt8)
|
|
17
|
-
n = objects.shape[0]
|
|
18
|
-
res = _decode(n, objects)
|
|
19
|
-
Numo::SFloat.from_binary(res).reshape(n, d)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|