MCPcopy Create free account
hub / github.com/MemTensor/MemOS / delete

Method delete

src/memos/mem_os/core.py:1036–1061  ·  view source on GitHub ↗

Delete a textual memory from a MemCube by memory_id. Args: mem_cube_id (str): The identifier of the MemCube to delete the memory from. memory_id (str): The identifier of the memory to delete.

(self, mem_cube_id: str, memory_id: str, user_id: str | None = None)

Source from the content-addressed store, hash-verified

1034 )
1035
1036 def delete(self, mem_cube_id: str, memory_id: str, user_id: str | None = None) -> None:
1037 """
1038 Delete a textual memory from a MemCube by memory_id.
1039
1040 Args:
1041 mem_cube_id (str): The identifier of the MemCube to delete the memory from.
1042 memory_id (str): The identifier of the memory to delete.
1043 """
1044 assert mem_cube_id in self.mem_cubes, (
1045 f"MemCube with ID {mem_cube_id} does not exist. please regiester"
1046 )
1047 target_user_id = user_id if user_id is not None else self.user_id
1048 # Validate user has access to this cube
1049 self._validate_cube_access(target_user_id, mem_cube_id)
1050 if mem_cube_id is None:
1051 # Try to find a default cube for the user
1052 accessible_cubes = self.user_manager.get_user_cubes(target_user_id)
1053 if not accessible_cubes:
1054 raise ValueError(
1055 f"No accessible cubes found for user '{target_user_id}'. Please register a cube first."
1056 )
1057 mem_cube_id = accessible_cubes[0].cube_id # TODO not only first
1058 else:
1059 self._validate_cube_access(target_user_id, mem_cube_id)
1060 self.mem_cubes[mem_cube_id].text_mem.delete(memory_id)
1061 logger.info(f"MemCube {mem_cube_id} deleted memory {memory_id}")
1062
1063 def delete_all(self, mem_cube_id: str | None = None, user_id: str | None = None) -> None:
1064 """

Callers 15

recordSuccessMethod · 0.45
handleMethod · 0.45
isValidSessionMethod · 0.45
handleLogoutMethod · 0.45
recordSuccessMethod · 0.45
handleMethod · 0.45
isValidSessionMethod · 0.45
handleLogoutMethod · 0.45
installSectionObserverFunction · 0.45
finishTransportFunction · 0.45
handleLineFunction · 0.45
serverRequestFunction · 0.45

Calls 3

_validate_cube_accessMethod · 0.95
infoMethod · 0.65
get_user_cubesMethod · 0.45

Tested by 7

removeItemFunction · 0.36
removeItemFunction · 0.36
removeItemFunction · 0.36
test_deleteMethod · 0.36
test_delete_memoriesMethod · 0.36
test_delete_and_get_allFunction · 0.36
test_deleteFunction · 0.36