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.
@@ -46,6 +46,7 @@ struct ResultHandler;
46
46
  struct SearchParametersHNSW : SearchParameters {
47
47
  int efSearch = 16;
48
48
  bool check_relative_distance = true;
49
+ bool bounded_queue = true;
49
50
 
50
51
  ~SearchParametersHNSW() {}
51
52
  };
@@ -141,9 +142,6 @@ struct HNSW {
141
142
  /// enough?
142
143
  bool check_relative_distance = true;
143
144
 
144
- /// number of entry points in levels > 0.
145
- int upper_beam = 1;
146
-
147
145
  /// use bounded queue during exploration
148
146
  bool search_bounded_queue = true;
149
147
 
@@ -184,7 +182,8 @@ struct HNSW {
184
182
  float d_nearest,
185
183
  int level,
186
184
  omp_lock_t* locks,
187
- VisitedTable& vt);
185
+ VisitedTable& vt,
186
+ bool keep_max_size_level0 = false);
188
187
 
189
188
  /** add point pt_id on all levels <= pt_level and build the link
190
189
  * structure for them. */
@@ -193,7 +192,8 @@ struct HNSW {
193
192
  int pt_level,
194
193
  int pt_id,
195
194
  std::vector<omp_lock_t>& locks,
196
- VisitedTable& vt);
195
+ VisitedTable& vt,
196
+ bool keep_max_size_level0 = false);
197
197
 
198
198
  /// search interface for 1 point, single thread
199
199
  HNSWStats search(
@@ -211,7 +211,8 @@ struct HNSW {
211
211
  const float* nearest_d,
212
212
  int search_type,
213
213
  HNSWStats& search_stats,
214
- VisitedTable& vt) const;
214
+ VisitedTable& vt,
215
+ const SearchParametersHNSW* params = nullptr) const;
215
216
 
216
217
  void reset();
217
218
 
@@ -224,40 +225,70 @@ struct HNSW {
224
225
  DistanceComputer& qdis,
225
226
  std::priority_queue<NodeDistFarther>& input,
226
227
  std::vector<NodeDistFarther>& output,
227
- int max_size);
228
+ int max_size,
229
+ bool keep_max_size_level0 = false);
228
230
 
229
231
  void permute_entries(const idx_t* map);
230
232
  };
231
233
 
232
234
  struct HNSWStats {
233
- size_t n1, n2, n3;
234
- size_t ndis;
235
- size_t nreorder;
236
-
237
- HNSWStats(
238
- size_t n1 = 0,
239
- size_t n2 = 0,
240
- size_t n3 = 0,
241
- size_t ndis = 0,
242
- size_t nreorder = 0)
243
- : n1(n1), n2(n2), n3(n3), ndis(ndis), nreorder(nreorder) {}
235
+ size_t n1 = 0; /// number of vectors searched
236
+ size_t n2 =
237
+ 0; /// number of queries for which the candidate list is exhausted
238
+ size_t ndis = 0; /// number of distances computed
239
+ size_t nhops = 0; /// number of hops aka number of edges traversed
244
240
 
245
241
  void reset() {
246
- n1 = n2 = n3 = 0;
242
+ n1 = n2 = 0;
247
243
  ndis = 0;
248
- nreorder = 0;
244
+ nhops = 0;
249
245
  }
250
246
 
251
247
  void combine(const HNSWStats& other) {
252
248
  n1 += other.n1;
253
249
  n2 += other.n2;
254
- n3 += other.n3;
255
250
  ndis += other.ndis;
256
- nreorder += other.nreorder;
251
+ nhops += other.nhops;
257
252
  }
258
253
  };
259
254
 
260
255
  // global var that collects them all
261
256
  FAISS_API extern HNSWStats hnsw_stats;
262
257
 
258
+ int search_from_candidates(
259
+ const HNSW& hnsw,
260
+ DistanceComputer& qdis,
261
+ ResultHandler<HNSW::C>& res,
262
+ HNSW::MinimaxHeap& candidates,
263
+ VisitedTable& vt,
264
+ HNSWStats& stats,
265
+ int level,
266
+ int nres_in = 0,
267
+ const SearchParametersHNSW* params = nullptr);
268
+
269
+ HNSWStats greedy_update_nearest(
270
+ const HNSW& hnsw,
271
+ DistanceComputer& qdis,
272
+ int level,
273
+ HNSW::storage_idx_t& nearest,
274
+ float& d_nearest);
275
+
276
+ std::priority_queue<HNSW::Node> search_from_candidate_unbounded(
277
+ const HNSW& hnsw,
278
+ const HNSW::Node& node,
279
+ DistanceComputer& qdis,
280
+ int ef,
281
+ VisitedTable* vt,
282
+ HNSWStats& stats);
283
+
284
+ void search_neighbors_to_add(
285
+ HNSW& hnsw,
286
+ DistanceComputer& qdis,
287
+ std::priority_queue<HNSW::NodeDistCloser>& results,
288
+ int entry_point,
289
+ float d_entry_point,
290
+ int level,
291
+ VisitedTable& vt,
292
+ bool reference_version = false);
293
+
263
294
  } // 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.
@@ -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.
@@ -104,10 +104,10 @@ int dgemm_(
104
104
 
105
105
  namespace {
106
106
 
107
- void fmat_inverse(float* a, int n) {
108
- int info;
109
- int lwork = n * n;
110
- std::vector<int> ipiv(n);
107
+ void fmat_inverse(float* a, FINTEGER n) {
108
+ FINTEGER info;
109
+ FINTEGER lwork = n * n;
110
+ std::vector<FINTEGER> ipiv(n);
111
111
  std::vector<float> workspace(lwork);
112
112
 
113
113
  sgetrf_(&n, &n, a, &n, ipiv.data(), &info);
@@ -123,10 +123,10 @@ void dfvec_add(size_t d, const double* a, const float* b, double* c) {
123
123
  }
124
124
  }
125
125
 
126
- void dmat_inverse(double* a, int n) {
127
- int info;
128
- int lwork = n * n;
129
- std::vector<int> ipiv(n);
126
+ void dmat_inverse(double* a, FINTEGER n) {
127
+ FINTEGER info;
128
+ FINTEGER lwork = n * n;
129
+ std::vector<FINTEGER> ipiv(n);
130
130
  std::vector<double> workspace(lwork);
131
131
 
132
132
  dgetrf_(&n, &n, a, &n, ipiv.data(), &info);
@@ -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.
@@ -38,6 +38,23 @@ struct DummyScaler {
38
38
  return simd16uint16(0);
39
39
  }
40
40
 
41
+ #ifdef __AVX512F__
42
+ inline simd64uint8 lookup(const simd64uint8&, const simd64uint8&) const {
43
+ FAISS_THROW_MSG("DummyScaler::lookup should not be called.");
44
+ return simd64uint8(0);
45
+ }
46
+
47
+ inline simd32uint16 scale_lo(const simd64uint8&) const {
48
+ FAISS_THROW_MSG("DummyScaler::scale_lo should not be called.");
49
+ return simd32uint16(0);
50
+ }
51
+
52
+ inline simd32uint16 scale_hi(const simd64uint8&) const {
53
+ FAISS_THROW_MSG("DummyScaler::scale_hi should not be called.");
54
+ return simd32uint16(0);
55
+ }
56
+ #endif
57
+
41
58
  template <class dist_t>
42
59
  inline dist_t scale_one(const dist_t&) const {
43
60
  FAISS_THROW_MSG("DummyScaler::scale_one should not be called.");
@@ -67,6 +84,23 @@ struct NormTableScaler {
67
84
  return (simd16uint16(res) >> 8) * scale_simd;
68
85
  }
69
86
 
87
+ #ifdef __AVX512F__
88
+ inline simd64uint8 lookup(const simd64uint8& lut, const simd64uint8& c)
89
+ const {
90
+ return lut.lookup_4_lanes(c);
91
+ }
92
+
93
+ inline simd32uint16 scale_lo(const simd64uint8& res) const {
94
+ auto scale_simd_wide = simd32uint16(scale_simd, scale_simd);
95
+ return simd32uint16(res) * scale_simd_wide;
96
+ }
97
+
98
+ inline simd32uint16 scale_hi(const simd64uint8& res) const {
99
+ auto scale_simd_wide = simd32uint16(scale_simd, scale_simd);
100
+ return (simd32uint16(res) >> 8) * scale_simd_wide;
101
+ }
102
+ #endif
103
+
70
104
  // for non-SIMD implem 2, 3, 4
71
105
  template <class dist_t>
72
106
  inline dist_t scale_one(const dist_t& x) const {
@@ -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.
@@ -154,15 +154,20 @@ NNDescent::NNDescent(const int d, const int K) : K(K), d(d) {
154
154
  NNDescent::~NNDescent() {}
155
155
 
156
156
  void NNDescent::join(DistanceComputer& qdis) {
157
+ idx_t check_period = InterruptCallback::get_period_hint(d * search_L);
158
+ for (idx_t i0 = 0; i0 < (idx_t)ntotal; i0 += check_period) {
159
+ idx_t i1 = std::min(i0 + check_period, (idx_t)ntotal);
157
160
  #pragma omp parallel for default(shared) schedule(dynamic, 100)
158
- for (int n = 0; n < ntotal; n++) {
159
- graph[n].join([&](int i, int j) {
160
- if (i != j) {
161
- float dist = qdis.symmetric_dis(i, j);
162
- graph[i].insert(j, dist);
163
- graph[j].insert(i, dist);
164
- }
165
- });
161
+ for (idx_t n = i0; n < i1; n++) {
162
+ graph[n].join([&](int i, int j) {
163
+ if (i != j) {
164
+ float dist = qdis.symmetric_dis(i, j);
165
+ graph[i].insert(j, dist);
166
+ graph[j].insert(i, dist);
167
+ }
168
+ });
169
+ }
170
+ InterruptCallback::check();
166
171
  }
167
172
  }
168
173
 
@@ -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,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/impl/NSG.h>
11
9
 
12
10
  #include <algorithm>
@@ -18,43 +16,16 @@
18
16
 
19
17
  namespace faiss {
20
18
 
21
- namespace nsg {
22
-
23
19
  namespace {
24
20
 
21
+ using LockGuard = std::lock_guard<std::mutex>;
22
+
25
23
  // It needs to be smaller than 0
26
24
  constexpr int EMPTY_ID = -1;
27
25
 
28
- /* Wrap the distance computer into one that negates the
29
- distances. This makes supporting INNER_PRODUCE search easier */
30
-
31
- struct NegativeDistanceComputer : DistanceComputer {
32
- /// owned by this
33
- DistanceComputer* basedis;
26
+ } // anonymous namespace
34
27
 
35
- explicit NegativeDistanceComputer(DistanceComputer* basedis)
36
- : basedis(basedis) {}
37
-
38
- void set_query(const float* x) override {
39
- basedis->set_query(x);
40
- }
41
-
42
- /// compute distance of vector i to current query
43
- float operator()(idx_t i) override {
44
- return -(*basedis)(i);
45
- }
46
-
47
- /// compute distance between two stored vectors
48
- float symmetric_dis(idx_t i, idx_t j) override {
49
- return -basedis->symmetric_dis(i, j);
50
- }
51
-
52
- ~NegativeDistanceComputer() override {
53
- delete basedis;
54
- }
55
- };
56
-
57
- } // namespace
28
+ namespace nsg {
58
29
 
59
30
  DistanceComputer* storage_distance_computer(const Index* storage) {
60
31
  if (is_similarity_metric(storage->metric_type)) {
@@ -64,14 +35,8 @@ DistanceComputer* storage_distance_computer(const Index* storage) {
64
35
  }
65
36
  }
66
37
 
67
- } // namespace nsg
68
-
69
- using namespace nsg;
70
-
71
- using LockGuard = std::lock_guard<std::mutex>;
72
-
73
38
  struct Neighbor {
74
- int id;
39
+ int32_t id;
75
40
  float distance;
76
41
  bool flag;
77
42
 
@@ -85,7 +50,7 @@ struct Neighbor {
85
50
  };
86
51
 
87
52
  struct Node {
88
- int id;
53
+ int32_t id;
89
54
  float distance;
90
55
 
91
56
  Node() = default;
@@ -94,6 +59,11 @@ struct Node {
94
59
  inline bool operator<(const Node& other) const {
95
60
  return distance < other.distance;
96
61
  }
62
+
63
+ // to keep the compiler happy
64
+ inline bool operator<(int other) const {
65
+ return id < other;
66
+ }
97
67
  };
98
68
 
99
69
  inline int insert_into_pool(Neighbor* addr, int K, Neighbor nn) {
@@ -135,6 +105,10 @@ inline int insert_into_pool(Neighbor* addr, int K, Neighbor nn) {
135
105
  return right;
136
106
  }
137
107
 
108
+ } // namespace nsg
109
+
110
+ using namespace nsg;
111
+
138
112
  NSG::NSG(int R) : R(R), rng(0x0903) {
139
113
  L = R + 32;
140
114
  C = R + 100;
@@ -282,9 +256,11 @@ void NSG::search_on_graph(
282
256
  std::vector<int> init_ids(pool_size);
283
257
 
284
258
  int num_ids = 0;
285
- for (int i = 0; i < init_ids.size() && i < graph.K; i++) {
286
- int id = (int)graph.at(ep, i);
287
- if (id < 0 || id >= ntotal) {
259
+ std::vector<index_t> neighbors(graph.K);
260
+ size_t nneigh = graph.get_neighbors(ep, neighbors.data());
261
+ for (int i = 0; i < init_ids.size() && i < nneigh; i++) {
262
+ int id = (int)neighbors[i];
263
+ if (id >= ntotal) {
288
264
  continue;
289
265
  }
290
266
 
@@ -325,9 +301,10 @@ void NSG::search_on_graph(
325
301
  retset[k].flag = false;
326
302
  int n = retset[k].id;
327
303
 
328
- for (int m = 0; m < graph.K; m++) {
329
- int id = (int)graph.at(n, m);
330
- if (id < 0 || id > ntotal || vt.get(id)) {
304
+ size_t nneigh_for_n = graph.get_neighbors(n, neighbors.data());
305
+ for (int m = 0; m < nneigh_for_n; m++) {
306
+ int id = neighbors[m];
307
+ if (id > ntotal || vt.get(id)) {
331
308
  continue;
332
309
  }
333
310
  vt.set(id);
@@ -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 <memory>
@@ -40,11 +38,12 @@ namespace faiss {
40
38
  */
41
39
 
42
40
  struct DistanceComputer; // from AuxIndexStructures
43
- struct Neighbor;
44
- struct Node;
45
41
 
46
42
  namespace nsg {
47
43
 
44
+ struct Neighbor;
45
+ struct Node;
46
+
48
47
  /***********************************************************
49
48
  * Graph structure to store a graph.
50
49
  *
@@ -75,7 +74,7 @@ struct Graph {
75
74
  }
76
75
 
77
76
  // release the allocated memory if needed
78
- ~Graph() {
77
+ virtual ~Graph() {
79
78
  if (own_fields) {
80
79
  delete[] data;
81
80
  }
@@ -90,6 +89,17 @@ struct Graph {
90
89
  inline node_t& at(int i, int j) {
91
90
  return data[i * K + j];
92
91
  }
92
+
93
+ // get all neighbors of node i (used during search only)
94
+ virtual size_t get_neighbors(int i, node_t* neighbors) const {
95
+ for (int j = 0; j < K; j++) {
96
+ if (data[i * K + j] < 0) {
97
+ return j;
98
+ }
99
+ neighbors[j] = data[i * K + j];
100
+ }
101
+ return K;
102
+ }
93
103
  };
94
104
 
95
105
  DistanceComputer* storage_distance_computer(const Index* storage);
@@ -99,6 +109,8 @@ DistanceComputer* storage_distance_computer(const Index* storage);
99
109
  struct NSG {
100
110
  /// internal storage of vectors (32 bits: this is expensive)
101
111
  using storage_idx_t = int32_t;
112
+ using Node = nsg::Node;
113
+ using Neighbor = nsg::Neighbor;
102
114
 
103
115
  int ntotal = 0; ///< nb of nodes
104
116
 
@@ -112,7 +124,7 @@ struct NSG {
112
124
 
113
125
  int enterpoint; ///< enterpoint
114
126
 
115
- std::shared_ptr<nsg::Graph<int>> final_graph; ///< NSG graph structure
127
+ std::shared_ptr<nsg::Graph<int32_t>> final_graph; ///< NSG graph structure
116
128
 
117
129
  bool is_built = false; ///< NSG is built or not
118
130
 
@@ -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.
@@ -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.
@@ -11,7 +11,6 @@
11
11
  #include <cstdio>
12
12
  #include <cstring>
13
13
  #include <memory>
14
- #include <random>
15
14
 
16
15
  #include <algorithm>
17
16
 
@@ -20,7 +19,6 @@
20
19
  #include <faiss/impl/FaissAssert.h>
21
20
  #include <faiss/utils/distances.h>
22
21
  #include <faiss/utils/hamming.h>
23
- #include <faiss/utils/utils.h>
24
22
 
25
23
  extern "C" {
26
24
 
@@ -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.
@@ -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.
@@ -61,6 +61,7 @@ void ProductQuantizer::set_derived_values() {
61
61
  "The dimension of the vector (d) should be a multiple of the number of subquantizers (M)");
62
62
  dsub = d / M;
63
63
  code_size = (nbits * M + 7) / 8;
64
+ FAISS_THROW_IF_MSG(nbits > 24, "nbits larger than 24 is not practical.");
64
65
  ksub = 1 << nbits;
65
66
  centroids.resize(d * ksub);
66
67
  verbose = false;
@@ -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.
@@ -21,7 +21,11 @@
21
21
 
22
22
  namespace faiss {
23
23
 
24
- /** Product Quantizer. Implemented only for METRIC_L2 */
24
+ /** Product Quantizer.
25
+ * PQ is trained using k-means, minimizing the L2 distance to centroids.
26
+ * PQ supports L2 and Inner Product search, however the quantization error is
27
+ * biased towards L2 distance.
28
+ */
25
29
  struct ProductQuantizer : Quantizer {
26
30
  size_t M; ///< number of subquantizers
27
31
  size_t nbits; ///< number of bits per quantization index
@@ -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.
@@ -492,40 +492,6 @@ void ResidualQuantizer::refine_beam(
492
492
  * Functions using the dot products between codebook entries
493
493
  *******************************************************************/
494
494
 
495
- void ResidualQuantizer::compute_codebook_tables() {
496
- cent_norms.resize(total_codebook_size);
497
- fvec_norms_L2sqr(
498
- cent_norms.data(), codebooks.data(), d, total_codebook_size);
499
- size_t cross_table_size = 0;
500
- for (int m = 0; m < M; m++) {
501
- size_t K = (size_t)1 << nbits[m];
502
- cross_table_size += K * codebook_offsets[m];
503
- }
504
- codebook_cross_products.resize(cross_table_size);
505
- size_t ofs = 0;
506
- for (int m = 1; m < M; m++) {
507
- FINTEGER ki = (size_t)1 << nbits[m];
508
- FINTEGER kk = codebook_offsets[m];
509
- FINTEGER di = d;
510
- float zero = 0, one = 1;
511
- assert(ofs + ki * kk <= cross_table_size);
512
- sgemm_("Transposed",
513
- "Not transposed",
514
- &ki,
515
- &kk,
516
- &di,
517
- &one,
518
- codebooks.data() + d * kk,
519
- &di,
520
- codebooks.data(),
521
- &di,
522
- &zero,
523
- codebook_cross_products.data() + ofs,
524
- &ki);
525
- ofs += ki * kk;
526
- }
527
- }
528
-
529
495
  void ResidualQuantizer::refine_beam_LUT(
530
496
  size_t n,
531
497
  const float* query_norms, // size n