-
Notifications
You must be signed in to change notification settings - Fork 15.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add single execution option for ConversationalRetrievalChain #5066
add single execution option for ConversationalRetrievalChain #5066
Conversation
I believe this feature provides practical values. Can I get a review on this one? @hwchase17 @dev2049 |
Hello guys, we're having a similar issue with the Thanks in advance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
making question_generator optional makes sense to me! but don't think we should be messing with prompts at runtime, you should be able to set those when instantiating the chain in first place
and "context" | ||
not in self.combine_docs_chain.llm_chain.prompt.input_variables | ||
): | ||
self.combine_docs_chain.llm_chain.prompt = CHAT_RETRIEVAL_QA_PROMPT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do this at runtime, why not set the prompt of combine_docs_chain when instantiating the ConversationalRetrievalChain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense! Just made the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dev2049 can you review again?
db0f390
to
fd0153e
Compare
i think we need just better documentation around conversational retrieval chains in general |
I have updated the notebook to show how to set |
Hoping this can get merged soon since I need this patch for a work project! @hwchase17 @dev2049 any feedback? |
👀👀👀 |
b92120d
to
98794d1
Compare
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
@dev2049 @hwchase17 can you take a look at this PR? Sorry for chasing.. |
@@ -36,6 +37,7 @@ def format_document(doc: Document, prompt: BasePromptTemplate) -> str: | |||
class BaseCombineDocumentsChain(Chain, ABC): | |||
"""Base interface for chains combining documents.""" | |||
|
|||
llm_chain: LLMChain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes because we set the prompt
variable like
combine_docs_chain.llm_chain.prompt = CHAT_RETRIEVAL_QA_PROMPT
in the validate_combine_docs_chain
function for the error handling and I found I have to put the type there to pass the linting check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leferradkw let me know if any other questions! Hope to get the PR merged soon! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then add a unit test to prove the constructor is working well and the interface is the same as before
How can I implement this solution in my project? |
98794d1
to
c496d5b
Compare
@@ -36,6 +37,7 @@ def format_document(doc: Document, prompt: BasePromptTemplate) -> str: | |||
class BaseCombineDocumentsChain(Chain, ABC): | |||
"""Base interface for chains combining documents.""" | |||
|
|||
llm_chain: LLMChain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then add a unit test to prove the constructor is working well and the interface is the same as before
c496d5b
to
2f42514
Compare
A must needed feature. I am looking for this. |
@jpzhangvincent Hi , could you, please, resolve the merging issues and address the last comments (if needed)? After that, ping me and I push this PR for the review. Thanks! |
2f42514
to
929e3c0
Compare
@jpzhangvincent It is again :( Could you, please, resolve the merging issues? After that ping me and I push this PR for the review. Thanks! |
@leo-gan I believe I have fixed the merge conflicts. I tried to add a test or an example in the notebook(if needed) but not sure where/which file to add specifically. Open to suggestion! |
@jpzhangvincent There are failed unit tests and pydantic compatibility tests. When you fix them we will be ready. |
b33137d
to
4418657
Compare
@leo-gan I believe I had resolved the test issues.. please review again and feel free to make code changes directly! |
@baskaryan @leo-gan Okay I have addressed the feedback and added a unit test. Hopeful we can get this merged soon since it could be low-hanging fruit but useful feature. |
@baskaryan @leo-gan @hwchase17 thoughts on merging this PR? |
Can you please review again? Thanks! @baskaryan @leo-gan |
Thank you for this. Closing because this is readily achievable with create_retrieval_chain. See the example snippet in the API reference. You can also reference this guide on migrating from ConversationalRetrievalChain to LCEL implementations. Please let me know if you have any other concerns. |
add single execution option for ConversationalRetrievalChain
question_generator
(chain) argument optional to allow it to bypass the rephrasing step and use a custom prompt to combine thechat_history
,context
andquestion
together for single execution. This could give users more flexibility based on their use cases and requirements.Fixes #5123
Before submitting
I updated the notebook to include the
## ConversationalRetrievalChain with only custom combine_docs_chain
sectionWho can review?
Community members can review the PR once tests pass. Tag maintainers/contributors who might be interested:
@hwchase17 @dev2049