Files
faiss/tests/test_binary_autotune.py
T
Gilbert Gilb's f72867d4ab support SearchParameters for IndexBinary (#4761)
Summary:
- Add support ParameterSpace for IndexBinaryHNSW and IndexBinaryIVF
- Add support SearchParameters in search() method for IndexBinaryHNSW and IndexBinaryIVF
- Add support for passing parameters to IndexBinaryHNSW and IndexBinaryIVF from CAPI

fixes https://github.com/facebookresearch/faiss/issues/3503

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4761

Reviewed By: mdouze

Differential Revision: D91060658

Pulled By: juancarpio27

fbshipit-source-id: f8cd87fc020d410bf2982636d2aa393e6d7e3410
2026-02-04 00:03:15 -08:00

62 lines
2.1 KiB
Python

# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import faiss
class TestBinaryParameterSpace(unittest.TestCase):
def test_nprobe(self):
d = 64
quantizer = faiss.IndexBinaryFlat(d)
index = faiss.IndexBinaryIVF(quantizer, d, 32)
ps = faiss.ParameterSpace()
ps.set_index_parameter(index, "nprobe", 5)
self.assertEqual(index.nprobe, 5)
def test_nprobe_2(self):
d = 64
quantizer = faiss.IndexBinaryFlat(d)
index_ivf = faiss.IndexBinaryIVF(quantizer, d, 32)
index = faiss.IndexBinaryIDMap(index_ivf)
ps = faiss.ParameterSpace()
ps.set_index_parameter(index, "nprobe", 5)
index2 = faiss.downcast_IndexBinary(index.index)
self.assertEqual(index2.nprobe, 5)
def test_efSearch(self):
d = 64
index = faiss.IndexBinaryHNSW(d, 32)
ps = faiss.ParameterSpace()
ps.set_index_parameter(index, "efSearch", 10)
self.assertEqual(index.hnsw.efSearch, 10)
def test_efConstruction(self):
d = 64
index = faiss.IndexBinaryHNSW(d, 32)
ps = faiss.ParameterSpace()
ps.set_index_parameter(index, "efConstruction", 40)
self.assertEqual(index.hnsw.efConstruction, 40)
def test_quantizer_efSearch(self):
d = 64
quantizer = faiss.IndexBinaryHNSW(d, 32)
index = faiss.IndexBinaryIVF(quantizer, d, 32)
ps = faiss.ParameterSpace()
ps.set_index_parameter(index, "quantizer_efSearch", 8)
quantizer2 = faiss.downcast_IndexBinary(index.quantizer)
self.assertEqual(quantizer2.hnsw.efSearch, 8)
def test_quantizer_efConstruction(self):
d = 64
quantizer = faiss.IndexBinaryHNSW(d, 32)
index = faiss.IndexBinaryIVF(quantizer, d, 32)
ps = faiss.ParameterSpace()
ps.set_index_parameter(index, "quantizer_efConstruction", 50)
quantizer2 = faiss.downcast_IndexBinary(index.quantizer)
self.assertEqual(quantizer2.hnsw.efConstruction, 50)