langchain_astradb.chat_message_histories
.AstraDBChatMessageHistory¶
- class langchain_astradb.chat_message_histories.AstraDBChatMessageHistory(*, session_id: str, collection_name: str = 'langchain_message_store', token: str | TokenProvider | None = None, api_endpoint: str | None = None, environment: 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]¶
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 (str | TokenProvider | None) â API token for Astra DB usage, either in the form of a string or a subclass of astrapy.authentication.TokenProvider. If not provided, the environment variable ASTRA_DB_APPLICATION_TOKEN is inspected.
api_endpoint (str | None) â full URL to the API endpoint, such as https://<DB-ID>-us-east1.apps.astra.datastax.com. If not provided, the environment variable ASTRA_DB_API_ENDPOINT is inspected.
environment (str | None) â a string specifying the environment of the target Data API. If omitted, defaults to âprodâ (Astra DB production). Other values are in astrapy.constants.Environment enum class.
astra_db_client (AstraDB | None) â DEPRECATED starting from version 0.3.5. Please use âtokenâ, âapi_endpointâ and optionally âenvironmentâ. you can pass an already-created âastrapy.db.AstraDBâ instance (alternatively to âtokenâ, âapi_endpointâ and âenvironmentâ).
async_astra_db_client (AsyncAstraDB | None) â DEPRECATED starting from version 0.3.5. Please use âtokenâ, âapi_endpointâ and optionally âenvironmentâ. you can pass an already-created âastrapy.db.AsyncAstraDBâ instance (alternatively to âtokenâ, âapi_endpointâ and âenvironmentâ).
namespace (str | None) â namespace (aka keyspace) where the collection is created. If not provided, the environment variable ASTRA_DB_KEYSPACE is inspected. 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.
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 | TokenProvider | None = None, api_endpoint: str | None = None, environment: 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 (str | TokenProvider | None) â API token for Astra DB usage, either in the form of a string or a subclass of astrapy.authentication.TokenProvider. If not provided, the environment variable ASTRA_DB_APPLICATION_TOKEN is inspected.
api_endpoint (str | None) â full URL to the API endpoint, such as https://<DB-ID>-us-east1.apps.astra.datastax.com. If not provided, the environment variable ASTRA_DB_API_ENDPOINT is inspected.
environment (str | None) â a string specifying the environment of the target Data API. If omitted, defaults to âprodâ (Astra DB production). Other values are in astrapy.constants.Environment enum class.
astra_db_client (AstraDB | None) â DEPRECATED starting from version 0.3.5. Please use âtokenâ, âapi_endpointâ and optionally âenvironmentâ. you can pass an already-created âastrapy.db.AstraDBâ instance (alternatively to âtokenâ, âapi_endpointâ and âenvironmentâ).
async_astra_db_client (AsyncAstraDB | None) â DEPRECATED starting from version 0.3.5. Please use âtokenâ, âapi_endpointâ and optionally âenvironmentâ. you can pass an already-created âastrapy.db.AsyncAstraDBâ instance (alternatively to âtokenâ, âapi_endpointâ and âenvironmentâ).
namespace (str | None) â namespace (aka keyspace) where the collection is created. If not provided, the environment variable ASTRA_DB_KEYSPACE is inspected. 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.
- 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: 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.
- 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: 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 to the store.
- Return type
None
- async aget_messages() list[langchain_core.messages.base.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