hr_chatbot / retriever.py
Syed Junaid Iqbal
Update retriever.py
ab0a523
raw
history blame contribute delete
748 Bytes
import pickle
from langchain.retrievers import EnsembleRetriever
from langchain.vectorstores import FAISS
from langchain.embeddings import GooglePalmEmbeddings
from langchain.memory import ConversationBufferMemory
def retriever():
embeddings = GooglePalmEmbeddings(google_api_key= google_api_key)
#to read bm25 object
with open('./bm25', 'rb') as file:
bm25_retriever = pickle.load(file)
bm25_retriever.k = 2
# Load FAISS
faiss_vectorstore = FAISS.load_local("./vector_db/", embeddings)
faiss_retriever = faiss_vectorstore.as_retriever(search_kwargs={"k": 1})
# initialize the ensemble retriever
return EnsembleRetriever( retrievers=[bm25_retriever, faiss_retriever], weights=[0.5, 0.5] )