faiss 0.2.6 → 0.2.7
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 +4 -0
- data/ext/faiss/extconf.rb +1 -1
- data/lib/faiss/version.rb +1 -1
- data/lib/faiss.rb +2 -2
- data/vendor/faiss/faiss/AutoTune.cpp +15 -4
- data/vendor/faiss/faiss/AutoTune.h +0 -1
- data/vendor/faiss/faiss/Clustering.cpp +1 -5
- data/vendor/faiss/faiss/Clustering.h +0 -2
- data/vendor/faiss/faiss/IVFlib.h +0 -2
- data/vendor/faiss/faiss/Index.h +1 -2
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.cpp +17 -3
- data/vendor/faiss/faiss/IndexAdditiveQuantizer.h +10 -1
- data/vendor/faiss/faiss/IndexBinary.h +0 -1
- data/vendor/faiss/faiss/IndexBinaryFlat.cpp +2 -1
- data/vendor/faiss/faiss/IndexBinaryFlat.h +4 -0
- data/vendor/faiss/faiss/IndexBinaryHash.cpp +1 -3
- data/vendor/faiss/faiss/IndexBinaryIVF.cpp +273 -48
- data/vendor/faiss/faiss/IndexBinaryIVF.h +18 -11
- data/vendor/faiss/faiss/IndexFastScan.cpp +13 -10
- data/vendor/faiss/faiss/IndexFastScan.h +5 -1
- data/vendor/faiss/faiss/IndexFlat.cpp +16 -3
- data/vendor/faiss/faiss/IndexFlat.h +1 -1
- data/vendor/faiss/faiss/IndexFlatCodes.cpp +5 -0
- data/vendor/faiss/faiss/IndexFlatCodes.h +7 -2
- data/vendor/faiss/faiss/IndexHNSW.cpp +3 -6
- data/vendor/faiss/faiss/IndexHNSW.h +0 -1
- data/vendor/faiss/faiss/IndexIDMap.cpp +4 -4
- data/vendor/faiss/faiss/IndexIDMap.h +0 -2
- data/vendor/faiss/faiss/IndexIVF.cpp +155 -129
- data/vendor/faiss/faiss/IndexIVF.h +121 -61
- data/vendor/faiss/faiss/IndexIVFAdditiveQuantizer.cpp +2 -2
- data/vendor/faiss/faiss/IndexIVFFastScan.cpp +12 -11
- data/vendor/faiss/faiss/IndexIVFFastScan.h +6 -1
- data/vendor/faiss/faiss/IndexIVFPQ.cpp +221 -165
- data/vendor/faiss/faiss/IndexIVFPQ.h +1 -0
- data/vendor/faiss/faiss/IndexIVFPQFastScan.cpp +6 -1
- data/vendor/faiss/faiss/IndexIVFSpectralHash.cpp +0 -2
- data/vendor/faiss/faiss/IndexNNDescent.cpp +1 -2
- data/vendor/faiss/faiss/IndexNNDescent.h +0 -1
- data/vendor/faiss/faiss/IndexNSG.cpp +1 -2
- data/vendor/faiss/faiss/IndexPQ.cpp +7 -9
- data/vendor/faiss/faiss/IndexRefine.cpp +1 -1
- data/vendor/faiss/faiss/IndexReplicas.cpp +3 -4
- data/vendor/faiss/faiss/IndexReplicas.h +0 -1
- data/vendor/faiss/faiss/IndexRowwiseMinMax.cpp +8 -1
- data/vendor/faiss/faiss/IndexRowwiseMinMax.h +7 -0
- data/vendor/faiss/faiss/IndexShards.cpp +26 -109
- data/vendor/faiss/faiss/IndexShards.h +2 -3
- data/vendor/faiss/faiss/IndexShardsIVF.cpp +246 -0
- data/vendor/faiss/faiss/IndexShardsIVF.h +42 -0
- data/vendor/faiss/faiss/MetaIndexes.cpp +86 -0
- data/vendor/faiss/faiss/MetaIndexes.h +29 -0
- data/vendor/faiss/faiss/MetricType.h +14 -0
- data/vendor/faiss/faiss/VectorTransform.cpp +8 -10
- data/vendor/faiss/faiss/VectorTransform.h +1 -3
- data/vendor/faiss/faiss/clone_index.cpp +232 -18
- data/vendor/faiss/faiss/cppcontrib/SaDecodeKernels.h +25 -3
- data/vendor/faiss/faiss/cppcontrib/detail/CoarseBitType.h +7 -0
- data/vendor/faiss/faiss/cppcontrib/detail/UintReader.h +78 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-avx2-inl.h +20 -6
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-inl.h +7 -1
- data/vendor/faiss/faiss/cppcontrib/sa_decode/Level2-neon-inl.h +21 -7
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMax-inl.h +7 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/MinMaxFP16-inl.h +7 -0
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-avx2-inl.h +10 -3
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-inl.h +7 -1
- data/vendor/faiss/faiss/cppcontrib/sa_decode/PQ-neon-inl.h +11 -3
- data/vendor/faiss/faiss/gpu/GpuAutoTune.cpp +25 -2
- data/vendor/faiss/faiss/gpu/GpuCloner.cpp +76 -29
- data/vendor/faiss/faiss/gpu/GpuCloner.h +2 -2
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.h +14 -13
- data/vendor/faiss/faiss/gpu/GpuDistance.h +18 -6
- data/vendor/faiss/faiss/gpu/GpuIndex.h +23 -21
- data/vendor/faiss/faiss/gpu/GpuIndexBinaryFlat.h +10 -10
- data/vendor/faiss/faiss/gpu/GpuIndexFlat.h +11 -12
- data/vendor/faiss/faiss/gpu/GpuIndexIVF.h +29 -50
- data/vendor/faiss/faiss/gpu/GpuIndexIVFFlat.h +3 -3
- data/vendor/faiss/faiss/gpu/GpuIndexIVFPQ.h +8 -8
- data/vendor/faiss/faiss/gpu/GpuIndexIVFScalarQuantizer.h +4 -4
- data/vendor/faiss/faiss/gpu/impl/IndexUtils.h +2 -5
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.cpp +9 -7
- data/vendor/faiss/faiss/gpu/impl/RemapIndices.h +4 -4
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper-inl.h +2 -2
- data/vendor/faiss/faiss/gpu/perf/IndexWrapper.h +1 -1
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexBinaryFlat.cpp +55 -6
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexFlat.cpp +20 -6
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFFlat.cpp +95 -25
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFPQ.cpp +67 -16
- data/vendor/faiss/faiss/gpu/test/TestGpuIndexIVFScalarQuantizer.cpp +4 -4
- data/vendor/faiss/faiss/gpu/test/TestUtils.cpp +7 -7
- data/vendor/faiss/faiss/gpu/test/TestUtils.h +4 -4
- data/vendor/faiss/faiss/gpu/test/demo_ivfpq_indexing_gpu.cpp +1 -1
- data/vendor/faiss/faiss/gpu/utils/DeviceUtils.h +6 -0
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.cpp +0 -7
- data/vendor/faiss/faiss/impl/AdditiveQuantizer.h +9 -9
- data/vendor/faiss/faiss/impl/AuxIndexStructures.cpp +1 -1
- data/vendor/faiss/faiss/impl/AuxIndexStructures.h +2 -7
- data/vendor/faiss/faiss/impl/CodePacker.cpp +67 -0
- data/vendor/faiss/faiss/impl/CodePacker.h +71 -0
- data/vendor/faiss/faiss/impl/DistanceComputer.h +0 -2
- data/vendor/faiss/faiss/impl/HNSW.cpp +3 -7
- data/vendor/faiss/faiss/impl/HNSW.h +6 -9
- data/vendor/faiss/faiss/impl/IDSelector.cpp +1 -1
- data/vendor/faiss/faiss/impl/IDSelector.h +39 -1
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.cpp +62 -51
- data/vendor/faiss/faiss/impl/LocalSearchQuantizer.h +11 -12
- data/vendor/faiss/faiss/impl/NNDescent.cpp +3 -9
- data/vendor/faiss/faiss/impl/NNDescent.h +10 -10
- data/vendor/faiss/faiss/impl/NSG.cpp +1 -6
- data/vendor/faiss/faiss/impl/NSG.h +4 -7
- data/vendor/faiss/faiss/impl/PolysemousTraining.cpp +1 -15
- data/vendor/faiss/faiss/impl/PolysemousTraining.h +11 -10
- data/vendor/faiss/faiss/impl/ProductAdditiveQuantizer.cpp +0 -7
- data/vendor/faiss/faiss/impl/ProductQuantizer.cpp +25 -12
- data/vendor/faiss/faiss/impl/ProductQuantizer.h +2 -4
- data/vendor/faiss/faiss/impl/Quantizer.h +6 -3
- data/vendor/faiss/faiss/impl/ResidualQuantizer.cpp +796 -174
- data/vendor/faiss/faiss/impl/ResidualQuantizer.h +16 -8
- data/vendor/faiss/faiss/impl/ScalarQuantizer.cpp +3 -5
- data/vendor/faiss/faiss/impl/ScalarQuantizer.h +4 -4
- data/vendor/faiss/faiss/impl/ThreadedIndex-inl.h +3 -3
- data/vendor/faiss/faiss/impl/ThreadedIndex.h +4 -4
- data/vendor/faiss/faiss/impl/code_distance/code_distance-avx2.h +291 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance-generic.h +74 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance.h +123 -0
- data/vendor/faiss/faiss/impl/code_distance/code_distance_avx512.h +102 -0
- data/vendor/faiss/faiss/impl/index_read.cpp +13 -10
- data/vendor/faiss/faiss/impl/index_write.cpp +3 -4
- data/vendor/faiss/faiss/impl/kmeans1d.cpp +0 -1
- data/vendor/faiss/faiss/impl/kmeans1d.h +3 -3
- data/vendor/faiss/faiss/impl/lattice_Zn.cpp +1 -1
- data/vendor/faiss/faiss/impl/platform_macros.h +61 -0
- data/vendor/faiss/faiss/impl/pq4_fast_scan.cpp +48 -4
- data/vendor/faiss/faiss/impl/pq4_fast_scan.h +18 -4
- data/vendor/faiss/faiss/impl/pq4_fast_scan_search_qbs.cpp +2 -2
- data/vendor/faiss/faiss/index_factory.cpp +8 -10
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.cpp +29 -12
- data/vendor/faiss/faiss/invlists/BlockInvertedLists.h +8 -2
- data/vendor/faiss/faiss/invlists/DirectMap.cpp +1 -1
- data/vendor/faiss/faiss/invlists/DirectMap.h +2 -4
- data/vendor/faiss/faiss/invlists/InvertedLists.cpp +118 -18
- data/vendor/faiss/faiss/invlists/InvertedLists.h +44 -4
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.cpp +3 -3
- data/vendor/faiss/faiss/invlists/OnDiskInvertedLists.h +1 -1
- data/vendor/faiss/faiss/python/python_callbacks.cpp +1 -1
- data/vendor/faiss/faiss/python/python_callbacks.h +1 -1
- data/vendor/faiss/faiss/utils/AlignedTable.h +3 -1
- data/vendor/faiss/faiss/utils/Heap.cpp +139 -3
- data/vendor/faiss/faiss/utils/Heap.h +35 -1
- data/vendor/faiss/faiss/utils/approx_topk/approx_topk.h +84 -0
- data/vendor/faiss/faiss/utils/approx_topk/avx2-inl.h +196 -0
- data/vendor/faiss/faiss/utils/approx_topk/generic.h +138 -0
- data/vendor/faiss/faiss/utils/approx_topk/mode.h +34 -0
- data/vendor/faiss/faiss/utils/approx_topk_hamming/approx_topk_hamming.h +367 -0
- data/vendor/faiss/faiss/utils/distances.cpp +61 -7
- data/vendor/faiss/faiss/utils/distances.h +11 -0
- data/vendor/faiss/faiss/utils/distances_fused/avx512.cpp +346 -0
- data/vendor/faiss/faiss/utils/distances_fused/avx512.h +36 -0
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.cpp +42 -0
- data/vendor/faiss/faiss/utils/distances_fused/distances_fused.h +40 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.cpp +352 -0
- data/vendor/faiss/faiss/utils/distances_fused/simdlib_based.h +32 -0
- data/vendor/faiss/faiss/utils/distances_simd.cpp +515 -327
- data/vendor/faiss/faiss/utils/extra_distances-inl.h +17 -1
- data/vendor/faiss/faiss/utils/extra_distances.cpp +37 -8
- data/vendor/faiss/faiss/utils/extra_distances.h +2 -1
- data/vendor/faiss/faiss/utils/fp16-fp16c.h +7 -0
- data/vendor/faiss/faiss/utils/fp16-inl.h +7 -0
- data/vendor/faiss/faiss/utils/fp16.h +7 -0
- data/vendor/faiss/faiss/utils/hamming-inl.h +0 -456
- data/vendor/faiss/faiss/utils/hamming.cpp +104 -120
- data/vendor/faiss/faiss/utils/hamming.h +21 -10
- data/vendor/faiss/faiss/utils/hamming_distance/avx2-inl.h +535 -0
- data/vendor/faiss/faiss/utils/hamming_distance/common.h +48 -0
- data/vendor/faiss/faiss/utils/hamming_distance/generic-inl.h +519 -0
- data/vendor/faiss/faiss/utils/hamming_distance/hamdis-inl.h +26 -0
- data/vendor/faiss/faiss/utils/hamming_distance/neon-inl.h +614 -0
- data/vendor/faiss/faiss/utils/partitioning.cpp +21 -25
- data/vendor/faiss/faiss/utils/simdlib_avx2.h +344 -3
- data/vendor/faiss/faiss/utils/simdlib_emulated.h +390 -0
- data/vendor/faiss/faiss/utils/simdlib_neon.h +655 -130
- data/vendor/faiss/faiss/utils/sorting.cpp +692 -0
- data/vendor/faiss/faiss/utils/sorting.h +71 -0
- data/vendor/faiss/faiss/utils/transpose/transpose-avx2-inl.h +165 -0
- data/vendor/faiss/faiss/utils/utils.cpp +4 -176
- data/vendor/faiss/faiss/utils/utils.h +2 -9
- metadata +29 -3
- data/vendor/faiss/faiss/gpu/GpuClonerOptions.cpp +0 -26
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d0e67c5b23ef30f3632f8f878bba1ed8be7cbf8212c21a799daca8a65c23fcb
|
|
4
|
+
data.tar.gz: d3bcbf4453ece0531cb3cfa017bf60327fffa47401a27451ccb501c11431911e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 50f4c6ef3b637b708e0860f524eabb64b708868ce8210153f0868ff846a67ec24c4f229cf9146ab1dea0113b033e2287866ced15e750297ae79822cf9f131fe2
|
|
7
|
+
data.tar.gz: a3b0df6f2377c7381fdaab54f56e97a80ebaf5e752b92ba04b5d7a256c493a2bcbb14d60e4eeeb26a0d044f3159b4e416699ab6ecf774eb92f6e6014958d20b7
|
data/CHANGELOG.md
CHANGED
data/ext/faiss/extconf.rb
CHANGED
|
@@ -26,7 +26,7 @@ $CXXFLAGS << " -std=c++17 $(optflags) -DFINTEGER=int " << with_config("optflags"
|
|
|
26
26
|
ext = File.expand_path(".", __dir__)
|
|
27
27
|
vendor = File.expand_path("../../vendor/faiss", __dir__)
|
|
28
28
|
|
|
29
|
-
$srcs = Dir["{#{ext},#{vendor}/faiss,#{vendor}/faiss/{impl,invlists,utils}}/*.{cpp}"]
|
|
29
|
+
$srcs = Dir["{#{ext},#{vendor}/faiss,#{vendor}/faiss/{impl,invlists,utils}/**}/*.{cpp}"]
|
|
30
30
|
$objs = $srcs.map { |v| v.sub(/cpp\z/, "o") }
|
|
31
31
|
abort "Faiss not found" unless find_header("faiss/Index.h", vendor)
|
|
32
32
|
$VPATH << vendor
|
data/lib/faiss/version.rb
CHANGED
data/lib/faiss.rb
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
#include <faiss/IndexPreTransform.h>
|
|
33
33
|
#include <faiss/IndexRefine.h>
|
|
34
34
|
#include <faiss/IndexScalarQuantizer.h>
|
|
35
|
+
#include <faiss/IndexShardsIVF.h>
|
|
35
36
|
#include <faiss/MetaIndexes.h>
|
|
36
37
|
#include <faiss/VectorTransform.h>
|
|
37
38
|
|
|
@@ -354,7 +355,7 @@ void ParameterSpace::initialize(const Index* index) {
|
|
|
354
355
|
index = ix->index;
|
|
355
356
|
}
|
|
356
357
|
|
|
357
|
-
if (DC(
|
|
358
|
+
if (DC(IndexIVFInterface)) {
|
|
358
359
|
{
|
|
359
360
|
ParameterRange& pr = add_range("nprobe");
|
|
360
361
|
for (int i = 0; i < 13; i++) {
|
|
@@ -461,6 +462,16 @@ void ParameterSpace::set_index_parameter(
|
|
|
461
462
|
set_index_parameter(ix->index, name, val);
|
|
462
463
|
return;
|
|
463
464
|
}
|
|
465
|
+
if (DC(IndexShardsIVF)) {
|
|
466
|
+
// special handling because the nprobe is set at the sub-class level
|
|
467
|
+
// but other params are set on the class itself
|
|
468
|
+
if (name.find("quantizer_") == 0 && name != "nprobe" &&
|
|
469
|
+
name != "quantizer_nprobe") {
|
|
470
|
+
std::string sub_name = name.substr(strlen("quantizer_"));
|
|
471
|
+
set_index_parameter(ix->quantizer, sub_name, val);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
464
475
|
if (DC(ThreadedIndex<Index>)) {
|
|
465
476
|
// call on all sub-indexes
|
|
466
477
|
auto fn = [this, name, val](int /* no */, Index* subIndex) {
|
|
@@ -608,7 +619,7 @@ void ParameterSpace::explore(
|
|
|
608
619
|
if (n_experiments == 0) {
|
|
609
620
|
for (size_t cno = 0; cno < n_comb; cno++) {
|
|
610
621
|
set_index_parameters(index, cno);
|
|
611
|
-
std::vector<
|
|
622
|
+
std::vector<idx_t> I(nq * crit.nnn);
|
|
612
623
|
std::vector<float> D(nq * crit.nnn);
|
|
613
624
|
|
|
614
625
|
double t0 = getmillisecs();
|
|
@@ -677,7 +688,7 @@ void ParameterSpace::explore(
|
|
|
677
688
|
}
|
|
678
689
|
|
|
679
690
|
set_index_parameters(index, cno);
|
|
680
|
-
std::vector<
|
|
691
|
+
std::vector<idx_t> I(nq * crit.nnn);
|
|
681
692
|
std::vector<float> D(nq * crit.nnn);
|
|
682
693
|
|
|
683
694
|
double t0 = getmillisecs();
|
|
@@ -688,7 +699,7 @@ void ParameterSpace::explore(
|
|
|
688
699
|
do {
|
|
689
700
|
if (thread_over_batches) {
|
|
690
701
|
#pragma omp parallel for
|
|
691
|
-
for (
|
|
702
|
+
for (idx_t q0 = 0; q0 < nq; q0 += batchsize) {
|
|
692
703
|
size_t q1 = q0 + batchsize;
|
|
693
704
|
if (q1 > nq)
|
|
694
705
|
q1 = nq;
|
|
@@ -24,7 +24,6 @@ namespace faiss {
|
|
|
24
24
|
* higher is better.
|
|
25
25
|
*/
|
|
26
26
|
struct AutoTuneCriterion {
|
|
27
|
-
typedef Index::idx_t idx_t;
|
|
28
27
|
idx_t nq; ///< nb of queries this criterion is evaluated on
|
|
29
28
|
idx_t nnn; ///< nb of NNs that the query should request
|
|
30
29
|
idx_t gt_nnn; ///< nb of GT NNs required to evaluate criterion
|
|
@@ -88,8 +88,6 @@ void Clustering::train(
|
|
|
88
88
|
|
|
89
89
|
namespace {
|
|
90
90
|
|
|
91
|
-
using idx_t = Clustering::idx_t;
|
|
92
|
-
|
|
93
91
|
idx_t subsample_training_set(
|
|
94
92
|
const Clustering& clus,
|
|
95
93
|
idx_t nx,
|
|
@@ -374,7 +372,7 @@ void Clustering::train_encoded(
|
|
|
374
372
|
std::unique_ptr<float[]> dis(new float[nx]);
|
|
375
373
|
|
|
376
374
|
// remember best iteration for redo
|
|
377
|
-
bool lower_is_better = index.metric_type
|
|
375
|
+
bool lower_is_better = !is_similarity_metric(index.metric_type);
|
|
378
376
|
float best_obj = lower_is_better ? HUGE_VALF : -HUGE_VALF;
|
|
379
377
|
std::vector<ClusteringIterationStats> best_iteration_stats;
|
|
380
378
|
std::vector<float> best_centroids;
|
|
@@ -624,8 +622,6 @@ ProgressiveDimClustering::ProgressiveDimClustering(
|
|
|
624
622
|
|
|
625
623
|
namespace {
|
|
626
624
|
|
|
627
|
-
using idx_t = Index::idx_t;
|
|
628
|
-
|
|
629
625
|
void copy_columns(idx_t n, idx_t d1, const float* src, idx_t d2, float* dest) {
|
|
630
626
|
idx_t d = std::min(d1, d2);
|
|
631
627
|
for (idx_t i = 0; i < n; i++) {
|
|
@@ -61,7 +61,6 @@ struct ClusteringIterationStats {
|
|
|
61
61
|
*
|
|
62
62
|
*/
|
|
63
63
|
struct Clustering : ClusteringParameters {
|
|
64
|
-
typedef Index::idx_t idx_t;
|
|
65
64
|
size_t d; ///< dimension of the vectors
|
|
66
65
|
size_t k; ///< nb of centroids
|
|
67
66
|
|
|
@@ -154,7 +153,6 @@ struct ProgressiveDimIndexFactory {
|
|
|
154
153
|
* https://arxiv.org/abs/1509.05195
|
|
155
154
|
*/
|
|
156
155
|
struct ProgressiveDimClustering : ProgressiveDimClusteringParameters {
|
|
157
|
-
using idx_t = Index::idx_t;
|
|
158
156
|
size_t d; ///< dimension of the vectors
|
|
159
157
|
size_t k; ///< nb of centroids
|
|
160
158
|
|
data/vendor/faiss/faiss/IVFlib.h
CHANGED
|
@@ -48,8 +48,6 @@ IndexIVF* try_extract_index_ivf(Index* index);
|
|
|
48
48
|
*/
|
|
49
49
|
void merge_into(Index* index0, Index* index1, bool shift_ids);
|
|
50
50
|
|
|
51
|
-
typedef Index::idx_t idx_t;
|
|
52
|
-
|
|
53
51
|
/* Returns the cluster the embeddings belong to.
|
|
54
52
|
*
|
|
55
53
|
* @param index Index, which should be an IVF index
|
data/vendor/faiss/faiss/Index.h
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
#define FAISS_VERSION_MAJOR 1
|
|
20
20
|
#define FAISS_VERSION_MINOR 7
|
|
21
|
-
#define FAISS_VERSION_PATCH
|
|
21
|
+
#define FAISS_VERSION_PATCH 4
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* @namespace faiss
|
|
@@ -62,7 +62,6 @@ struct SearchParameters {
|
|
|
62
62
|
* although the internal representation may vary.
|
|
63
63
|
*/
|
|
64
64
|
struct Index {
|
|
65
|
-
using idx_t = int64_t; ///< all indices are this type
|
|
66
65
|
using component_t = float;
|
|
67
66
|
using distance_t = float;
|
|
68
67
|
|
|
@@ -484,7 +484,7 @@ ResidualCoarseQuantizer::ResidualCoarseQuantizer(
|
|
|
484
484
|
int d, ///< dimensionality of the input vectors
|
|
485
485
|
const std::vector<size_t>& nbits,
|
|
486
486
|
MetricType metric)
|
|
487
|
-
: AdditiveCoarseQuantizer(d, &rq, metric), rq(d, nbits)
|
|
487
|
+
: AdditiveCoarseQuantizer(d, &rq, metric), rq(d, nbits) {
|
|
488
488
|
FAISS_THROW_IF_NOT(rq.tot_bits <= 63);
|
|
489
489
|
is_trained = false;
|
|
490
490
|
}
|
|
@@ -520,10 +520,15 @@ void ResidualCoarseQuantizer::search(
|
|
|
520
520
|
idx_t k,
|
|
521
521
|
float* distances,
|
|
522
522
|
idx_t* labels,
|
|
523
|
-
const SearchParameters *
|
|
523
|
+
const SearchParameters * params_in
|
|
524
524
|
) const {
|
|
525
525
|
|
|
526
|
-
|
|
526
|
+
float beam_factor = this->beam_factor;
|
|
527
|
+
if (params_in) {
|
|
528
|
+
auto params = dynamic_cast<const SearchParametersResidualCoarseQuantizer*>(params_in);
|
|
529
|
+
FAISS_THROW_IF_NOT_MSG(params, "need SearchParametersResidualCoarseQuantizer parameters");
|
|
530
|
+
beam_factor = params->beam_factor;
|
|
531
|
+
}
|
|
527
532
|
|
|
528
533
|
if (beam_factor < 0) {
|
|
529
534
|
AdditiveCoarseQuantizer::search(n, x, k, distances, labels);
|
|
@@ -585,6 +590,15 @@ void ResidualCoarseQuantizer::search(
|
|
|
585
590
|
}
|
|
586
591
|
}
|
|
587
592
|
|
|
593
|
+
void ResidualCoarseQuantizer::initialize_from(const ResidualCoarseQuantizer &other) {
|
|
594
|
+
FAISS_THROW_IF_NOT(rq.M <= other.rq.M);
|
|
595
|
+
rq.initialize_from(other.rq);
|
|
596
|
+
set_beam_factor(other.beam_factor);
|
|
597
|
+
is_trained = other.is_trained;
|
|
598
|
+
ntotal = (idx_t)1 << aq->tot_bits;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
|
|
588
602
|
/**************************************************************************************
|
|
589
603
|
* LocalSearchCoarseQuantizer
|
|
590
604
|
**************************************************************************************/
|
|
@@ -187,6 +187,11 @@ struct AdditiveCoarseQuantizer : Index {
|
|
|
187
187
|
void reset() override;
|
|
188
188
|
};
|
|
189
189
|
|
|
190
|
+
struct SearchParametersResidualCoarseQuantizer : SearchParameters {
|
|
191
|
+
float beam_factor = 4.0f;
|
|
192
|
+
~SearchParametersResidualCoarseQuantizer() {}
|
|
193
|
+
};
|
|
194
|
+
|
|
190
195
|
/** The ResidualCoarseQuantizer is a bit specialized compared to the
|
|
191
196
|
* default AdditiveCoarseQuantizer because it can use a beam search
|
|
192
197
|
* at search time (slow but may be useful for very large vocabularies) */
|
|
@@ -196,7 +201,7 @@ struct ResidualCoarseQuantizer : AdditiveCoarseQuantizer {
|
|
|
196
201
|
|
|
197
202
|
/// factor between the beam size and the search k
|
|
198
203
|
/// if negative, use exact search-to-centroid
|
|
199
|
-
float beam_factor;
|
|
204
|
+
float beam_factor = 4.0f;
|
|
200
205
|
|
|
201
206
|
/// computes centroid norms if required
|
|
202
207
|
void set_beam_factor(float new_beam_factor);
|
|
@@ -226,6 +231,10 @@ struct ResidualCoarseQuantizer : AdditiveCoarseQuantizer {
|
|
|
226
231
|
idx_t* labels,
|
|
227
232
|
const SearchParameters* params = nullptr) const override;
|
|
228
233
|
|
|
234
|
+
/** Copy the M first codebook levels from other. Useful to crop a
|
|
235
|
+
* ResidualQuantizer to its first M quantizers. */
|
|
236
|
+
void initialize_from(const ResidualCoarseQuantizer& other);
|
|
237
|
+
|
|
229
238
|
ResidualCoarseQuantizer();
|
|
230
239
|
};
|
|
231
240
|
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
#include <faiss/IndexBinary.h>
|
|
16
16
|
|
|
17
|
+
#include <faiss/utils/approx_topk/mode.h>
|
|
18
|
+
|
|
17
19
|
namespace faiss {
|
|
18
20
|
|
|
19
21
|
/** Index that stores the full vectors and performs exhaustive search. */
|
|
@@ -28,6 +30,8 @@ struct IndexBinaryFlat : IndexBinary {
|
|
|
28
30
|
|
|
29
31
|
size_t query_batch_size = 32;
|
|
30
32
|
|
|
33
|
+
ApproxTopK_mode_t approx_topk_mode = ApproxTopK_mode_t::EXACT_TOPK;
|
|
34
|
+
|
|
31
35
|
explicit IndexBinaryFlat(idx_t d);
|
|
32
36
|
|
|
33
37
|
void add(idx_t n, const uint8_t* x) override;
|
|
@@ -108,8 +108,6 @@ struct FlipEnumerator {
|
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
110
|
|
|
111
|
-
using idx_t = Index::idx_t;
|
|
112
|
-
|
|
113
111
|
struct RangeSearchResults {
|
|
114
112
|
int radius;
|
|
115
113
|
RangeQueryResult& qres;
|
|
@@ -353,7 +351,7 @@ template <class HammingComputer, class SearchResults>
|
|
|
353
351
|
static void verify_shortlist(
|
|
354
352
|
const IndexBinaryFlat& index,
|
|
355
353
|
const uint8_t* q,
|
|
356
|
-
const std::unordered_set<
|
|
354
|
+
const std::unordered_set<idx_t>& shortlist,
|
|
357
355
|
SearchResults& res) {
|
|
358
356
|
size_t code_size = index.code_size;
|
|
359
357
|
size_t nlist = 0, ndis = 0, n0 = 0;
|