langchain: RetrievalQA & RetrievalQAWithSourcesChain chains cannot be serialized/saved or loaded
VectorDBQA
is being deprecated in favour of RetrievalQA
& similarly, VectorDBQAWithSourcesChain
is being deprecated for RetrievalQAWithSourcesChain
.
Currently, VectorDBQA
& VectorDBQAWithSourcesChain
chains can be serialized using vec_chain.save(...)
because they have _chain_type
property - https://github.com/hwchase17/langchain/blob/3bd5a99b835fa320d02aa733cb0c0bc4a87724fa/langchain/chains/qa_with_sources/vector_db.py#L67
However, RetrievalQA
& RetrievalQAWithSourcesChain
do not have that property and raise the following error when trying to save with ret_chain.save("ret_chain.yaml")
:
File [~/.pyenv/versions/3.8.15/envs/internalqa/lib/python3.8/site-packages/langchain/chains/base.py:45](https://file+.vscode-resource.vscode-cdn.net/Users/smohammed/Development/hackweek-internalqa/~/.pyenv/versions/3.8.15/envs/internalqa/lib/python3.8/site-packages/langchain/chains/base.py:45), in Chain._chain_type(self)
[43](file:///Users/smohammed/.pyenv/versions/3.8.15/envs/internalqa/lib/python3.8/site-packages/langchain/chains/base.py?line=42) @property
[44](file:///Users/smohammed/.pyenv/versions/3.8.15/envs/internalqa/lib/python3.8/site-packages/langchain/chains/base.py?line=43) def _chain_type(self) -> str:
---> [45](file:///Users/smohammed/.pyenv/versions/3.8.15/envs/internalqa/lib/python3.8/site-packages/langchain/chains/base.py?line=44) raise NotImplementedError("Saving not supported for this chain type.")
NotImplementedError: Saving not supported for this chain type.
There isn’t any functions to support loading RetrievalQA either, unlike the VectorQA counterparts: https://github.com/hwchase17/langchain/blob/3bd5a99b835fa320d02aa733cb0c0bc4a87724fa/langchain/chains/loading.py#L313-L356
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 9
- Comments: 15
Commits related to this issue
- Implement saving and loading of RetrievalQA chain (#5818) <!-- Thank you for contributing to LangChain! Your PR will appear in our release under the title you set. Please make sure it highlights yo... — committed to langchain-ai/langchain by liangz1 a year ago
- Implement saving and loading of RetrievalQA chain (#5818) <!-- Thank you for contributing to LangChain! Your PR will appear in our release under the title you set. Please make sure it highlights yo... — committed to Undertone0809/langchain by liangz1 a year ago
- Implement saving and loading of RetrievalQA chain (#5818) <!-- Thank you for contributing to LangChain! Your PR will appear in our release under the title you set. Please make sure it highlights yo... — committed to kacperlukawski/langchain by liangz1 a year ago
- enable serde retrieval qa with sources (#10132) #3983 mentions serialization/deserialization issues with both `RetrievalQA` & `RetrievalQAWithSourcesChain`. `RetrievalQA` has already been fixed in ... — committed to langchain-ai/langchain by markoarnauto 10 months ago
This worked for me when I called the chain using lambda instead of directly, no idea why
So, Change from this:
to this
I’m on Langchain v0.0.219 and still running into this issue with RetrievalQAWithSourcesChain where I’m getting an error that Saving not supported for this chain type.
Note that I have RetrievalQAWithSourcesChain defined as a tool going into another agent. (This works fine on its own with a qa_chain(query))
qa_chain =RetrievalQAWithSourcesChain.from_chain_type(llm=llm, chain_type="stuff", retriever=pinecone_retriever.as_retriever(), verbose=True, reduce_k_below_max_tokens=True)
Here I turn it into a tool
Doing a query on agent_aggregator has the following error. I did remove this specific tool and everything works fine, so it’s isolated to RetrievalQAWithSourcesChain being a tool in this other agent.
Major apologies if this is the wrong issue thread, I’m pretty sure it’s related but can move it somewhere more appropriate if needed.
Any thought on what could be happening?
@shessenauer
Having the exact same problem!
Here’s my stacktrace:
`
When using the Retrieval QA From Sources chain everything works fine. However I have to combine it with other tools into an agent.
See this other issue: https://github.com/hwchase17/langchain/issues/1844 however it didn’t helped me.
I am on LangChain 0.0.231
Just want to mention, this was working fine in previous versions, but I’m not sure when exactly it got broken.