How to save vector embeddings `FAISS` in MongoDB?

1.8k views Asked by At

I am using LangChain for building some stuff and came across one of the most prominent index-based vector database FAISS. Following is the command of how I am using the FAISS vector database:

from langchain.document_loaders import PyMuPDFLoader
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import FAISS

loader = PyMuPDFLoader('path/to/pdf_file.pdf')
raw_texts = loader.load_and_split()

embeddings = OpenAIEmbeddings()

vectorstore = FAISS.from_documents(raw_texts, embeddings)

In the above code, I want to store the vectorstore in a MongoDB database. Is there any way to load these vectorstores on MongoDB and extract them with similarity_search with respect to input prompt?

1

There are 1 answers

1
Da Xue On

I am encountering the same situation, by far I found out that we can not save the vector content directly into the Mongo DB but we can expect to save the Index of the FAISS DB.