nat.plugins.memmachine.memmachine_editor#

Attributes#

Classes#

MemMachineEditor

Wrapper class that implements nat interfaces for MemMachine integrations.

Module Contents#

logger#
class MemMachineEditor(memmachine_instance: Any)#

Bases: nat.memory.interfaces.MemoryEditor

Wrapper class that implements nat interfaces for MemMachine integrations. Uses the MemMachine Python SDK (MemMachineClient) as documented at: MemMachine/MemMachine

Supports both episodic and semantic memory through the unified SDK interface.

User needs to add MemMachine SDK ids as metadata to the MemoryItem:

  • session_id

  • agent_id

  • project_id

  • org_id

Initialize class with MemMachine instance.

Args:

memmachine_instance: Preinstantiated MemMachineClient or Project object.

_memmachine#
_is_client#
_is_project#
_get_memory_instance(
user_id: str,
session_id: str,
agent_id: str,
project_id: str | None = None,
org_id: str | None = None,
) Any#

Get or create a memory instance for the given context using the MemMachine SDK.

Args:

user_id: User identifier session_id: Session identifier agent_id: Agent identifier project_id: Optional project identifier (default: “default-project”) org_id: Optional organization identifier (default: “default-org”)

Returns:

Memory instance from MemMachine SDK

async add_items(items: list[nat.memory.models.MemoryItem]) None#

Insert Multiple MemoryItems into the memory using the MemMachine SDK. Each MemoryItem is translated and uploaded through the MemMachine API.

All memories are added to both episodic and semantic memory types.

async search(
query: str,
top_k: int = 5,
\*\*kwargs,
) list[nat.memory.models.MemoryItem]#

Retrieve items relevant to the given query using the MemMachine SDK.

Args:

query (str): The query string to match. top_k (int): Maximum number of items to return. kwargs: Other keyword arguments for search.

Keyword arguments must include user_id. May also include session_id, agent_id, project_id, org_id.

Returns:

list[MemoryItem]: The most relevant MemoryItems for the given query.

async remove_items(\*\*kwargs) None#

Remove items using the MemMachine SDK.

Args:

kwargs (dict): Keyword arguments to pass to the remove-items method.

Should include either memory_id or user_id. May also include session_id, agent_id, project_id, org_id. For memory_id deletion, may include memory_type (‘episodic’ or ‘semantic’).