import faiss
import numpy as np
d = 64 nb = 100000 nq = 10000 np.random.seed(1234) xb = np.random.random((nb, d)).astype('float32') xb[:, 0] += np.arange(nb) / 1000.
xq = np.random.random((nq, d)).astype('float32')
xq[:, 0] += np.arange(nq) / 1000.
m = 8 k = 4 n_bit = 4 bbs = 32 index = faiss.IndexPQFastScan(d, m, n_bit, faiss.METRIC_L2, bbs)
assert not index.is_trained
index.train(xb) assert index.is_trained
index.add(xb)
D, I = index.search(xb[:5], k) print(I)
print(D)
index.nprobe = 10 D, I = index.search(xq, k) print(I[-5:])