memoryscope.core.worker.backend
- class memoryscope.core.worker.backend.ContraRepeatWorker(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]
-
The ContraRepeatWorker class specializes in processing memory nodes to identify and handle contradictory and repetitive information. It extends the base functionality of MemoryBaseWorker.
Responsibilities: - Collects observation nodes from various memory categories. - Constructs a prompt with these observations for language model analysis. - Parses the model's response to detect contradictions or redundancies. - Adjusts the status of memory nodes based on the analysis. - Persists the updated node statuses back into memory.
- FILE_PATH: str = '/home/runner/work/MemoryScope/MemoryScope/memoryscope/core/worker/backend/contra_repeat_worker.py'
- class memoryscope.core.worker.backend.GetObservationWithTimeWorker(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]
-
A specialized worker class that extends GetObservationWorker functionality to handle retrieval of observations which include associated timestamp information from chat messages.
- FILE_PATH: str = '/home/runner/work/MemoryScope/MemoryScope/memoryscope/core/worker/backend/get_observation_with_time_worker.py'
- OBS_STORE_KEY: str = 'new_obs_with_time_nodes'
- filter_messages() List[Message] [源代码]
Filters the chat messages to only include those which contain time-related keywords.
- 返回:
A list of filtered messages that mention time.
- 返回类型:
List[Message]
- build_message(filter_messages: List[Message]) List[Message] [源代码]
- Constructs a prompt message for obtaining observations with timestamp information
based on filtered chat messages.
This method processes each filtered message with the timestamp information. It then organizes these timestamped messages into a structured prompt that includes a system prompt, few-shot examples, and the concatenated user queries.
- class memoryscope.core.worker.backend.GetObservationWorker(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]
-
A specialized worker class to generate the observations from the original chat histories.
- FILE_PATH: str = '/home/runner/work/MemoryScope/MemoryScope/memoryscope/core/worker/backend/get_observation_worker.py'
- OBS_STORE_KEY: str = 'new_obs_nodes'
- add_observation(message: Message, time_infer: str, obs_content: str, keywords: str)[源代码]
Builds a MemoryNode containing the observation details.
- 参数:
message (Message) -- The source message from which the observation is derived.
time_infer (str) -- The inferred time if available.
obs_content (str) -- The content of the observation.
keywords (str) -- Keywords associated with the observation.
- 返回:
The constructed MemoryNode containing the observation.
- 返回类型:
- filter_messages() List[Message] [源代码]
Filters the chat messages to only include those which not contain time-related keywords.
- 返回:
A list of filtered messages that mention time.
- 返回类型:
List[Message]
- class memoryscope.core.worker.backend.GetReflectionSubjectWorker(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]
-
A specialized worker class responsible for retrieving unreflected memory nodes, generating reflection prompts with current insights, invoking an LLM for fresh insights, parsing the LLM responses, forming new insight nodes, and updating memory statuses accordingly.
- FILE_PATH: str = '/home/runner/work/MemoryScope/MemoryScope/memoryscope/core/worker/backend/get_reflection_subject_worker.py'
- new_insight_node(insight_key: str) MemoryNode [源代码]
Creates a new MemoryNode for an insight with the given key, enriched with current datetime metadata.
- 参数:
insight_key (str) -- The unique identifier for the insight.
- 返回:
A new MemoryNode instance representing the insight, marked as new and of type INSIGHT.
- 返回类型:
- class memoryscope.core.worker.backend.InfoFilterWorker(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]
-
This worker filters and modifies the chat message history (self.chat_messages) by retaining only the messages that include significant information. It then constructs a prompt from these filtered messages, utilizes an AI model to process this prompt, parses the AI's generated response to allocate scores, and ultimately retains messages in self.chat_messages based on these assigned scores.
- FILE_PATH: str = '/home/runner/work/MemoryScope/MemoryScope/memoryscope/core/worker/backend/info_filter_worker.py'
- class memoryscope.core.worker.backend.LoadMemoryWorker(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]
-
- retrieve_not_reflected_memory(**kwargs)
The wrapper function that manages the timing of the original function.
- 参数:
*args -- Variable length argument list for the decorated function.
**kwargs -- Arbitrary keyword arguments for the decorated function.
- 返回:
The result of the decorated function.
- 返回类型:
Any
- retrieve_not_updated_memory(**kwargs)
The wrapper function that manages the timing of the original function.
- 参数:
*args -- Variable length argument list for the decorated function.
**kwargs -- Arbitrary keyword arguments for the decorated function.
- 返回:
The result of the decorated function.
- 返回类型:
Any
- retrieve_insight_memory(**kwargs)
The wrapper function that manages the timing of the original function.
- 参数:
*args -- Variable length argument list for the decorated function.
**kwargs -- Arbitrary keyword arguments for the decorated function.
- 返回:
The result of the decorated function.
- 返回类型:
Any
- retrieve_today_memory(**kwargs)
The wrapper function that manages the timing of the original function.
- 参数:
*args -- Variable length argument list for the decorated function.
**kwargs -- Arbitrary keyword arguments for the decorated function.
- 返回:
The result of the decorated function.
- 返回类型:
Any
- class memoryscope.core.worker.backend.LongContraRepeatWorker(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]
-
Manages and updates memory entries within a conversation scope by identifying and handling contradictions or redundancies. It extends the base MemoryBaseWorker to provide specialized functionality for long conversations with potential contradictory or repetitive statements.
- FILE_PATH: str = '/home/runner/work/MemoryScope/MemoryScope/memoryscope/core/worker/backend/long_contra_repeat_worker.py'
- retrieve_similar_content(node: ~memoryscope.scheme.memory_node.MemoryNode) -> (<class 'memoryscope.scheme.memory_node.MemoryNode'>, typing.List[memoryscope.scheme.memory_node.MemoryNode])[源代码]
Retrieves memory nodes with content similar to the given node, filtering by user/target/status/memory_type. Only returns nodes whose similarity score meets or exceeds the predefined threshold.
- 参数:
node (MemoryNode) -- The reference node used to find similar content in memory.
- 返回:
A tuple containing the original node and a list of similar nodes that passed the similarity threshold.
- 返回类型:
Tuple[MemoryNode, List[MemoryNode]]
- class memoryscope.core.worker.backend.UpdateInsightWorker(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]
-
This class is responsible for updating insight value in a memory system. It filters insight nodes based on their association with observed nodes, utilizes a ranking model to prioritize them, generates refreshed insights via an LLM, and manages node statuses and content updates, incorporating features for concurrent execution and logging.
- FILE_PATH: str = '/home/runner/work/MemoryScope/MemoryScope/memoryscope/core/worker/backend/update_insight_worker.py'
- filter_obs_nodes(insight_node: ~memoryscope.scheme.memory_node.MemoryNode, obs_nodes: ~typing.List[~memoryscope.scheme.memory_node.MemoryNode]) -> (<class 'memoryscope.scheme.memory_node.MemoryNode'>, typing.List[memoryscope.scheme.memory_node.MemoryNode], <class 'float'>)[源代码]
Filters observed nodes based on their relevance to a given insight node using a ranking model.
- 参数:
insight_node (MemoryNode) -- The insight node used as the basis for filtering.
obs_nodes (List[MemoryNode]) -- A list of observed nodes to be filtered.
- 返回:
- A tuple containing:
The original insight node.
A list of filtered observed nodes that are relevant to the insight node.
The maximum relevance score among the filtered nodes.
- 返回类型:
tuple
- update_insight_node(insight_node: MemoryNode, insight_value: str)[源代码]
Updates the MemoryNode with the new insight value.
- 参数:
insight_node (MemoryNode) -- The MemoryNode whose insight value needs to be updated.
insight_value (str) -- The new insight value.
- 返回:
The updated MemoryNode with potentially revised insight value.
- 返回类型:
- update_insight(insight_node: MemoryNode, filtered_nodes: List[MemoryNode]) MemoryNode [源代码]
Updates the insight value of a given MemoryNode based on the context from a list of filtered MemoryNodes.
- 参数:
insight_node (MemoryNode) -- The MemoryNode whose insight value needs to be updated.
filtered_nodes (List[MemoryNode]) -- A list of MemoryNodes used as context for updating the insight.
- 返回:
The updated MemoryNode with potentially revised insight value.
- 返回类型:
- class memoryscope.core.worker.backend.UpdateMemoryWorker(embedding_model: str = '', generation_model: str = '', rank_model: str = '', **kwargs)[源代码]
-
- from_query()[源代码]
Creates a MemoryNode from the provided query if present in chat_kwargs.
- 返回:
A list containing a single MemoryNode created from the query.
- 返回类型:
List[MemoryNode]
- from_memory_key()[源代码]
Retrieves memories based on the memory key if it exists.
- 返回:
A list of MemoryNode objects retrieved using the memory key.
- 返回类型:
List[MemoryNode]
- delete_all()[源代码]
Marks all memories for deletion by setting their action_status to 'DELETE'.
- 返回:
A list of all MemoryNode objects marked for deletion.
- 返回类型:
List[MemoryNode]
- delete_memory()[源代码]
Marks specific memories for deletion based on query or memory_id present in chat_kwargs.
- 返回:
A list of MemoryNode objects marked for deletion based on the query or memory_id.
- 返回类型:
List[MemoryNode]