Amazon AWS DynamoDB is a fully managed NoSQL
database service that provides fast and predictable performance with seamless scalability.
This notebook goes over how to use DynamoDB
to store chat message history with DynamoDBChatMessageHistory
class.
Setup
First make sure you have correctly configured the AWS CLI. Then make sure you have installed thelangchain-community
package, so we need to install that. We also need to install the boto3
package.
Create Table
Now, create theDynamoDB
Table where we will be storing messages:
DynamoDBChatMessageHistory
DynamoDBChatMessageHistory with Custom Endpoint URL
Sometimes it is useful to specify the URL to the AWS endpoint to connect to. For instance, when you are running locally against Localstack. For those cases you can specify the URL via theendpoint_url
parameter in the constructor.
DynamoDBChatMessageHistory With Composite Keys
The default key for DynamoDBChatMessageHistory is{"SessionId": self.session_id}
, but you can modify this to match your table design.
Primary Key Name
You may modify the primary key by passing in a primary_key_name value in the constructor, resulting in the following:{self.primary_key_name: self.session_id}
Composite Keys
When using an existing DynamoDB table, you may need to modify the key structure from the default of to something including a Sort Key. To do this you may use thekey
parameter.
Passing a value for key will override the primary_key parameter, and the resulting key structure will be the passed value.