faiss 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -0
  3. data/LICENSE.txt +18 -18
  4. data/README.md +4 -4
  5. data/ext/faiss/ext.cpp +11 -307
  6. data/ext/faiss/extconf.rb +3 -3
  7. data/ext/faiss/index.cpp +132 -0
  8. data/ext/faiss/index_binary.cpp +81 -0
  9. data/ext/faiss/kmeans.cpp +36 -0
  10. data/ext/faiss/pca_matrix.cpp +34 -0
  11. data/ext/faiss/product_quantizer.cpp +54 -0
  12. data/ext/faiss/utils.cpp +40 -0
  13. data/ext/faiss/utils.h +16 -0
  14. data/lib/faiss/version.rb +1 -1
  15. data/vendor/faiss/{AutoTune.cpp → faiss/AutoTune.cpp} +44 -41
  16. data/vendor/faiss/{AutoTune.h → faiss/AutoTune.h} +6 -3
  17. data/vendor/faiss/faiss/Clustering.cpp +531 -0
  18. data/vendor/faiss/{Clustering.h → faiss/Clustering.h} +39 -11
  19. data/vendor/faiss/{IVFlib.cpp → faiss/IVFlib.cpp} +110 -15
  20. data/vendor/faiss/{IVFlib.h → faiss/IVFlib.h} +30 -8
  21. data/vendor/faiss/{Index.cpp → faiss/Index.cpp} +3 -4
  22. data/vendor/faiss/{Index.h → faiss/Index.h} +7 -26
  23. data/vendor/faiss/{Index2Layer.cpp → faiss/Index2Layer.cpp} +12 -12
  24. data/vendor/faiss/{Index2Layer.h → faiss/Index2Layer.h} +0 -0
  25. data/vendor/faiss/{IndexBinary.cpp → faiss/IndexBinary.cpp} +5 -5
  26. data/vendor/faiss/{IndexBinary.h → faiss/IndexBinary.h} +8 -4
  27. data/vendor/faiss/{IndexBinaryFlat.cpp → faiss/IndexBinaryFlat.cpp} +5 -0
  28. data/vendor/faiss/{IndexBinaryFlat.h → faiss/IndexBinaryFlat.h} +3 -0
  29. data/vendor/faiss/{IndexBinaryFromFloat.cpp → faiss/IndexBinaryFromFloat.cpp} +1 -0
  30. data/vendor/faiss/{IndexBinaryFromFloat.h → faiss/IndexBinaryFromFloat.h} +0 -0
  31. data/vendor/faiss/{IndexBinaryHNSW.cpp → faiss/IndexBinaryHNSW.cpp} +1 -2
  32. data/vendor/faiss/{IndexBinaryHNSW.h → faiss/IndexBinaryHNSW.h} +0 -0
  33. data/vendor/faiss/faiss/IndexBinaryHash.cpp +491 -0
  34. data/vendor/faiss/faiss/IndexBinaryHash.h +117 -0
  35. data/vendor/faiss/{IndexBinaryIVF.cpp → faiss/IndexBinaryIVF.cpp} +167 -121
  36. data/vendor/faiss/{IndexBinaryIVF.h → faiss/IndexBinaryIVF.h} +15 -5
  37. data/vendor/faiss/{IndexFlat.cpp → faiss/IndexFlat.cpp} +0 -148
  38. data/vendor/faiss/{IndexFlat.h → faiss/IndexFlat.h} +2 -52
  39. data/vendor/faiss/{IndexHNSW.cpp → faiss/IndexHNSW.cpp} +135 -53
  40. data/vendor/faiss/{IndexHNSW.h → faiss/IndexHNSW.h} +3 -3
  41. data/vendor/faiss/{IndexIVF.cpp → faiss/IndexIVF.cpp} +312 -146
  42. data/vendor/faiss/{IndexIVF.h → faiss/IndexIVF.h} +49 -19
  43. data/vendor/faiss/{IndexIVFFlat.cpp → faiss/IndexIVFFlat.cpp} +28 -62
  44. data/vendor/faiss/{IndexIVFFlat.h → faiss/IndexIVFFlat.h} +3 -12
  45. data/vendor/faiss/{IndexIVFPQ.cpp → faiss/IndexIVFPQ.cpp} +97 -49
  46. data/vendor/faiss/{IndexIVFPQ.h → faiss/IndexIVFPQ.h} +36 -19
  47. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +1116 -0
  48. data/vendor/faiss/faiss/IndexIVFPQFastScan.h +166 -0
  49. data/vendor/faiss/{IndexIVFPQR.cpp → faiss/IndexIVFPQR.cpp} +13 -12
  50. data/vendor/faiss/{IndexIVFPQR.h → faiss/IndexIVFPQR.h} +2 -1
  51. data/vendor/faiss/{IndexIVFSpectralHash.cpp → faiss/IndexIVFSpectralHash.cpp} +4 -5
  52. data/vendor/faiss/{IndexIVFSpectralHash.h → faiss/IndexIVFSpectralHash.h} +0 -0
  53. data/vendor/faiss/{IndexLSH.cpp → faiss/IndexLSH.cpp} +0 -0
  54. data/vendor/faiss/{IndexLSH.h → faiss/IndexLSH.h} +4 -1
  55. data/vendor/faiss/{IndexLattice.cpp → faiss/IndexLattice.cpp} +0 -0
  56. data/vendor/faiss/{IndexLattice.h → faiss/IndexLattice.h} +0 -0
  57. data/vendor/faiss/{IndexPQ.cpp → faiss/IndexPQ.cpp} +40 -24
  58. data/vendor/faiss/{IndexPQ.h → faiss/IndexPQ.h} +3 -1
  59. data/vendor/faiss/faiss/IndexPQFastScan.cpp +536 -0
  60. data/vendor/faiss/faiss/IndexPQFastScan.h +111 -0
  61. data/vendor/faiss/{IndexPreTransform.cpp → faiss/IndexPreTransform.cpp} +47 -1
  62. data/vendor/faiss/{IndexPreTransform.h → faiss/IndexPreTransform.h} +2 -0
  63. data/vendor/faiss/faiss/IndexRefine.cpp +256 -0
  64. data/vendor/faiss/faiss/IndexRefine.h +73 -0
  65. data/vendor/faiss/{IndexReplicas.cpp → faiss/IndexReplicas.cpp} +102 -10
  66. data/vendor/faiss/{IndexReplicas.h → faiss/IndexReplicas.h} +6 -0
  67. data/vendor/faiss/{IndexScalarQuantizer.cpp → faiss/IndexScalarQuantizer.cpp} +13 -6
  68. data/vendor/faiss/{IndexScalarQuantizer.h → faiss/IndexScalarQuantizer.h} +1 -1
  69. data/vendor/faiss/{IndexShards.cpp → faiss/IndexShards.cpp} +37 -12
  70. data/vendor/faiss/{IndexShards.h → faiss/IndexShards.h} +3 -4
  71. data/vendor/faiss/{MatrixStats.cpp → faiss/MatrixStats.cpp} +0 -0
  72. data/vendor/faiss/{MatrixStats.h → faiss/MatrixStats.h} +0 -0
  73. data/vendor/faiss/{MetaIndexes.cpp → faiss/MetaIndexes.cpp} +5 -4
  74. data/vendor/faiss/{MetaIndexes.h → faiss/MetaIndexes.h} +0 -0
  75. data/vendor/faiss/faiss/MetricType.h +36 -0
  76. data/vendor/faiss/{VectorTransform.cpp → faiss/VectorTransform.cpp} +4 -3
  77. data/vendor/faiss/{VectorTransform.h → faiss/VectorTransform.h} +0 -0
  78. data/vendor/faiss/{clone_index.cpp → faiss/clone_index.cpp} +0 -0
  79. data/vendor/faiss/{clone_index.h → faiss/clone_index.h} +0 -0
  80. data/vendor/faiss/{gpu → faiss/gpu}/GpuAutoTune.cpp +0 -0
  81. data/vendor/faiss/{gpu → faiss/gpu}/GpuAutoTune.h +0 -0
  82. data/vendor/faiss/{gpu → faiss/gpu}/GpuCloner.cpp +18 -14
  83. data/vendor/faiss/{gpu → faiss/gpu}/GpuCloner.h +6 -7
  84. data/vendor/faiss/{gpu → faiss/gpu}/GpuClonerOptions.cpp +1 -1
  85. data/vendor/faiss/{gpu → faiss/gpu}/GpuClonerOptions.h +0 -0
  86. data/vendor/faiss/faiss/gpu/GpuDistance.h +153 -0
  87. data/vendor/faiss/{gpu → faiss/gpu}/GpuFaissAssert.h +0 -0
  88. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndex.h +25 -17
  89. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexBinaryFlat.h +15 -8
  90. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexFlat.h +46 -31
  91. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVF.h +21 -4
  92. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFFlat.h +32 -5
  93. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFPQ.h +43 -16
  94. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFScalarQuantizer.h +33 -5
  95. data/vendor/faiss/{gpu → faiss/gpu}/GpuIndicesOptions.h +0 -0
  96. data/vendor/faiss/faiss/gpu/GpuResources.cpp +200 -0
  97. data/vendor/faiss/faiss/gpu/GpuResources.h +268 -0
  98. data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +605 -0
  99. data/vendor/faiss/faiss/gpu/StandardGpuResources.h +204 -0
  100. data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +547 -0
  101. data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +51 -0
  102. data/vendor/faiss/{gpu → faiss/gpu}/impl/RemapIndices.cpp +3 -3
  103. data/vendor/faiss/{gpu → faiss/gpu}/impl/RemapIndices.h +3 -2
  104. data/vendor/faiss/{gpu → faiss/gpu}/perf/IndexWrapper-inl.h +1 -1
  105. data/vendor/faiss/{gpu → faiss/gpu}/perf/IndexWrapper.h +1 -1
  106. data/vendor/faiss/{gpu → faiss/gpu}/perf/PerfClustering.cpp +1 -1
  107. data/vendor/faiss/{gpu → faiss/gpu}/perf/PerfIVFPQAdd.cpp +0 -0
  108. data/vendor/faiss/{gpu → faiss/gpu}/perf/WriteIndex.cpp +0 -0
  109. data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +274 -0
  110. data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexBinaryFlat.cpp +0 -0
  111. data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexFlat.cpp +50 -28
  112. data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexIVFFlat.cpp +7 -2
  113. data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexIVFPQ.cpp +246 -45
  114. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +231 -0
  115. data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuMemoryException.cpp +0 -0
  116. data/vendor/faiss/{gpu → faiss/gpu}/test/TestUtils.cpp +4 -2
  117. data/vendor/faiss/{gpu → faiss/gpu}/test/TestUtils.h +33 -0
  118. data/vendor/faiss/{gpu → faiss/gpu}/test/demo_ivfpq_indexing_gpu.cpp +7 -5
  119. data/vendor/faiss/{gpu → faiss/gpu}/utils/DeviceUtils.h +7 -1
  120. data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +214 -0
  121. data/vendor/faiss/{gpu → faiss/gpu}/utils/StackDeviceMemory.h +25 -40
  122. data/vendor/faiss/{gpu → faiss/gpu}/utils/StaticUtils.h +6 -0
  123. data/vendor/faiss/{gpu → faiss/gpu}/utils/Timer.cpp +5 -6
  124. data/vendor/faiss/{gpu → faiss/gpu}/utils/Timer.h +2 -2
  125. data/vendor/faiss/{impl → faiss/impl}/AuxIndexStructures.cpp +18 -0
  126. data/vendor/faiss/{impl → faiss/impl}/AuxIndexStructures.h +22 -8
  127. data/vendor/faiss/{impl → faiss/impl}/FaissAssert.h +1 -0
  128. data/vendor/faiss/{impl → faiss/impl}/FaissException.cpp +26 -0
  129. data/vendor/faiss/{impl → faiss/impl}/FaissException.h +4 -0
  130. data/vendor/faiss/{impl → faiss/impl}/HNSW.cpp +28 -31
  131. data/vendor/faiss/{impl → faiss/impl}/HNSW.h +19 -11
  132. data/vendor/faiss/{impl → faiss/impl}/PolysemousTraining.cpp +1 -1
  133. data/vendor/faiss/{impl → faiss/impl}/PolysemousTraining.h +10 -10
  134. data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +137 -0
  135. data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer.cpp +32 -134
  136. data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer.h +44 -47
  137. data/vendor/faiss/faiss/impl/ResultHandler.h +452 -0
  138. data/vendor/faiss/{impl → faiss/impl}/ScalarQuantizer.cpp +90 -56
  139. data/vendor/faiss/{impl → faiss/impl}/ScalarQuantizer.h +7 -1
  140. data/vendor/faiss/{impl → faiss/impl}/ThreadedIndex-inl.h +0 -0
  141. data/vendor/faiss/{impl → faiss/impl}/ThreadedIndex.h +0 -0
  142. data/vendor/faiss/{impl → faiss/impl}/index_read.cpp +182 -135
  143. data/vendor/faiss/{impl → faiss/impl}/index_write.cpp +138 -68
  144. data/vendor/faiss/faiss/impl/io.cpp +288 -0
  145. data/vendor/faiss/{impl → faiss/impl}/io.h +60 -3
  146. data/vendor/faiss/faiss/impl/io_macros.h +57 -0
  147. data/vendor/faiss/{impl → faiss/impl}/lattice_Zn.cpp +38 -36
  148. data/vendor/faiss/{impl → faiss/impl}/lattice_Zn.h +3 -3
  149. data/vendor/faiss/faiss/impl/platform_macros.h +68 -0
  150. data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +272 -0
  151. data/vendor/faiss/faiss/impl/pq4_fast_scan.h +169 -0
  152. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +180 -0
  153. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +354 -0
  154. data/vendor/faiss/faiss/impl/simd_result_handlers.h +559 -0
  155. data/vendor/faiss/{index_factory.cpp → faiss/index_factory.cpp} +145 -20
  156. data/vendor/faiss/{index_factory.h → faiss/index_factory.h} +0 -0
  157. data/vendor/faiss/{index_io.h → faiss/index_io.h} +8 -1
  158. data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +151 -0
  159. data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +76 -0
  160. data/vendor/faiss/faiss/invlists/DirectMap.cpp +267 -0
  161. data/vendor/faiss/faiss/invlists/DirectMap.h +120 -0
  162. data/vendor/faiss/{InvertedLists.cpp → faiss/invlists/InvertedLists.cpp} +74 -5
  163. data/vendor/faiss/{InvertedLists.h → faiss/invlists/InvertedLists.h} +33 -1
  164. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +107 -0
  165. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +63 -0
  166. data/vendor/faiss/{OnDiskInvertedLists.cpp → faiss/invlists/OnDiskInvertedLists.cpp} +161 -8
  167. data/vendor/faiss/{OnDiskInvertedLists.h → faiss/invlists/OnDiskInvertedLists.h} +31 -8
  168. data/vendor/faiss/faiss/python/python_callbacks.cpp +112 -0
  169. data/vendor/faiss/faiss/python/python_callbacks.h +52 -0
  170. data/vendor/faiss/faiss/utils/AlignedTable.h +141 -0
  171. data/vendor/faiss/{utils → faiss/utils}/Heap.cpp +7 -9
  172. data/vendor/faiss/{utils → faiss/utils}/Heap.h +61 -52
  173. data/vendor/faiss/{utils → faiss/utils}/WorkerThread.cpp +0 -0
  174. data/vendor/faiss/{utils → faiss/utils}/WorkerThread.h +0 -0
  175. data/vendor/faiss/{utils → faiss/utils}/distances.cpp +190 -331
  176. data/vendor/faiss/{utils → faiss/utils}/distances.h +30 -21
  177. data/vendor/faiss/{utils → faiss/utils}/distances_simd.cpp +282 -55
  178. data/vendor/faiss/{utils → faiss/utils}/extra_distances.cpp +9 -9
  179. data/vendor/faiss/{utils → faiss/utils}/extra_distances.h +0 -0
  180. data/vendor/faiss/{utils → faiss/utils}/hamming-inl.h +5 -7
  181. data/vendor/faiss/{utils → faiss/utils}/hamming.cpp +94 -14
  182. data/vendor/faiss/{utils → faiss/utils}/hamming.h +24 -3
  183. data/vendor/faiss/faiss/utils/ordered_key_value.h +98 -0
  184. data/vendor/faiss/faiss/utils/partitioning.cpp +1256 -0
  185. data/vendor/faiss/faiss/utils/partitioning.h +69 -0
  186. data/vendor/faiss/faiss/utils/quantize_lut.cpp +277 -0
  187. data/vendor/faiss/faiss/utils/quantize_lut.h +80 -0
  188. data/vendor/faiss/{utils → faiss/utils}/random.cpp +5 -5
  189. data/vendor/faiss/{utils → faiss/utils}/random.h +0 -0
  190. data/vendor/faiss/faiss/utils/simdlib.h +31 -0
  191. data/vendor/faiss/faiss/utils/simdlib_avx2.h +461 -0
  192. data/vendor/faiss/faiss/utils/simdlib_emulated.h +589 -0
  193. data/vendor/faiss/{utils → faiss/utils}/utils.cpp +27 -124
  194. data/vendor/faiss/{utils → faiss/utils}/utils.h +4 -15
  195. metadata +195 -277
  196. data/lib/faiss/ext.bundle +0 -0
  197. data/vendor/faiss/Clustering.cpp +0 -261
  198. data/vendor/faiss/c_api/AutoTune_c.cpp +0 -83
  199. data/vendor/faiss/c_api/AutoTune_c.h +0 -64
  200. data/vendor/faiss/c_api/Clustering_c.cpp +0 -139
  201. data/vendor/faiss/c_api/Clustering_c.h +0 -117
  202. data/vendor/faiss/c_api/IndexFlat_c.cpp +0 -140
  203. data/vendor/faiss/c_api/IndexFlat_c.h +0 -115
  204. data/vendor/faiss/c_api/IndexIVFFlat_c.cpp +0 -64
  205. data/vendor/faiss/c_api/IndexIVFFlat_c.h +0 -58
  206. data/vendor/faiss/c_api/IndexIVF_c.cpp +0 -92
  207. data/vendor/faiss/c_api/IndexIVF_c.h +0 -135
  208. data/vendor/faiss/c_api/IndexLSH_c.cpp +0 -37
  209. data/vendor/faiss/c_api/IndexLSH_c.h +0 -40
  210. data/vendor/faiss/c_api/IndexShards_c.cpp +0 -44
  211. data/vendor/faiss/c_api/IndexShards_c.h +0 -42
  212. data/vendor/faiss/c_api/Index_c.cpp +0 -105
  213. data/vendor/faiss/c_api/Index_c.h +0 -183
  214. data/vendor/faiss/c_api/MetaIndexes_c.cpp +0 -49
  215. data/vendor/faiss/c_api/MetaIndexes_c.h +0 -49
  216. data/vendor/faiss/c_api/clone_index_c.cpp +0 -23
  217. data/vendor/faiss/c_api/clone_index_c.h +0 -32
  218. data/vendor/faiss/c_api/error_c.h +0 -42
  219. data/vendor/faiss/c_api/error_impl.cpp +0 -27
  220. data/vendor/faiss/c_api/error_impl.h +0 -16
  221. data/vendor/faiss/c_api/faiss_c.h +0 -58
  222. data/vendor/faiss/c_api/gpu/GpuAutoTune_c.cpp +0 -96
  223. data/vendor/faiss/c_api/gpu/GpuAutoTune_c.h +0 -56
  224. data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.cpp +0 -52
  225. data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.h +0 -68
  226. data/vendor/faiss/c_api/gpu/GpuIndex_c.cpp +0 -17
  227. data/vendor/faiss/c_api/gpu/GpuIndex_c.h +0 -30
  228. data/vendor/faiss/c_api/gpu/GpuIndicesOptions_c.h +0 -38
  229. data/vendor/faiss/c_api/gpu/GpuResources_c.cpp +0 -86
  230. data/vendor/faiss/c_api/gpu/GpuResources_c.h +0 -66
  231. data/vendor/faiss/c_api/gpu/StandardGpuResources_c.cpp +0 -54
  232. data/vendor/faiss/c_api/gpu/StandardGpuResources_c.h +0 -53
  233. data/vendor/faiss/c_api/gpu/macros_impl.h +0 -42
  234. data/vendor/faiss/c_api/impl/AuxIndexStructures_c.cpp +0 -220
  235. data/vendor/faiss/c_api/impl/AuxIndexStructures_c.h +0 -149
  236. data/vendor/faiss/c_api/index_factory_c.cpp +0 -26
  237. data/vendor/faiss/c_api/index_factory_c.h +0 -30
  238. data/vendor/faiss/c_api/index_io_c.cpp +0 -42
  239. data/vendor/faiss/c_api/index_io_c.h +0 -50
  240. data/vendor/faiss/c_api/macros_impl.h +0 -110
  241. data/vendor/faiss/demos/demo_imi_flat.cpp +0 -151
  242. data/vendor/faiss/demos/demo_imi_pq.cpp +0 -199
  243. data/vendor/faiss/demos/demo_ivfpq_indexing.cpp +0 -146
  244. data/vendor/faiss/demos/demo_sift1M.cpp +0 -252
  245. data/vendor/faiss/gpu/GpuDistance.h +0 -52
  246. data/vendor/faiss/gpu/GpuResources.cpp +0 -52
  247. data/vendor/faiss/gpu/GpuResources.h +0 -73
  248. data/vendor/faiss/gpu/StandardGpuResources.cpp +0 -295
  249. data/vendor/faiss/gpu/StandardGpuResources.h +0 -114
  250. data/vendor/faiss/gpu/utils/DeviceMemory.cpp +0 -77
  251. data/vendor/faiss/gpu/utils/DeviceMemory.h +0 -71
  252. data/vendor/faiss/gpu/utils/MemorySpace.cpp +0 -89
  253. data/vendor/faiss/gpu/utils/MemorySpace.h +0 -44
  254. data/vendor/faiss/gpu/utils/StackDeviceMemory.cpp +0 -239
  255. data/vendor/faiss/impl/io.cpp +0 -142
  256. data/vendor/faiss/misc/test_blas.cpp +0 -84
  257. data/vendor/faiss/tests/test_binary_flat.cpp +0 -64
  258. data/vendor/faiss/tests/test_dealloc_invlists.cpp +0 -183
  259. data/vendor/faiss/tests/test_ivfpq_codec.cpp +0 -67
  260. data/vendor/faiss/tests/test_ivfpq_indexing.cpp +0 -98
  261. data/vendor/faiss/tests/test_lowlevel_ivf.cpp +0 -566
  262. data/vendor/faiss/tests/test_merge.cpp +0 -258
  263. data/vendor/faiss/tests/test_omp_threads.cpp +0 -14
  264. data/vendor/faiss/tests/test_ondisk_ivf.cpp +0 -220
  265. data/vendor/faiss/tests/test_pairs_decoding.cpp +0 -189
  266. data/vendor/faiss/tests/test_params_override.cpp +0 -231
  267. data/vendor/faiss/tests/test_pq_encoding.cpp +0 -98
  268. data/vendor/faiss/tests/test_sliding_ivf.cpp +0 -240
  269. data/vendor/faiss/tests/test_threaded_index.cpp +0 -253
  270. data/vendor/faiss/tests/test_transfer_invlists.cpp +0 -159
  271. data/vendor/faiss/tutorial/cpp/1-Flat.cpp +0 -98
  272. data/vendor/faiss/tutorial/cpp/2-IVFFlat.cpp +0 -81
  273. data/vendor/faiss/tutorial/cpp/3-IVFPQ.cpp +0 -93
  274. data/vendor/faiss/tutorial/cpp/4-GPU.cpp +0 -119
  275. data/vendor/faiss/tutorial/cpp/5-Multiple-GPUs.cpp +0 -99
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0369e5dda330b1490e48a88863baa01df9cadfa570078892cec439f82efaad1
4
- data.tar.gz: bb7d89fa17f782e8163b114b520b8c2c082cf37661b4b6fc4593460dc5958484
3
+ metadata.gz: '02752578b25cfcc61a7bb0e06e1d0dbc2d78175796cf99a44184a4e7298de073'
4
+ data.tar.gz: ec678cf766efa90be0e013b342be6f95e42c6e67c4aa6de1b9e3b6f4c59d8699
5
5
  SHA512:
6
- metadata.gz: 0a9f1515d142d11c688f1a9cdbcf9af0c36fa3fc98b240f236554b1067cf2daad1cefa377d18d236674b8fc1b94d64a3acc070c2528c47b68f4d231f29b7648d
7
- data.tar.gz: ae02808dbda4831c7165c987b77c72f9d436bba94e3e28d372f69ceee18fb4971c6cc99a2bf7ce9bd9a9a6e4befcd372515a728bf379294ecc870f2c58f85eb2
6
+ metadata.gz: 9342c736f6ce775b8561f0fc066b565e38f8d38470f98ea51b9635f371bb8efdbb9e049874588847fb11360da006da3ec0ca28d44fc6f844d970d91f648f1b03
7
+ data.tar.gz: e70f220fdc76a37fcf5a06beba2b07f0315bbbb3dab7b396a8f932c04746e11454bd57ed527d18d55436352bd823d1e33e341046697fd36b124f7e64fbb72f38
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## 0.1.6 (2021-03-21)
2
+
3
+ - Added support for inner product to `IndexIVFFlat` and `IndexIVFPQ`
4
+ - Added `ParameterSpace`
5
+ - Added `nprobe=` method
6
+
7
+ ## 0.1.5 (2021-03-14)
8
+
9
+ - Added `--with-optflags` option
10
+ - Added support for inner product to `IndexHNSWFlat`
11
+
12
+ ## 0.1.4 (2021-02-04)
13
+
14
+ - Updated Faiss to 1.7.0
15
+
16
+ ## 0.1.3 (2020-10-22)
17
+
18
+ - Updated Faiss to 1.6.4
19
+
20
+ ## 0.1.2 (2020-08-17)
21
+
22
+ - Updated Faiss to 1.6.3
23
+
1
24
  ## 0.1.1 (2020-03-09)
2
25
 
3
26
  - Vendored library
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2020 Andrew Kane
2
-
3
1
  MIT License
4
2
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
3
+ Copyright (c) Facebook, Inc. and its affiliates.
4
+ Copyright (c) 2020-2021 Andrew Kane
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
12
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
15
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Learn more about [Faiss](https://engineering.fb.com/data-infrastructure/faiss-a-library-for-efficient-similarity-search/)
6
6
 
7
- [![Build Status](https://travis-ci.org/ankane/faiss.svg?branch=master)](https://travis-ci.org/ankane/faiss)
7
+ [![Build Status](https://github.com/ankane/faiss/workflows/build/badge.svg?branch=master)](https://github.com/ankane/faiss/actions)
8
8
 
9
9
  ## Installation
10
10
 
@@ -24,7 +24,7 @@ Add this line to your application’s Gemfile:
24
24
  gem 'faiss'
25
25
  ```
26
26
 
27
- Faiss is not available for Windows yet
27
+ It can take a few minutes to compile the gem. Faiss is not available for Windows.
28
28
 
29
29
  ## Getting Started
30
30
 
@@ -200,10 +200,10 @@ Data can be an array of arrays
200
200
  [[1, 2, 3], [4, 5, 6]]
201
201
  ```
202
202
 
203
- Or a Numo NArray
203
+ Or a Numo array
204
204
 
205
205
  ```ruby
206
- Numo::SFloat.new(3, 2).seq
206
+ Numo::NArray.cast([[1, 2, 3], [4, 5, 6]])
207
207
  ```
208
208
 
209
209
  ## History
data/ext/faiss/ext.cpp CHANGED
@@ -1,315 +1,19 @@
1
- #include <faiss/IndexFlat.h>
2
- #include <faiss/IndexHNSW.h>
3
- #include <faiss/IndexIVFFlat.h>
4
- #include <faiss/IndexLSH.h>
5
- #include <faiss/IndexScalarQuantizer.h>
6
- #include <faiss/IndexPQ.h>
7
- #include <faiss/IndexIVFPQ.h>
8
- #include <faiss/IndexIVFPQR.h>
9
-
10
- #include <faiss/IndexBinaryFlat.h>
11
- #include <faiss/IndexBinaryIVF.h>
12
- #include <faiss/index_factory.h>
13
- #include <faiss/index_io.h>
14
-
15
- #include <faiss/Clustering.h>
16
- #include <faiss/VectorTransform.h>
17
-
18
- #include <rice/Array.hpp>
19
- #include <rice/Class.hpp>
20
- #include <rice/Constructor.hpp>
21
1
  #include <rice/Module.hpp>
22
2
 
23
- float* float_array(Rice::Object o)
24
- {
25
- Rice::String s = o.call("to_binary");
26
- return (float*) s.c_str();
27
- }
28
-
29
- uint8_t* uint8_array(Rice::Object o)
30
- {
31
- Rice::String s = o.call("to_binary");
32
- return (uint8_t*) s.c_str();
33
- }
34
-
35
- // TODO return Numo::SFloat
36
- Rice::String result(float* ptr, int64_t length)
37
- {
38
- return Rice::String(std::string((char*) ptr, length * sizeof(float)));
39
- }
40
-
41
- // TODO return Numo::UInt8
42
- Rice::String result(uint8_t* ptr, int64_t length)
43
- {
44
- return Rice::String(std::string((char*) ptr, length * sizeof(uint8_t)));
45
- }
46
-
47
- // TODO return Numo::Int32
48
- Rice::String result(int32_t* ptr, int64_t length)
49
- {
50
- return Rice::String(std::string((char*) ptr, length * sizeof(int32_t)));
51
- }
52
-
53
- // TODO return Numo::Int64
54
- Rice::String result(int64_t* ptr, int64_t length)
55
- {
56
- return Rice::String(std::string((char*) ptr, length * sizeof(int64_t)));
57
- }
3
+ void init_index(Rice::Module& m);
4
+ void init_index_binary(Rice::Module& m);
5
+ void init_kmeans(Rice::Module& m);
6
+ void init_pca_matrix(Rice::Module& m);
7
+ void init_product_quantizer(Rice::Module& m);
58
8
 
59
9
  extern "C"
60
10
  void Init_ext()
61
11
  {
62
- Rice::Module rb_mFaiss = Rice::define_module("Faiss")
63
- .define_singleton_method(
64
- "index_binary_factory",
65
- *[](int d, const char *description) {
66
- return faiss::index_binary_factory(d, description);
67
- });
68
-
69
- Rice::define_class_under<faiss::Index>(rb_mFaiss, "Index")
70
- .define_method(
71
- "d",
72
- *[](faiss::Index &self) {
73
- return self.d;
74
- })
75
- .define_method(
76
- "trained?",
77
- *[](faiss::Index &self) {
78
- return self.is_trained;
79
- })
80
- .define_method(
81
- "ntotal",
82
- *[](faiss::Index &self) {
83
- return self.ntotal;
84
- })
85
- .define_method(
86
- "_train",
87
- *[](faiss::Index &self, int64_t n, Rice::Object o) {
88
- const float *x = float_array(o);
89
- self.train(n, x);
90
- })
91
- .define_method(
92
- "_add",
93
- *[](faiss::Index &self, int64_t n, Rice::Object o) {
94
- const float *x = float_array(o);
95
- self.add(n, x);
96
- })
97
- .define_method(
98
- "_search",
99
- *[](faiss::Index &self, int64_t n, Rice::Object o, int64_t k) {
100
- const float *x = float_array(o);
101
- float *distances = new float[k * n];
102
- int64_t *labels = new int64_t[k * n];
103
-
104
- self.search(n, x, k, distances, labels);
105
-
106
- auto dstr = result(distances, k * n);
107
- auto lstr = result(labels, k * n);
108
-
109
- Rice::Array ret;
110
- ret.push(dstr);
111
- ret.push(lstr);
112
- return ret;
113
- })
114
- .define_method(
115
- "save",
116
- *[](faiss::Index &self, const char *fname) {
117
- faiss::write_index(&self, fname);
118
- })
119
- .define_singleton_method(
120
- "load",
121
- *[](const char *fname) {
122
- return faiss::read_index(fname);
123
- });
124
-
125
- Rice::define_class_under<faiss::IndexBinary>(rb_mFaiss, "IndexBinary")
126
- .define_method(
127
- "d",
128
- *[](faiss::Index &self) {
129
- return self.d;
130
- })
131
- .define_method(
132
- "trained?",
133
- *[](faiss::IndexBinary &self) {
134
- return self.is_trained;
135
- })
136
- .define_method(
137
- "ntotal",
138
- *[](faiss::IndexBinary &self) {
139
- return self.ntotal;
140
- })
141
- .define_method(
142
- "_train",
143
- *[](faiss::IndexBinary &self, int64_t n, Rice::Object o) {
144
- const uint8_t *x = uint8_array(o);
145
- self.train(n, x);
146
- })
147
- .define_method(
148
- "_add",
149
- *[](faiss::IndexBinary &self, int64_t n, Rice::Object o) {
150
- const uint8_t *x = uint8_array(o);
151
- self.add(n, x);
152
- })
153
- .define_method(
154
- "_search",
155
- *[](faiss::IndexBinary &self, int64_t n, Rice::Object o, int64_t k) {
156
- const uint8_t *x = uint8_array(o);
157
- int32_t *distances = new int32_t[k * n];
158
- int64_t *labels = new int64_t[k * n];
159
-
160
- self.search(n, x, k, distances, labels);
161
-
162
- auto dstr = result(distances, k * n);
163
- auto lstr = result(labels, k * n);
164
-
165
- Rice::Array ret;
166
- ret.push(dstr);
167
- ret.push(lstr);
168
- return ret;
169
- })
170
- .define_method(
171
- "save",
172
- *[](faiss::IndexBinary &self, const char *fname) {
173
- faiss::write_index_binary(&self, fname);
174
- })
175
- .define_singleton_method(
176
- "load",
177
- *[](const char *fname) {
178
- return faiss::read_index_binary(fname);
179
- });
180
-
181
- Rice::define_class_under<faiss::IndexFlatL2, faiss::Index>(rb_mFaiss, "IndexFlatL2")
182
- .define_constructor(Rice::Constructor<faiss::IndexFlatL2, int64_t>());
183
-
184
- Rice::define_class_under<faiss::IndexFlatIP, faiss::Index>(rb_mFaiss, "IndexFlatIP")
185
- .define_constructor(Rice::Constructor<faiss::IndexFlatIP, int64_t>());
186
-
187
- Rice::define_class_under<faiss::IndexHNSWFlat, faiss::Index>(rb_mFaiss, "IndexHNSWFlat")
188
- .define_constructor(Rice::Constructor<faiss::IndexHNSWFlat, int, int>());
189
-
190
- Rice::define_class_under<faiss::IndexIVFFlat, faiss::Index>(rb_mFaiss, "IndexIVFFlat")
191
- .define_constructor(Rice::Constructor<faiss::IndexIVFFlat, faiss::Index*, size_t, size_t>());
192
-
193
- Rice::define_class_under<faiss::IndexLSH, faiss::Index>(rb_mFaiss, "IndexLSH")
194
- .define_constructor(Rice::Constructor<faiss::IndexLSH, int64_t, int>());
195
-
196
- Rice::define_class_under<faiss::IndexScalarQuantizer, faiss::Index>(rb_mFaiss, "IndexScalarQuantizer")
197
- .define_constructor(Rice::Constructor<faiss::IndexScalarQuantizer, int, faiss::ScalarQuantizer::QuantizerType>());
198
-
199
- Rice::define_class_under<faiss::IndexPQ, faiss::Index>(rb_mFaiss, "IndexPQ")
200
- .define_constructor(Rice::Constructor<faiss::IndexPQ, int, size_t, size_t>());
201
-
202
- Rice::define_class_under<faiss::IndexIVFScalarQuantizer, faiss::Index>(rb_mFaiss, "IndexIVFScalarQuantizer")
203
- .define_constructor(Rice::Constructor<faiss::IndexIVFScalarQuantizer, faiss::Index*, size_t, size_t, faiss::ScalarQuantizer::QuantizerType>());
204
-
205
- Rice::define_class_under<faiss::IndexIVFPQ, faiss::Index>(rb_mFaiss, "IndexIVFPQ")
206
- .define_constructor(Rice::Constructor<faiss::IndexIVFPQ, faiss::Index*, size_t, size_t, size_t, size_t>());
207
-
208
- Rice::define_class_under<faiss::IndexIVFPQR, faiss::Index>(rb_mFaiss, "IndexIVFPQR")
209
- .define_constructor(Rice::Constructor<faiss::IndexIVFPQR, faiss::Index*, size_t, size_t, size_t, size_t, size_t, size_t>());
210
-
211
- Rice::define_class_under<faiss::IndexBinaryFlat, faiss::IndexBinary>(rb_mFaiss, "IndexBinaryFlat")
212
- .define_constructor(Rice::Constructor<faiss::IndexBinaryFlat, int64_t>());
213
-
214
- Rice::define_class_under<faiss::IndexBinaryIVF, faiss::IndexBinary>(rb_mFaiss, "IndexBinaryIVF")
215
- .define_constructor(Rice::Constructor<faiss::IndexBinaryIVF, faiss::IndexBinary*, size_t, size_t>());
216
-
217
- Rice::define_class_under<faiss::Clustering>(rb_mFaiss, "Kmeans")
218
- .define_constructor(Rice::Constructor<faiss::Clustering, int, int>())
219
- .define_method(
220
- "d",
221
- *[](faiss::Clustering &self) {
222
- return self.d;
223
- })
224
- .define_method(
225
- "k",
226
- *[](faiss::Clustering &self) {
227
- return self.k;
228
- })
229
- .define_method(
230
- "_centroids",
231
- *[](faiss::Clustering &self) {
232
- float *centroids = new float[self.k * self.d];
233
- for (size_t i = 0; i < self.centroids.size(); i++) {
234
- centroids[i] = self.centroids[i];
235
- }
236
- return result(centroids, self.k * self.d);
237
- })
238
- .define_method(
239
- "_train",
240
- *[](faiss::Clustering &self, int64_t n, Rice::Object o, faiss::Index & index) {
241
- const float *x = float_array(o);
242
- self.train(n, x, index);
243
- });
244
-
245
- Rice::define_class_under<faiss::PCAMatrix>(rb_mFaiss, "PCAMatrix")
246
- .define_constructor(Rice::Constructor<faiss::PCAMatrix, int, int>())
247
- .define_method(
248
- "d_in",
249
- *[](faiss::PCAMatrix &self) {
250
- return self.d_in;
251
- })
252
- .define_method(
253
- "d_out",
254
- *[](faiss::PCAMatrix &self) {
255
- return self.d_out;
256
- })
257
- .define_method(
258
- "_train",
259
- *[](faiss::PCAMatrix &self, int64_t n, Rice::Object o) {
260
- const float *x = float_array(o);
261
- self.train(n, x);
262
- })
263
- .define_method(
264
- "_apply",
265
- *[](faiss::PCAMatrix &self, int64_t n, Rice::Object o) {
266
- const float *x = float_array(o);
267
- float* res = self.apply(n, x);
268
- return result(res, n * self.d_out);
269
- });
12
+ auto m = Rice::define_module("Faiss");
270
13
 
271
- Rice::define_class_under<faiss::ProductQuantizer>(rb_mFaiss, "ProductQuantizer")
272
- .define_constructor(Rice::Constructor<faiss::ProductQuantizer, size_t, size_t, size_t>())
273
- .define_method(
274
- "d",
275
- *[](faiss::ProductQuantizer &self) {
276
- return self.d;
277
- })
278
- .define_method(
279
- "m",
280
- *[](faiss::ProductQuantizer &self) {
281
- return self.M;
282
- })
283
- .define_method(
284
- "_train",
285
- *[](faiss::ProductQuantizer &self, int n, Rice::Object o) {
286
- const float *x = float_array(o);
287
- self.train(n, x);
288
- })
289
- .define_method(
290
- "_compute_codes",
291
- *[](faiss::ProductQuantizer &self, int n, Rice::Object o) {
292
- const float *x = float_array(o);
293
- uint8_t *codes = new uint8_t[n * self.M];
294
- self.compute_codes(x, codes, n);
295
- return result(codes, n * self.M);
296
- })
297
- .define_method(
298
- "_decode",
299
- *[](faiss::ProductQuantizer &self, int n, Rice::Object o) {
300
- const uint8_t *codes = uint8_array(o);
301
- float *x = new float[n * self.d];
302
- self.decode(codes, x, n);
303
- return result(x, n * self.d);
304
- })
305
- .define_method(
306
- "save",
307
- *[](faiss::ProductQuantizer &self, const char *fname) {
308
- faiss::write_ProductQuantizer(&self, fname);
309
- })
310
- .define_singleton_method(
311
- "load",
312
- *[](const char *fname) {
313
- return faiss::read_ProductQuantizer(fname);
314
- });
14
+ init_index(m);
15
+ init_index_binary(m);
16
+ init_kmeans(m);
17
+ init_pca_matrix(m);
18
+ init_product_quantizer(m);
315
19
  }
data/ext/faiss/extconf.rb CHANGED
@@ -4,12 +4,12 @@ abort "BLAS not found" unless have_library("blas")
4
4
  abort "LAPACK not found" unless have_library("lapack")
5
5
  abort "OpenMP not found" unless have_library("omp") || have_library("gomp")
6
6
 
7
- $CXXFLAGS << " -std=c++11 -march=native -DFINTEGER=int"
7
+ $CXXFLAGS << " -std=c++11 -DFINTEGER=int " << with_config("optflags", "-march=native")
8
8
 
9
9
  ext = File.expand_path(".", __dir__)
10
- vendor = File.expand_path("../../vendor", __dir__)
10
+ vendor = File.expand_path("../../vendor/faiss", __dir__)
11
11
 
12
- $srcs = Dir["{#{ext},#{vendor}/faiss,#{vendor}/faiss/impl,#{vendor}/faiss/utils}/*.{cpp}"]
12
+ $srcs = Dir["{#{ext},#{vendor}/faiss,#{vendor}/faiss/{impl,invlists,utils}}/*.{cpp}"]
13
13
  $objs = $srcs.map { |v| v.sub(/cpp\z/, "o") }
14
14
  $INCFLAGS << " -I#{vendor}"
15
15
  $VPATH << vendor