faiss 0.1.2 → 0.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/ext/faiss/extconf.rb +1 -1
- data/lib/faiss/version.rb +1 -1
- data/vendor/faiss/benchs/bench_6bit_codec.cpp +80 -0
- data/vendor/faiss/c_api/AutoTune_c.h +2 -0
- data/vendor/faiss/c_api/IndexShards_c.cpp +0 -6
- data/vendor/faiss/c_api/IndexShards_c.h +1 -4
- data/vendor/faiss/c_api/gpu/GpuAutoTune_c.cpp +4 -2
- data/vendor/faiss/c_api/gpu/GpuClonerOptions_c.cpp +1 -1
- data/vendor/faiss/c_api/gpu/GpuIndex_c.cpp +1 -1
- data/vendor/faiss/c_api/gpu/GpuResources_c.cpp +1 -1
- data/vendor/faiss/c_api/gpu/StandardGpuResources_c.cpp +1 -1
- data/vendor/faiss/demos/demo_imi_flat.cpp +5 -2
- data/vendor/faiss/demos/demo_imi_pq.cpp +6 -2
- data/vendor/faiss/demos/demo_ivfpq_indexing.cpp +7 -2
- data/vendor/faiss/{AutoTune.cpp → faiss/AutoTune.cpp} +9 -9
- data/vendor/faiss/{AutoTune.h → faiss/AutoTune.h} +0 -0
- data/vendor/faiss/{Clustering.cpp → faiss/Clustering.cpp} +13 -12
- data/vendor/faiss/{Clustering.h → faiss/Clustering.h} +0 -0
- data/vendor/faiss/{DirectMap.cpp → faiss/DirectMap.cpp} +0 -0
- data/vendor/faiss/{DirectMap.h → faiss/DirectMap.h} +0 -0
- data/vendor/faiss/{IVFlib.cpp → faiss/IVFlib.cpp} +86 -11
- data/vendor/faiss/{IVFlib.h → faiss/IVFlib.h} +26 -8
- data/vendor/faiss/{Index.cpp → faiss/Index.cpp} +0 -0
- data/vendor/faiss/{Index.h → faiss/Index.h} +1 -1
- data/vendor/faiss/{Index2Layer.cpp → faiss/Index2Layer.cpp} +12 -11
- data/vendor/faiss/{Index2Layer.h → faiss/Index2Layer.h} +0 -0
- data/vendor/faiss/{IndexBinary.cpp → faiss/IndexBinary.cpp} +2 -1
- data/vendor/faiss/{IndexBinary.h → faiss/IndexBinary.h} +0 -0
- data/vendor/faiss/{IndexBinaryFlat.cpp → faiss/IndexBinaryFlat.cpp} +0 -0
- data/vendor/faiss/{IndexBinaryFlat.h → faiss/IndexBinaryFlat.h} +0 -0
- data/vendor/faiss/{IndexBinaryFromFloat.cpp → faiss/IndexBinaryFromFloat.cpp} +1 -0
- data/vendor/faiss/{IndexBinaryFromFloat.h → faiss/IndexBinaryFromFloat.h} +0 -0
- data/vendor/faiss/{IndexBinaryHNSW.cpp → faiss/IndexBinaryHNSW.cpp} +1 -2
- data/vendor/faiss/{IndexBinaryHNSW.h → faiss/IndexBinaryHNSW.h} +0 -0
- data/vendor/faiss/{IndexBinaryHash.cpp → faiss/IndexBinaryHash.cpp} +16 -7
- data/vendor/faiss/{IndexBinaryHash.h → faiss/IndexBinaryHash.h} +2 -1
- data/vendor/faiss/{IndexBinaryIVF.cpp → faiss/IndexBinaryIVF.cpp} +10 -16
- data/vendor/faiss/{IndexBinaryIVF.h → faiss/IndexBinaryIVF.h} +1 -1
- data/vendor/faiss/{IndexFlat.cpp → faiss/IndexFlat.cpp} +0 -0
- data/vendor/faiss/{IndexFlat.h → faiss/IndexFlat.h} +0 -0
- data/vendor/faiss/{IndexHNSW.cpp → faiss/IndexHNSW.cpp} +63 -32
- data/vendor/faiss/{IndexHNSW.h → faiss/IndexHNSW.h} +0 -0
- data/vendor/faiss/{IndexIVF.cpp → faiss/IndexIVF.cpp} +129 -46
- data/vendor/faiss/{IndexIVF.h → faiss/IndexIVF.h} +7 -3
- data/vendor/faiss/{IndexIVFFlat.cpp → faiss/IndexIVFFlat.cpp} +6 -5
- data/vendor/faiss/{IndexIVFFlat.h → faiss/IndexIVFFlat.h} +0 -0
- data/vendor/faiss/{IndexIVFPQ.cpp → faiss/IndexIVFPQ.cpp} +9 -8
- data/vendor/faiss/{IndexIVFPQ.h → faiss/IndexIVFPQ.h} +4 -2
- data/vendor/faiss/{IndexIVFPQR.cpp → faiss/IndexIVFPQR.cpp} +3 -1
- data/vendor/faiss/{IndexIVFPQR.h → faiss/IndexIVFPQR.h} +0 -0
- data/vendor/faiss/{IndexIVFSpectralHash.cpp → faiss/IndexIVFSpectralHash.cpp} +1 -1
- data/vendor/faiss/{IndexIVFSpectralHash.h → faiss/IndexIVFSpectralHash.h} +0 -0
- data/vendor/faiss/{IndexLSH.cpp → faiss/IndexLSH.cpp} +0 -0
- data/vendor/faiss/{IndexLSH.h → faiss/IndexLSH.h} +0 -0
- data/vendor/faiss/{IndexLattice.cpp → faiss/IndexLattice.cpp} +0 -0
- data/vendor/faiss/{IndexLattice.h → faiss/IndexLattice.h} +0 -0
- data/vendor/faiss/{IndexPQ.cpp → faiss/IndexPQ.cpp} +6 -6
- data/vendor/faiss/{IndexPQ.h → faiss/IndexPQ.h} +3 -1
- data/vendor/faiss/{IndexPreTransform.cpp → faiss/IndexPreTransform.cpp} +0 -0
- data/vendor/faiss/{IndexPreTransform.h → faiss/IndexPreTransform.h} +0 -0
- data/vendor/faiss/{IndexReplicas.cpp → faiss/IndexReplicas.cpp} +102 -10
- data/vendor/faiss/{IndexReplicas.h → faiss/IndexReplicas.h} +6 -0
- data/vendor/faiss/{IndexScalarQuantizer.cpp → faiss/IndexScalarQuantizer.cpp} +3 -3
- data/vendor/faiss/{IndexScalarQuantizer.h → faiss/IndexScalarQuantizer.h} +0 -0
- data/vendor/faiss/{IndexShards.cpp → faiss/IndexShards.cpp} +37 -12
- data/vendor/faiss/{IndexShards.h → faiss/IndexShards.h} +3 -4
- data/vendor/faiss/{InvertedLists.cpp → faiss/InvertedLists.cpp} +2 -2
- data/vendor/faiss/{InvertedLists.h → faiss/InvertedLists.h} +1 -0
- data/vendor/faiss/{MatrixStats.cpp → faiss/MatrixStats.cpp} +0 -0
- data/vendor/faiss/{MatrixStats.h → faiss/MatrixStats.h} +0 -0
- data/vendor/faiss/{MetaIndexes.cpp → faiss/MetaIndexes.cpp} +5 -3
- data/vendor/faiss/{MetaIndexes.h → faiss/MetaIndexes.h} +0 -0
- data/vendor/faiss/{MetricType.h → faiss/MetricType.h} +0 -0
- data/vendor/faiss/{OnDiskInvertedLists.cpp → faiss/OnDiskInvertedLists.cpp} +141 -3
- data/vendor/faiss/{OnDiskInvertedLists.h → faiss/OnDiskInvertedLists.h} +27 -7
- data/vendor/faiss/{VectorTransform.cpp → faiss/VectorTransform.cpp} +4 -3
- data/vendor/faiss/{VectorTransform.h → faiss/VectorTransform.h} +0 -0
- data/vendor/faiss/{clone_index.cpp → faiss/clone_index.cpp} +0 -0
- data/vendor/faiss/{clone_index.h → faiss/clone_index.h} +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuAutoTune.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuAutoTune.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuCloner.cpp +14 -14
- data/vendor/faiss/{gpu → faiss/gpu}/GpuCloner.h +6 -7
- data/vendor/faiss/{gpu → faiss/gpu}/GpuClonerOptions.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuClonerOptions.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuDistance.h +12 -4
- data/vendor/faiss/{gpu → faiss/gpu}/GpuFaissAssert.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndex.h +3 -9
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexBinaryFlat.h +7 -7
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexFlat.h +35 -10
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVF.h +1 -2
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFFlat.h +4 -3
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFPQ.h +21 -4
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndexIVFScalarQuantizer.h +4 -3
- data/vendor/faiss/{gpu → faiss/gpu}/GpuIndicesOptions.h +0 -0
- data/vendor/faiss/faiss/gpu/GpuResources.cpp +200 -0
- data/vendor/faiss/faiss/gpu/GpuResources.h +264 -0
- data/vendor/faiss/faiss/gpu/StandardGpuResources.cpp +572 -0
- data/vendor/faiss/{gpu → faiss/gpu}/StandardGpuResources.h +83 -15
- data/vendor/faiss/{gpu → faiss/gpu}/impl/RemapIndices.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/impl/RemapIndices.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/perf/IndexWrapper-inl.h +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/perf/IndexWrapper.h +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/perf/PerfClustering.cpp +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/perf/PerfIVFPQAdd.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/perf/WriteIndex.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexBinaryFlat.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexFlat.cpp +1 -1
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexIVFFlat.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuIndexIVFPQ.cpp +141 -52
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestGpuMemoryException.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestUtils.cpp +4 -2
- data/vendor/faiss/{gpu → faiss/gpu}/test/TestUtils.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/test/demo_ivfpq_indexing_gpu.cpp +7 -5
- data/vendor/faiss/{gpu → faiss/gpu}/utils/DeviceUtils.h +1 -1
- data/vendor/faiss/faiss/gpu/utils/StackDeviceMemory.cpp +213 -0
- data/vendor/faiss/{gpu → faiss/gpu}/utils/StackDeviceMemory.h +25 -40
- data/vendor/faiss/{gpu → faiss/gpu}/utils/StaticUtils.h +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/utils/Timer.cpp +0 -0
- data/vendor/faiss/{gpu → faiss/gpu}/utils/Timer.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/AuxIndexStructures.cpp +1 -0
- data/vendor/faiss/{impl → faiss/impl}/AuxIndexStructures.h +3 -1
- data/vendor/faiss/{impl → faiss/impl}/FaissAssert.h +1 -0
- data/vendor/faiss/{impl → faiss/impl}/FaissException.cpp +26 -0
- data/vendor/faiss/{impl → faiss/impl}/FaissException.h +4 -0
- data/vendor/faiss/{impl → faiss/impl}/HNSW.cpp +26 -26
- data/vendor/faiss/{impl → faiss/impl}/HNSW.h +19 -11
- data/vendor/faiss/{impl → faiss/impl}/PolysemousTraining.cpp +1 -1
- data/vendor/faiss/{impl → faiss/impl}/PolysemousTraining.h +1 -1
- data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer-inl.h +0 -1
- data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer.cpp +9 -9
- data/vendor/faiss/{impl → faiss/impl}/ProductQuantizer.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/ScalarQuantizer.cpp +63 -39
- data/vendor/faiss/{impl → faiss/impl}/ScalarQuantizer.h +1 -1
- data/vendor/faiss/{impl → faiss/impl}/ThreadedIndex-inl.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/ThreadedIndex.h +0 -0
- data/vendor/faiss/{impl → faiss/impl}/index_read.cpp +99 -116
- data/vendor/faiss/{impl → faiss/impl}/index_write.cpp +15 -50
- data/vendor/faiss/{impl → faiss/impl}/io.cpp +15 -10
- data/vendor/faiss/{impl → faiss/impl}/io.h +22 -8
- data/vendor/faiss/faiss/impl/io_macros.h +57 -0
- data/vendor/faiss/{impl → faiss/impl}/lattice_Zn.cpp +52 -36
- data/vendor/faiss/{impl → faiss/impl}/lattice_Zn.h +3 -3
- data/vendor/faiss/faiss/impl/platform_macros.h +24 -0
- data/vendor/faiss/{index_factory.cpp → faiss/index_factory.cpp} +33 -12
- data/vendor/faiss/{index_factory.h → faiss/index_factory.h} +0 -0
- data/vendor/faiss/{index_io.h → faiss/index_io.h} +55 -1
- data/vendor/faiss/faiss/python/python_callbacks.cpp +112 -0
- data/vendor/faiss/faiss/python/python_callbacks.h +45 -0
- data/vendor/faiss/{utils → faiss/utils}/Heap.cpp +5 -5
- data/vendor/faiss/{utils → faiss/utils}/Heap.h +1 -3
- data/vendor/faiss/{utils → faiss/utils}/WorkerThread.cpp +0 -0
- data/vendor/faiss/{utils → faiss/utils}/WorkerThread.h +0 -0
- data/vendor/faiss/{utils → faiss/utils}/distances.cpp +28 -13
- data/vendor/faiss/{utils → faiss/utils}/distances.h +2 -1
- data/vendor/faiss/{utils → faiss/utils}/distances_simd.cpp +5 -5
- data/vendor/faiss/{utils → faiss/utils}/extra_distances.cpp +8 -7
- data/vendor/faiss/{utils → faiss/utils}/extra_distances.h +0 -0
- data/vendor/faiss/{utils → faiss/utils}/hamming-inl.h +1 -3
- data/vendor/faiss/{utils → faiss/utils}/hamming.cpp +8 -7
- data/vendor/faiss/{utils → faiss/utils}/hamming.h +7 -1
- data/vendor/faiss/{utils → faiss/utils}/random.cpp +5 -5
- data/vendor/faiss/{utils → faiss/utils}/random.h +0 -0
- data/vendor/faiss/{utils → faiss/utils}/utils.cpp +27 -28
- data/vendor/faiss/{utils → faiss/utils}/utils.h +4 -0
- data/vendor/faiss/misc/test_blas.cpp +4 -1
- data/vendor/faiss/tests/test_binary_flat.cpp +0 -2
- data/vendor/faiss/tests/test_dealloc_invlists.cpp +6 -1
- data/vendor/faiss/tests/test_ivfpq_codec.cpp +4 -1
- data/vendor/faiss/tests/test_ivfpq_indexing.cpp +6 -4
- data/vendor/faiss/tests/test_lowlevel_ivf.cpp +12 -5
- data/vendor/faiss/tests/test_merge.cpp +6 -3
- data/vendor/faiss/tests/test_ondisk_ivf.cpp +7 -2
- data/vendor/faiss/tests/test_pairs_decoding.cpp +5 -1
- data/vendor/faiss/tests/test_params_override.cpp +7 -2
- data/vendor/faiss/tests/test_sliding_ivf.cpp +10 -4
- data/vendor/faiss/tutorial/cpp/1-Flat.cpp +14 -8
- data/vendor/faiss/tutorial/cpp/2-IVFFlat.cpp +11 -7
- data/vendor/faiss/tutorial/cpp/3-IVFPQ.cpp +12 -7
- data/vendor/faiss/tutorial/cpp/4-GPU.cpp +6 -3
- data/vendor/faiss/tutorial/cpp/5-Multiple-GPUs.cpp +7 -3
- metadata +154 -153
- data/vendor/faiss/gpu/GpuResources.cpp +0 -52
- data/vendor/faiss/gpu/GpuResources.h +0 -73
- data/vendor/faiss/gpu/StandardGpuResources.cpp +0 -303
- data/vendor/faiss/gpu/utils/DeviceMemory.cpp +0 -77
- data/vendor/faiss/gpu/utils/DeviceMemory.h +0 -71
- data/vendor/faiss/gpu/utils/MemorySpace.cpp +0 -89
- data/vendor/faiss/gpu/utils/MemorySpace.h +0 -44
- data/vendor/faiss/gpu/utils/StackDeviceMemory.cpp +0 -239
File without changes
|
File without changes
|
File without changes
|
@@ -14,6 +14,7 @@
|
|
14
14
|
#include <faiss/IndexPreTransform.h>
|
15
15
|
#include <faiss/impl/FaissAssert.h>
|
16
16
|
#include <faiss/MetaIndexes.h>
|
17
|
+
#include <faiss/utils/utils.h>
|
17
18
|
|
18
19
|
|
19
20
|
|
@@ -180,9 +181,9 @@ SlidingIndexWindow::SlidingIndexWindow (Index *index): index (index) {
|
|
180
181
|
n_slice = 0;
|
181
182
|
IndexIVF* index_ivf = const_cast<IndexIVF*>(extract_index_ivf (index));
|
182
183
|
ils = dynamic_cast<ArrayInvertedLists *> (index_ivf->invlists);
|
183
|
-
nlist = ils->nlist;
|
184
184
|
FAISS_THROW_IF_NOT_MSG (ils,
|
185
185
|
"only supports indexes with ArrayInvertedLists");
|
186
|
+
nlist = ils->nlist;
|
186
187
|
sizes.resize(nlist);
|
187
188
|
}
|
188
189
|
|
@@ -310,17 +311,34 @@ void set_invlist_range (Index *index, long i0, long i1,
|
|
310
311
|
ivf->ntotal = index->ntotal = ntotal;
|
311
312
|
}
|
312
313
|
|
314
|
+
static size_t count_ndis(const IndexIVF * index_ivf, size_t n_list_scan,
|
315
|
+
const idx_t *Iq)
|
316
|
+
{
|
317
|
+
size_t nb_dis = 0;
|
318
|
+
const InvertedLists *il = index_ivf->invlists;
|
319
|
+
for (idx_t i = 0; i < n_list_scan; i++) {
|
320
|
+
if (Iq[i] >= 0) {
|
321
|
+
nb_dis += il->list_size(Iq[i]);
|
322
|
+
}
|
323
|
+
}
|
324
|
+
return nb_dis;
|
325
|
+
}
|
326
|
+
|
327
|
+
|
313
328
|
|
314
329
|
void search_with_parameters (const Index *index,
|
315
330
|
idx_t n, const float *x, idx_t k,
|
316
331
|
float *distances, idx_t *labels,
|
317
|
-
IVFSearchParameters *params,
|
318
|
-
size_t *nb_dis_ptr
|
332
|
+
const IVFSearchParameters *params,
|
333
|
+
size_t *nb_dis_ptr,
|
334
|
+
double *ms_per_stage)
|
319
335
|
{
|
320
336
|
FAISS_THROW_IF_NOT (params);
|
321
337
|
const float *prev_x = x;
|
322
338
|
ScopeDeleter<float> del;
|
323
339
|
|
340
|
+
double t0 = getmillisecs();
|
341
|
+
|
324
342
|
if (auto ip = dynamic_cast<const IndexPreTransform *> (index)) {
|
325
343
|
x = ip->apply_chain (n, x);
|
326
344
|
if (x != prev_x) {
|
@@ -329,6 +347,8 @@ void search_with_parameters (const Index *index,
|
|
329
347
|
index = ip->index;
|
330
348
|
}
|
331
349
|
|
350
|
+
double t1 = getmillisecs();
|
351
|
+
|
332
352
|
std::vector<idx_t> Iq(params->nprobe * n);
|
333
353
|
std::vector<float> Dq(params->nprobe * n);
|
334
354
|
|
@@ -339,21 +359,76 @@ void search_with_parameters (const Index *index,
|
|
339
359
|
Dq.data(), Iq.data());
|
340
360
|
|
341
361
|
if (nb_dis_ptr) {
|
342
|
-
|
343
|
-
const InvertedLists *il = index_ivf->invlists;
|
344
|
-
for (idx_t i = 0; i < n * params->nprobe; i++) {
|
345
|
-
if (Iq[i] >= 0) {
|
346
|
-
nb_dis += il->list_size(Iq[i]);
|
347
|
-
}
|
348
|
-
}
|
349
|
-
*nb_dis_ptr = nb_dis;
|
362
|
+
*nb_dis_ptr = count_ndis (index_ivf, n * params->nprobe, Iq.data());
|
350
363
|
}
|
351
364
|
|
365
|
+
double t2 = getmillisecs();
|
366
|
+
|
352
367
|
index_ivf->search_preassigned(n, x, k, Iq.data(), Dq.data(),
|
353
368
|
distances, labels,
|
354
369
|
false, params);
|
370
|
+
double t3 = getmillisecs();
|
371
|
+
if (ms_per_stage) {
|
372
|
+
ms_per_stage[0] = t1 - t0;
|
373
|
+
ms_per_stage[1] = t2 - t1;
|
374
|
+
ms_per_stage[2] = t3 - t2;
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
void range_search_with_parameters (const Index *index,
|
379
|
+
idx_t n, const float *x, float radius,
|
380
|
+
RangeSearchResult *result,
|
381
|
+
const IVFSearchParameters *params,
|
382
|
+
size_t *nb_dis_ptr,
|
383
|
+
double *ms_per_stage)
|
384
|
+
{
|
385
|
+
FAISS_THROW_IF_NOT (params);
|
386
|
+
const float *prev_x = x;
|
387
|
+
ScopeDeleter<float> del;
|
388
|
+
|
389
|
+
double t0 = getmillisecs();
|
390
|
+
|
391
|
+
if (auto ip = dynamic_cast<const IndexPreTransform *> (index)) {
|
392
|
+
x = ip->apply_chain (n, x);
|
393
|
+
if (x != prev_x) {
|
394
|
+
del.set(x);
|
395
|
+
}
|
396
|
+
index = ip->index;
|
397
|
+
}
|
398
|
+
|
399
|
+
double t1 = getmillisecs();
|
400
|
+
|
401
|
+
std::vector<idx_t> Iq(params->nprobe * n);
|
402
|
+
std::vector<float> Dq(params->nprobe * n);
|
403
|
+
|
404
|
+
const IndexIVF *index_ivf = dynamic_cast<const IndexIVF *>(index);
|
405
|
+
FAISS_THROW_IF_NOT (index_ivf);
|
406
|
+
|
407
|
+
index_ivf->quantizer->search(n, x, params->nprobe,
|
408
|
+
Dq.data(), Iq.data());
|
409
|
+
|
410
|
+
if (nb_dis_ptr) {
|
411
|
+
*nb_dis_ptr = count_ndis (index_ivf, n * params->nprobe, Iq.data());
|
412
|
+
}
|
413
|
+
|
414
|
+
double t2 = getmillisecs();
|
415
|
+
|
416
|
+
index_ivf->range_search_preassigned(
|
417
|
+
n, x, radius, Iq.data(), Dq.data(),
|
418
|
+
result, false, params
|
419
|
+
);
|
420
|
+
|
421
|
+
double t3 = getmillisecs();
|
422
|
+
if (ms_per_stage) {
|
423
|
+
ms_per_stage[0] = t1 - t0;
|
424
|
+
ms_per_stage[1] = t2 - t1;
|
425
|
+
ms_per_stage[2] = t3 - t2;
|
426
|
+
}
|
355
427
|
}
|
356
428
|
|
357
429
|
|
358
430
|
|
431
|
+
|
432
|
+
|
433
|
+
|
359
434
|
} } // namespace faiss::ivflib
|
@@ -120,14 +120,32 @@ ArrayInvertedLists * get_invlist_range (const Index *index,
|
|
120
120
|
void set_invlist_range (Index *index, long i0, long i1,
|
121
121
|
ArrayInvertedLists * src);
|
122
122
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
123
|
+
/** search an IndexIVF, possibly embedded in an IndexPreTransform with
|
124
|
+
* given parameters. This is a way to set the nprobe and get
|
125
|
+
* statdistics in a thread-safe way.
|
126
|
+
*
|
127
|
+
* Optionally returns (if non-nullptr):
|
128
|
+
* - nb_dis: number of distances computed
|
129
|
+
* - ms_per_stage: [0]: preprocessing time
|
130
|
+
* [1]: coarse quantization,
|
131
|
+
* [2]: list scanning
|
132
|
+
*/
|
133
|
+
void search_with_parameters (
|
134
|
+
const Index *index,
|
135
|
+
idx_t n, const float *x, idx_t k,
|
136
|
+
float *distances, idx_t *labels,
|
137
|
+
const IVFSearchParameters *params,
|
138
|
+
size_t *nb_dis = nullptr,
|
139
|
+
double *ms_per_stage = nullptr);
|
140
|
+
|
141
|
+
/** same as search_with_parameters but for range search */
|
142
|
+
void range_search_with_parameters (
|
143
|
+
const Index *index,
|
144
|
+
idx_t n, const float *x, float radius,
|
145
|
+
RangeSearchResult *result,
|
146
|
+
const IVFSearchParameters *params,
|
147
|
+
size_t *nb_dis = nullptr,
|
148
|
+
double *ms_per_stage = nullptr);
|
131
149
|
|
132
150
|
|
133
151
|
|
File without changes
|
@@ -9,12 +9,13 @@
|
|
9
9
|
|
10
10
|
#include <faiss/Index2Layer.h>
|
11
11
|
|
12
|
+
#include <cinttypes>
|
12
13
|
#include <cmath>
|
13
14
|
#include <cstdio>
|
14
15
|
#include <cassert>
|
15
16
|
#include <stdint.h>
|
16
17
|
|
17
|
-
#ifdef
|
18
|
+
#ifdef __SSE3__
|
18
19
|
#include <immintrin.h>
|
19
20
|
#endif
|
20
21
|
|
@@ -77,7 +78,7 @@ Index2Layer::~Index2Layer ()
|
|
77
78
|
void Index2Layer::train(idx_t n, const float* x)
|
78
79
|
{
|
79
80
|
if (verbose) {
|
80
|
-
printf ("training level-1 quantizer %
|
81
|
+
printf ("training level-1 quantizer %" PRId64 " vectors in %dD\n",
|
81
82
|
n, d);
|
82
83
|
}
|
83
84
|
|
@@ -104,7 +105,7 @@ void Index2Layer::train(idx_t n, const float* x)
|
|
104
105
|
}
|
105
106
|
|
106
107
|
if (verbose)
|
107
|
-
printf ("training %zdx%zd product quantizer on %
|
108
|
+
printf ("training %zdx%zd product quantizer on %" PRId64 " vectors in %dD\n",
|
108
109
|
pq.M, pq.ksub, n, d);
|
109
110
|
pq.verbose = verbose;
|
110
111
|
pq.train (n, residuals.data());
|
@@ -119,7 +120,7 @@ void Index2Layer::add(idx_t n, const float* x)
|
|
119
120
|
for (idx_t i0 = 0; i0 < n; i0 += bs) {
|
120
121
|
idx_t i1 = std::min(i0 + bs, n);
|
121
122
|
if (verbose) {
|
122
|
-
printf("Index2Layer::add: adding %
|
123
|
+
printf("Index2Layer::add: adding %" PRId64 ":%" PRId64 " / %" PRId64 "\n",
|
123
124
|
i0, i1, n);
|
124
125
|
}
|
125
126
|
add (i1 - i0, x + i0 * d);
|
@@ -172,14 +173,14 @@ void Index2Layer::search(
|
|
172
173
|
|
173
174
|
void Index2Layer::reconstruct_n(idx_t i0, idx_t ni, float* recons) const
|
174
175
|
{
|
175
|
-
float recons1
|
176
|
+
std::vector<float> recons1(d);
|
176
177
|
FAISS_THROW_IF_NOT (i0 >= 0 && i0 + ni <= ntotal);
|
177
178
|
const uint8_t *rp = &codes[i0 * code_size];
|
178
179
|
|
179
180
|
for (idx_t i = 0; i < ni; i++) {
|
180
181
|
idx_t key = 0;
|
181
182
|
memcpy (&key, rp, code_size_1);
|
182
|
-
q1.quantizer->reconstruct (key, recons1);
|
183
|
+
q1.quantizer->reconstruct (key, recons1.data());
|
183
184
|
rp += code_size_1;
|
184
185
|
pq.decode (rp, recons);
|
185
186
|
for (idx_t j = 0; j < d; j++) {
|
@@ -270,7 +271,7 @@ struct DistanceXPQ4 : Distance2Level {
|
|
270
271
|
}
|
271
272
|
|
272
273
|
float operator () (idx_t i) override {
|
273
|
-
#ifdef
|
274
|
+
#ifdef __SSE3__
|
274
275
|
const uint8_t *code = storage.codes.data() + i * storage.code_size;
|
275
276
|
long key = 0;
|
276
277
|
memcpy (&key, code, storage.code_size_1);
|
@@ -323,7 +324,7 @@ struct Distance2xXPQ4 : Distance2Level {
|
|
323
324
|
long key01 = 0;
|
324
325
|
memcpy (&key01, code, storage.code_size_1);
|
325
326
|
code += storage.code_size_1;
|
326
|
-
#ifdef
|
327
|
+
#ifdef __SSE3__
|
327
328
|
|
328
329
|
// walking pointers
|
329
330
|
const float *qa = q;
|
@@ -361,7 +362,7 @@ struct Distance2xXPQ4 : Distance2Level {
|
|
361
362
|
|
362
363
|
|
363
364
|
DistanceComputer * Index2Layer::get_distance_computer() const {
|
364
|
-
#ifdef
|
365
|
+
#ifdef __SSE3__
|
365
366
|
const MultiIndexQuantizer *mi =
|
366
367
|
dynamic_cast<MultiIndexQuantizer*> (q1.quantizer);
|
367
368
|
|
@@ -416,13 +417,13 @@ void Index2Layer::sa_decode (idx_t n, const uint8_t *bytes, float *x) const
|
|
416
417
|
std::vector<float> residual (d);
|
417
418
|
|
418
419
|
#pragma omp for
|
419
|
-
for (
|
420
|
+
for (idx_t i = 0; i < n; i++) {
|
420
421
|
const uint8_t *code = bytes + i * code_size;
|
421
422
|
int64_t list_no = q1.decode_listno (code);
|
422
423
|
float *xi = x + i * d;
|
423
424
|
pq.decode (code + code_size_1, xi);
|
424
425
|
q1.quantizer->reconstruct (list_no, residual.data());
|
425
|
-
for (
|
426
|
+
for (int j = 0; j < d; j++) {
|
426
427
|
xi[j] += residual[j];
|
427
428
|
}
|
428
429
|
}
|
File without changes
|
@@ -10,6 +10,7 @@
|
|
10
10
|
#include <faiss/IndexBinary.h>
|
11
11
|
#include <faiss/impl/FaissAssert.h>
|
12
12
|
|
13
|
+
#include <cinttypes>
|
13
14
|
#include <cstring>
|
14
15
|
|
15
16
|
namespace faiss {
|
@@ -70,7 +71,7 @@ void IndexBinary::search_and_reconstruct(idx_t n, const uint8_t *x, idx_t k,
|
|
70
71
|
}
|
71
72
|
|
72
73
|
void IndexBinary::display() const {
|
73
|
-
printf("Index: %s -> %
|
74
|
+
printf("Index: %s -> %" PRId64 " elements\n", typeid (*this).name(), ntotal);
|
74
75
|
}
|
75
76
|
|
76
77
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -23,7 +23,6 @@
|
|
23
23
|
|
24
24
|
#include <sys/types.h>
|
25
25
|
#include <sys/stat.h>
|
26
|
-
#include <unistd.h>
|
27
26
|
#include <stdint.h>
|
28
27
|
|
29
28
|
#include <faiss/utils/random.h>
|
@@ -52,7 +51,7 @@ void hnsw_add_vertices(IndexBinaryHNSW& index_hnsw,
|
|
52
51
|
size_t ntotal = n0 + n;
|
53
52
|
double t0 = getmillisecs();
|
54
53
|
if (verbose) {
|
55
|
-
printf("hnsw_add_vertices: adding %
|
54
|
+
printf("hnsw_add_vertices: adding %zd elements on top of %zd "
|
56
55
|
"(preset_levels=%d)\n",
|
57
56
|
n, n0, int(preset_levels));
|
58
57
|
}
|
File without changes
|
@@ -5,11 +5,11 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
7
|
|
8
|
-
// Copyright 2004-present Facebook. All Rights Reserved
|
9
8
|
// -*- c++ -*-
|
10
9
|
|
11
10
|
#include <faiss/IndexBinaryHash.h>
|
12
11
|
|
12
|
+
#include <cinttypes>
|
13
13
|
#include <cstdio>
|
14
14
|
#include <memory>
|
15
15
|
|
@@ -19,6 +19,15 @@
|
|
19
19
|
#include <faiss/impl/AuxIndexStructures.h>
|
20
20
|
#include <faiss/impl/FaissAssert.h>
|
21
21
|
|
22
|
+
#ifdef _MSC_VER
|
23
|
+
#include <intrin.h>
|
24
|
+
|
25
|
+
static inline int __builtin_ctzll(uint64_t x) {
|
26
|
+
unsigned long ret;
|
27
|
+
_BitScanForward64(&ret, x);
|
28
|
+
return (int)ret;
|
29
|
+
}
|
30
|
+
#endif // _MSC_VER
|
22
31
|
|
23
32
|
namespace faiss {
|
24
33
|
|
@@ -222,7 +231,7 @@ void IndexBinaryHash::range_search(idx_t n, const uint8_t *x, int radius,
|
|
222
231
|
RangeSearchPartialResult pres (result);
|
223
232
|
|
224
233
|
#pragma omp for
|
225
|
-
for (
|
234
|
+
for (idx_t i = 0; i < n; i++) { // loop queries
|
226
235
|
RangeQueryResult & qres = pres.new_result (i);
|
227
236
|
RangeSearchResults res = {radius, qres};
|
228
237
|
const uint8_t *q = x + i * code_size;
|
@@ -246,7 +255,7 @@ void IndexBinaryHash::search(idx_t n, const uint8_t *x, idx_t k,
|
|
246
255
|
size_t nlist = 0, ndis = 0, n0 = 0;
|
247
256
|
|
248
257
|
#pragma omp parallel for if(n > 100) reduction(+: nlist, ndis, n0)
|
249
|
-
for (
|
258
|
+
for (idx_t i = 0; i < n; i++) {
|
250
259
|
int32_t * simi = distances + k * i;
|
251
260
|
idx_t * idxi = labels + k * i;
|
252
261
|
|
@@ -272,10 +281,10 @@ size_t IndexBinaryHash::hashtable_size() const
|
|
272
281
|
void IndexBinaryHash::display() const
|
273
282
|
{
|
274
283
|
for (auto it = invlists.begin(); it != invlists.end(); ++it) {
|
275
|
-
printf("%
|
284
|
+
printf("%" PRId64 ": [", it->first);
|
276
285
|
const std::vector<idx_t> & v = it->second.ids;
|
277
286
|
for (auto x: v) {
|
278
|
-
printf("%
|
287
|
+
printf("%" PRId64 " ", x);
|
279
288
|
}
|
280
289
|
printf("]\n");
|
281
290
|
|
@@ -437,7 +446,7 @@ void IndexBinaryMultiHash::range_search(idx_t n, const uint8_t *x, int radius,
|
|
437
446
|
RangeSearchPartialResult pres (result);
|
438
447
|
|
439
448
|
#pragma omp for
|
440
|
-
for (
|
449
|
+
for (idx_t i = 0; i < n; i++) { // loop queries
|
441
450
|
RangeQueryResult & qres = pres.new_result (i);
|
442
451
|
RangeSearchResults res = {radius, qres};
|
443
452
|
const uint8_t *q = x + i * code_size;
|
@@ -461,7 +470,7 @@ void IndexBinaryMultiHash::search(idx_t n, const uint8_t *x, idx_t k,
|
|
461
470
|
size_t nlist = 0, ndis = 0, n0 = 0;
|
462
471
|
|
463
472
|
#pragma omp parallel for if(n > 100) reduction(+: nlist, ndis, n0)
|
464
|
-
for (
|
473
|
+
for (idx_t i = 0; i < n; i++) {
|
465
474
|
int32_t * simi = distances + k * i;
|
466
475
|
idx_t * idxi = labels + k * i;
|
467
476
|
|
@@ -17,6 +17,7 @@
|
|
17
17
|
|
18
18
|
#include <faiss/IndexBinary.h>
|
19
19
|
#include <faiss/IndexBinaryFlat.h>
|
20
|
+
#include <faiss/impl/platform_macros.h>
|
20
21
|
#include <faiss/utils/Heap.h>
|
21
22
|
|
22
23
|
|
@@ -71,7 +72,7 @@ struct IndexBinaryHashStats {
|
|
71
72
|
void reset ();
|
72
73
|
};
|
73
74
|
|
74
|
-
extern IndexBinaryHashStats indexBinaryHash_stats;
|
75
|
+
FAISS_API extern IndexBinaryHashStats indexBinaryHash_stats;
|
75
76
|
|
76
77
|
|
77
78
|
/** just uses the b first bits as a hash value */
|