facebookresearch / faiss

A library for efficient similarity search and clustering of dense vectors.
https://faiss.ai
MIT License
31.57k stars 3.65k forks source link

How to reconstruct() from an IVF index use add_with_ids #3983

Closed czpmango closed 1 month ago

czpmango commented 1 month ago

I got the error DirectMap.cpp:82: direct map not initialized when reconstruct() from an IVF index.

import faiss
quantizer = faiss.IndexFlatL2(dim)
index = faiss.IndexIVFFlat(quantizer, dim, nb)
index.train(train_vectors)

index.add_with_ids(db_vectors, idx)
index.make_direct_map(False) # use nomap type
item0 = index.reconstruct(0)
print("Reconstructed item 0: ", item0)

Is there any solution for this scenario?

bshethmeta commented 1 month ago

Can you help me understand why setting make_direct_map to True will not work for your usecase?