mirror of
https://github.com/facebookresearch/faiss.git
synced 2025-06-03 21:54:02 +08:00
Changelog: - changed license: BSD+Patents -> MIT - propagates exceptions raised in sub-indexes of IndexShards and IndexReplicas - support for searching several inverted lists in parallel (parallel_mode != 0) - better support for PQ codes where nbit != 8 or 16 - IVFSpectralHash implementation: spectral hash codes inside an IVF - 6-bit per component scalar quantizer (4 and 8 bit were already supported) - combinations of inverted lists: HStackInvertedLists and VStackInvertedLists - configurable number of threads for OnDiskInvertedLists prefetching (including 0=no prefetch) - more test and demo code compatible with Python 3 (print with parentheses) - refactored benchmark code: data loading is now in a single file
23 lines
547 B
Python
23 lines
547 B
Python
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This source code is licensed under the MIT license found in the
|
|
# LICENSE file in the root directory of this source tree.
|
|
|
|
from __future__ import print_function
|
|
import faiss
|
|
from datasets import load_sift1M, evaluate
|
|
|
|
xb, xq, xt, gt = load_sift1M()
|
|
nq, d = xq.shape
|
|
|
|
k = 32
|
|
|
|
for nbits in 4, 6, 8, 10, 12:
|
|
index = faiss.IndexPQ(d, 8, nbits)
|
|
index.train(xt)
|
|
index.add(xb)
|
|
|
|
t, r = evaluate(index, xq, gt, k)
|
|
print("\t %7.3f ms per query, R@1 %.4f" % (t, r[1]))
|
|
del index
|