mirror of
https://github.com/facebookresearch/faiss.git
synced 2025-06-01 18:53:04 +08:00
First attempt at LSH matching with nbits (#3679)
Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3679 T195237796 Claims we should be able to incldue nbits in the LSH factory string. Their example is: ``` index = faiss.index_factory(128, 'LSH16rt') Returns the following error. faiss/index_factory.cpp:880: could not parse index string LSHrt_16 ``` This is my first attempt at modifying the regex to accept an integer for nbits. Can an expert help me understand what the domain of accepted strings should be so I can modify the regex as necessary? Reviewed By: ramilbakhshyiev Differential Revision: D60054776 fbshipit-source-id: e47074eb9986b7c1c702832fc0bf758f60f45290
This commit is contained in:
parent
8b5895ff79
commit
aed7b0e678
@ -530,11 +530,12 @@ Index* parse_other_indexes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IndexLSH
|
// IndexLSH
|
||||||
if (match("LSH(r?)(t?)")) {
|
if (match("LSH([0-9]*)(r?)(t?)")) {
|
||||||
bool rotate_data = sm[1].length() > 0;
|
int nbits = sm[1].length() > 0 ? std::stoi(sm[1].str()) : d;
|
||||||
bool train_thresholds = sm[2].length() > 0;
|
bool rotate_data = sm[2].length() > 0;
|
||||||
|
bool train_thresholds = sm[3].length() > 0;
|
||||||
FAISS_THROW_IF_NOT(metric == METRIC_L2);
|
FAISS_THROW_IF_NOT(metric == METRIC_L2);
|
||||||
return new IndexLSH(d, d, rotate_data, train_thresholds);
|
return new IndexLSH(d, nbits, rotate_data, train_thresholds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexLattice
|
// IndexLattice
|
||||||
|
@ -119,6 +119,12 @@ class TestFactory(unittest.TestCase):
|
|||||||
assert index.nlist == 65536 and index_nsg.nsg.R == 64
|
assert index.nlist == 65536 and index_nsg.nsg.R == 64
|
||||||
assert index.pq.M == 2 and index.pq.nbits == 8
|
assert index.pq.M == 2 and index.pq.nbits == 8
|
||||||
|
|
||||||
|
def test_factory_lsh(self):
|
||||||
|
index = faiss.index_factory(128, 'LSHrt')
|
||||||
|
self.assertEqual(index.nbits, 128)
|
||||||
|
index = faiss.index_factory(128, 'LSH16rt')
|
||||||
|
self.assertEqual(index.nbits, 16)
|
||||||
|
|
||||||
def test_factory_fast_scan(self):
|
def test_factory_fast_scan(self):
|
||||||
index = faiss.index_factory(56, "PQ28x4fs")
|
index = faiss.index_factory(56, "PQ28x4fs")
|
||||||
self.assertEqual(index.bbs, 32)
|
self.assertEqual(index.bbs, 32)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user