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

Method get

src/memos/mem_os/core.py:925–957  ·  view source on GitHub ↗

Get a textual memory from a MemCube. Args: mem_cube_id (str): The identifier of the MemCube to get the memory from. memory_id (str): The identifier of the memory to get. user_id (str, optional): The identifier of the user to get the memory from.

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

Source from the content-addressed store, hash-verified

923 logger.info(f"Add memory to {mem_cube_id} successfully")
924
925 def get(
926 self, mem_cube_id: str, memory_id: str, user_id: str | None = None
927 ) -> TextualMemoryItem | ActivationMemoryItem | ParametricMemoryItem:
928 """
929 Get a textual memory from a MemCube.
930
931 Args:
932 mem_cube_id (str): The identifier of the MemCube to get the memory from.
933 memory_id (str): The identifier of the memory to get.
934 user_id (str, optional): The identifier of the user to get the memory from.
935 If None, the default user is used.
936
937 Returns:
938 Union[TextualMemoryItem, ActivationMemoryItem, ParametricMemoryItem]: The requested memory item.
939 """
940 target_user_id = user_id if user_id is not None else self.user_id
941 # Validate user has access to this cube
942 self._validate_cube_access(target_user_id, mem_cube_id)
943 if mem_cube_id is None:
944 # Try to find a default cube for the user
945 accessible_cubes = self.user_manager.get_user_cubes(target_user_id)
946 if not accessible_cubes:
947 raise ValueError(
948 f"No accessible cubes found for user '{target_user_id}'. Please register a cube first."
949 )
950 mem_cube_id = accessible_cubes[0].cube_id # TODO not only first
951 else:
952 self._validate_cube_access(target_user_id, mem_cube_id)
953
954 assert mem_cube_id in self.mem_cubes, (
955 f"MemCube with ID {mem_cube_id} does not exist. please regiester"
956 )
957 return self.mem_cubes[mem_cube_id].text_mem.get(memory_id)
958
959 def get_all(
960 self, mem_cube_id: str | None = None, user_id: str | None = None

Callers

nothing calls this directly

Calls 3

_validate_cube_accessMethod · 0.95
getMethod · 0.65
get_user_cubesMethod · 0.45

Tested by

no test coverage detected