facebookresearch/faiss

FAISS-GPU "IndexFlat.search() missing 3 required positional arguments: 'k', 'distances', and 'labels'"

apiispanen opened this issue · 3 comments

Summary

Platform

OS: Running Linux with railway 64 bit

Faiss version: faiss-gpu==1.7.2; sys_platform == 'linux' and platform_machine == 'x86_64'

Installed from: Pip (Python 3.10)

Faiss compilation options:

Running on:

  • CPU
  • [ x] GPU

Interface:

  • C++
  • [ x] Python

Reproduction instructions

pip install faiss-gpu==1.7.2; sys_platform == 'linux' and platform_machine == 'x86_64'

Running this function with relevant FAISS data leads to two issues:

First issue is:

Traceback (most recent call last):

  File "/app/Leadoff/ai/embedder.py", line 30, in get_vector_results

    db = FAISS.deserialize_from_bytes(

  File "/usr/local/lib/python3.10/site-packages/langchain_community/vectorstores/faiss.py", line 1247, in deserialize_from_bytes

    ) = pickle.loads(  # ignore[pickle]: explicit-opt-in

ModuleNotFoundError: No module named 'faiss.swigfaiss_avx2'

Now, when we follow the logs on this issue (kyamagu/faiss-wheels#39) and act upon the results given
(adding this to our Dockerfile:

RUN cd /usr/local/lib/python3.10/site-packages/faiss && \
    ln -s swigfaiss.py swigfaiss_avx2.py

)

We get instead a new issue, which is this...

Second issue is:

Traceback (most recent call last):

  File "/app/Leadoff/ai/embedder.py", line 36, in get_vector_results

    docs = db.similarity_search_with_score(query=query, k=5)

  File "/usr/local/lib/python3.10/site-packages/langchain_community/vectorstores/faiss.py", line 514, in similarity_search_with_score

    docs = self.similarity_search_with_score_by_vector(

  File "/usr/local/lib/python3.10/site-packages/langchain_community/vectorstores/faiss.py", line 415, in similarity_search_with_score_by_vector

    scores, indices = self.index.search(vector, k if filter is None else fetch_k)

TypeError: IndexFlat.search() missing 3 required positional arguments: 'k', 'distances', and 'labels'

Here is my function:

def get_vector_results(query, vector_id=None, collection=vectors):
    print("Query:", query)
    print("Vector ID:", vector_id)
    print("Collection:", collection)
    if vector_id:
        # Check if the embeddings exist in MongoDB
        vector_obj = collection.find_one({"_id": ObjectId(vector_id)})
        try:
            if vector_obj:
                # Load embeddings from MongoDB
                print("Embeddings Loaded from MongoDB")
                if query == "":
                    return {"status": "failure", "message": [f"No Query Given"]}
                embeddings = OpenAIEmbeddings()
                db = FAISS.deserialize_from_bytes(
                    embeddings=embeddings,
                    serialized=vector_obj["vector_data"], # Vectorized data
                    allow_dangerous_deserialization=True,
                )
                # docs = db.similarity_search(query)
                docs = db.similarity_search_with_score(query=query, k=5)
                # disconnect from MongoDB
                # client.close()
                # print("VECTOR SEARCH for ", query, ":", docs)
                results = [
                    {"result": str(i), "score": str(score), "content": doc.page_content}
                    for i, (doc, score) in enumerate(docs)
                ]
                return {"status": "success", "message": results}
            else:
                return {"status": "failure", "message": [f"Vector Record not found!"]}
        except Exception as e:
            print("*!*!*!*!ERRORRRR", e)
            import traceback

            print(traceback.format_exc())
            return {"status": "failure", "message": [f"Vector Search Error! {e}"]}

    return {"status": "failure", "message": ["No Vector ID provided."]}

This happens every single time we run a FAISS.deserialize_from_bytes() object with similarity_search_with_score. Are other people getting this for FAISS GPU or is this only on my system?

Hi apiispanen@!
A couple of things:

  • Faiss should be installed via conda as per official faiss install instructions. Please use conda instead of pip to install faiss specifically.
  • The issue seems to be originating from inside lang-chain's usage of faiss. Since, we don't know much about how langchanin uses faiss, I'll suggest starting from their support. From a basic google search about the error, I see one relevant bug reported on langchain's side. The bug does mention platform incompatibily for faiss serialize/deserialize operations. Many people have seemed to find a solution for it too. Though, in order for us to debug this, we'll ask reproduce the issue by using faiss directly (not via langchain).

If you're able to reproduce the issue, please provide us the logs/errors. We'll be happy to help.

This issue is stale because it has been open for 7 days with no activity.

This issue was closed because it has been inactive for 7 days since being marked as stale.