facebookresearch / faiss

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

Set Python __slots__ on SWIG generated Python classes to avoid silent failures #3766

Open asadoughi opened 1 month ago

asadoughi commented 1 month ago

Summary

Use Python slots to specify public member variables on C++ classes to avoid silent failures.

Reproduction instructions

index = faiss.index_factory(256, “OPQ64,IVF16384,PQ64”)
index.nprobe = 16

In this example, the silent failure misleads a user to believe they have set the nprobe parameter on the IVFPQ index. However, they have set a new Python object attribute nprobe on IndexPretransform which has no effect on the index search.

mdouze commented 2 weeks ago

This seems to be a "new-object" specific feature. Would it work with our "old-object" model?