Search code examples
pythonpy-langchainfaiss

Cannot import langchain.vectorstores.FAISS, only langchain_community.vectorstores.faiss


I am in the process of building a RAG like the one in this Video. However, I cannot import FAISS like this.

from langchain.vectorstores import FAISS

LangChainDeprecationWarning: Importing vector stores from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:

`from langchain_community.vectorstores import faiss`.

However, it is possible to import faiss:

from langchain_community.vectorstores import faiss

But with this it is not possible to call faiss.from_text().

vectorstore = faiss.from_texts(text=text_chunks, embeddings=embeddings)

AttributeError: module 'langchain_community.vectorstores.faiss' has no attribute 'from_texts'

Is it no longer possible to call .from_text() with the current one? I didn't find anything about this in the documentation.

Python=3.10.13


Solution

  • The solution was for me to importing the FAISS class directly from the langchain.vectorstores.faiss module and then using the from_documents method.

    from langchain_community.vectorstores.faiss import FAISS
    

    I had importing the faiss module itself, rather than the FAISS class from the langchain.vectorstores.faiss module. The from_documents method is a class method of the FAISS class, not a function of the faiss module.