langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Issue: ConversationalRetrievalChain Fails to Distinguish User's Intention for Chat History Only or Chat History + Vector Store Answer

Open ShaneYuTH opened this issue 1 year ago • 3 comments

Issue you'd like to raise.

In my application, I am using the ConversationalRetrievalChain with "stuff" chain type, FAISS as the vector store and ConversationBufferMemory. I have noticed that when I ask a question related to a previous response (i.e. a request that is only looking for answers from chat history, such as a summarization request), the system still searches for answers from both the vector store and chat history. This often leads to incorrect or irrelevant answers (the summarization will include data from chat history as well as data that is never presented in previous conversation from vector store).

I've tried to address this issue by passing a custom prompt using combine_docs_chain_kwargs to specify whether a response should be generated based on the chat history only, or the chat history and the vector store. However, this approach hasn't been effective.

It seems that the system is currently unable to correctly discern the user's intention to exclusively use the chat history for generating a response. It's crucial that the system can accurately determine this to provide relevant and accurate responses.

Suggestion:

I propose that the system should be enhanced with a mechanism to first detect the user's intention to either:

Select a response from the chat history only, or Select a response from the chat history in combination with the vector store.

This could possibly be achieved by conditionally including or excluding certain parts of a prompt, such as {context} (from stuff_prompt.py, this is the default prompt used by stuff chain type), based on user input or intentions. However, this logic would need to be implemented during the data preparation for the template.

I haven't figured out a way to do so. Looking forward to your help!

ShaneYuTH avatar Jun 24 '23 04:06 ShaneYuTH

Answer generated by a 🤖

Answer

Thank you for bringing this issue to our attention and for proposing a solution. We appreciate your interest in contributing to LangChain.

Enhancing the system to accurately discern the user's intention to either select a response from the chat history only or from the chat history in combination with the vector store sounds like a valuable addition. Your suggestion to conditionally include or exclude certain parts of the prompt based on user input or intentions seems like a good approach.

We encourage you to create a pull request with your proposed solution. Our maintainers will review it and provide feedback. Your contribution will be greatly appreciated in improving the functionality of LangChain.

If you have any questions or need any assistance during the process, please feel free to ask.


This response is meant to be useful, save you time, and share context. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

dosubot[bot] avatar Jun 24 '23 04:06 dosubot[bot]

Can you not use a router chain to facilitate this?

ShantanuNair avatar Jul 07 '23 13:07 ShantanuNair

Can you not use a router chain to facilitate this?

After a quick glance through the router chain, this might be a pretty good solution to the above problem. Thanks for your info!

ShaneYuTH avatar Jul 07 '23 19:07 ShaneYuTH

After a quick glance through the router chain, this might be a pretty good solution to the above problem. Thanks for your info!

Have you solved the problem in this way?

heweapon avatar Jul 14 '23 07:07 heweapon

Hi, @ShaneYuTH! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, the issue is about the ConversationalRetrievalChain failing to distinguish the user's intention for chat history only or chat history + vector store answer. There have been some discussions and suggestions on how to enhance the system with a mechanism to detect the user's intention and conditionally include or exclude certain parts of the prompt. It seems that the problem has been resolved using the approach suggested by ShantanuNair.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.

Thank you for your contribution!

dosubot[bot] avatar Oct 23 '23 16:10 dosubot[bot]