Module zep_python.memory
Expand source code
from zep_python.memory.models import (
Memory,
MemorySearchPayload,
MemorySearchResult,
Message,
Session,
Summary,
)
__all__ = [
"Memory",
"Message",
"MemorySearchPayload",
"MemorySearchResult",
"Summary",
"Session",
]
Sub-modules
zep_python.memory.client
zep_python.memory.models
Classes
class Memory (**data: Any)
-
Represents a memory object with messages, metadata, and other attributes.
Attributes
messages
:Optional[List[Message]]
- A list of message objects, where each message contains a role and content.
metadata
:Optional[Dict[str, Any]]
- A dictionary containing metadata associated with the memory.
summary
:Optional[Summary]
- A Summary object.
uuid
:Optional[str]
- A unique identifier for the memory.
created_at
:Optional[str]
- The timestamp when the memory was created.
token_count
:Optional[int]
- The token count of the memory.
facts
:Optional[List[str]]
- Most recent list of facts derived from the session. Included only with perpetual memory type.
summary_instruction
:Optional[str]
- Additional instruction for generating the summary.
Methods
to_dict() -> Dict[str, Any]: Returns a dictionary representation of the message.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError
][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.self
is explicitly positional-only to allowself
as a field name.Expand source code
class Memory(BaseModel): """ Represents a memory object with messages, metadata, and other attributes. Attributes ---------- messages : Optional[List[Message]] A list of message objects, where each message contains a role and content. metadata : Optional[Dict[str, Any]] A dictionary containing metadata associated with the memory. summary : Optional[Summary] A Summary object. uuid : Optional[str] A unique identifier for the memory. created_at : Optional[str] The timestamp when the memory was created. token_count : Optional[int] The token count of the memory. facts : Optional[List[str]] Most recent list of facts derived from the session. Included only with perpetual memory type. summary_instruction : Optional[str] Additional instruction for generating the summary. Methods ------- to_dict() -> Dict[str, Any]: Returns a dictionary representation of the message. """ messages: Optional[List[Message]] = Field( default=[], description="A List of Messages or empty List is required", ) metadata: Optional[Dict[str, Any]] = Field(default=None) summary: Optional[Summary] = Field(default=None) uuid: Optional[str] = Field(default=None) created_at: Optional[str] = Field(default=None) token_count: Optional[int] = Field(default=None) facts: Optional[List[str]] = Field(default=None) summary_instruction: Optional[str] = Field(default=None) def to_dict(self) -> Dict[str, Any]: return self.model_dump(exclude_unset=True, exclude_none=True)
Ancestors
- pydantic.main.BaseModel
Class variables
var created_at : Optional[str]
var facts : Optional[List[str]]
var messages : Optional[List[Message]]
var metadata : Optional[Dict[str, Any]]
var model_computed_fields
var model_config
var model_fields
var summary : Optional[Summary]
var summary_instruction : Optional[str]
var token_count : Optional[int]
var uuid : Optional[str]
Methods
def to_dict(self) ‑> Dict[str, Any]
-
Expand source code
def to_dict(self) -> Dict[str, Any]: return self.model_dump(exclude_unset=True, exclude_none=True)
class MemorySearchPayload (**data: Any)
-
Represents a search payload for querying memory.
Attributes
metadata
:Dict[str, Any]
- Metadata associated with the search query.
text
:str
- The text of the search query.
search_scope
:Optional[str]
- Search over messages or summaries. Defaults to "messages". Must be one of "messages" or "summary".
search_type
:Optional[str]
- The type of search to perform. Defaults to "similarity". Must be one of "similarity" or "mmr".
mmr_lambda
:Optional[float]
- The lambda parameter for the MMR Reranking Algorithm.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError
][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.self
is explicitly positional-only to allowself
as a field name.Expand source code
class MemorySearchPayload(BaseModel): """ Represents a search payload for querying memory. Attributes ---------- metadata : Dict[str, Any] Metadata associated with the search query. text : str The text of the search query. search_scope : Optional[str] Search over messages or summaries. Defaults to "messages". Must be one of "messages" or "summary". search_type : Optional[str] The type of search to perform. Defaults to "similarity". Must be one of "similarity" or "mmr". mmr_lambda : Optional[float] The lambda parameter for the MMR Reranking Algorithm. """ text: Optional[str] = Field(default=None) metadata: Optional[Dict[str, Any]] = Field(default=None) search_scope: Optional[str] = Field(default="messages") search_type: Optional[str] = Field(default="similarity") mmr_lambda: Optional[float] = Field(default=None)
Ancestors
- pydantic.main.BaseModel
Class variables
var metadata : Optional[Dict[str, Any]]
var mmr_lambda : Optional[float]
var model_computed_fields
var model_config
var model_fields
var search_scope : Optional[str]
var search_type : Optional[str]
var text : Optional[str]
class MemorySearchResult (**data: Any)
-
Represents a search result from querying memory.
Attributes
message
:Optional[Message]
- The message matched by search.
summary
:Optional[Summary]
- The summary matched by search.
metadata
:Optional[Dict[str, Any]]
- Metadata associated with the search result.
score
:Optional[float]
- The score of the search result.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError
][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.self
is explicitly positional-only to allowself
as a field name.Expand source code
class MemorySearchResult(BaseModel): """ Represents a search result from querying memory. Attributes ---------- message : Optional[Message] The message matched by search. summary : Optional[Summary] The summary matched by search. metadata : Optional[Dict[str, Any]] Metadata associated with the search result. score : Optional[float] The score of the search result. """ message: Optional[Message] = None summary: Optional[Summary] = None metadata: Optional[Dict[str, Any]] = None score: Optional[float] = None
Ancestors
- pydantic.main.BaseModel
Class variables
var message : Optional[Message]
var metadata : Optional[Dict[str, Any]]
var model_computed_fields
var model_config
var model_fields
var score : Optional[float]
var summary : Optional[Summary]
class Message (**data: Any)
-
Represents a message in a conversation.
Attributes
uuid
:str
, optional- The unique identifier of the message.
created_at
:str
, optional- The timestamp of when the message was created.
role
:str
- The role of the sender of the message (e.g., "user", "assistant").
role_type
:RoleType
- The type of the role (e.g., "user", "system").
content
:str
- The content of the message.
token_count
:int
, optional- The number of tokens in the message.
Methods
to_dict() -> Dict[str, Any]: Returns a dictionary representation of the message.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError
][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.self
is explicitly positional-only to allowself
as a field name.Expand source code
class Message(BaseModel): """ Represents a message in a conversation. Attributes ---------- uuid : str, optional The unique identifier of the message. created_at : str, optional The timestamp of when the message was created. role : str The role of the sender of the message (e.g., "user", "assistant"). role_type: RoleType The type of the role (e.g., "user", "system"). content : str The content of the message. token_count : int, optional The number of tokens in the message. Methods ------- to_dict() -> Dict[str, Any]: Returns a dictionary representation of the message. """ role: str = Field("A role is required") role_type: RoleType = Field("A role type is required") content: str = Field("Content is required") uuid: Optional[str] = Field(default=None) created_at: Optional[str] = Field(default=None) token_count: Optional[int] = Field(default=None) metadata: Optional[Dict[str, Any]] = Field(default=None) @validator("role_type") def validate_role_type(cls, v): if isinstance(v, RoleType): return v if v not in RoleType._value2member_map_: raise ValueError(f"Invalid role type: {v}") return v def to_dict(self) -> Dict[str, Any]: """ Returns a dictionary representation of the message. Returns ------- Dict[str, Any] A dictionary containing the attributes of the message. """ return self.model_dump(exclude_unset=True, exclude_none=True)
Ancestors
- pydantic.main.BaseModel
Class variables
var content : str
var created_at : Optional[str]
var metadata : Optional[Dict[str, Any]]
var model_computed_fields
var model_config
var model_fields
var role : str
var role_type : RoleType
var token_count : Optional[int]
var uuid : Optional[str]
Static methods
def validate_role_type(v)
-
Expand source code
@validator("role_type") def validate_role_type(cls, v): if isinstance(v, RoleType): return v if v not in RoleType._value2member_map_: raise ValueError(f"Invalid role type: {v}") return v
Methods
def to_dict(self) ‑> Dict[str, Any]
-
Returns a dictionary representation of the message.
Returns
Dict[str, Any]
- A dictionary containing the attributes of the message.
Expand source code
def to_dict(self) -> Dict[str, Any]: """ Returns a dictionary representation of the message. Returns ------- Dict[str, Any] A dictionary containing the attributes of the message. """ return self.model_dump(exclude_unset=True, exclude_none=True)
class Session (**data: Any)
-
Represents a session object with a unique identifier, metadata, and other attributes.
Attributes
uuid
:Optional[str]
- A unique identifier for the session. This is generated server-side and is not expected to be present on creation.
created_at
:str
- The timestamp when the session was created. Generated by the server.
updated_at
:str
- The timestamp when the session was last updated. Generated by the server.
deleted_at
:Optional[datetime]
- The timestamp when the session was deleted. Generated by the server.
session_id
:str
- The unique identifier of the session.
metadata
:Dict[str, Any]
- The metadata associated with the session.
facts
:Optional[List[str]]
- A list of facts derived from the session.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError
][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.self
is explicitly positional-only to allowself
as a field name.Expand source code
class Session(BaseModel): """ Represents a session object with a unique identifier, metadata, and other attributes. Attributes ---------- uuid : Optional[str] A unique identifier for the session. This is generated server-side and is not expected to be present on creation. created_at : str The timestamp when the session was created. Generated by the server. updated_at : str The timestamp when the session was last updated. Generated by the server. deleted_at : Optional[datetime] The timestamp when the session was deleted. Generated by the server. session_id : str The unique identifier of the session. metadata : Dict[str, Any] The metadata associated with the session. facts : Optional[List[str]] A list of facts derived from the session. """ uuid: Optional[str] = None id: Optional[int] = None created_at: Optional[str] = None updated_at: Optional[str] = None deleted_at: Optional[str] = None session_id: str user_id: Optional[str] = None metadata: Optional[Dict[str, Any]] = None facts: Optional[List[str]] = Field(default=None)
Ancestors
- pydantic.main.BaseModel
Class variables
var created_at : Optional[str]
var deleted_at : Optional[str]
var facts : Optional[List[str]]
var id : Optional[int]
var metadata : Optional[Dict[str, Any]]
var model_computed_fields
var model_config
var model_fields
var session_id : str
var updated_at : Optional[str]
var user_id : Optional[str]
var uuid : Optional[str]
class Summary (**data: Any)
-
Represents a summary of a conversation.
Attributes
uuid
:str
- The unique identifier of the summary.
created_at
:str
- The timestamp of when the summary was created.
content
:str
- The content of the summary.
recent_message_uuid
:str
- The unique identifier of the most recent message in the conversation.
token_count
:int
- The number of tokens in the summary.
Methods
to_dict() -> Dict[str, Any]: Returns a dictionary representation of the summary.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError
][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.self
is explicitly positional-only to allowself
as a field name.Expand source code
class Summary(BaseModel): """ Represents a summary of a conversation. Attributes ---------- uuid : str The unique identifier of the summary. created_at : str The timestamp of when the summary was created. content : str The content of the summary. recent_message_uuid : str The unique identifier of the most recent message in the conversation. token_count : int The number of tokens in the summary. Methods ------- to_dict() -> Dict[str, Any]: Returns a dictionary representation of the summary. """ uuid: str = Field("A uuid is required") created_at: str = Field("A created_at is required") content: str = Field("Content is required") recent_message_uuid: str = Field("A recent_message_uuid is required") token_count: int = Field("A token_count is required") def to_dict(self) -> Dict[str, Any]: """ Returns a dictionary representation of the summary. Returns ------- Dict[str, Any] A dictionary containing the attributes of the summary. """ return self.model_dump(exclude_unset=True, exclude_none=True)
Ancestors
- pydantic.main.BaseModel
Class variables
var content : str
var created_at : str
var model_computed_fields
var model_config
var model_fields
var recent_message_uuid : str
var token_count : int
var uuid : str
Methods
def to_dict(self) ‑> Dict[str, Any]
-
Returns a dictionary representation of the summary.
Returns
Dict[str, Any]
- A dictionary containing the attributes of the summary.
Expand source code
def to_dict(self) -> Dict[str, Any]: """ Returns a dictionary representation of the summary. Returns ------- Dict[str, Any] A dictionary containing the attributes of the summary. """ return self.model_dump(exclude_unset=True, exclude_none=True)