Skip to content

Commit d0434be

Browse files
Michael Norrismeta-codesync[bot]
authored andcommitted
Fix cloning for IVFFlatPanorama (#4887)
Summary: Pull Request resolved: #4887 Has to be checked before IVFFlat, otherwise deserialize will give an IVFFlat rather than IVFFlatPanorama. Reviewed By: alibeklfc Differential Revision: D95647196 fbshipit-source-id: fe38144c5276fe85e1206013301f0b159acf1df7
1 parent bb298a2 commit d0434be

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

faiss/clone_index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ IndexIVF* Cloner::clone_IndexIVF(const IndexIVF* ivf) {
102102
TRYCLONE(IndexIVFRaBitQ, ivf)
103103

104104
TRYCLONE(IndexIVFFlatDedup, ivf)
105-
TRYCLONE(IndexIVFFlat, ivf)
106105
TRYCLONE(IndexIVFFlatPanorama, ivf)
106+
TRYCLONE(IndexIVFFlat, ivf)
107107

108108
TRYCLONE(IndexIVFSpectralHash, ivf)
109109

tests/test_ivflib.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,32 @@ def test_save_index_shards_by_centroids_rabitq_custom_sharding(self):
440440
)
441441
self.verify_sharded_ivf_indexes(
442442
template, xb, shard_count, self.custom_sharding_function)
443+
444+
def test_save_index_shards_by_centroids_panorama(self):
445+
"""Test sharding for IndexIVFFlatPanorama."""
446+
xb = np.random.rand(self.nb, self.d).astype('float32')
447+
quantizer = faiss.IndexFlatL2(self.d)
448+
n_levels = 4
449+
index = faiss.IndexIVFFlatPanorama(
450+
quantizer, self.d, self.nlist, n_levels)
451+
shard_count = 5
452+
453+
index.quantizer.add(xb)
454+
455+
template = str(random.randint(0, 100000)) + "shard.%d.panorama.index"
456+
faiss.shard_ivf_index_centroids(
457+
index,
458+
shard_count,
459+
template,
460+
None,
461+
True
462+
)
463+
464+
# Verify shards are IndexIVFFlatPanorama after read-back
465+
for i in range(shard_count):
466+
fname = template % i
467+
shard = faiss.read_index(fname)
468+
self.assertIsInstance(shard, faiss.IndexIVFFlatPanorama)
469+
470+
self.verify_sharded_ivf_indexes(
471+
template, xb, shard_count, self.default_sharding_function)

0 commit comments

Comments
 (0)