faiss 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (293) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/LICENSE.txt +1 -1
  4. data/lib/faiss/version.rb +1 -1
  5. data/vendor/faiss/faiss/AutoTune.cpp +2 -2
  6. data/vendor/faiss/faiss/AutoTune.h +3 -3
  7. data/vendor/faiss/faiss/Clustering.cpp +37 -6
  8. data/vendor/faiss/faiss/Clustering.h +12 -3
  9. data/vendor/faiss/faiss/IVFlib.cpp +6 -3
  10. data/vendor/faiss/faiss/IVFlib.h +2 -2
  11. data/vendor/faiss/faiss/Index.cpp +6 -2
  12. data/vendor/faiss/faiss/Index.h +30 -8
  13. data/vendor/faiss/faiss/Index2Layer.cpp +2 -2
  14. data/vendor/faiss/faiss/Index2Layer.h +2 -2
  15. data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +7 -7
  16. data/vendor/faiss/faiss/IndexAdditiveQuantizer.h +2 -2
  17. data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +14 -16
  18. data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +2 -2
  19. data/vendor/faiss/faiss/IndexBinary.cpp +13 -2
  20. data/vendor/faiss/faiss/IndexBinary.h +8 -2
  21. data/vendor/faiss/faiss/IndexBinaryFlat.cpp +2 -3
  22. data/vendor/faiss/faiss/IndexBinaryFlat.h +2 -2
  23. data/vendor/faiss/faiss/IndexBinaryFromFloat.cpp +2 -2
  24. data/vendor/faiss/faiss/IndexBinaryFromFloat.h +2 -2
  25. data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +2 -7
  26. data/vendor/faiss/faiss/IndexBinaryHNSW.h +3 -3
  27. data/vendor/faiss/faiss/IndexBinaryHash.cpp +2 -3
  28. data/vendor/faiss/faiss/IndexBinaryHash.h +2 -2
  29. data/vendor/faiss/faiss/IndexBinaryIVF.cpp +3 -3
  30. data/vendor/faiss/faiss/IndexBinaryIVF.h +2 -2
  31. data/vendor/faiss/faiss/IndexFastScan.cpp +32 -18
  32. data/vendor/faiss/faiss/IndexFastScan.h +11 -2
  33. data/vendor/faiss/faiss/IndexFlat.cpp +13 -10
  34. data/vendor/faiss/faiss/IndexFlat.h +2 -2
  35. data/vendor/faiss/faiss/IndexFlatCodes.cpp +170 -7
  36. data/vendor/faiss/faiss/IndexFlatCodes.h +25 -5
  37. data/vendor/faiss/faiss/IndexHNSW.cpp +156 -96
  38. data/vendor/faiss/faiss/IndexHNSW.h +54 -5
  39. data/vendor/faiss/faiss/IndexIDMap.cpp +19 -3
  40. data/vendor/faiss/faiss/IndexIDMap.h +5 -2
  41. data/vendor/faiss/faiss/IndexIVF.cpp +5 -6
  42. data/vendor/faiss/faiss/IndexIVF.h +13 -4
  43. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +21 -7
  44. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.h +5 -2
  45. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +3 -14
  46. data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +2 -4
  47. data/vendor/faiss/faiss/IndexIVFFastScan.cpp +201 -91
  48. data/vendor/faiss/faiss/IndexIVFFastScan.h +33 -9
  49. data/vendor/faiss/faiss/IndexIVFFlat.cpp +2 -2
  50. data/vendor/faiss/faiss/IndexIVFFlat.h +2 -2
  51. data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.cpp +2 -2
  52. data/vendor/faiss/faiss/IndexIVFIndependentQuantizer.h +2 -2
  53. data/vendor/faiss/faiss/IndexIVFPQ.cpp +3 -6
  54. data/vendor/faiss/faiss/IndexIVFPQ.h +2 -2
  55. data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +7 -14
  56. data/vendor/faiss/faiss/IndexIVFPQFastScan.h +2 -4
  57. data/vendor/faiss/faiss/IndexIVFPQR.cpp +2 -2
  58. data/vendor/faiss/faiss/IndexIVFPQR.h +2 -2
  59. data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +2 -3
  60. data/vendor/faiss/faiss/IndexIVFSpectralHash.h +2 -2
  61. data/vendor/faiss/faiss/IndexLSH.cpp +2 -3
  62. data/vendor/faiss/faiss/IndexLSH.h +2 -2
  63. data/vendor/faiss/faiss/IndexLattice.cpp +3 -21
  64. data/vendor/faiss/faiss/IndexLattice.h +5 -24
  65. data/vendor/faiss/faiss/IndexNNDescent.cpp +2 -31
  66. data/vendor/faiss/faiss/IndexNNDescent.h +3 -3
  67. data/vendor/faiss/faiss/IndexNSG.cpp +2 -5
  68. data/vendor/faiss/faiss/IndexNSG.h +3 -3
  69. data/vendor/faiss/faiss/IndexNeuralNetCodec.cpp +56 -0
  70. data/vendor/faiss/faiss/IndexNeuralNetCodec.h +49 -0
  71. data/vendor/faiss/faiss/IndexPQ.cpp +26 -26
  72. data/vendor/faiss/faiss/IndexPQ.h +2 -2
  73. data/vendor/faiss/faiss/IndexPQFastScan.cpp +2 -5
  74. data/vendor/faiss/faiss/IndexPQFastScan.h +2 -11
  75. data/vendor/faiss/faiss/IndexPreTransform.cpp +2 -2
  76. data/vendor/faiss/faiss/IndexPreTransform.h +3 -3
  77. data/vendor/faiss/faiss/IndexRefine.cpp +46 -9
  78. data/vendor/faiss/faiss/IndexRefine.h +9 -2
  79. data/vendor/faiss/faiss/IndexReplicas.cpp +2 -2
  80. data/vendor/faiss/faiss/IndexReplicas.h +2 -2
  81. data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +2 -2
  82. data/vendor/faiss/faiss/IndexRowwiseMinMax.h +2 -2
  83. data/vendor/faiss/faiss/IndexScalarQuantizer.cpp +5 -4
  84. data/vendor/faiss/faiss/IndexScalarQuantizer.h +2 -2
  85. data/vendor/faiss/faiss/IndexShards.cpp +2 -2
  86. data/vendor/faiss/faiss/IndexShards.h +2 -2
  87. data/vendor/faiss/faiss/IndexShardsIVF.cpp +2 -2
  88. data/vendor/faiss/faiss/IndexShardsIVF.h +2 -2
  89. data/vendor/faiss/faiss/MatrixStats.cpp +2 -2
  90. data/vendor/faiss/faiss/MatrixStats.h +2 -2
  91. data/vendor/faiss/faiss/MetaIndexes.cpp +2 -3
  92. data/vendor/faiss/faiss/MetaIndexes.h +2 -2
  93. data/vendor/faiss/faiss/MetricType.h +9 -4
  94. data/vendor/faiss/faiss/VectorTransform.cpp +2 -2
  95. data/vendor/faiss/faiss/VectorTransform.h +2 -2
  96. data/vendor/faiss/faiss/clone_index.cpp +2 -2
  97. data/vendor/faiss/faiss/clone_index.h +2 -2
  98. data/vendor/faiss/faiss/cppcontrib/SaDecodeKernels.h +2 -2
  99. data/vendor/faiss/faiss/cppcontrib/detail/CoarseBitType.h +2 -2
  100. data/vendor/faiss/faiss/cppcontrib/detail/UintReader.h +97 -19
  101. data/vendor/faiss/faiss/cppcontrib/factory_tools.cpp +192 -0
  102. data/vendor/faiss/faiss/cppcontrib/factory_tools.h +29 -0
  103. data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +2 -2
  104. data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +85 -32
  105. data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-neon-inl.h +2 -2
  106. data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMax-inl.h +2 -2
  107. data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMaxFP16-inl.h +2 -2
  108. data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +2 -2
  109. data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +2 -2
  110. data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-neon-inl.h +2 -2
  111. data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +2 -5
  112. data/vendor/faiss/faiss/gpu/GpuAutoTune.h +2 -2
  113. data/vendor/faiss/faiss/gpu/GpuCloner.cpp +45 -13
  114. data/vendor/faiss/faiss/gpu/GpuCloner.h +2 -2
  115. data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +12 -6
  116. data/vendor/faiss/faiss/gpu/GpuDistance.h +11 -7
  117. data/vendor/faiss/faiss/gpu/GpuFaissAssert.h +3 -3
  118. data/vendor/faiss/faiss/gpu/GpuIcmEncoder.h +2 -2
  119. data/vendor/faiss/faiss/gpu/GpuIndex.h +10 -15
  120. data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +2 -2
  121. data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +285 -0
  122. data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +2 -2
  123. data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +8 -2
  124. data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +4 -2
  125. data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +3 -3
  126. data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +2 -2
  127. data/vendor/faiss/faiss/gpu/GpuIndicesOptions.h +2 -2
  128. data/vendor/faiss/faiss/gpu/GpuResources.cpp +7 -2
  129. data/vendor/faiss/faiss/gpu/GpuResources.h +11 -4
  130. data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +66 -11
  131. data/vendor/faiss/faiss/gpu/StandardGpuResources.h +15 -5
  132. data/vendor/faiss/faiss/gpu/impl/IndexUtils.h +2 -2
  133. data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.cpp +28 -23
  134. data/vendor/faiss/faiss/gpu/impl/InterleavedCodes.h +2 -2
  135. data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +2 -2
  136. data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +2 -2
  137. data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -2
  138. data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +2 -2
  139. data/vendor/faiss/faiss/gpu/perf/PerfClustering.cpp +8 -2
  140. data/vendor/faiss/faiss/gpu/perf/PerfIVFPQAdd.cpp +2 -3
  141. data/vendor/faiss/faiss/gpu/perf/WriteIndex.cpp +2 -2
  142. data/vendor/faiss/faiss/gpu/test/TestCodePacking.cpp +10 -7
  143. data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +2 -2
  144. data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +54 -54
  145. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +144 -77
  146. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +51 -51
  147. data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +2 -2
  148. data/vendor/faiss/faiss/gpu/test/TestGpuMemoryException.cpp +3 -3
  149. data/vendor/faiss/faiss/gpu/test/TestGpuResidualQuantizer.cpp +70 -0
  150. data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +74 -4
  151. data/vendor/faiss/faiss/gpu/test/TestUtils.h +2 -2
  152. data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +3 -3
  153. data/vendor/faiss/faiss/gpu/utils/{RaftUtils.h → CuvsUtils.h} +12 -11
  154. data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +8 -2
  155. data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +2 -2
  156. data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.h +2 -2
  157. data/vendor/faiss/faiss/gpu/utils/StaticUtils.h +2 -2
  158. data/vendor/faiss/faiss/gpu/utils/Timer.cpp +6 -3
  159. data/vendor/faiss/faiss/gpu/utils/Timer.h +3 -3
  160. data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +79 -11
  161. data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +17 -5
  162. data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +27 -2
  163. data/vendor/faiss/faiss/impl/AuxIndexStructures.h +11 -3
  164. data/vendor/faiss/faiss/impl/CodePacker.cpp +2 -2
  165. data/vendor/faiss/faiss/impl/CodePacker.h +2 -2
  166. data/vendor/faiss/faiss/impl/DistanceComputer.h +48 -2
  167. data/vendor/faiss/faiss/impl/FaissAssert.h +6 -4
  168. data/vendor/faiss/faiss/impl/FaissException.cpp +2 -2
  169. data/vendor/faiss/faiss/impl/FaissException.h +2 -3
  170. data/vendor/faiss/faiss/impl/HNSW.cpp +378 -205
  171. data/vendor/faiss/faiss/impl/HNSW.h +55 -24
  172. data/vendor/faiss/faiss/impl/IDSelector.cpp +2 -2
  173. data/vendor/faiss/faiss/impl/IDSelector.h +2 -2
  174. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +10 -10
  175. data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +2 -2
  176. data/vendor/faiss/faiss/impl/LookupTableScaler.h +36 -2
  177. data/vendor/faiss/faiss/impl/NNDescent.cpp +15 -10
  178. data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
  179. data/vendor/faiss/faiss/impl/NSG.cpp +26 -49
  180. data/vendor/faiss/faiss/impl/NSG.h +20 -8
  181. data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +2 -2
  182. data/vendor/faiss/faiss/impl/PolysemousTraining.h +2 -2
  183. data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +2 -4
  184. data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +2 -2
  185. data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +2 -2
  186. data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +3 -2
  187. data/vendor/faiss/faiss/impl/ProductQuantizer.h +7 -3
  188. data/vendor/faiss/faiss/impl/Quantizer.h +2 -2
  189. data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +2 -36
  190. data/vendor/faiss/faiss/impl/ResidualQuantizer.h +3 -13
  191. data/vendor/faiss/faiss/impl/ResultHandler.h +153 -34
  192. data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +721 -104
  193. data/vendor/faiss/faiss/impl/ScalarQuantizer.h +5 -2
  194. data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +2 -2
  195. data/vendor/faiss/faiss/impl/ThreadedIndex.h +2 -2
  196. data/vendor/faiss/faiss/impl/code_distance/code_distance-avx2.h +7 -2
  197. data/vendor/faiss/faiss/impl/code_distance/code_distance-avx512.h +248 -0
  198. data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +2 -2
  199. data/vendor/faiss/faiss/impl/code_distance/code_distance-sve.h +440 -0
  200. data/vendor/faiss/faiss/impl/code_distance/code_distance.h +55 -2
  201. data/vendor/faiss/faiss/impl/index_read.cpp +31 -20
  202. data/vendor/faiss/faiss/impl/index_read_utils.h +37 -0
  203. data/vendor/faiss/faiss/impl/index_write.cpp +30 -16
  204. data/vendor/faiss/faiss/impl/io.cpp +15 -7
  205. data/vendor/faiss/faiss/impl/io.h +6 -6
  206. data/vendor/faiss/faiss/impl/io_macros.h +8 -9
  207. data/vendor/faiss/faiss/impl/kmeans1d.cpp +2 -3
  208. data/vendor/faiss/faiss/impl/kmeans1d.h +2 -2
  209. data/vendor/faiss/faiss/impl/lattice_Zn.cpp +2 -3
  210. data/vendor/faiss/faiss/impl/lattice_Zn.h +2 -2
  211. data/vendor/faiss/faiss/impl/platform_macros.h +34 -2
  212. data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +13 -2
  213. data/vendor/faiss/faiss/impl/pq4_fast_scan.h +20 -2
  214. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_1.cpp +3 -3
  215. data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +450 -3
  216. data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.cpp +8 -8
  217. data/vendor/faiss/faiss/impl/residual_quantizer_encode_steps.h +3 -3
  218. data/vendor/faiss/faiss/impl/simd_result_handlers.h +151 -67
  219. data/vendor/faiss/faiss/index_factory.cpp +51 -34
  220. data/vendor/faiss/faiss/index_factory.h +2 -2
  221. data/vendor/faiss/faiss/index_io.h +14 -7
  222. data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +30 -10
  223. data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +5 -2
  224. data/vendor/faiss/faiss/invlists/DirectMap.cpp +11 -3
  225. data/vendor/faiss/faiss/invlists/DirectMap.h +2 -2
  226. data/vendor/faiss/faiss/invlists/InvertedLists.cpp +57 -19
  227. data/vendor/faiss/faiss/invlists/InvertedLists.h +20 -11
  228. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.cpp +2 -2
  229. data/vendor/faiss/faiss/invlists/InvertedListsIOHook.h +2 -2
  230. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +23 -9
  231. data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +4 -3
  232. data/vendor/faiss/faiss/python/python_callbacks.cpp +5 -5
  233. data/vendor/faiss/faiss/python/python_callbacks.h +2 -2
  234. data/vendor/faiss/faiss/utils/AlignedTable.h +5 -3
  235. data/vendor/faiss/faiss/utils/Heap.cpp +2 -2
  236. data/vendor/faiss/faiss/utils/Heap.h +107 -2
  237. data/vendor/faiss/faiss/utils/NeuralNet.cpp +346 -0
  238. data/vendor/faiss/faiss/utils/NeuralNet.h +147 -0
  239. data/vendor/faiss/faiss/utils/WorkerThread.cpp +2 -2
  240. data/vendor/faiss/faiss/utils/WorkerThread.h +2 -2
  241. data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +2 -2
  242. data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +2 -2
  243. data/vendor/faiss/faiss/utils/approx_topk/generic.h +2 -2
  244. data/vendor/faiss/faiss/utils/approx_topk/mode.h +2 -2
  245. data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +2 -2
  246. data/vendor/faiss/faiss/utils/bf16.h +36 -0
  247. data/vendor/faiss/faiss/utils/distances.cpp +249 -90
  248. data/vendor/faiss/faiss/utils/distances.h +8 -8
  249. data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +2 -2
  250. data/vendor/faiss/faiss/utils/distances_fused/avx512.h +2 -2
  251. data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +2 -2
  252. data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +2 -2
  253. data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +2 -2
  254. data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.h +2 -2
  255. data/vendor/faiss/faiss/utils/distances_simd.cpp +1543 -56
  256. data/vendor/faiss/faiss/utils/extra_distances-inl.h +72 -2
  257. data/vendor/faiss/faiss/utils/extra_distances.cpp +87 -140
  258. data/vendor/faiss/faiss/utils/extra_distances.h +5 -4
  259. data/vendor/faiss/faiss/utils/fp16-arm.h +2 -2
  260. data/vendor/faiss/faiss/utils/fp16-fp16c.h +2 -2
  261. data/vendor/faiss/faiss/utils/fp16-inl.h +2 -2
  262. data/vendor/faiss/faiss/utils/fp16.h +2 -2
  263. data/vendor/faiss/faiss/utils/hamming-inl.h +2 -2
  264. data/vendor/faiss/faiss/utils/hamming.cpp +3 -4
  265. data/vendor/faiss/faiss/utils/hamming.h +2 -2
  266. data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +2 -2
  267. data/vendor/faiss/faiss/utils/hamming_distance/avx512-inl.h +490 -0
  268. data/vendor/faiss/faiss/utils/hamming_distance/common.h +2 -2
  269. data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +6 -3
  270. data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +7 -3
  271. data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +5 -5
  272. data/vendor/faiss/faiss/utils/ordered_key_value.h +2 -2
  273. data/vendor/faiss/faiss/utils/partitioning.cpp +2 -2
  274. data/vendor/faiss/faiss/utils/partitioning.h +2 -2
  275. data/vendor/faiss/faiss/utils/prefetch.h +2 -2
  276. data/vendor/faiss/faiss/utils/quantize_lut.cpp +2 -2
  277. data/vendor/faiss/faiss/utils/quantize_lut.h +2 -2
  278. data/vendor/faiss/faiss/utils/random.cpp +45 -2
  279. data/vendor/faiss/faiss/utils/random.h +27 -2
  280. data/vendor/faiss/faiss/utils/simdlib.h +12 -3
  281. data/vendor/faiss/faiss/utils/simdlib_avx2.h +2 -2
  282. data/vendor/faiss/faiss/utils/simdlib_avx512.h +296 -0
  283. data/vendor/faiss/faiss/utils/simdlib_emulated.h +2 -2
  284. data/vendor/faiss/faiss/utils/simdlib_neon.h +7 -4
  285. data/vendor/faiss/faiss/utils/simdlib_ppc64.h +1084 -0
  286. data/vendor/faiss/faiss/utils/sorting.cpp +2 -2
  287. data/vendor/faiss/faiss/utils/sorting.h +2 -2
  288. data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +2 -2
  289. data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +176 -0
  290. data/vendor/faiss/faiss/utils/utils.cpp +17 -10
  291. data/vendor/faiss/faiss/utils/utils.h +7 -3
  292. metadata +22 -11
  293. data/vendor/faiss/faiss/impl/code_distance/code_distance_avx512.h +0 -102
@@ -1,12 +1,10 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- // -*- c++ -*-
9
-
10
8
  #include <faiss/index_io.h>
11
9
 
12
10
  #include <faiss/impl/io.h>
@@ -15,13 +13,9 @@
15
13
  #include <cstdio>
16
14
  #include <cstdlib>
17
15
 
18
- #include <sys/stat.h>
19
- #include <sys/types.h>
20
-
21
16
  #include <faiss/invlists/InvertedListsIOHook.h>
22
17
 
23
18
  #include <faiss/impl/FaissAssert.h>
24
- #include <faiss/impl/io.h>
25
19
  #include <faiss/impl/io_macros.h>
26
20
  #include <faiss/utils/hamming.h>
27
21
 
@@ -314,7 +308,11 @@ static void write_HNSW(const HNSW* hnsw, IOWriter* f) {
314
308
  WRITE1(hnsw->max_level);
315
309
  WRITE1(hnsw->efConstruction);
316
310
  WRITE1(hnsw->efSearch);
317
- WRITE1(hnsw->upper_beam);
311
+
312
+ // // deprecated field
313
+ // WRITE1(hnsw->upper_beam);
314
+ constexpr int tmp_upper_beam = 1;
315
+ WRITE1(tmp_upper_beam);
318
316
  }
319
317
 
320
318
  static void write_NSG(const NSG* nsg, IOWriter* f) {
@@ -390,8 +388,12 @@ static void write_ivf_header(const IndexIVF* ivf, IOWriter* f) {
390
388
  write_direct_map(&ivf->direct_map, f);
391
389
  }
392
390
 
393
- void write_index(const Index* idx, IOWriter* f) {
394
- if (const IndexFlat* idxf = dynamic_cast<const IndexFlat*>(idx)) {
391
+ void write_index(const Index* idx, IOWriter* f, int io_flags) {
392
+ if (idx == nullptr) {
393
+ // eg. for a storage component of HNSW that is set to nullptr
394
+ uint32_t h = fourcc("null");
395
+ WRITE1(h);
396
+ } else if (const IndexFlat* idxf = dynamic_cast<const IndexFlat*>(idx)) {
395
397
  uint32_t h =
396
398
  fourcc(idxf->metric_type == METRIC_INNER_PRODUCT ? "IxFI"
397
399
  : idxf->metric_type == METRIC_L2 ? "IxF2"
@@ -760,12 +762,24 @@ void write_index(const Index* idx, IOWriter* f) {
760
762
  : dynamic_cast<const IndexHNSWPQ*>(idx) ? fourcc("IHNp")
761
763
  : dynamic_cast<const IndexHNSWSQ*>(idx) ? fourcc("IHNs")
762
764
  : dynamic_cast<const IndexHNSW2Level*>(idx) ? fourcc("IHN2")
765
+ : dynamic_cast<const IndexHNSWCagra*>(idx) ? fourcc("IHNc")
763
766
  : 0;
764
767
  FAISS_THROW_IF_NOT(h != 0);
765
768
  WRITE1(h);
766
769
  write_index_header(idxhnsw, f);
770
+ if (h == fourcc("IHNc")) {
771
+ WRITE1(idxhnsw->keep_max_size_level0);
772
+ auto idx_hnsw_cagra = dynamic_cast<const IndexHNSWCagra*>(idxhnsw);
773
+ WRITE1(idx_hnsw_cagra->base_level_only);
774
+ WRITE1(idx_hnsw_cagra->num_base_level_search_entrypoints);
775
+ }
767
776
  write_HNSW(&idxhnsw->hnsw, f);
768
- write_index(idxhnsw->storage, f);
777
+ if (io_flags & IO_FLAG_SKIP_STORAGE) {
778
+ uint32_t n4 = fourcc("null");
779
+ WRITE1(n4);
780
+ } else {
781
+ write_index(idxhnsw->storage, f);
782
+ }
769
783
  } else if (const IndexNSG* idxnsg = dynamic_cast<const IndexNSG*>(idx)) {
770
784
  uint32_t h = dynamic_cast<const IndexNSGFlat*>(idx) ? fourcc("INSf")
771
785
  : dynamic_cast<const IndexNSGPQ*>(idx) ? fourcc("INSp")
@@ -841,14 +855,14 @@ void write_index(const Index* idx, IOWriter* f) {
841
855
  }
842
856
  }
843
857
 
844
- void write_index(const Index* idx, FILE* f) {
858
+ void write_index(const Index* idx, FILE* f, int io_flags) {
845
859
  FileIOWriter writer(f);
846
- write_index(idx, &writer);
860
+ write_index(idx, &writer, io_flags);
847
861
  }
848
862
 
849
- void write_index(const Index* idx, const char* fname) {
863
+ void write_index(const Index* idx, const char* fname, int io_flags) {
850
864
  FileIOWriter writer(fname);
851
- write_index(idx, &writer);
865
+ write_index(idx, &writer, io_flags);
852
866
  }
853
867
 
854
868
  void write_VectorTransform(const VectorTransform* vt, const char* fname) {
@@ -1,5 +1,5 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -20,11 +20,11 @@ namespace faiss {
20
20
  * IO functions
21
21
  ***********************************************************************/
22
22
 
23
- int IOReader::fileno() {
23
+ int IOReader::filedescriptor() {
24
24
  FAISS_THROW_MSG("IOReader does not support memory mapping");
25
25
  }
26
26
 
27
- int IOWriter::fileno() {
27
+ int IOWriter::filedescriptor() {
28
28
  FAISS_THROW_MSG("IOWriter does not support memory mapping");
29
29
  }
30
30
 
@@ -85,8 +85,12 @@ size_t FileIOReader::operator()(void* ptr, size_t size, size_t nitems) {
85
85
  return fread(ptr, size, nitems, f);
86
86
  }
87
87
 
88
- int FileIOReader::fileno() {
88
+ int FileIOReader::filedescriptor() {
89
+ #ifdef _AIX
90
+ return fileno(f);
91
+ #else
89
92
  return ::fileno(f);
93
+ #endif
90
94
  }
91
95
 
92
96
  FileIOWriter::FileIOWriter(FILE* wf) : f(wf) {}
@@ -116,8 +120,12 @@ size_t FileIOWriter::operator()(const void* ptr, size_t size, size_t nitems) {
116
120
  return fwrite(ptr, size, nitems, f);
117
121
  }
118
122
 
119
- int FileIOWriter::fileno() {
123
+ int FileIOWriter::filedescriptor() {
124
+ #ifdef _AIX
125
+ return fileno(f);
126
+ #else
120
127
  return ::fileno(f);
128
+ #endif
121
129
  }
122
130
 
123
131
  /***********************************************************************
@@ -259,7 +267,7 @@ std::string fourcc_inv_printable(uint32_t x) {
259
267
  str += c;
260
268
  } else {
261
269
  char buf[10];
262
- sprintf(buf, "\\x%02x", c);
270
+ snprintf(buf, sizeof(buf), "\\x%02x", c);
263
271
  str += buf;
264
272
  }
265
273
  }
@@ -1,5 +1,5 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -32,7 +32,7 @@ struct IOReader {
32
32
  virtual size_t operator()(void* ptr, size_t size, size_t nitems) = 0;
33
33
 
34
34
  // return a file number that can be memory-mapped
35
- virtual int fileno();
35
+ virtual int filedescriptor();
36
36
 
37
37
  virtual ~IOReader() {}
38
38
  };
@@ -45,7 +45,7 @@ struct IOWriter {
45
45
  virtual size_t operator()(const void* ptr, size_t size, size_t nitems) = 0;
46
46
 
47
47
  // return a file number that can be memory-mapped
48
- virtual int fileno();
48
+ virtual int filedescriptor();
49
49
 
50
50
  virtual ~IOWriter() noexcept(false) {}
51
51
  };
@@ -73,7 +73,7 @@ struct FileIOReader : IOReader {
73
73
 
74
74
  size_t operator()(void* ptr, size_t size, size_t nitems) override;
75
75
 
76
- int fileno() override;
76
+ int filedescriptor() override;
77
77
  };
78
78
 
79
79
  struct FileIOWriter : IOWriter {
@@ -88,7 +88,7 @@ struct FileIOWriter : IOWriter {
88
88
 
89
89
  size_t operator()(const void* ptr, size_t size, size_t nitems) override;
90
90
 
91
- int fileno() override;
91
+ int filedescriptor() override;
92
92
  };
93
93
 
94
94
  /*******************************************************
@@ -1,5 +1,5 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -29,6 +29,12 @@
29
29
 
30
30
  #define READ1(x) READANDCHECK(&(x), 1)
31
31
 
32
+ #define READ1_DUMMY(x_type) \
33
+ { \
34
+ x_type x = {}; \
35
+ READ1(x); \
36
+ }
37
+
32
38
  // will fail if we write 256G of data at once...
33
39
  #define READVECTOR(vec) \
34
40
  { \
@@ -39,13 +45,6 @@
39
45
  READANDCHECK((vec).data(), size); \
40
46
  }
41
47
 
42
- #define READSTRING(s) \
43
- { \
44
- size_t size = (s).size(); \
45
- WRITEANDCHECK(&size, 1); \
46
- WRITEANDCHECK((s).c_str(), size); \
47
- }
48
-
49
48
  #define WRITEANDCHECK(ptr, n) \
50
49
  { \
51
50
  size_t ret = (*f)(ptr, sizeof(*(ptr)), n); \
@@ -1,12 +1,11 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
8
  #include <algorithm>
9
- #include <cstdint>
10
9
  #include <cstring>
11
10
  #include <functional>
12
11
  #include <numeric>
@@ -1,5 +1,5 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -16,7 +16,6 @@
16
16
 
17
17
  #include <algorithm>
18
18
  #include <queue>
19
- #include <unordered_map>
20
19
  #include <unordered_set>
21
20
 
22
21
  #include <faiss/impl/platform_macros.h>
@@ -1,5 +1,5 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -39,6 +39,7 @@
39
39
  // redefine the GCC intrinsics with Windows equivalents
40
40
 
41
41
  #include <intrin.h>
42
+ #include <limits.h>
42
43
 
43
44
  #ifndef __clang__
44
45
  inline int __builtin_ctzll(uint64_t x) {
@@ -59,7 +60,16 @@ inline int __builtin_ctz(unsigned long x) {
59
60
 
60
61
  #ifndef __clang__
61
62
  inline int __builtin_clzll(uint64_t x) {
63
+ #if defined(_M_X64) || defined(__x86_64__)
62
64
  return (int)__lzcnt64(x);
65
+ #elif defined(_M_ARM64)
66
+ unsigned long index;
67
+ int count = sizeof(uint64_t) * CHAR_BIT;
68
+ if (_BitScanReverse64(&index, x)) {
69
+ count = count - 1 - index;
70
+ }
71
+ return count;
72
+ #endif
63
73
  }
64
74
  #endif
65
75
 
@@ -127,6 +137,13 @@ inline int __builtin_clzll(uint64_t x) {
127
137
  __pragma(float_control(precise, off, push))
128
138
  #define FAISS_PRAGMA_IMPRECISE_FUNCTION_END __pragma(float_control(pop))
129
139
  #elif defined(__clang__)
140
+ #if defined(__PPC__)
141
+ #define FAISS_PRAGMA_IMPRECISE_LOOP \
142
+ _Pragma("clang loop vectorize_width(4) interleave_count(8)")
143
+ #define FAISS_PRAGMA_IMPRECISE_FUNCTION_BEGIN \
144
+ _Pragma("float_control(precise, off, push)")
145
+ #define FAISS_PRAGMA_IMPRECISE_FUNCTION_END _Pragma("float_control(pop)")
146
+ #else
130
147
  #define FAISS_PRAGMA_IMPRECISE_LOOP \
131
148
  _Pragma("clang loop vectorize(enable) interleave(enable)")
132
149
 
@@ -144,6 +161,7 @@ inline int __builtin_clzll(uint64_t x) {
144
161
  #define FAISS_PRAGMA_IMPRECISE_FUNCTION_BEGIN
145
162
  #define FAISS_PRAGMA_IMPRECISE_FUNCTION_END
146
163
  #endif
164
+ #endif
147
165
  #elif defined(__GNUC__)
148
166
  // Unfortunately, GCC does not provide a pragma for detecting it.
149
167
  // So, we have to stick to GNUC, which is defined by MANY compilers.
@@ -165,3 +183,17 @@ inline int __builtin_clzll(uint64_t x) {
165
183
  #endif
166
184
 
167
185
  // clang-format on
186
+
187
+ /*******************************************************
188
+ * BIGENDIAN specific macros
189
+ *******************************************************/
190
+ #if !defined(_MSC_VER) && \
191
+ (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
192
+ #define FAISS_BIG_ENDIAN
193
+ #endif
194
+
195
+ #define Swap2Bytes(val) ((((val) >> 8) & 0x00FF) | (((val) << 8) & 0xFF00))
196
+
197
+ #define Swap4Bytes(val) \
198
+ ((((val) >> 24) & 0x000000FF) | (((val) >> 8) & 0x0000FF00) | \
199
+ (((val) << 8) & 0x00FF0000) | (((val) << 24) & 0xFF000000))
@@ -1,11 +1,12 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
8
  #include <faiss/impl/FaissAssert.h>
9
+ #include <faiss/impl/platform_macros.h>
9
10
  #include <faiss/impl/pq4_fast_scan.h>
10
11
  #include <faiss/impl/simd_result_handlers.h>
11
12
 
@@ -58,8 +59,13 @@ void pq4_pack_codes(
58
59
  return;
59
60
  }
60
61
  memset(blocks, 0, nb * nsq / 2);
62
+ #ifdef FAISS_BIG_ENDIAN
63
+ const uint8_t perm0[16] = {
64
+ 8, 0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7};
65
+ #else
61
66
  const uint8_t perm0[16] = {
62
67
  0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15};
68
+ #endif
63
69
 
64
70
  uint8_t* codes2 = blocks;
65
71
  for (size_t i0 = 0; i0 < nb; i0 += bbs) {
@@ -93,8 +99,13 @@ void pq4_pack_codes_range(
93
99
  size_t bbs,
94
100
  size_t nsq,
95
101
  uint8_t* blocks) {
102
+ #ifdef FAISS_BIG_ENDIAN
103
+ const uint8_t perm0[16] = {
104
+ 8, 0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7};
105
+ #else
96
106
  const uint8_t perm0[16] = {
97
107
  0, 8, 1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15};
108
+ #endif
98
109
 
99
110
  // range of affected blocks
100
111
  size_t block0 = i0 / bbs;
@@ -1,5 +1,5 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -189,4 +189,22 @@ void pq4_accumulate_loop_qbs(
189
189
  SIMDResultHandler& res,
190
190
  const NormTableScaler* scaler = nullptr);
191
191
 
192
+ /** Wrapper of pq4_accumulate_loop_qbs using simple StoreResultHandler
193
+ * and DummyScaler
194
+ *
195
+ * @param nq number of queries
196
+ * @param ntotal2 number of database elements (multiple of 32)
197
+ * @param nsq number of sub-quantizers (muliple of 2)
198
+ * @param codes packed codes array
199
+ * @param LUT packed look-up table
200
+ * @param accu array to store the results
201
+ */
202
+ void accumulate_to_mem(
203
+ int nq,
204
+ size_t ntotal2,
205
+ int nsq,
206
+ const uint8_t* codes,
207
+ const uint8_t* LUT,
208
+ uint16_t* accu);
209
+
192
210
  } // namespace faiss
@@ -1,5 +1,5 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -217,7 +217,7 @@ void pq4_accumulate_loop(
217
217
  SIMDResultHandler& res,
218
218
  const NormTableScaler* scaler) {
219
219
  Run_pq4_accumulate_loop consumer;
220
- dispatch_SIMDResultHanlder(
220
+ dispatch_SIMDResultHandler(
221
221
  res, consumer, nq, nb, bbs, nsq, codes, LUT, scaler);
222
222
  }
223
223