langchain.memory.zep_memory.ZepMemory¶
- class langchain.memory.zep_memory.ZepMemory(session_id: str, url: str = 'http://localhost:8000', api_key: Optional[str] = None, output_key: Optional[str] = None, input_key: Optional[str] = None, return_messages: bool = False, human_prefix: str = 'Human', ai_prefix: str = 'AI', memory_key: str = 'history')[source]¶
Bases:
ConversationBufferMemoryPersist your chain history to the Zep Memory Server.
The number of messages returned by Zep and when the Zep server summarizes chat histories is configurable. See the Zep documentation for more details.
Documentation: https://docs.getzep.com
Example
- memory = ZepMemory(
session_id=session_id, # Identifies your user or a user’s session url=ZEP_API_URL, # Your Zep server’s URL api_key=<your_api_key>, # Optional memory_key=”history”, # Ensure this matches the key used in
# chain’s prompt template
- return_messages=True, # Does your prompt template expect a string
# or a list of Messages?
)
- chain = LLMChain(memory=memory,…) # Configure your chain to use the ZepMemory
instance
Note
To persist metadata alongside your chat history, your will need to create a
custom Chain class that overrides the prep_outputs method to include the metadata in the call to self.memory.save_context.
Zep provides long-term conversation storage for LLM apps. The server stores, summarizes, embeds, indexes, and enriches conversational AI chat histories, and exposes them via simple, low-latency APIs.
For server installation instructions and more, see: https://docs.getzep.com/deployment/quickstart/
For more information on the zep-python package, see: https://github.com/getzep/zep-python
Initialize ZepMemory.
- Parameters
session_id (str) – Identifies your user or a user’s session
url (str, optional) – Your Zep server’s URL. Defaults to “http://localhost:8000”.
api_key (Optional[str], optional) – Your Zep API key. Defaults to None.
output_key (Optional[str], optional) – The key to use for the output message. Defaults to None.
input_key (Optional[str], optional) – The key to use for the input message. Defaults to None.
return_messages (bool, optional) – Does your prompt template expect a string or a list of Messages? Defaults to False i.e. return a string.
human_prefix (str, optional) – The prefix to use for human messages. Defaults to “Human”.
ai_prefix (str, optional) – The prefix to use for AI messages. Defaults to “AI”.
memory_key (str, optional) – The key to use for the memory. Defaults to “history”. Ensure that this matches the key used in chain’s prompt template.
- param ai_prefix: str = 'AI'¶
- param chat_memory: ZepChatMessageHistory [Required]¶
- param human_prefix: str = 'Human'¶
- param input_key: Optional[str] = None¶
- param output_key: Optional[str] = None¶
- param return_messages: bool = False¶
- clear() None¶
Clear memory contents.
- load_memory_variables(inputs: Dict[str, Any]) Dict[str, Any]¶
Return history buffer.
- save_context(inputs: Dict[str, Any], outputs: Dict[str, str], metadata: Optional[Dict[str, Any]] = None) None[source]¶
Save context from this conversation to buffer.
- Parameters
inputs (Dict[str, Any]) – The inputs to the chain.
outputs (Dict[str, str]) – The outputs from the chain.
metadata (Optional[Dict[str, Any]], optional) – Any metadata to save with the context. Defaults to None
- Returns
None
- to_json() Union[SerializedConstructor, SerializedNotImplemented]¶
- to_json_not_implemented() SerializedNotImplemented¶
- property buffer: Any¶
String buffer of memory.
- property lc_attributes: Dict¶
Return a list of attribute names that should be included in the serialized kwargs. These attributes must be accepted by the constructor.
- property lc_namespace: List[str]¶
Return the namespace of the langchain object. eg. [“langchain”, “llms”, “openai”]
- property lc_secrets: Dict[str, str]¶
Return a map of constructor argument names to secret ids. eg. {“openai_api_key”: “OPENAI_API_KEY”}
- property lc_serializable: bool¶
Return whether or not the class is serializable.