Issue
i'm trying to create a chatbot using OpenAi Langchain and a cloud database (MongoDb in my case). What I do, is load a PDF, I read the data, create chunks from it and then create embeddings using "text-embedding-ada-002" by OpenAi. After that I store in my DB the filename, the text of the PDF the list of embeddings, and the list of messages. It works good, but the problem is that i want to load the list of embeddings to create the Conversation Chain, but i don't know if it is possible to create it from the list of embeddings of i should save another thing and not the list of embeddings, because i don't want to create them each time i open the chat of the current PDf
If i use something like this to generate the vector store and then run the below code to create the conversation chain it works, but i want to load the list of embeddings i saved in the db
def get_embeddings(chunks: list[str]):
embeddings = OpenAIEmbeddings()
vector_store = MongoDBAtlasVectorSearch.from_texts(
texts=chunks,
embedding=embeddings,
collection=embeddings_collection,
index_name=ATLAS_VECTOR_SEARCH_INDEX_NAME,
)
return vector_store
def get_conversation_chain(vector_store):
memory = ConversationBufferMemory(
memory_key="chat_history",
vector_store=vector_store,
similarity_threshold=0.8,
max_memory_size=100,
return_messages=True,
input_key="question")
conversation_chain = ConversationalRetrievalChain.from_llm(
retriever=vector_store.as_retriever(),
llm=llm,
memory=memory)
result = conversation_chain({"question": "what is the text about"})
print(result)
return conversation_chain
Is there a way to create a vector_store from the list of embeddings i saved? or should i use another type of conversation chain?
Solution
Langchain has integration with Mongo db atlas, check this tutorial: https://python.langchain.com/docs/integrations/vectorstores/mongodb_atlas
Alternatively, you try using vector databases for this. Use ChromaDB or Pinecone to store vectors and store other information in metadata.
Answered By - Nikoloz Naskidashvili
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.