langchain.memory.chat_message_histories.dynamodb.DynamoDBChatMessageHistory

class langchain.memory.chat_message_histories.dynamodb.DynamoDBChatMessageHistory(table_name: str, session_id: str, endpoint_url: Optional[str] = None, primary_key_name: str = 'SessionId', key: Optional[Dict[str, str]] = None, boto3_session: Optional[Session] = None, kms_key_id: Optional[str] = None)[source]

Chat message history that stores history in AWS DynamoDB.

This class expects that a DynamoDB table exists with name table_name

Parameters
  • table_name – name of the DynamoDB table

  • session_id – arbitrary key that is used to store the messages of a single chat session.

  • endpoint_url – URL of the AWS endpoint to connect to. This argument is optional and useful for test purposes, like using Localstack. If you plan to use AWS cloud service, you normally don’t have to worry about setting the endpoint_url.

  • primary_key_name – name of the primary key of the DynamoDB table. This argument is optional, defaulting to “SessionId”.

  • key – an optional dictionary with a custom primary and secondary key. This argument is optional, but useful when using composite dynamodb keys, or isolating records based off of application details such as a user id. This may also contain global and local secondary index keys.

  • kms_key_id – an optional AWS KMS Key ID, AWS KMS Key ARN, or AWS KMS Alias for client-side encryption

Attributes

messages

Retrieve the messages from DynamoDB

Methods

__init__(table_name, session_id[, ...])

add_ai_message(message)

Convenience method for adding an AI message string to the store.

add_message(message)

Append the message to the record in DynamoDB

add_user_message(message)

Convenience method for adding a human message string to the store.

clear()

Clear session memory from DynamoDB

__init__(table_name: str, session_id: str, endpoint_url: Optional[str] = None, primary_key_name: str = 'SessionId', key: Optional[Dict[str, str]] = None, boto3_session: Optional[Session] = None, kms_key_id: Optional[str] = None)[source]
add_ai_message(message: str) None

Convenience method for adding an AI message string to the store.

Parameters

message – The string contents of an AI message.

add_message(message: BaseMessage) None[source]

Append the message to the record in DynamoDB

add_user_message(message: str) None

Convenience method for adding a human message string to the store.

Parameters

message – The string contents of a human message.

clear() None[source]

Clear session memory from DynamoDB

Examples using DynamoDBChatMessageHistory