-
Notifications
You must be signed in to change notification settings - Fork 15.8k
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
Core: Handle Failed Cache Reads For Non-Serializable Objects #27989
base: master
Are you sure you want to change the base?
Core: Handle Failed Cache Reads For Non-Serializable Objects #27989
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
Where do tests for |
@jacoblee93 Do you mind having a look at this? |
@baskaryan Can someone have a look at this? |
hey there! Sorry for the delay on this one. Could you add some tests either to this, or even better to some of the integration packages where you're seeing this failure mode with InMemoryCache? I don't fully understand why this needs to be implemented on BaseChatModel, instead of fixing on a specific cache that has a bug. |
@efriis Thanks for taking the time to look into it. The fix is on BaseChatModel because the root cause of the issue has to do with how the cache reads are converted into a ChatResult. Any cache implementation that tries to read an unsupported object from its serialized version will run into this error. Do you know where the ideal place to add tests for this? I looked into the test directories but found no designated directory/file for tests that focus on (de)serialization. |
if this is the fix that's necessary, would recommend adding to this will help me understand what the issue is |
@FarhanChowdhury248 let me know if you're interested in writing some of those unit tests! Otherwise I'll close later this week (and folks are always welcome to reopen once those are up demonstrating the issue) |
Hey @efriis. I plan on getting on this after tomorrow, when my last exam is done. Sorry I haven't been able to keep up with this. |
This PR fixes the issue mentioned in #27264.
Description
Bug
Many caching implementations for chat model results (as defined in
langchain_core/caches.py
) require cached objects to beSerializable
in order to properly perform the cache read and write. In cases where they are not, the lookup may fail when the cache attempts to de-serialize the cached data into a list ofChatGeneration
objects. On such failure, many caches inlangchain_core\caches.py
fail over to returning a list ofGeneration
objects that contain the serialized data strings.When these are read by
BaseChatModel
in_generate_with_cache
or_agenerate_with_cache
, the cached result is fed into aChatGeneration
object, which does not acceptGeneration
objects, leading to the error.Fix
Add a check in
_generate_with_cache
and_agenerate_with_cache
to verify the cached results are of typeChatGeneration[]
. If not, skip the lookup and treat the case as an uncached one.