I am trying to make a simple QA chatbot which is able to remember the past conversation and answer question about previous messages.
I use Chromadb as a vectorstore to store the chat history and search relevant pieces of information when needed.
When I chat with the bot, it kind of remembers our conversation, but after a few messages, most of the time it becomes unable to give me correct answers about my previous messages.
Sometimes it can't even answer after one or two messages.
How can I improve this behaviour to be able to easily retrieve any piece of information at any time?
Here is my code:
chroma_client = chromadb.Client()
history_vectorstore = Chroma(client=chroma_client, embedding_function=embeddings)
retriever = history_vectorstore.as_retriever(search_kwargs=dict(k=2))
memory = VectorStoreRetrieverMemory(retriever=retriever, memory_key="chat_history", input_key="human_input")
template = """You are a chatbot having a conversation with a human.
{context}
{chat_history}
Human: {human_input}
Chatbot:"""
prompt = PromptTemplate(
input_variables=["chat_history", "human_input", "context"], template=template
)
llm=OpenAI(temperature=1)memory_key="chat_history", input_key="human_input")
chain = load_qa_chain(
llm, chain_type="stuff", memory=memory, prompt=prompt
)