I want to make a chatbot, that should answer questions from the context, in my case, a vector database. It is doing that perfectly. But I also want it to answer questions, which are not in the vector database. But it is unable to do so. It only is able to answer from the context.
This is the prompt template I have for this:
template = """Answer the question in your own words from the
context given to you.
If questions are asked where there is no relevant context available, please answer from
what you know.
Context: {context}
Chat history: {chat_history}
Human: {question}
Assistant:"""
My prompt is as follows:
prompt = PromptTemplate(
input_variables=["context", "chat_history", "question"], template=template
)
For the memory, I provided an initial question:
memory.save_context({"input": "Who is the founder of India?"},
{"output": "Gandhi"})
For the QA Retrieval, I am using the following code:
qa = RetrievalQA.from_chain_type(
llm=llm,
retriever=vectorstore.as_retriever(),
memory=memory,
chain_type_kwargs={'prompt': prompt}
)
But when I ask about a question:
question= "What did I ask about India?"
result = qa({"query": question})
It doesn't have any answer for that. Although this question is stored in the chat history. It is only able to answer questions from the vector database. I will greatly appreciate a help in this.