faiss 0.4.3 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +2 -0
- data/ext/faiss/index.cpp +33 -6
- data/ext/faiss/index_binary.cpp +17 -4
- data/ext/faiss/kmeans.cpp +6 -6
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/faiss/AutoTune.cpp +2 -3
- data/vendor/faiss/faiss/AutoTune.h +1 -1
- data/vendor/faiss/faiss/Clustering.cpp +2 -2
- data/vendor/faiss/faiss/Clustering.h +2 -2
- data/vendor/faiss/faiss/IVFlib.cpp +26 -51
- data/vendor/faiss/faiss/IVFlib.h +1 -1
- data/vendor/faiss/faiss/Index.cpp +11 -0
- data/vendor/faiss/faiss/Index.h +34 -11
- data/vendor/faiss/faiss/Index2Layer.cpp +1 -1
- data/vendor/faiss/faiss/Index2Layer.h +2 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +1 -0
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.cpp +9 -4
- data/vendor/faiss/faiss/IndexAdditiveQuantizerFastScan.h +5 -1
- data/vendor/faiss/faiss/IndexBinary.h +7 -7
- data/vendor/faiss/faiss/IndexBinaryFromFloat.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryHNSW.cpp +8 -2
- data/vendor/faiss/faiss/IndexBinaryHNSW.h +1 -1
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +3 -3
- data/vendor/faiss/faiss/IndexBinaryHash.h +5 -5
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +7 -6
- data/vendor/faiss/faiss/IndexFastScan.cpp +125 -49
- data/vendor/faiss/faiss/IndexFastScan.h +102 -7
- data/vendor/faiss/faiss/IndexFlat.cpp +374 -4
- data/vendor/faiss/faiss/IndexFlat.h +81 -1
- data/vendor/faiss/faiss/IndexHNSW.cpp +93 -2
- data/vendor/faiss/faiss/IndexHNSW.h +58 -2
- data/vendor/faiss/faiss/IndexIDMap.cpp +14 -13
- data/vendor/faiss/faiss/IndexIDMap.h +6 -6
- data/vendor/faiss/faiss/IndexIVF.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVF.h +5 -5
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.cpp +9 -3
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizerFastScan.h +3 -1
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +176 -90
- data/vendor/faiss/faiss/IndexIVFFastScan.h +173 -18
- data/vendor/faiss/faiss/IndexIVFFlat.cpp +1 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.cpp +251 -0
- data/vendor/faiss/faiss/IndexIVFFlatPanorama.h +64 -0
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +3 -1
- data/vendor/faiss/faiss/IndexIVFPQ.h +1 -1
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +134 -2
- data/vendor/faiss/faiss/IndexIVFPQFastScan.h +7 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQ.cpp +99 -8
- data/vendor/faiss/faiss/IndexIVFRaBitQ.h +4 -1
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.cpp +828 -0
- data/vendor/faiss/faiss/IndexIVFRaBitQFastScan.h +252 -0
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +1 -1
- data/vendor/faiss/faiss/IndexIVFSpectralHash.h +1 -1
- data/vendor/faiss/faiss/IndexNNDescent.cpp +1 -1
- data/vendor/faiss/faiss/IndexNSG.cpp +1 -1
- data/vendor/faiss/faiss/IndexNeuralNetCodec.h +1 -1
- data/vendor/faiss/faiss/IndexPQ.cpp +4 -1
- data/vendor/faiss/faiss/IndexPQ.h +1 -1
- data/vendor/faiss/faiss/IndexPQFastScan.cpp +6 -2
- data/vendor/faiss/faiss/IndexPQFastScan.h +5 -1
- data/vendor/faiss/faiss/IndexPreTransform.cpp +14 -0
- data/vendor/faiss/faiss/IndexPreTransform.h +9 -0
- data/vendor/faiss/faiss/IndexRaBitQ.cpp +96 -13
- data/vendor/faiss/faiss/IndexRaBitQ.h +11 -2
- data/vendor/faiss/faiss/IndexRaBitQFastScan.cpp +731 -0
- data/vendor/faiss/faiss/IndexRaBitQFastScan.h +175 -0
- data/vendor/faiss/faiss/IndexRefine.cpp +49 -0
- data/vendor/faiss/faiss/IndexRefine.h +17 -0
- data/vendor/faiss/faiss/IndexShards.cpp +1 -1
- data/vendor/faiss/faiss/MatrixStats.cpp +3 -3
- data/vendor/faiss/faiss/MetricType.h +1 -1
- data/vendor/faiss/faiss/VectorTransform.h +2 -2
- data/vendor/faiss/faiss/clone_index.cpp +5 -1
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +1 -1
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +3 -1
- data/vendor/faiss/faiss/gpu/GpuIndex.h +11 -11
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryCagra.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +1 -1
- data/vendor/faiss/faiss/gpu/GpuIndexCagra.h +11 -7
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +1 -1
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIcmEncoder.cpp +7 -0
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +1 -1
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +2 -2
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +1 -1
- data/vendor/faiss/faiss/impl/CodePacker.h +2 -2
- data/vendor/faiss/faiss/impl/DistanceComputer.h +77 -6
- data/vendor/faiss/faiss/impl/FastScanDistancePostProcessing.h +53 -0
- data/vendor/faiss/faiss/impl/HNSW.cpp +295 -16
- data/vendor/faiss/faiss/impl/HNSW.h +35 -6
- data/vendor/faiss/faiss/impl/IDSelector.cpp +2 -2
- data/vendor/faiss/faiss/impl/IDSelector.h +4 -4
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +4 -4
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/LookupTableScaler.h +1 -1
- data/vendor/faiss/faiss/impl/NNDescent.cpp +1 -1
- data/vendor/faiss/faiss/impl/NNDescent.h +2 -2
- data/vendor/faiss/faiss/impl/NSG.cpp +1 -1
- data/vendor/faiss/faiss/impl/Panorama.cpp +193 -0
- data/vendor/faiss/faiss/impl/Panorama.h +204 -0
- data/vendor/faiss/faiss/impl/PanoramaStats.cpp +33 -0
- data/vendor/faiss/faiss/impl/PanoramaStats.h +38 -0
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +5 -5
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +1 -1
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ProductQuantizer-inl.h +2 -0
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/RaBitQStats.cpp +29 -0
- data/vendor/faiss/faiss/impl/RaBitQStats.h +56 -0
- data/vendor/faiss/faiss/impl/RaBitQUtils.cpp +294 -0
- data/vendor/faiss/faiss/impl/RaBitQUtils.h +330 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizer.cpp +304 -223
- data/vendor/faiss/faiss/impl/RaBitQuantizer.h +72 -4
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.cpp +362 -0
- data/vendor/faiss/faiss/impl/RaBitQuantizerMultiBit.h +112 -0
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +1 -1
- data/vendor/faiss/faiss/impl/ResultHandler.h +4 -4
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +7 -10
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +2 -4
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +7 -4
- data/vendor/faiss/faiss/impl/index_read.cpp +238 -10
- data/vendor/faiss/faiss/impl/index_write.cpp +212 -19
- data/vendor/faiss/faiss/impl/io.cpp +2 -2
- data/vendor/faiss/faiss/impl/io.h +4 -4
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +1 -1
- data/vendor/faiss/faiss/impl/kmeans1d.h +1 -1
- data/vendor/faiss/faiss/impl/lattice_Zn.h +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.cpp +2 -2
- data/vendor/faiss/faiss/impl/mapped_io.h +4 -3
- data/vendor/faiss/faiss/impl/maybe_owned_vector.h +8 -1
- data/vendor/faiss/faiss/impl/platform_macros.h +12 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +30 -4
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +14 -8
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +5 -6
- data/vendor/faiss/faiss/impl/simd_result_handlers.h +55 -11
- data/vendor/faiss/faiss/impl/svs_io.cpp +86 -0
- data/vendor/faiss/faiss/impl/svs_io.h +67 -0
- data/vendor/faiss/faiss/impl/zerocopy_io.h +1 -1
- data/vendor/faiss/faiss/index_factory.cpp +217 -8
- data/vendor/faiss/faiss/index_factory.h +1 -1
- data/vendor/faiss/faiss/index_io.h +1 -1
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +1 -1
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +115 -1
- data/vendor/faiss/faiss/invlists/InvertedLists.h +46 -0
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +1 -1
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
- data/vendor/faiss/faiss/svs/IndexSVSFaissUtils.h +261 -0
- data/vendor/faiss/faiss/svs/IndexSVSFlat.cpp +117 -0
- data/vendor/faiss/faiss/svs/IndexSVSFlat.h +66 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamana.cpp +245 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamana.h +137 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.cpp +39 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLVQ.h +42 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.cpp +149 -0
- data/vendor/faiss/faiss/svs/IndexSVSVamanaLeanVec.h +58 -0
- data/vendor/faiss/faiss/utils/AlignedTable.h +1 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +2 -2
- data/vendor/faiss/faiss/utils/Heap.h +3 -3
- data/vendor/faiss/faiss/utils/NeuralNet.cpp +1 -1
- data/vendor/faiss/faiss/utils/NeuralNet.h +3 -3
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +2 -2
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +1 -1
- data/vendor/faiss/faiss/utils/distances.cpp +0 -3
- data/vendor/faiss/faiss/utils/distances.h +2 -2
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +3 -1
- data/vendor/faiss/faiss/utils/hamming-inl.h +2 -0
- data/vendor/faiss/faiss/utils/hamming.cpp +7 -6
- data/vendor/faiss/faiss/utils/hamming.h +1 -1
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +1 -2
- data/vendor/faiss/faiss/utils/partitioning.cpp +5 -5
- data/vendor/faiss/faiss/utils/partitioning.h +2 -2
- data/vendor/faiss/faiss/utils/rabitq_simd.h +222 -336
- data/vendor/faiss/faiss/utils/random.cpp +1 -1
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +1 -1
- data/vendor/faiss/faiss/utils/simdlib_avx512.h +1 -1
- data/vendor/faiss/faiss/utils/simdlib_neon.h +2 -2
- data/vendor/faiss/faiss/utils/transpose/transpose-avx512-inl.h +1 -1
- data/vendor/faiss/faiss/utils/utils.cpp +9 -2
- data/vendor/faiss/faiss/utils/utils.h +2 -2
- metadata +29 -1
|
@@ -29,11 +29,13 @@
|
|
|
29
29
|
#include <faiss/IndexIVFAdditiveQuantizer.h>
|
|
30
30
|
#include <faiss/IndexIVFAdditiveQuantizerFastScan.h>
|
|
31
31
|
#include <faiss/IndexIVFFlat.h>
|
|
32
|
+
#include <faiss/IndexIVFFlatPanorama.h>
|
|
32
33
|
#include <faiss/IndexIVFIndependentQuantizer.h>
|
|
33
34
|
#include <faiss/IndexIVFPQ.h>
|
|
34
35
|
#include <faiss/IndexIVFPQFastScan.h>
|
|
35
36
|
#include <faiss/IndexIVFPQR.h>
|
|
36
37
|
#include <faiss/IndexIVFRaBitQ.h>
|
|
38
|
+
#include <faiss/IndexIVFRaBitQFastScan.h>
|
|
37
39
|
#include <faiss/IndexIVFSpectralHash.h>
|
|
38
40
|
#include <faiss/IndexLSH.h>
|
|
39
41
|
#include <faiss/IndexLattice.h>
|
|
@@ -43,8 +45,16 @@
|
|
|
43
45
|
#include <faiss/IndexPQFastScan.h>
|
|
44
46
|
#include <faiss/IndexPreTransform.h>
|
|
45
47
|
#include <faiss/IndexRaBitQ.h>
|
|
48
|
+
#include <faiss/IndexRaBitQFastScan.h>
|
|
46
49
|
#include <faiss/IndexRefine.h>
|
|
47
50
|
#include <faiss/IndexRowwiseMinMax.h>
|
|
51
|
+
#ifdef FAISS_ENABLE_SVS
|
|
52
|
+
#include <faiss/impl/svs_io.h>
|
|
53
|
+
#include <faiss/svs/IndexSVSFlat.h>
|
|
54
|
+
#include <faiss/svs/IndexSVSVamana.h>
|
|
55
|
+
#include <faiss/svs/IndexSVSVamanaLVQ.h>
|
|
56
|
+
#include <faiss/svs/IndexSVSVamanaLeanVec.h>
|
|
57
|
+
#endif
|
|
48
58
|
#include <faiss/IndexScalarQuantizer.h>
|
|
49
59
|
#include <faiss/MetaIndexes.h>
|
|
50
60
|
#include <faiss/VectorTransform.h>
|
|
@@ -68,9 +78,10 @@ namespace faiss {
|
|
|
68
78
|
**************************************************************/
|
|
69
79
|
|
|
70
80
|
// This is a baseline functionality for reading mmapped and zerocopied vector.
|
|
71
|
-
// * if `beforeknown_size` is defined, then a size of the vector won't be
|
|
81
|
+
// * if `beforeknown_size` is defined, then a size of the vector won't be
|
|
82
|
+
// read.
|
|
72
83
|
// * if `size_multiplier` is defined, then a size will be multiplied by it.
|
|
73
|
-
// * returns true is the case was handled;
|
|
84
|
+
// * returns true is the case was handled; otherwise, false
|
|
74
85
|
template <typename VectorT>
|
|
75
86
|
bool read_vector_base(
|
|
76
87
|
VectorT& target,
|
|
@@ -181,7 +192,7 @@ void read_vector(VectorT& target, IOReader* f) {
|
|
|
181
192
|
// a replacement for READXBVECTOR
|
|
182
193
|
template <typename VectorT>
|
|
183
194
|
void read_xb_vector(VectorT& target, IOReader* f) {
|
|
184
|
-
// size is not known beforehand,
|
|
195
|
+
// size is not known beforehand, multiply the size 4x
|
|
185
196
|
if (read_vector_base<VectorT>(target, f, std::nullopt, 4)) {
|
|
186
197
|
return;
|
|
187
198
|
}
|
|
@@ -325,6 +336,34 @@ InvertedLists* read_InvertedLists(IOReader* f, int io_flags) {
|
|
|
325
336
|
"read_InvertedLists:"
|
|
326
337
|
" WARN! inverted lists not stored with IVF object\n");
|
|
327
338
|
return nullptr;
|
|
339
|
+
} else if (h == fourcc("ilpn") && !(io_flags & IO_FLAG_SKIP_IVF_DATA)) {
|
|
340
|
+
size_t nlist, code_size, n_levels;
|
|
341
|
+
READ1(nlist);
|
|
342
|
+
READ1(code_size);
|
|
343
|
+
READ1(n_levels);
|
|
344
|
+
auto ailp = new ArrayInvertedListsPanorama(nlist, code_size, n_levels);
|
|
345
|
+
std::vector<size_t> sizes(nlist);
|
|
346
|
+
read_ArrayInvertedLists_sizes(f, sizes);
|
|
347
|
+
for (size_t i = 0; i < nlist; i++) {
|
|
348
|
+
ailp->ids[i].resize(sizes[i]);
|
|
349
|
+
size_t num_elems =
|
|
350
|
+
((sizes[i] + ArrayInvertedListsPanorama::kBatchSize - 1) /
|
|
351
|
+
ArrayInvertedListsPanorama::kBatchSize) *
|
|
352
|
+
ArrayInvertedListsPanorama::kBatchSize;
|
|
353
|
+
ailp->codes[i].resize(num_elems * code_size);
|
|
354
|
+
ailp->cum_sums[i].resize(num_elems * (n_levels + 1));
|
|
355
|
+
}
|
|
356
|
+
for (size_t i = 0; i < nlist; i++) {
|
|
357
|
+
size_t n = sizes[i];
|
|
358
|
+
if (n > 0) {
|
|
359
|
+
read_vector_with_known_size(
|
|
360
|
+
ailp->codes[i], f, ailp->codes[i].size());
|
|
361
|
+
read_vector_with_known_size(ailp->ids[i], f, n);
|
|
362
|
+
read_vector_with_known_size(
|
|
363
|
+
ailp->cum_sums[i], f, ailp->cum_sums[i].size());
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return ailp;
|
|
328
367
|
} else if (h == fourcc("ilar") && !(io_flags & IO_FLAG_SKIP_IVF_DATA)) {
|
|
329
368
|
auto ails = new ArrayInvertedLists(0, 0);
|
|
330
369
|
READ1(ails->nlist);
|
|
@@ -575,11 +614,19 @@ ProductQuantizer* read_ProductQuantizer(IOReader* reader) {
|
|
|
575
614
|
return pq;
|
|
576
615
|
}
|
|
577
616
|
|
|
578
|
-
static void read_RaBitQuantizer(
|
|
579
|
-
|
|
617
|
+
static void read_RaBitQuantizer(
|
|
618
|
+
RaBitQuantizer* rabitq,
|
|
619
|
+
IOReader* f,
|
|
620
|
+
bool multi_bit = true) {
|
|
580
621
|
READ1(rabitq->d);
|
|
581
622
|
READ1(rabitq->code_size);
|
|
582
623
|
READ1(rabitq->metric_type);
|
|
624
|
+
|
|
625
|
+
if (multi_bit) {
|
|
626
|
+
READ1(rabitq->nb_bits);
|
|
627
|
+
} else {
|
|
628
|
+
rabitq->nb_bits = 1;
|
|
629
|
+
}
|
|
583
630
|
}
|
|
584
631
|
|
|
585
632
|
void read_direct_map(DirectMap* dm, IOReader* f) {
|
|
@@ -681,6 +728,20 @@ Index* read_index(IOReader* f, int io_flags) {
|
|
|
681
728
|
if (h == fourcc("null")) {
|
|
682
729
|
// denotes a missing index, useful for some cases
|
|
683
730
|
return nullptr;
|
|
731
|
+
} else if (h == fourcc("IxFP")) {
|
|
732
|
+
int d;
|
|
733
|
+
size_t n_levels, batch_size;
|
|
734
|
+
READ1(d);
|
|
735
|
+
READ1(n_levels);
|
|
736
|
+
READ1(batch_size);
|
|
737
|
+
IndexFlatL2Panorama* idxp =
|
|
738
|
+
new IndexFlatL2Panorama(d, n_levels, batch_size);
|
|
739
|
+
READ1(idxp->ntotal);
|
|
740
|
+
READ1(idxp->is_trained);
|
|
741
|
+
READVECTOR(idxp->codes);
|
|
742
|
+
READVECTOR(idxp->cum_sums);
|
|
743
|
+
idxp->verbose = false;
|
|
744
|
+
idx = idxp;
|
|
684
745
|
} else if (
|
|
685
746
|
h == fourcc("IxFI") || h == fourcc("IxF2") || h == fourcc("IxFl")) {
|
|
686
747
|
IndexFlat* idxf;
|
|
@@ -927,6 +988,13 @@ Index* read_index(IOReader* f, int io_flags) {
|
|
|
927
988
|
}
|
|
928
989
|
read_InvertedLists(ivfl, f, io_flags);
|
|
929
990
|
idx = ivfl;
|
|
991
|
+
} else if (h == fourcc("IwPn")) {
|
|
992
|
+
IndexIVFFlatPanorama* ivfp = new IndexIVFFlatPanorama();
|
|
993
|
+
read_ivf_header(ivfp, f);
|
|
994
|
+
ivfp->code_size = ivfp->d * sizeof(float);
|
|
995
|
+
READ1(ivfp->n_levels);
|
|
996
|
+
read_InvertedLists(ivfp, f, io_flags);
|
|
997
|
+
idx = ivfp;
|
|
930
998
|
} else if (h == fourcc("IwFl")) {
|
|
931
999
|
IndexIVFFlat* ivfl = new IndexIVFFlat();
|
|
932
1000
|
read_ivf_header(ivfl, f);
|
|
@@ -1058,13 +1126,19 @@ Index* read_index(IOReader* f, int io_flags) {
|
|
|
1058
1126
|
read_index_header(imiq, f);
|
|
1059
1127
|
read_ProductQuantizer(&imiq->pq, f);
|
|
1060
1128
|
idx = imiq;
|
|
1061
|
-
} else if (h == fourcc("IxRF")) {
|
|
1129
|
+
} else if (h == fourcc("IxRF") || h == fourcc("IxRP")) {
|
|
1062
1130
|
IndexRefine* idxrf = new IndexRefine();
|
|
1063
1131
|
read_index_header(idxrf, f);
|
|
1064
1132
|
idxrf->base_index = read_index(f, io_flags);
|
|
1065
1133
|
idxrf->refine_index = read_index(f, io_flags);
|
|
1066
1134
|
READ1(idxrf->k_factor);
|
|
1067
|
-
if (
|
|
1135
|
+
if (h == fourcc("IxRP")) {
|
|
1136
|
+
// then make a RefineFlatPanorama with it
|
|
1137
|
+
IndexRefine* idxrf_old = idxrf;
|
|
1138
|
+
idxrf = new IndexRefinePanorama();
|
|
1139
|
+
*idxrf = *idxrf_old;
|
|
1140
|
+
delete idxrf_old;
|
|
1141
|
+
} else if (dynamic_cast<IndexFlat*>(idxrf->refine_index)) {
|
|
1068
1142
|
// then make a RefineFlat with it
|
|
1069
1143
|
IndexRefine* idxrf_old = idxrf;
|
|
1070
1144
|
idxrf = new IndexRefineFlat();
|
|
@@ -1099,11 +1173,15 @@ Index* read_index(IOReader* f, int io_flags) {
|
|
|
1099
1173
|
idx = idxp;
|
|
1100
1174
|
} else if (
|
|
1101
1175
|
h == fourcc("IHNf") || h == fourcc("IHNp") || h == fourcc("IHNs") ||
|
|
1102
|
-
h == fourcc("IHN2") || h == fourcc("IHNc") || h == fourcc("IHc2")
|
|
1176
|
+
h == fourcc("IHN2") || h == fourcc("IHNc") || h == fourcc("IHc2") ||
|
|
1177
|
+
h == fourcc("IHfP")) {
|
|
1103
1178
|
IndexHNSW* idxhnsw = nullptr;
|
|
1104
1179
|
if (h == fourcc("IHNf")) {
|
|
1105
1180
|
idxhnsw = new IndexHNSWFlat();
|
|
1106
1181
|
}
|
|
1182
|
+
if (h == fourcc("IHfP")) {
|
|
1183
|
+
idxhnsw = new IndexHNSWFlatPanorama();
|
|
1184
|
+
}
|
|
1107
1185
|
if (h == fourcc("IHNp")) {
|
|
1108
1186
|
idxhnsw = new IndexHNSWPQ();
|
|
1109
1187
|
}
|
|
@@ -1120,6 +1198,15 @@ Index* read_index(IOReader* f, int io_flags) {
|
|
|
1120
1198
|
idxhnsw = new IndexHNSWCagra();
|
|
1121
1199
|
}
|
|
1122
1200
|
read_index_header(idxhnsw, f);
|
|
1201
|
+
if (h == fourcc("IHfP")) {
|
|
1202
|
+
auto idx_panorama = dynamic_cast<IndexHNSWFlatPanorama*>(idxhnsw);
|
|
1203
|
+
size_t nlevels;
|
|
1204
|
+
READ1(nlevels);
|
|
1205
|
+
const_cast<size_t&>(idx_panorama->num_panorama_levels) = nlevels;
|
|
1206
|
+
const_cast<size_t&>(idx_panorama->panorama_level_width) =
|
|
1207
|
+
(idx_panorama->d + nlevels - 1) / nlevels;
|
|
1208
|
+
READVECTOR(idx_panorama->cum_sums);
|
|
1209
|
+
}
|
|
1123
1210
|
if (h == fourcc("IHNc") || h == fourcc("IHc2")) {
|
|
1124
1211
|
READ1(idxhnsw->keep_max_size_level0);
|
|
1125
1212
|
auto idx_hnsw_cagra = dynamic_cast<IndexHNSWCagra*>(idxhnsw);
|
|
@@ -1132,6 +1219,7 @@ Index* read_index(IOReader* f, int io_flags) {
|
|
|
1132
1219
|
}
|
|
1133
1220
|
}
|
|
1134
1221
|
read_HNSW(&idxhnsw->hnsw, f);
|
|
1222
|
+
idxhnsw->hnsw.is_panorama = (h == fourcc("IHfP"));
|
|
1135
1223
|
idxhnsw->storage = read_index(f, io_flags);
|
|
1136
1224
|
idxhnsw->own_fields = idxhnsw->storage != nullptr;
|
|
1137
1225
|
if (h == fourcc("IHNp") && !(io_flags & IO_FLAG_PQ_SKIP_SDC_TABLE)) {
|
|
@@ -1224,24 +1312,162 @@ Index* read_index(IOReader* f, int io_flags) {
|
|
|
1224
1312
|
imm->own_fields = true;
|
|
1225
1313
|
|
|
1226
1314
|
idx = imm;
|
|
1315
|
+
} else if (h == fourcc("Irfs")) {
|
|
1316
|
+
IndexRaBitQFastScan* idxqfs = new IndexRaBitQFastScan();
|
|
1317
|
+
read_index_header(idxqfs, f);
|
|
1318
|
+
read_RaBitQuantizer(&idxqfs->rabitq, f, true);
|
|
1319
|
+
READVECTOR(idxqfs->center);
|
|
1320
|
+
READ1(idxqfs->qb);
|
|
1321
|
+
READVECTOR(idxqfs->flat_storage);
|
|
1322
|
+
|
|
1323
|
+
READ1(idxqfs->bbs);
|
|
1324
|
+
READ1(idxqfs->ntotal2);
|
|
1325
|
+
READ1(idxqfs->M2);
|
|
1326
|
+
READ1(idxqfs->code_size);
|
|
1327
|
+
|
|
1328
|
+
const size_t M_fastscan = (idxqfs->d + 3) / 4;
|
|
1329
|
+
constexpr size_t nbits_fastscan = 4;
|
|
1330
|
+
idxqfs->M = M_fastscan;
|
|
1331
|
+
idxqfs->nbits = nbits_fastscan;
|
|
1332
|
+
idxqfs->ksub = (1 << nbits_fastscan);
|
|
1333
|
+
|
|
1334
|
+
READVECTOR(idxqfs->codes);
|
|
1335
|
+
idx = idxqfs;
|
|
1227
1336
|
} else if (h == fourcc("Ixrq")) {
|
|
1228
1337
|
IndexRaBitQ* idxq = new IndexRaBitQ();
|
|
1229
1338
|
read_index_header(idxq, f);
|
|
1230
|
-
read_RaBitQuantizer(&idxq->rabitq, f);
|
|
1339
|
+
read_RaBitQuantizer(&idxq->rabitq, f, false);
|
|
1231
1340
|
READVECTOR(idxq->codes);
|
|
1232
1341
|
READVECTOR(idxq->center);
|
|
1233
1342
|
READ1(idxq->qb);
|
|
1343
|
+
|
|
1344
|
+
// rabitq.nb_bits is already set to 1 by read_RaBitQuantizer
|
|
1345
|
+
idxq->code_size = idxq->rabitq.code_size;
|
|
1346
|
+
idx = idxq;
|
|
1347
|
+
} else if (h == fourcc("Ixrr")) {
|
|
1348
|
+
// Ixrr = multi-bit format (new)
|
|
1349
|
+
IndexRaBitQ* idxq = new IndexRaBitQ();
|
|
1350
|
+
read_index_header(idxq, f);
|
|
1351
|
+
read_RaBitQuantizer(&idxq->rabitq, f, true); // Reads nb_bits from file
|
|
1352
|
+
READVECTOR(idxq->codes);
|
|
1353
|
+
READVECTOR(idxq->center);
|
|
1354
|
+
READ1(idxq->qb);
|
|
1355
|
+
|
|
1234
1356
|
idxq->code_size = idxq->rabitq.code_size;
|
|
1235
1357
|
idx = idxq;
|
|
1236
1358
|
} else if (h == fourcc("Iwrq")) {
|
|
1237
1359
|
IndexIVFRaBitQ* ivrq = new IndexIVFRaBitQ();
|
|
1238
1360
|
read_ivf_header(ivrq, f);
|
|
1239
|
-
read_RaBitQuantizer(&ivrq->rabitq, f);
|
|
1361
|
+
read_RaBitQuantizer(&ivrq->rabitq, f, false);
|
|
1362
|
+
READ1(ivrq->code_size);
|
|
1363
|
+
READ1(ivrq->by_residual);
|
|
1364
|
+
READ1(ivrq->qb);
|
|
1365
|
+
|
|
1366
|
+
// rabitq.nb_bits is already set to 1 by read_RaBitQuantizer
|
|
1367
|
+
// Update rabitq to match nb_bits
|
|
1368
|
+
ivrq->rabitq.code_size =
|
|
1369
|
+
ivrq->rabitq.compute_code_size(ivrq->d, ivrq->rabitq.nb_bits);
|
|
1370
|
+
ivrq->code_size = ivrq->rabitq.code_size;
|
|
1371
|
+
read_InvertedLists(ivrq, f, io_flags);
|
|
1372
|
+
idx = ivrq;
|
|
1373
|
+
} else if (h == fourcc("Iwrr")) {
|
|
1374
|
+
// Iwrr = multi-bit format (new)
|
|
1375
|
+
IndexIVFRaBitQ* ivrq = new IndexIVFRaBitQ();
|
|
1376
|
+
read_ivf_header(ivrq, f);
|
|
1377
|
+
read_RaBitQuantizer(&ivrq->rabitq, f, true); // Reads nb_bits from file
|
|
1240
1378
|
READ1(ivrq->code_size);
|
|
1241
1379
|
READ1(ivrq->by_residual);
|
|
1242
1380
|
READ1(ivrq->qb);
|
|
1381
|
+
|
|
1382
|
+
// Update rabitq to match nb_bits
|
|
1383
|
+
ivrq->rabitq.code_size =
|
|
1384
|
+
ivrq->rabitq.compute_code_size(ivrq->d, ivrq->rabitq.nb_bits);
|
|
1385
|
+
ivrq->code_size = ivrq->rabitq.code_size;
|
|
1243
1386
|
read_InvertedLists(ivrq, f, io_flags);
|
|
1244
1387
|
idx = ivrq;
|
|
1388
|
+
}
|
|
1389
|
+
#ifdef FAISS_ENABLE_SVS
|
|
1390
|
+
else if (
|
|
1391
|
+
h == fourcc("ILVQ") || h == fourcc("ISVL") || h == fourcc("ISVD")) {
|
|
1392
|
+
IndexSVSVamana* svs;
|
|
1393
|
+
if (h == fourcc("ILVQ")) {
|
|
1394
|
+
svs = new IndexSVSVamanaLVQ();
|
|
1395
|
+
} else if (h == fourcc("ISVL")) {
|
|
1396
|
+
svs = new IndexSVSVamanaLeanVec();
|
|
1397
|
+
} else if (h == fourcc("ISVD")) {
|
|
1398
|
+
svs = new IndexSVSVamana();
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
read_index_header(svs, f);
|
|
1402
|
+
READ1(svs->graph_max_degree);
|
|
1403
|
+
READ1(svs->alpha);
|
|
1404
|
+
READ1(svs->search_window_size);
|
|
1405
|
+
READ1(svs->search_buffer_capacity);
|
|
1406
|
+
READ1(svs->construction_window_size);
|
|
1407
|
+
READ1(svs->max_candidate_pool_size);
|
|
1408
|
+
READ1(svs->prune_to);
|
|
1409
|
+
READ1(svs->use_full_search_history);
|
|
1410
|
+
READ1(svs->storage_kind);
|
|
1411
|
+
if (h == fourcc("ISVL")) {
|
|
1412
|
+
READ1(dynamic_cast<IndexSVSVamanaLeanVec*>(svs)->leanvec_d);
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
bool initialized;
|
|
1416
|
+
READ1(initialized);
|
|
1417
|
+
if (initialized) {
|
|
1418
|
+
faiss::svs_io::ReaderStreambuf rbuf(f);
|
|
1419
|
+
std::istream is(&rbuf);
|
|
1420
|
+
svs->deserialize_impl(is);
|
|
1421
|
+
}
|
|
1422
|
+
if (h == fourcc("ISVL")) {
|
|
1423
|
+
bool trained;
|
|
1424
|
+
READ1(trained);
|
|
1425
|
+
if (trained) {
|
|
1426
|
+
faiss::svs_io::ReaderStreambuf rbuf(f);
|
|
1427
|
+
std::istream is(&rbuf);
|
|
1428
|
+
dynamic_cast<IndexSVSVamanaLeanVec*>(svs)
|
|
1429
|
+
->deserialize_training_data(is);
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
idx = svs;
|
|
1433
|
+
} else if (h == fourcc("ISVF")) {
|
|
1434
|
+
IndexSVSFlat* svs = new IndexSVSFlat();
|
|
1435
|
+
read_index_header(svs, f);
|
|
1436
|
+
|
|
1437
|
+
bool initialized;
|
|
1438
|
+
READ1(initialized);
|
|
1439
|
+
if (initialized) {
|
|
1440
|
+
faiss::svs_io::ReaderStreambuf rbuf(f);
|
|
1441
|
+
std::istream is(&rbuf);
|
|
1442
|
+
svs->deserialize_impl(is);
|
|
1443
|
+
idx = svs;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
#endif // FAISS_ENABLE_SVS
|
|
1447
|
+
else if (h == fourcc("Iwrf")) {
|
|
1448
|
+
IndexIVFRaBitQFastScan* ivrqfs = new IndexIVFRaBitQFastScan();
|
|
1449
|
+
read_ivf_header(ivrqfs, f);
|
|
1450
|
+
read_RaBitQuantizer(&ivrqfs->rabitq, f);
|
|
1451
|
+
READ1(ivrqfs->by_residual);
|
|
1452
|
+
READ1(ivrqfs->code_size);
|
|
1453
|
+
READ1(ivrqfs->bbs);
|
|
1454
|
+
READ1(ivrqfs->qbs2);
|
|
1455
|
+
READ1(ivrqfs->M2);
|
|
1456
|
+
READ1(ivrqfs->implem);
|
|
1457
|
+
READ1(ivrqfs->qb);
|
|
1458
|
+
READ1(ivrqfs->centered);
|
|
1459
|
+
READVECTOR(ivrqfs->flat_storage);
|
|
1460
|
+
|
|
1461
|
+
// Initialize FastScan base class fields
|
|
1462
|
+
const size_t M_fastscan = (ivrqfs->d + 3) / 4;
|
|
1463
|
+
constexpr size_t nbits_fastscan = 4;
|
|
1464
|
+
ivrqfs->M = M_fastscan;
|
|
1465
|
+
ivrqfs->nbits = nbits_fastscan;
|
|
1466
|
+
ivrqfs->ksub = (1 << nbits_fastscan);
|
|
1467
|
+
|
|
1468
|
+
read_InvertedLists(ivrqfs, f, io_flags);
|
|
1469
|
+
ivrqfs->init_code_packer();
|
|
1470
|
+
idx = ivrqfs;
|
|
1245
1471
|
} else {
|
|
1246
1472
|
FAISS_THROW_FMT(
|
|
1247
1473
|
"Index type 0x%08x (\"%s\") not recognized",
|
|
@@ -1396,6 +1622,7 @@ IndexBinary* read_index_binary(IOReader* f, int io_flags) {
|
|
|
1396
1622
|
IndexBinaryHNSW* idxhnsw = new IndexBinaryHNSW();
|
|
1397
1623
|
read_index_binary_header(idxhnsw, f);
|
|
1398
1624
|
read_HNSW(&idxhnsw->hnsw, f);
|
|
1625
|
+
idxhnsw->hnsw.is_panorama = false;
|
|
1399
1626
|
idxhnsw->storage = read_index_binary(f, io_flags);
|
|
1400
1627
|
idxhnsw->own_fields = true;
|
|
1401
1628
|
idx = idxhnsw;
|
|
@@ -1406,6 +1633,7 @@ IndexBinary* read_index_binary(IOReader* f, int io_flags) {
|
|
|
1406
1633
|
READ1(idxhnsw->base_level_only);
|
|
1407
1634
|
READ1(idxhnsw->num_base_level_search_entrypoints);
|
|
1408
1635
|
read_HNSW(&idxhnsw->hnsw, f);
|
|
1636
|
+
idxhnsw->hnsw.is_panorama = false;
|
|
1409
1637
|
idxhnsw->storage = read_index_binary(f, io_flags);
|
|
1410
1638
|
idxhnsw->own_fields = true;
|
|
1411
1639
|
idx = idxhnsw;
|