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

1.6k views Asked by At

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

2

There are 2 answers

0
AndyEverything On BEST ANSWER

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.

0
Nishith R On

First, you'll have to import the langchain community package like so: from langchain_community.vectorstores.faiss import FAISS

Then, you can use vectorstore = FAISS.from_texts(texts = text_chunks, embedding = embeddings)

Works as far I know.