faiss 0.3.1 → 0.3.3

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.
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,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.
@@ -17,11 +17,7 @@
17
17
  #include <faiss/impl/IDSelector.h>
18
18
  #include <faiss/impl/LookupTableScaler.h>
19
19
  #include <faiss/impl/ResultHandler.h>
20
- #include <faiss/utils/distances.h>
21
- #include <faiss/utils/extra_distances.h>
22
20
  #include <faiss/utils/hamming.h>
23
- #include <faiss/utils/random.h>
24
- #include <faiss/utils/utils.h>
25
21
 
26
22
  #include <faiss/impl/pq4_fast_scan.h>
27
23
  #include <faiss/impl/simd_result_handlers.h>
@@ -37,22 +33,22 @@ inline size_t roundup(size_t a, size_t b) {
37
33
 
38
34
  void IndexFastScan::init_fastscan(
39
35
  int d,
40
- size_t M_2,
41
- size_t nbits_2,
36
+ size_t M_init,
37
+ size_t nbits_init,
42
38
  MetricType metric,
43
39
  int bbs) {
44
- FAISS_THROW_IF_NOT(nbits_2 == 4);
40
+ FAISS_THROW_IF_NOT(nbits_init == 4);
45
41
  FAISS_THROW_IF_NOT(bbs % 32 == 0);
46
42
  this->d = d;
47
- this->M = M_2;
48
- this->nbits = nbits_2;
43
+ this->M = M_init;
44
+ this->nbits = nbits_init;
49
45
  this->metric_type = metric;
50
46
  this->bbs = bbs;
51
- ksub = (1 << nbits_2);
47
+ ksub = (1 << nbits_init);
52
48
 
53
- code_size = (M_2 * nbits_2 + 7) / 8;
49
+ code_size = (M_init * nbits_init + 7) / 8;
54
50
  ntotal = ntotal2 = 0;
55
- M2 = roundup(M_2, 2);
51
+ M2 = roundup(M_init, 2);
56
52
  is_trained = false;
57
53
  }
58
54
 
@@ -189,6 +185,7 @@ void estimators_from_tables_generic(
189
185
  dt += index.ksub;
190
186
  }
191
187
  }
188
+
192
189
  if (C::cmp(heap_dis[0], dis)) {
193
190
  heap_pop<C>(k, heap_dis, heap_ids);
194
191
  heap_push<C>(k, heap_dis, heap_ids, dis, j);
@@ -203,17 +200,18 @@ ResultHandlerCompare<C, false>* make_knn_handler(
203
200
  idx_t k,
204
201
  size_t ntotal,
205
202
  float* distances,
206
- idx_t* labels) {
203
+ idx_t* labels,
204
+ const IDSelector* sel = nullptr) {
207
205
  using HeapHC = HeapHandler<C, false>;
208
206
  using ReservoirHC = ReservoirHandler<C, false>;
209
207
  using SingleResultHC = SingleResultHandler<C, false>;
210
208
 
211
209
  if (k == 1) {
212
- return new SingleResultHC(n, ntotal, distances, labels);
210
+ return new SingleResultHC(n, ntotal, distances, labels, sel);
213
211
  } else if (impl % 2 == 0) {
214
- return new HeapHC(n, ntotal, k, distances, labels);
212
+ return new HeapHC(n, ntotal, k, distances, labels, sel);
215
213
  } else /* if (impl % 2 == 1) */ {
216
- return new ReservoirHC(n, ntotal, k, 2 * k, distances, labels);
214
+ return new ReservoirHC(n, ntotal, k, 2 * k, distances, labels, sel);
217
215
  }
218
216
  }
219
217
 
@@ -547,6 +545,22 @@ void IndexFastScan::search_implem_14(
547
545
  }
548
546
  }
549
547
 
548
+ template void IndexFastScan::search_dispatch_implem<true>(
549
+ idx_t n,
550
+ const float* x,
551
+ idx_t k,
552
+ float* distances,
553
+ idx_t* labels,
554
+ const NormTableScaler* scaler) const;
555
+
556
+ template void IndexFastScan::search_dispatch_implem<false>(
557
+ idx_t n,
558
+ const float* x,
559
+ idx_t k,
560
+ float* distances,
561
+ idx_t* labels,
562
+ const NormTableScaler* scaler) const;
563
+
550
564
  void IndexFastScan::reconstruct(idx_t key, float* recons) const {
551
565
  std::vector<uint8_t> code(code_size, 0);
552
566
  BitstringWriter bsw(code.data(), code_size);
@@ -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.
@@ -133,6 +133,15 @@ struct IndexFastScan : Index {
133
133
 
134
134
  void merge_from(Index& otherIndex, idx_t add_id = 0) override;
135
135
  void check_compatible_for_merge(const Index& otherIndex) const override;
136
+
137
+ /// standalone codes interface (but the codes are flattened)
138
+ size_t sa_code_size() const override {
139
+ return code_size;
140
+ }
141
+
142
+ void sa_encode(idx_t n, const float* x, uint8_t* bytes) const override {
143
+ compute_codes(bytes, n, x);
144
+ }
136
145
  };
137
146
 
138
147
  struct FastScanStats {
@@ -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
  #include <faiss/utils/extra_distances.h>
17
17
  #include <faiss/utils/prefetch.h>
18
18
  #include <faiss/utils/sorting.h>
19
- #include <faiss/utils/utils.h>
20
19
  #include <cstring>
21
20
 
22
21
  namespace faiss {
@@ -41,15 +40,19 @@ void IndexFlat::search(
41
40
  } else if (metric_type == METRIC_L2) {
42
41
  float_maxheap_array_t res = {size_t(n), size_t(k), labels, distances};
43
42
  knn_L2sqr(x, get_xb(), d, n, ntotal, &res, nullptr, sel);
44
- } else if (is_similarity_metric(metric_type)) {
45
- float_minheap_array_t res = {size_t(n), size_t(k), labels, distances};
46
- knn_extra_metrics(
47
- x, get_xb(), d, n, ntotal, metric_type, metric_arg, &res);
48
43
  } else {
49
- FAISS_THROW_IF_NOT(!sel);
50
- float_maxheap_array_t res = {size_t(n), size_t(k), labels, distances};
44
+ FAISS_THROW_IF_NOT(!sel); // TODO implement with selector
51
45
  knn_extra_metrics(
52
- x, get_xb(), d, n, ntotal, metric_type, metric_arg, &res);
46
+ x,
47
+ get_xb(),
48
+ d,
49
+ n,
50
+ ntotal,
51
+ metric_type,
52
+ metric_arg,
53
+ k,
54
+ distances,
55
+ labels);
53
56
  }
54
57
  }
55
58
 
@@ -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.
@@ -12,6 +12,8 @@
12
12
  #include <faiss/impl/DistanceComputer.h>
13
13
  #include <faiss/impl/FaissAssert.h>
14
14
  #include <faiss/impl/IDSelector.h>
15
+ #include <faiss/impl/ResultHandler.h>
16
+ #include <faiss/utils/extra_distances.h>
15
17
 
16
18
  namespace faiss {
17
19
 
@@ -30,6 +32,15 @@ void IndexFlatCodes::add(idx_t n, const float* x) {
30
32
  ntotal += n;
31
33
  }
32
34
 
35
+ void IndexFlatCodes::add_sa_codes(
36
+ idx_t n,
37
+ const uint8_t* codes_in,
38
+ const idx_t* /* xids */) {
39
+ codes.resize((ntotal + n) * code_size);
40
+ memcpy(codes.data() + (ntotal * code_size), codes_in, n * code_size);
41
+ ntotal += n;
42
+ }
43
+
33
44
  void IndexFlatCodes::reset() {
34
45
  codes.clear();
35
46
  ntotal = 0;
@@ -70,11 +81,6 @@ void IndexFlatCodes::reconstruct(idx_t key, float* recons) const {
70
81
  reconstruct_n(key, 1, recons);
71
82
  }
72
83
 
73
- FlatCodesDistanceComputer* IndexFlatCodes::get_FlatCodesDistanceComputer()
74
- const {
75
- FAISS_THROW_MSG("not implemented");
76
- }
77
-
78
84
  void IndexFlatCodes::check_compatible_for_merge(const Index& otherIndex) const {
79
85
  // minimal sanity checks
80
86
  const IndexFlatCodes* other =
@@ -114,4 +120,161 @@ void IndexFlatCodes::permute_entries(const idx_t* perm) {
114
120
  std::swap(codes, new_codes);
115
121
  }
116
122
 
123
+ namespace {
124
+
125
+ template <class VD>
126
+ struct GenericFlatCodesDistanceComputer : FlatCodesDistanceComputer {
127
+ const IndexFlatCodes& codec;
128
+ const VD vd;
129
+ // temp buffers
130
+ std::vector<uint8_t> code_buffer;
131
+ std::vector<float> vec_buffer;
132
+ const float* query = nullptr;
133
+
134
+ GenericFlatCodesDistanceComputer(const IndexFlatCodes* codec, const VD& vd)
135
+ : FlatCodesDistanceComputer(codec->codes.data(), codec->code_size),
136
+ codec(*codec),
137
+ vd(vd),
138
+ code_buffer(codec->code_size * 4),
139
+ vec_buffer(codec->d * 4) {}
140
+
141
+ void set_query(const float* x) override {
142
+ query = x;
143
+ }
144
+
145
+ float operator()(idx_t i) override {
146
+ codec.sa_decode(1, codes + i * code_size, vec_buffer.data());
147
+ return vd(query, vec_buffer.data());
148
+ }
149
+
150
+ float distance_to_code(const uint8_t* code) override {
151
+ codec.sa_decode(1, code, vec_buffer.data());
152
+ return vd(query, vec_buffer.data());
153
+ }
154
+
155
+ float symmetric_dis(idx_t i, idx_t j) override {
156
+ codec.sa_decode(1, codes + i * code_size, vec_buffer.data());
157
+ codec.sa_decode(1, codes + j * code_size, vec_buffer.data() + vd.d);
158
+ return vd(vec_buffer.data(), vec_buffer.data() + vd.d);
159
+ }
160
+
161
+ void distances_batch_4(
162
+ const idx_t idx0,
163
+ const idx_t idx1,
164
+ const idx_t idx2,
165
+ const idx_t idx3,
166
+ float& dis0,
167
+ float& dis1,
168
+ float& dis2,
169
+ float& dis3) override {
170
+ uint8_t* cp = code_buffer.data();
171
+ for (idx_t i : {idx0, idx1, idx2, idx3}) {
172
+ memcpy(cp, codes + i * code_size, code_size);
173
+ cp += code_size;
174
+ }
175
+ // potential benefit is if batch decoding is more efficient than 1 by 1
176
+ // decoding
177
+ codec.sa_decode(4, code_buffer.data(), vec_buffer.data());
178
+ dis0 = vd(query, vec_buffer.data());
179
+ dis1 = vd(query, vec_buffer.data() + vd.d);
180
+ dis2 = vd(query, vec_buffer.data() + 2 * vd.d);
181
+ dis3 = vd(query, vec_buffer.data() + 3 * vd.d);
182
+ }
183
+ };
184
+
185
+ struct Run_get_distance_computer {
186
+ using T = FlatCodesDistanceComputer*;
187
+
188
+ template <class VD>
189
+ FlatCodesDistanceComputer* f(const VD& vd, const IndexFlatCodes* codec) {
190
+ return new GenericFlatCodesDistanceComputer<VD>(codec, vd);
191
+ }
192
+ };
193
+
194
+ template <class BlockResultHandler>
195
+ struct Run_search_with_decompress {
196
+ using T = void;
197
+
198
+ template <class VectorDistance>
199
+ void f(VectorDistance& vd,
200
+ const IndexFlatCodes* index_ptr,
201
+ const float* xq,
202
+ BlockResultHandler& res) {
203
+ // Note that there seems to be a clang (?) bug that "sometimes" passes
204
+ // the const Index & parameters by value, so to be on the safe side,
205
+ // it's better to use pointers.
206
+ const IndexFlatCodes& index = *index_ptr;
207
+ size_t ntotal = index.ntotal;
208
+ using SingleResultHandler =
209
+ typename BlockResultHandler::SingleResultHandler;
210
+ using DC = GenericFlatCodesDistanceComputer<VectorDistance>;
211
+ #pragma omp parallel // if (res.nq > 100)
212
+ {
213
+ std::unique_ptr<DC> dc(new DC(&index, vd));
214
+ SingleResultHandler resi(res);
215
+ #pragma omp for
216
+ for (int64_t q = 0; q < res.nq; q++) {
217
+ resi.begin(q);
218
+ dc->set_query(xq + vd.d * q);
219
+ for (size_t i = 0; i < ntotal; i++) {
220
+ if (res.is_in_selection(i)) {
221
+ float dis = (*dc)(i);
222
+ resi.add_result(dis, i);
223
+ }
224
+ }
225
+ resi.end();
226
+ }
227
+ }
228
+ }
229
+ };
230
+
231
+ struct Run_search_with_decompress_res {
232
+ using T = void;
233
+
234
+ template <class ResultHandler>
235
+ void f(ResultHandler& res, const IndexFlatCodes* index, const float* xq) {
236
+ Run_search_with_decompress<ResultHandler> r;
237
+ dispatch_VectorDistance(
238
+ index->d,
239
+ index->metric_type,
240
+ index->metric_arg,
241
+ r,
242
+ index,
243
+ xq,
244
+ res);
245
+ }
246
+ };
247
+
248
+ } // anonymous namespace
249
+
250
+ FlatCodesDistanceComputer* IndexFlatCodes::get_FlatCodesDistanceComputer()
251
+ const {
252
+ Run_get_distance_computer r;
253
+ return dispatch_VectorDistance(d, metric_type, metric_arg, r, this);
254
+ }
255
+
256
+ void IndexFlatCodes::search(
257
+ idx_t n,
258
+ const float* x,
259
+ idx_t k,
260
+ float* distances,
261
+ idx_t* labels,
262
+ const SearchParameters* params) const {
263
+ Run_search_with_decompress_res r;
264
+ const IDSelector* sel = params ? params->sel : nullptr;
265
+ dispatch_knn_ResultHandler(
266
+ n, distances, labels, k, metric_type, sel, r, this, x);
267
+ }
268
+
269
+ void IndexFlatCodes::range_search(
270
+ idx_t n,
271
+ const float* x,
272
+ float radius,
273
+ RangeSearchResult* result,
274
+ const SearchParameters* params) const {
275
+ const IDSelector* sel = params ? params->sel : nullptr;
276
+ Run_search_with_decompress_res r;
277
+ dispatch_range_ResultHandler(result, radius, metric_type, sel, r, this, x);
278
+ }
279
+
117
280
  } // namespace faiss
@@ -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
  #pragma once
11
9
 
12
10
  #include <faiss/Index.h>
@@ -45,13 +43,32 @@ struct IndexFlatCodes : Index {
45
43
  * different from the usual ones: the new ids are shifted */
46
44
  size_t remove_ids(const IDSelector& sel) override;
47
45
 
48
- /** a FlatCodesDistanceComputer offers a distance_to_code method */
46
+ /** a FlatCodesDistanceComputer offers a distance_to_code method
47
+ *
48
+ * The default implementation explicitly decodes the vector with sa_decode.
49
+ */
49
50
  virtual FlatCodesDistanceComputer* get_FlatCodesDistanceComputer() const;
50
51
 
51
52
  DistanceComputer* get_distance_computer() const override {
52
53
  return get_FlatCodesDistanceComputer();
53
54
  }
54
55
 
56
+ /** Search implemented by decoding */
57
+ void search(
58
+ idx_t n,
59
+ const float* x,
60
+ idx_t k,
61
+ float* distances,
62
+ idx_t* labels,
63
+ const SearchParameters* params = nullptr) const override;
64
+
65
+ void range_search(
66
+ idx_t n,
67
+ const float* x,
68
+ float radius,
69
+ RangeSearchResult* result,
70
+ const SearchParameters* params = nullptr) const override;
71
+
55
72
  // returns a new instance of a CodePacker
56
73
  CodePacker* get_CodePacker() const;
57
74
 
@@ -59,6 +76,9 @@ struct IndexFlatCodes : Index {
59
76
 
60
77
  virtual void merge_from(Index& otherIndex, idx_t add_id = 0) override;
61
78
 
79
+ virtual void add_sa_codes(idx_t n, const uint8_t* x, const idx_t* xids)
80
+ override;
81
+
62
82
  // permute_entries. perm of size ntotal maps new to old positions
63
83
  void permute_entries(const idx_t* perm);
64
84
  };