ChatHistoryMemory
class ChatHistoryMemory(AgentMemory):
An agent memory wrapper of :obj:ChatHistoryBlock
.
Parameters:
- context_creator (BaseContextCreator): A model context creator.
- storage (BaseKeyValueStorage, optional): A storage backend for storing chat history. If
None
, an :obj:InMemoryKeyValueStorage
will be used. (default: :obj:None
)
- window_size (int, optional): The number of recent chat messages to retrieve. If not provided, the entire chat history will be retrieved. (default: :obj:
None
)
- agent_id (str, optional): The ID of the agent associated with the chat history.
init
def __init__(
self,
context_creator: BaseContextCreator,
storage: Optional[BaseKeyValueStorage] = None,
window_size: Optional[int] = None,
agent_id: Optional[str] = None
):
agent_id
agent_id
def agent_id(self, val: Optional[str]):
retrieve
write_records
def write_records(self, records: List[MemoryRecord]):
get_context_creator
def get_context_creator(self):
clear
VectorDBMemory
class VectorDBMemory(AgentMemory):
An agent memory wrapper of :obj:VectorDBBlock
. This memory queries
messages stored in the vector database. Notice that the most recent
messages will not be added to the context.
Parameters:
- context_creator (BaseContextCreator): A model context creator.
- storage (BaseVectorStorage, optional): A vector storage storage. If
None
, an :obj:QdrantStorage
will be used. (default: :obj:None
)
- retrieve_limit (int, optional): The maximum number of messages to be added into the context. (default: :obj:
3
)
- agent_id (str, optional): The ID of the agent associated with the messages stored in the vector database.
init
def __init__(
self,
context_creator: BaseContextCreator,
storage: Optional[BaseVectorStorage] = None,
retrieve_limit: int = 3,
agent_id: Optional[str] = None
):
agent_id
agent_id
def agent_id(self, val: Optional[str]):
retrieve
write_records
def write_records(self, records: List[MemoryRecord]):
get_context_creator
def get_context_creator(self):
clear
Removes all records from the vector database memory.
LongtermAgentMemory
class LongtermAgentMemory(AgentMemory):
An implementation of the :obj:AgentMemory
abstract base class for
augmenting ChatHistoryMemory with VectorDBMemory.
Parameters:
- context_creator (BaseContextCreator): A model context creator.
- chat_history_block (Optional[ChatHistoryBlock], optional): A chat history block. If
None
, a :obj:ChatHistoryBlock
will be used. (default: :obj:None
)
- vector_db_block (Optional[VectorDBBlock], optional): A vector database block. If
None
, a :obj:VectorDBBlock
will be used. (default: :obj:None
)
- retrieve_limit (int, optional): The maximum number of messages to be added into the context. (default: :obj:
3
)
- agent_id (str, optional): The ID of the agent associated with the chat history and the messages stored in the vector database.
init
def __init__(
self,
context_creator: BaseContextCreator,
chat_history_block: Optional[ChatHistoryBlock] = None,
vector_db_block: Optional[VectorDBBlock] = None,
retrieve_limit: int = 3,
agent_id: Optional[str] = None
):
agent_id
agent_id
def agent_id(self, val: Optional[str]):
get_context_creator
def get_context_creator(self):
Returns:
BaseContextCreator: The context creator used by the memory.
retrieve
Returns:
List[ContextRecord]: A list of context records retrieved from both
the chat history and the vector database.
write_records
def write_records(self, records: List[MemoryRecord]):
Converts the provided chat messages into vector representations and
writes them to the vector database.
Parameters:
- records (List[MemoryRecord]): Messages to be added to the vector database.
clear
Removes all records from the memory.
Responses are generated using AI and may contain mistakes.