kyamagu / faiss-wheels

Unofficial faiss wheel builder
MIT License
298 stars 38 forks source link

Importing faiss.swigfaiss leads to error #111

Closed pritam-dey3 closed 2 months ago

pritam-dey3 commented 2 months ago

Describe the bug I was trying to import faiss.swigfaiss.Index to static type index in my code. But it took me quite some painful hours to figure out the issue.

To Reproduce The following code works.

import faiss
# from faiss.swigfaiss import Index
import numpy as np

index = faiss.index_factory(16, "IDMap,Flat")
emb = np.random.uniform(0, 1, (8, 16)).astype(np.float32)

index.train(emb)

however, the following code fails

import faiss
from faiss.swigfaiss import Index
import numpy as np

index = faiss.index_factory(16, "IDMap,Flat")
emb = np.random.uniform(0, 1, (8, 16)).astype(np.float32)

index.train(emb)
  File "<string>", line 9, in <module>
TypeError: IndexIDMap.train() missing 1 required positional argument: 'x'

In conda installation, both the above code works fine.

Desktop (please complete the following information):

kyamagu commented 2 months ago

Hmm, this seems not to happen in the following:

import faiss
from faiss.swigfaiss_avx2 import Index
import numpy as np

index = faiss.index_factory(16, "IDMap,Flat")
emb = np.random.uniform(0, 1, (8, 16)).astype(np.float32)
index.train(emb)

This indicates something is wrong when the optimization flag is not set

kyamagu commented 2 months ago

Btw, it is possible to import Index in the following way:

import faiss
from faiss import Index
pritam-dey3 commented 2 months ago

Btw, it is possible to import Index in the following way:

import faiss
from faiss import Index

This solves my problem. Thanks