Tony20100/langchain_full huggingface dataset:
langchain_community.chat_message_histories.mongodb.MongoDBChatMessageHistory¶
class langchain_community.chat_message_histories.mongodb.MongoDBChatMessageHistory(connection_string: str, session_id: str, database_name: str = 'chat_history', collection_name: str = 'message_store', create_index: bool = True)[source]¶
[Deprecated] Chat message history that stores history in MongoDB.
Parameters
connection_string (str) – connection string to connect to MongoDB
session_id (str) – arbitrary key that is used to store the messages
of a single chat session.
database_name (str) – name of the database to use
collection_name (str) – name of the collection to use
create_index (bool) – whether to create an index with name SessionId. Set to False if
such an index already exists.
Notes
Deprecated since version 0.0.25.
Attributes
messages
Retrieve the messages from MongoDB
Methods
__init__(connection_string, 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 MongoDB
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 MongoDB
__init__(connection_string: str, session_id: str, database_name: str = 'chat_history', collection_name: str = 'message_store', create_index: bool = True)[source]¶
Parameters
connection_string (str) – 
session_id (str) – 
database_name (str) – 
collection_name (str) –
database_name (str) – 
collection_name (str) – 
create_index (bool) – 
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 MongoDB
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
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 MongoDB
Return type
None
langchain_community.chat_message_histories.rocksetdb.RocksetChatMessageHistory¶
class langchain_community.chat_message_histories.rocksetdb.RocksetChatMessageHistory(session_id: str, client: ~typing.Any, collection: str, workspace: str = 'commons', messages_key: str = 'messages', sync: bool = False, message_uuid_method: ~typing.Callable[[], ~typing.Union[str, int]] = <function RocksetChatMessageHistory.<lambda>>)[source]¶
Uses Rockset to store chat messages.
To use, ensure that the rockset python package installed.
Example
from langchain_community.chat_message_histories import (
    RocksetChatMessageHistory
)
from rockset import RocksetClient
history = RocksetChatMessageHistory(
    session_id="MySession",
    client=RocksetClient(),
    collection="langchain_demo",
    sync=True
)
history.add_user_message("hi!")
history.add_ai_message("whats up?")
print(history.messages)  # noqa: T201
Constructs a new RocksetChatMessageHistory.
Parameters
session_id (-) – The ID of the chat session
client (-) – The RocksetClient object to use to query
collection (-) – The name of the collection to use to store chat
messages. If a collection with the given name
does not exist in the workspace, it is created.
workspace (-) – The workspace containing collection. Defaults
to “commons”
messages_key (-) – The DB column containing message history.
Defaults to “messages”
sync (-) – Whether to wait for messages to be added. Defaults
to False. NOTE: setting this to True will slow
down performance.
message_uuid_method (-) – The method that generates message IDs.
If set, all messages will have an id field within the
If set, all messages will have an id field within the
additional_kwargs property. If this param is not set
and sync is False, message IDs will not be created.
If this param is not set and sync is True, the
uuid.uuid4 method will be used to create message IDs.
Attributes
ADD_TIMEOUT_MS
CREATE_TIMEOUT_MS
SLEEP_INTERVAL_MS
messages
Messages in this chat history.
Methods
__init__(session_id, client, collection[, ...])
Constructs a new RocksetChatMessageHistory.
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 history.
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()
Removes all messages from the chat history
__init__(session_id: str, client: ~typing.Any, collection: str, workspace: str = 'commons', messages_key: str = 'messages', sync: bool = False, message_uuid_method: ~typing.Callable[[], ~typing.Union[str, int]] = <function RocksetChatMessageHistory.<lambda>>) → None[source]¶
Constructs a new RocksetChatMessageHistory.
Parameters
session_id (-) – The ID of the chat session
client (-) – The RocksetClient object to use to query
collection (-) – The name of the collection to use to store chat
messages. If a collection with the given name
does not exist in the workspace, it is created.
workspace (-) – The workspace containing collection. Defaults
to “commons”
workspace (-) – The workspace containing collection. Defaults
to “commons”
messages_key (-) – The DB column containing message history.
Defaults to “messages”
sync (-) – Whether to wait for messages to be added. Defaults
to False. NOTE: setting this to True will slow
down performance.
message_uuid_method (-) – The method that generates message IDs.
If set, all messages will have an id field within the
additional_kwargs property. If this param is not set
and sync is False, message IDs will not be created.
If this param is not set and sync is True, the
uuid.uuid4 method will be used to create message IDs.
Return type
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]¶
Add a Message object to the history.
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
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]¶
Removes all messages from the chat history
Return type
None
Examples using RocksetChatMessageHistory¶
Rockset
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. If not provided, the environment
variable ASTRA_DB_APPLICATION_TOKEN is inspected.
api_endpoint (Optional[str]) – 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.
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.
If not provided, the environment variable ASTRA_DB_KEYSPACE is
inspected. Defaults to the database’s “default namespace”.
setup_mode (SetupMode) –
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.
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. If not provided, the environment
variable ASTRA_DB_APPLICATION_TOKEN is inspected.
api_endpoint (Optional[str]) – 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.
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.
If not provided, the environment variable ASTRA_DB_KEYSPACE is
inspected. 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
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]¶
Add a list of messages.
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.zep.SearchScope¶
class langchain_community.chat_message_histories.zep.SearchScope(value)[source]¶
Scope for the document search. Messages or Summaries?
messages = 'messages'¶
Search chat history messages.
summary = 'summary'¶
Search chat history summaries.
Examples using SearchScope¶
Zep Open Source
langchain_community.chat_message_histories.file.FileChatMessageHistory¶
class langchain_community.chat_message_histories.file.FileChatMessageHistory(file_path: str)[source]¶
Chat message history that stores history in a local file.
Initialize the file path for the chat history.
Parameters
file_path (str) – The path to the local file to store the chat history.
Attributes
messages
Retrieve the messages from the local file
Methods
__init__(file_path)
Initialize the file path for the chat history.
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 the local file
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 the local file
__init__(file_path: str) → None[source]¶
Initialize the file path for the chat history.
Parameters
file_path (str) – The path to the local file to store the chat history.
Return type
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
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 the local file
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]¶
Clear session memory from the local file
Return type
None
langchain_community.chat_message_histories.cassandra.CassandraChatMessageHistory¶
class langchain_community.chat_message_histories.cassandra.CassandraChatMessageHistory(session_id: str, session: Optional[Session] = None, keyspace: Optional[str] = None, table_name: str = 'message_store', ttl_seconds: Optional[int] = None, *, setup_mode: SetupMode = SetupMode.SYNC)[source]¶
Chat message history that stores history in Cassandra.
Parameters
session_id (str) – arbitrary key that is used to store the messages
of a single chat session.
session (Optional[Session]) – Cassandra driver session.
If not provided, it is resolved from cassio.
keyspace (Optional[str]) – Cassandra key space. If not provided, it is resolved from cassio.
table_name (str) – name of the table to use.
ttl_seconds (Optional[int]) – time-to-live (seconds) for automatic expiration
of stored entries. None (default) for no expiration.
setup_mode (SetupMode) – mode used to create the Cassandra table (SYNC, ASYNC or OFF).
Attributes
messages
Retrieve all session messages from DB
Methods
__init__(session_id[, session, keyspace, ...])
Chat message history that stores history in Cassandra.
aadd_messages(messages)
Add a list of messages.
aclear()
Clear session memory from DB
add_ai_message(message)
Convenience method for adding an AI message string to the store.
add_message(message)
Write a message to the table
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()
Retrieve all session messages from DB
clear()
Clear session memory from DB
aget_messages()
Retrieve all session messages from DB
clear()
Clear session memory from DB
__init__(session_id: str, session: Optional[Session] = None, keyspace: Optional[str] = None, table_name: str = 'message_store', ttl_seconds: Optional[int] = None, *, setup_mode: SetupMode = SetupMode.SYNC) → None[source]¶
Chat message history that stores history in Cassandra.
Parameters
session_id (str) – arbitrary key that is used to store the messages
of a single chat session.
session (Optional[Session]) – Cassandra driver session.
If not provided, it is resolved from cassio.
keyspace (Optional[str]) – Cassandra key space. If not provided, it is resolved from cassio.
table_name (str) – name of the table to use.
ttl_seconds (Optional[int]) – time-to-live (seconds) for automatic expiration
of stored entries. None (default) for no expiration.
setup_mode (SetupMode) – mode used to create the Cassandra table (SYNC, ASYNC or OFF).
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]¶
Clear session memory from DB
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.
Parameters
message (Union[AIMessage, str]) – The AI message to add.
Return type
None
add_message(message: BaseMessage) → None[source]¶
Write a message to the table
Parameters
message (BaseMessage) – A message to write.
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][source]¶
Retrieve all session messages from DB
Return type
List[BaseMessage]
clear() → None[source]¶
Clear session memory from DB
Return type
None
Examples using CassandraChatMessageHistory¶
Cassandra
Cassandra