AstraDBChatMessageHistory#
- class langchain_community.chat_message_histories.astradb.AstraDBChatMessageHistory(*, session_id: str, collection_name: str = 'langchain_message_store', token: str | None = None, api_endpoint: str | None = None, astra_db_client: AstraDB | None = None, async_astra_db_client: AsyncAstraDB | None = None, namespace: str | None = None, setup_mode: SetupMode = SetupMode.SYNC, pre_delete_collection: bool = False)[source]#
Deprecated since version 0.0.25: Use
:class:`~langchain_astradb.AstraDBChatMessageHistory`
instead. It will be removed in None==1.0.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.
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)Async add a list of messages.
aclear
()Async 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.
Async version of getting messages.
clear
()Remove all messages from the store
- __init__(*, session_id: str, collection_name: str = 'langchain_message_store', token: str | None = None, api_endpoint: str | None = None, astra_db_client: AstraDB | None = None, async_astra_db_client: AsyncAstraDB | None = None, namespace: str | None = 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]#
Async add a list of messages.
- Parameters:
messages (Sequence[BaseMessage]) – A sequence of BaseMessage objects to store.
- Return type:
None
- add_ai_message(message: 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 (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.
- Raises:
NotImplementedError – If the sub-class has not implemented an efficient add_messages method.
- 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 sequence of BaseMessage objects to store.
- Return type:
None
- add_user_message(message: 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 (HumanMessage | str) – The human message to add to the store.
- 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]
Examples using AstraDBChatMessageHistory