Tony20100/langchain_full huggingface dataset:
langchain_community.chat_message_histories.redis.RedisChatMessageHistory¶
class langchain_community.chat_message_histories.redis.RedisChatMessageHistory(session_id: str, url: str = 'redis://localhost:6379/0', key_prefix: str = 'message_store:', ttl: Optional[int] = None)[source]¶
Chat message history stored in a Redis database.
Attributes
key
Construct the record key to use
messages
Retrieve the messages from Redis
Methods
__init__(session_id[, url, key_prefix, ttl])
aadd_messages(messages)
Add a list of messages.
aclear()
Remove all messages from the store
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 Redis
add_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Async version of getting messages.
clear()
Clear session memory from Redis
Parameters
session_id (str) – 
url (str) – 
key_prefix (str) – 
ttl (Optional[int]) – 
__init__(session_id: str, url: str = 'redis://localhost:6379/0', key_prefix: str = 'message_store:', ttl: Optional[int] = None)[source]¶
Parameters
session_id (str) – 
url (str) – 
key_prefix (str) – 
ttl (Optional[int]) – 
async aadd_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
async aclear() → None¶
Remove all messages from the store
Return type
None
async aclear() → None¶
Remove all messages from the store
Return type
None
add_ai_message(message: Union[AIMessage, str]) → None¶
Convenience method for adding an AI message string to the store.
Please note that this is a convenience method. Code should favor the bulk
add_messages interface instead to save on round-trips to the underlying
persistence layer.
This method may be deprecated in a future release.
Parameters
message (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None[source]¶
Append the message to the record in Redis
Parameters
message (BaseMessage) – 
Return type
None
add_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Implementations should over-ride this method to handle bulk addition of messages
in an efficient manner to avoid unnecessary round-trips to the underlying store.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[HumanMessage, str]) → None¶
Convenience method for adding a human message string to the store.
Please note that this is a convenience method. Code should favor the
bulk add_messages interface instead to save on round-trips to the underlying
persistence layer.
This method may be deprecated in a future release.
Parameters
message (Union[HumanMessage, str]) – The human message to add
Return type
None
async aget_messages() → List[BaseMessage]¶
Async version of getting messages.
Can over-ride this method to provide an efficient async implementation.
In general, fetching messages may involve IO to the underlying
persistence layer.
Return type
List[BaseMessage]
clear() → None[source]¶
langchain_community.chat_message_histories.astradb.AstraDBChatMessageHistory¶
class langchain_community.chat_message_histories.astradb.AstraDBChatMessageHistory(*, session_id: str, collection_name: str = 'langchain_message_store', token: Optional[str] = None, api_endpoint: Optional[str] = None, astra_db_client: Optional[AstraDB] = None, async_astra_db_client: Optional[AsyncAstraDB] = None, namespace: Optional[str] = None, setup_mode: SetupMode = SetupMode.SYNC, pre_delete_collection: bool = False)[source]¶
[Deprecated]
Notes
Deprecated since version 0.0.25.
Chat message history that stores history in Astra DB.
Parameters
session_id (str) – arbitrary key that is used to store the messages
of a single chat session.
collection_name (str) – name of the Astra DB collection to create/use.
token (Optional[str]) – API token for Astra DB usage.
api_endpoint (Optional[str]) – full URL to the API endpoint,
such as “https://<DB-ID>-us-east1.apps.astra.datastax.com”.
astra_db_client (Optional[AstraDB]) – alternative to token+api_endpoint,
you can pass an already-created ‘astrapy.db.AstraDB’ instance.
async_astra_db_client (Optional[AsyncAstraDB]) – alternative to token+api_endpoint,
you can pass an already-created ‘astrapy.db.AsyncAstraDB’ instance.
namespace (Optional[str]) – namespace (aka keyspace) where the
collection is created. Defaults to the database’s “default namespace”.
setup_mode (SetupMode) – mode used to create the Astra DB collection (SYNC, ASYNC or
OFF).
pre_delete_collection (bool) – whether to delete the collection
OFF).
pre_delete_collection (bool) – whether to delete the collection
before creating it. If False and the collection already exists,
the collection will be used as is.
Attributes
messages
Retrieve all session messages from DB
Methods
__init__(*, session_id[, collection_name, ...])
Chat message history that stores history in Astra DB.
aadd_messages(messages)
Add a list of messages.
aclear()
Remove all messages from the store
add_ai_message(message)
Convenience method for adding an AI message string to the store.
add_message(message)
Add a Message object to the store.
add_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Async version of getting messages.
clear()
Remove all messages from the store
__init__(*, session_id: str, collection_name: str = 'langchain_message_store', token: Optional[str] = None, api_endpoint: Optional[str] = None, astra_db_client: Optional[AstraDB] = None, async_astra_db_client: Optional[AsyncAstraDB] = None, namespace: Optional[str] = None, setup_mode: SetupMode = SetupMode.SYNC, pre_delete_collection: bool = False) → None[source]¶
Chat message history that stores history in Astra DB.
Parameters
session_id (str) – arbitrary key that is used to store the messages
of a single chat session.
collection_name (str) – name of the Astra DB collection to create/use.
token (Optional[str]) – API token for Astra DB usage.
api_endpoint (Optional[str]) – full URL to the API endpoint,
such as “https://<DB-ID>-us-east1.apps.astra.datastax.com”.
astra_db_client (Optional[AstraDB]) – alternative to token+api_endpoint,
you can pass an already-created ‘astrapy.db.AstraDB’ instance.
async_astra_db_client (Optional[AsyncAstraDB]) – alternative to token+api_endpoint,
you can pass an already-created ‘astrapy.db.AsyncAstraDB’ instance.
namespace (Optional[str]) – namespace (aka keyspace) where the
collection is created. Defaults to the database’s “default namespace”.
setup_mode (SetupMode) – mode used to create the Astra DB collection (SYNC, ASYNC or
OFF).
pre_delete_collection (bool) – whether to delete the collection
before creating it. If False and the collection already exists,
the collection will be used as is.
Return type
None
async aadd_messages(messages: Sequence[BaseMessage]) → None[source]¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
async aclear() → None[source]¶
Remove all messages from the store
Return type
None
add_ai_message(message: Union[AIMessage, str]) → None¶
Convenience method for adding an AI message string to the store.
Please note that this is a convenience method. Code should favor the bulk
add_messages interface instead to save on round-trips to the underlying
persistence layer.
This method may be deprecated in a future release.
Parameters
message (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None¶
Add a Message object to the store.
Parameters
message (BaseMessage) – A BaseMessage object to store.
Return type
None
add_messages(messages: Sequence[BaseMessage]) → None[source]¶
Return type
None
add_messages(messages: Sequence[BaseMessage]) → None[source]¶
Add a list of messages.
Implementations should over-ride this method to handle bulk addition of messages
in an efficient manner to avoid unnecessary round-trips to the underlying store.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[HumanMessage, str]) → None¶
Convenience method for adding a human message string to the store.
Please note that this is a convenience method. Code should favor the
bulk add_messages interface instead to save on round-trips to the underlying
persistence layer.
This method may be deprecated in a future release.
Parameters
message (Union[HumanMessage, str]) – The human message to add
Return type
None
async aget_messages() → List[BaseMessage][source]¶
Async version of getting messages.
Can over-ride this method to provide an efficient async implementation.
In general, fetching messages may involve IO to the underlying
persistence layer.
Return type
List[BaseMessage]
clear() → None[source]¶
Remove all messages from the store
Return type
None
Examples using AstraDBChatMessageHistory¶
Astra DB
langchain_community.chat_message_histories.dynamodb.DynamoDBChatMessageHistory¶
class langchain_community.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, ttl: Optional[int] = None, ttl_key_name: str = 'expireAt', history_size: Optional[int] = 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 (str) – name of the DynamoDB table
session_id (str) – arbitrary key that is used to store the messages
of a single chat session.
endpoint_url (Optional[str]) – 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 (str) – name of the primary key of the DynamoDB table. This argument
is optional, defaulting to “SessionId”.
key (Optional[Dict[str, str]]) – 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 (Optional[str]) – an optional AWS KMS Key ID, AWS KMS Key ARN, or AWS KMS Alias for
client-side encryption
client-side encryption
ttl (Optional[int]) – Optional Time-to-live (TTL) in seconds. Allows you to define a per-item
expiration timestamp that indicates when an item can be deleted from the
table. DynamoDB handles deletion of expired items without consuming
write throughput. To enable this feature on the table, follow the
[AWS DynamoDB documentation](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/time-to-live-ttl-how-to.html)
history_size (Optional[int]) – Maximum number of messages to store. If None then there is no
limit. If not None then only the latest history_size messages are stored.
boto3_session (Optional[Session]) – 
ttl_key_name (str) – 
Attributes
messages
Retrieve the messages from DynamoDB
Methods
__init__(table_name, session_id[, ...])
aadd_messages(messages)
Add a list of messages.
aclear()
Remove all messages from the store
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_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Async version of getting messages.
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, ttl: Optional[int] = None, ttl_key_name: str = 'expireAt', history_size: Optional[int] = None)[source]¶
Parameters
Parameters
table_name (str) – 
session_id (str) – 
endpoint_url (Optional[str]) – 
primary_key_name (str) – 
key (Optional[Dict[str, str]]) – 
boto3_session (Optional[Session]) – 
kms_key_id (Optional[str]) – 
ttl (Optional[int]) – 
ttl_key_name (str) – 
history_size (Optional[int]) – 
async aadd_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
async aclear() → None¶
Remove all messages from the store
Return type
None
add_ai_message(message: Union[AIMessage, str]) → None¶
Convenience method for adding an AI message string to the store.
Please note that this is a convenience method. Code should favor the bulk
add_messages interface instead to save on round-trips to the underlying
persistence layer.
This method may be deprecated in a future release.
Parameters
message (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None[source]¶
Append the message to the record in DynamoDB
Parameters
message (BaseMessage) – 
Return type
None
add_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Implementations should over-ride this method to handle bulk addition of messages
in an efficient manner to avoid unnecessary round-trips to the underlying store.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[HumanMessage, str]) → None¶
None
add_user_message(message: Union[HumanMessage, str]) → None¶
Convenience method for adding a human message string to the store.
Please note that this is a convenience method. Code should favor the
bulk add_messages interface instead to save on round-trips to the underlying
persistence layer.
This method may be deprecated in a future release.
Parameters
message (Union[HumanMessage, str]) – The human message to add
Return type
None
async aget_messages() → List[BaseMessage]¶
Async version of getting messages.
Can over-ride this method to provide an efficient async implementation.
In general, fetching messages may involve IO to the underlying
persistence layer.
Return type
List[BaseMessage]
clear() → None[source]¶
Clear session memory from DynamoDB
Return type
None
Examples using DynamoDBChatMessageHistory¶
AWS
AWS DynamoDB
langchain_community.chat_message_histories.momento.MomentoChatMessageHistory¶
class langchain_community.chat_message_histories.momento.MomentoChatMessageHistory(session_id: str, cache_client: momento.CacheClient, cache_name: str, *, key_prefix: str = 'message_store:', ttl: Optional[timedelta] = None, ensure_cache_exists: bool = True)[source]¶
Chat message history cache that uses Momento as a backend.
See https://gomomento.com/
Instantiate a chat message history cache that uses Momento as a backend.
Note: to instantiate the cache client passed to MomentoChatMessageHistory,
you must have a Momento account at https://gomomento.com/.
Parameters
session_id (str) – The session ID to use for this chat session.
cache_client (CacheClient) – The Momento cache client.
cache_name (str) – The name of the cache to use to store the messages.
key_prefix (str, optional) – The prefix to apply to the cache key.
Defaults to “message_store:”.
ttl (Optional[timedelta], optional) – The TTL to use for the messages.
Defaults to None, ie the default TTL of the cache will be used.
ensure_cache_exists (bool, optional) – Create the cache if it doesn’t exist.
Defaults to True.
Raises
ImportError – Momento python package is not installed.
TypeError – cache_client is not of type momento.CacheClientObject
Attributes
messages
Retrieve the messages from Momento.
Methods
__init__(session_id, cache_client, cache_name, *)
Instantiate a chat message history cache that uses Momento as a backend.
aadd_messages(messages)
Add a list of messages.
aclear()
Remove all messages from the store
add_ai_message(message)
aclear()
Remove all messages from the store
add_ai_message(message)
Convenience method for adding an AI message string to the store.
add_message(message)
Store a message in the cache.
add_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Async version of getting messages.
clear()
Remove the session's messages from the cache.
from_client_params(session_id, cache_name, ...)
Construct cache from CacheClient parameters.
__init__(session_id: str, cache_client: momento.CacheClient, cache_name: str, *, key_prefix: str = 'message_store:', ttl: Optional[timedelta] = None, ensure_cache_exists: bool = True)[source]¶
Instantiate a chat message history cache that uses Momento as a backend.
Note: to instantiate the cache client passed to MomentoChatMessageHistory,
you must have a Momento account at https://gomomento.com/.
Parameters
session_id (str) – The session ID to use for this chat session.
cache_client (CacheClient) – The Momento cache client.
cache_name (str) – The name of the cache to use to store the messages.
key_prefix (str, optional) – The prefix to apply to the cache key.
Defaults to “message_store:”.
ttl (Optional[timedelta], optional) – The TTL to use for the messages.
Defaults to None, ie the default TTL of the cache will be used.
ensure_cache_exists (bool, optional) – Create the cache if it doesn’t exist.
Defaults to True.
Raises
ImportError – Momento python package is not installed.
TypeError – cache_client is not of type momento.CacheClientObject
async aadd_messages(messages: Sequence[BaseMessage]) → None¶
async aadd_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
async aclear() → None¶
Remove all messages from the store
Return type
None
add_ai_message(message: Union[AIMessage, str]) → None¶
Convenience method for adding an AI message string to the store.
Please note that this is a convenience method. Code should favor the bulk
add_messages interface instead to save on round-trips to the underlying
persistence layer.
This method may be deprecated in a future release.
Parameters
message (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None[source]¶
Store a message in the cache.
Parameters
message (BaseMessage) – The message object to store.
Raises
SdkException – Momento service or network error.
Exception – Unexpected response.
Return type
None
add_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Implementations should over-ride this method to handle bulk addition of messages
in an efficient manner to avoid unnecessary round-trips to the underlying store.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[HumanMessage, str]) → None¶
Convenience method for adding a human message string to the store.
Please note that this is a convenience method. Code should favor the
bulk add_messages interface instead to save on round-trips to the underlying
persistence layer.
This method may be deprecated in a future release.
Parameters
message (Union[HumanMessage, str]) – The human message to add
Return type
None
Return type
None
async aget_messages() → List[BaseMessage]¶
Async version of getting messages.
Can over-ride this method to provide an efficient async implementation.
In general, fetching messages may involve IO to the underlying
persistence layer.
Return type
List[BaseMessage]
clear() → None[source]¶
Remove the session’s messages from the cache.
Raises
SdkException – Momento service or network error.
Exception – Unexpected response.
Return type
None
classmethod from_client_params(session_id: str, cache_name: str, ttl: timedelta, *, configuration: Optional[momento.config.Configuration] = None, api_key: Optional[str] = None, auth_token: Optional[str] = None, **kwargs: Any) → MomentoChatMessageHistory[source]¶
Construct cache from CacheClient parameters.
Parameters
session_id (str) – 
cache_name (str) – 
ttl (timedelta) – 
configuration (Optional[momento.config.Configuration]) – 
api_key (Optional[str]) – 
auth_token (Optional[str]) – 
kwargs (Any) – 
Return type
MomentoChatMessageHistory
Examples using MomentoChatMessageHistory¶
Momento
Momento Cache
langchain_community.chat_message_histories.firestore.FirestoreChatMessageHistory¶
class langchain_community.chat_message_histories.firestore.FirestoreChatMessageHistory(collection_name: str, session_id: str, user_id: str, firestore_client: Optional[Client] = None)[source]¶
Chat message history backed by Google Firestore.
Initialize a new instance of the FirestoreChatMessageHistory class.
Parameters
collection_name (str) – The name of the collection to use.
session_id (str) – The session ID for the chat..
user_id (str) – The user ID for the chat.
firestore_client (Optional[Client]) – 
Attributes
messages
A property or attribute that returns a list of messages.
Methods
__init__(collection_name, session_id, user_id)
Initialize a new instance of the FirestoreChatMessageHistory class.
aadd_messages(messages)
Add a list of messages.
aclear()
Remove all messages from the store
add_ai_message(message)
Convenience method for adding an AI message string to the store.
add_message(message)
Add a Message object to the store.
add_messages(messages)
Add a list of messages.
add_user_message(message)
Convenience method for adding a human message string to the store.
aget_messages()
Async version of getting messages.
clear()
Clear session memory from this memory and Firestore.
load_messages()
Retrieve the messages from Firestore
prepare_firestore()
Prepare the Firestore client.
upsert_messages([new_message])
Update the Firestore document.
__init__(collection_name: str, session_id: str, user_id: str, firestore_client: Optional[Client] = None)[source]¶
Initialize a new instance of the FirestoreChatMessageHistory class.
Parameters
collection_name (str) – The name of the collection to use.
Parameters
collection_name (str) – The name of the collection to use.
session_id (str) – The session ID for the chat..
user_id (str) – The user ID for the chat.
firestore_client (Optional[Client]) – 
async aadd_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
async aclear() → None¶
Remove all messages from the store
Return type
None
add_ai_message(message: Union[AIMessage, str]) → None¶
Convenience method for adding an AI message string to the store.
Please note that this is a convenience method. Code should favor the bulk
add_messages interface instead to save on round-trips to the underlying
persistence layer.
This method may be deprecated in a future release.
Parameters
message (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None[source]¶
Add a Message object to the store.
Parameters
message (BaseMessage) – A BaseMessage object to store.
Return type
None
add_messages(messages: Sequence[BaseMessage]) → None¶
Add a list of messages.
Implementations should over-ride this method to handle bulk addition of messages
in an efficient manner to avoid unnecessary round-trips to the underlying store.
Parameters
messages (Sequence[BaseMessage]) – A list of BaseMessage objects to store.
Return type
None
add_user_message(message: Union[HumanMessage, str]) → None¶
Convenience method for adding a human message string to the store.
Please note that this is a convenience method. Code should favor the
bulk add_messages interface instead to save on round-trips to the underlying