langchain_astradb.chat_message_histories
.AstraDBChatMessageHistory¶
- class langchain_astradb.chat_message_histories.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]¶
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) –
pre_delete_collection (bool) –
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.
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) –
pre_delete_collection (bool) –
- 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
- 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]¶
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]