Update a textual memory in a MemCube by text_memory_id and text_memory_id. Args: mem_cube_id (str): The identifier of the MemCube to update the memory in. memory_id (str): The identifier of the textual memory to update. text_memory_item (TextualM
(
self,
mem_cube_id: str,
memory_id: str,
text_memory_item: TextualMemoryItem | dict[str, Any],
user_id: str | None = None,
)
| 995 | return result |
| 996 | |
| 997 | def update( |
| 998 | self, |
| 999 | mem_cube_id: str, |
| 1000 | memory_id: str, |
| 1001 | text_memory_item: TextualMemoryItem | dict[str, Any], |
| 1002 | user_id: str | None = None, |
| 1003 | ) -> None: |
| 1004 | """ |
| 1005 | Update a textual memory in a MemCube by text_memory_id and text_memory_id. |
| 1006 | |
| 1007 | Args: |
| 1008 | mem_cube_id (str): The identifier of the MemCube to update the memory in. |
| 1009 | memory_id (str): The identifier of the textual memory to update. |
| 1010 | text_memory_item (TextualMemoryItem | dict[str, Any]): The updated textual memory item. |
| 1011 | """ |
| 1012 | assert mem_cube_id in self.mem_cubes, ( |
| 1013 | f"MemCube with ID {mem_cube_id} does not exist. please regiester" |
| 1014 | ) |
| 1015 | target_user_id = user_id if user_id is not None else self.user_id |
| 1016 | # Validate user has access to this cube |
| 1017 | self._validate_cube_access(target_user_id, mem_cube_id) |
| 1018 | if mem_cube_id is None: |
| 1019 | # Try to find a default cube for the user |
| 1020 | accessible_cubes = self.user_manager.get_user_cubes(target_user_id) |
| 1021 | if not accessible_cubes: |
| 1022 | raise ValueError( |
| 1023 | f"No accessible cubes found for user '{target_user_id}'. Please register a cube first." |
| 1024 | ) |
| 1025 | mem_cube_id = accessible_cubes[0].cube_id # TODO not only first |
| 1026 | else: |
| 1027 | self._validate_cube_access(target_user_id, mem_cube_id) |
| 1028 | if self.mem_cubes[mem_cube_id].config.text_mem.backend != "tree_text": |
| 1029 | self.mem_cubes[mem_cube_id].text_mem.update(memory_id, memories=text_memory_item) |
| 1030 | logger.info(f"MemCube {mem_cube_id} updated memory {memory_id}") |
| 1031 | else: |
| 1032 | logger.warning( |
| 1033 | f" {self.mem_cubes[mem_cube_id].config.text_mem.backend} does not support update memory" |
| 1034 | ) |
| 1035 | |
| 1036 | def delete(self, mem_cube_id: str, memory_id: str, user_id: str | None = None) -> None: |
| 1037 | """ |