mongodb
¤
This module contains the MongoDBMessageHistory class, which is used to store chat message history in a MongoDB database.
Classes:
Name | Description |
---|---|
MongoDBMessageHistory |
Chat message history that stores history in MongoDB. |
Attributes:
Name | Type | Description |
---|---|---|
DEFAULT_COLLECTION_NAME |
A collection name for the MongoDB database. |
|
DEFAULT_CONNECTION_STRING |
A connection string for a MongoDB database. |
|
DEFAULT_DBNAME |
A database name for the MongoDB database. |
DEFAULT_COLLECTION_NAME
module-attribute
¤
DEFAULT_COLLECTION_NAME = 'message_store'
A collection name for the MongoDB database.
DEFAULT_CONNECTION_STRING
module-attribute
¤
DEFAULT_CONNECTION_STRING = 'mongodb://localhost:27017'
A connection string for a MongoDB database.
DEFAULT_DBNAME
module-attribute
¤
DEFAULT_DBNAME = 'chat_history'
A database name for the MongoDB database.
MongoDBMessageHistory
¤
MongoDBMessageHistory(
session_id: str,
connection_string: str = DEFAULT_CONNECTION_STRING,
database_name: str = DEFAULT_DBNAME,
collection_name: str = DEFAULT_COLLECTION_NAME,
)
Bases: BaseChatMessageHistory
Chat message history that stores history in MongoDB.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connection_string |
str
|
connection string to connect to MongoDB |
DEFAULT_CONNECTION_STRING
|
session_id |
str
|
Arbitrary key that is used to store the messages for a single chat session. |
required |
database_name |
str
|
name of the database to use |
DEFAULT_DBNAME
|
collection_name |
str
|
name of the collection to use |
DEFAULT_COLLECTION_NAME
|
Methods:
Name | Description |
---|---|
add_message |
Append the message to the record in MongoDB |
clear |
Clear session memory from MongoDB |
Attributes:
Name | Type | Description |
---|---|---|
history |
List[Message]
|
Retrieve the messages from MongoDB |
Source code in src/declarai/memory/mongodb.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
add_message
¤
add_message(message: Message) -> None
Append the message to the record in MongoDB
Source code in src/declarai/memory/mongodb.py
71 72 73 74 75 76 77 78 |
|
clear
¤
clear() -> None
Clear session memory from MongoDB
Source code in src/declarai/memory/mongodb.py
80 81 82 |
|