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:
Bhavik Sheth 2024-07-24 10:28:51 -07:00 committed by Facebook GitHub Bot
parent 8b5895ff79
commit aed7b0e678
2 changed files with 11 additions and 4 deletions

View File

@ -530,11 +530,12 @@ Index* parse_other_indexes(
}
// IndexLSH
if (match("LSH(r?)(t?)")) {
bool rotate_data = sm[1].length() > 0;
bool train_thresholds = sm[2].length() > 0;
if (match("LSH([0-9]*)(r?)(t?)")) {
int nbits = sm[1].length() > 0 ? std::stoi(sm[1].str()) : d;
bool rotate_data = sm[2].length() > 0;
bool train_thresholds = sm[3].length() > 0;
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

View File

@ -119,6 +119,12 @@ class TestFactory(unittest.TestCase):
assert index.nlist == 65536 and index_nsg.nsg.R == 64
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):
index = faiss.index_factory(56, "PQ28x4fs")
self.assertEqual(index.bbs, 32)