CouchbaseChatMessageHistory#

class langchain_couchbase.chat_message_histories.CouchbaseChatMessageHistory(*, cluster: Cluster, bucket_name: str, scope_name: str, collection_name: str, session_id: str, session_id_key: str = 'session_id', message_key: str = 'message', create_index: bool = True, ttl: timedelta | None = None)[source]#

Couchbase Chat Message History Chat message history that uses Couchbase as the storage

Initialize the Couchbase Chat Message History :param cluster: couchbase cluster object with active connection. :type cluster: Cluster :param bucket_name: name of the bucket to store documents in. :type bucket_name: str :param scope_name: name of the scope in bucket to store documents in. :type scope_name: str :param collection_name: name of the collection in the scope to store

documents in.

Parameters:
  • session_id (str) – value for the session used to associate messages from a single chat session. It is stored as a field in the chat message.

  • session_id_key (str) – name of the field to use for the session id. Set to “session_id” by default.

  • message_key (str) – name of the field to use for the messages Set to “message” by default.

  • create_index (bool) – create an index if True. Set to True by default.

  • ttl (timedelta) – time to live for the documents in the collection. When set, the documents are automatically deleted after the ttl expires.

  • cluster (Cluster)

  • bucket_name (str)

  • scope_name (str)

  • collection_name (str)

Attributes

messages

Get all messages in the cache associated with the session_id

Methods

__init__(*, cluster, bucket_name, ...[, ...])

Initialize the Couchbase Chat Message History :param cluster: couchbase cluster object with active connection. :type cluster: Cluster :param bucket_name: name of the bucket to store documents in. :type bucket_name: str :param scope_name: name of the scope in bucket to store documents in. :type scope_name: str :param collection_name: name of the collection in the scope to store documents in. :type collection_name: str :param session_id: value for the session used to associate messages from a single chat session. It is stored as a field in the chat message. :type session_id: str :param session_id_key: name of the field to use for the session id. Set to "session_id" by default. :type session_id_key: str :param message_key: name of the field to use for the messages Set to "message" by default. :type message_key: str :param create_index: create an index if True. Set to True by default. :type create_index: bool :param ttl: time to live for the documents in the collection. When set, the documents are automatically deleted after the ttl expires. :type ttl: timedelta.

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 to the cache

add_messages(messages)

Add messages to the cache in a batched manner

add_user_message(message)

Convenience method for adding a human message string to the store.

aget_messages()

Async version of getting messages.

clear()

Clear the cache

__init__(*, cluster: Cluster, bucket_name: str, scope_name: str, collection_name: str, session_id: str, session_id_key: str = 'session_id', message_key: str = 'message', create_index: bool = True, ttl: timedelta | None = None) None[source]#

Initialize the Couchbase Chat Message History :param cluster: couchbase cluster object with active connection. :type cluster: Cluster :param bucket_name: name of the bucket to store documents in. :type bucket_name: str :param scope_name: name of the scope in bucket to store documents in. :type scope_name: str :param collection_name: name of the collection in the scope to store

documents in.

Parameters:
  • session_id (str) – value for the session used to associate messages from a single chat session. It is stored as a field in the chat message.

  • session_id_key (str) – name of the field to use for the session id. Set to “session_id” by default.

  • message_key (str) – name of the field to use for the messages Set to “message” by default.

  • create_index (bool) – create an index if True. Set to True by default.

  • ttl (timedelta) – time to live for the documents in the collection. When set, the documents are automatically deleted after the ttl expires.

  • cluster (Cluster)

  • bucket_name (str)

  • scope_name (str)

  • collection_name (str)

Return type:

None

async aadd_messages(messages: Sequence[BaseMessage]) None#

Async add a list of messages.

Parameters:

messages (Sequence[BaseMessage]) – A sequence of BaseMessage objects to store.

Return type:

None

async aclear() None#

Async remove all messages from the 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[source]#

Add a message to the cache

Parameters:

message (BaseMessage)

Return type:

None

add_messages(messages: Sequence[BaseMessage]) None[source]#

Add messages to the cache in a batched manner

Parameters:

messages (Sequence[BaseMessage])

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]#

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 the cache

Return type:

None