-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_faiss.py
32 lines (25 loc) · 998 Bytes
/
query_faiss.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
from dotenv import load_dotenv
from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings, OpenAI
from langchain.chains.retrieval import create_retrieval_chain
from langchain.chains.combine_documents import create_stuff_documents_chain
from langchain import hub
def main():
# Load environment variables from a .env file
load_dotenv()
embeddings = OpenAIEmbeddings()
new_vectorstore = FAISS.load_local(
"faiss_index_react", embeddings, allow_dangerous_deserialization=True
)
retrieval_qa_chat_prompt = hub.pull("langchain-ai/retrieval-qa-chat")
combine_docs_chain = create_stuff_documents_chain(
OpenAI(), retrieval_qa_chat_prompt
)
retrieval_chain = create_retrieval_chain(
new_vectorstore.as_retriever(), combine_docs_chain
)
res = retrieval_chain.invoke({"input": "Give me the gist of ReAct in 3 sentences."})
print(res["answer"])
if __name__ == "__main__":
main()