-
Notifications
You must be signed in to change notification settings - Fork 15.7k
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
community[patch]: update dynamodb chat history to update instead of overwrite #22397
Merged
eyurtsev
merged 2 commits into
langchain-ai:master
from
Davi-Schumacher:fix-dynamodb-chat-history-put-overwrite
Dec 16, 2024
Merged
community[patch]: update dynamodb chat history to update instead of overwrite #22397
eyurtsev
merged 2 commits into
langchain-ai:master
from
Davi-Schumacher:fix-dynamodb-chat-history-put-overwrite
Dec 16, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
dosubot
bot
added
size:L
This PR changes 100-499 lines, ignoring generated files.
🔌: aws
Primarily related to Amazon Web Services (AWS) integrations
🤖:improvement
Medium size change to existing code to handle new use-cases
labels
Jun 2, 2024
Davi-Schumacher
force-pushed
the
fix-dynamodb-chat-history-put-overwrite
branch
3 times, most recently
from
November 3, 2024 20:58
fc4c447
to
98023e1
Compare
Hi @eyurtsev, can I get some guidance on what it would take to get this PR in shape for review/approval? |
Davi-Schumacher
force-pushed
the
fix-dynamodb-chat-history-put-overwrite
branch
from
November 10, 2024 23:35
baa221b
to
df863f2
Compare
…ead of put_item this allows someone to use the same chat session record to store additional attributes by updating the History attribute without overwriting the entire record
Davi-Schumacher
force-pushed
the
fix-dynamodb-chat-history-put-overwrite
branch
from
November 10, 2024 23:41
df863f2
to
ebe1485
Compare
eyurtsev
reviewed
Dec 11, 2024
@Davi-Schumacher looks good, could you confirm whether we need to escape any of the values to avoid sql injection? |
eyurtsev
approved these changes
Dec 11, 2024
dosubot
bot
added
the
lgtm
PR looks good. Use to confirm that a PR is ready for merging.
label
Dec 11, 2024
eyurtsev
changed the title
community: update dynamodb chat history to update instead of overwrite
community[patch]: update dynamodb chat history to update instead of overwrite
Dec 11, 2024
eyurtsev
added
the
waiting-on-author
PR Status: Confirmation from author is required
label
Dec 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
🔌: aws
Primarily related to Amazon Web Services (AWS) integrations
community
Related to langchain-community
🤖:improvement
Medium size change to existing code to handle new use-cases
lgtm
PR looks good. Use to confirm that a PR is ready for merging.
size:L
This PR changes 100-499 lines, ignoring generated files.
waiting-on-author
PR Status: Confirmation from author is required
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
The current implementation of
DynamoDBChatMessageHistory
updates theHistory
attribute for a given chat history record by first extracting the existing contents into memory, appending the new message, and then using theput_item
method to put the record back. This has the effect of overwriting any additional attributes someone may want to include in the record, like chat session metadata.This PR suggests changing from using
put_item
to usingupdate_item
instead which will keep any other attributes in the record untouched. The change is backward compatible sinceupdate_item
is an "upsert" operation, creating the record if it doesn't already exist, otherwise updating itDependencies:
None
Tests and docs:
No unit tests currently exist for the
DynamoDBChatMessageHistory
class. This PR adds the filelibs/community/tests/unit_tests/chat_message_histories/test_dynamodb_chat_message_history.py
to test theadd_message
andclear
methods. I wanted to use the moto library to mock DynamoDB calls but I could not get poetry to resolve it so I mocked those calls myself in the test. Therefore, no test dependencies were added.The change was tested on a test DynamoDB table as well. The first three images below show the current behavior. First a message is added to chat history, then a value is inserted in the record in some other attribute, and finally another message is added to the record, destroying the other attribute.
The next three images show the new behavior. Once again a value is added to an attribute other than the History attribute, but now when the followup message is added it does not destroy that other attribute. The History attribute itself is unaffected by this change.
The doc located at
docs/docs/integrations/memory/aws_dynamodb.ipynb
required no changes and was tested as well.