Find answers from the community

Updated 2 years ago

TypeError: in method 'IndexFlat_add', ar...

At a glance

A community member is experiencing an issue with the Faiss index in the GPT Index library, where they are encountering a TypeError related to float32 vs float64 data types. Another community member suggests that the issue may be resolved by changing the data type to float32 when adding documents and querying the index. The community members also discuss potential pull requests that may address the issue, and recommend installing the latest version of the library from the main branch to use the fix.

Useful resources
Same issue here. Did you find a solution? I only found this: https://github.com/facebookresearch/faiss/issues/461
j
a
8 comments
@acw500 for some reason i can't jump to the prev comment, what issue are you running into?
Hello @jerryjliu0 when using the Faiss index in a very straightforward way we are getting the following exception:

TypeError: in method 'IndexFlatCodes_add', argument 3 of type 'float const *'
Relevant frames include:
File "./lib/python3.8/site-packages/gpt_index/indices/vector_store/faiss.py", line 102, in _add_document_to_index

and

File "./lib/python3.8/site-packages/faiss/swigfaiss_avx2.py", line 2112, in add
return _swigfaiss_avx2.IndexFlatCodes_add(self, n, x)

It appears to be related to float32 vs 64. Will ty to debug this morning.
OK so in _add_document_to_index I changed the np.array instantiation to specify dtype=np.float32 and the problem appears to be fixed. I don't know if this will create some undesirable side effects. Things appear to work now.

text_embedding_np = np.array(text_embedding, dtype=np.float32)[np.newaxis, :]

Same issue on the query side. query/vector_store/faiss.py:91

query_embedding_np = np.array(query_embedding, dtype=np.float32)[np.newaxis, :]
which should resolve your issue
i haven't cut a release with all these changes yet but you can pip install gpt index from the main branch if you want to use the fix
Add a reply
Sign up and join the conversation on Discord