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

Method _read_memory

src/memos/mem_reader/simple_struct.py:659–747  ·  view source on GitHub ↗

1. raw file: [ [ {"type": "file", "file": "str"} ], [ {"type": "file", "file": "str"} ],... ] 2. text chat: scene_data = [ [ {role: user, ...}, {role: assistant, ...},

(
        self,
        messages: list[MessagesType],
        type: str,
        info: dict[str, Any],
        mode: str = "fine",
        **kwargs,
    )

Source from the content-addressed store, hash-verified

657 return memory_list
658
659 def _read_memory(
660 self,
661 messages: list[MessagesType],
662 type: str,
663 info: dict[str, Any],
664 mode: str = "fine",
665 **kwargs,
666 ) -> list[list[TextualMemoryItem]]:
667 """
668 1. raw file:
669 [
670 [
671 {"type": "file", "file": "str"}
672 ],
673 [
674 {"type": "file", "file": "str"}
675 ],...
676 ]
677 2. text chat:
678 scene_data = [
679 [ {role: user, ...}, {role: assistant, ...}, ... ],
680 [ {role: user, ...}, {role: assistant, ...}, ... ],
681 [ ... ]
682 ]
683 """
684 list_scene_data_info = self.get_scene_data_info(messages, type)
685
686 memory_list = []
687 if type == "chat":
688 processing_func = self._process_chat_data
689 elif type == "doc":
690 processing_func = self._process_doc_data
691 else:
692 processing_func = self._process_doc_data
693
694 # Process Q&A pairs concurrently with context propagation
695 with ContextThreadPoolExecutor() as executor:
696 futures = [
697 executor.submit(processing_func, scene_data_info, info, mode=mode)
698 for scene_data_info in list_scene_data_info
699 ]
700 for future in concurrent.futures.as_completed(futures):
701 try:
702 res_memory = future.result()
703 if res_memory is not None:
704 memory_list.append(res_memory)
705 except Exception as e:
706 logger.error(f"Task failed with exception: {e}")
707 logger.error(traceback.format_exc())
708
709 if os.getenv("SIMPLE_STRUCT_ADD_FILTER", "false") == "true":
710 # Build inputs
711 combined_messages = []
712 for group_messages in messages:
713 combined_messages.extend(group_messages)
714
715 for group_id in range(len(memory_list)):
716 try:

Callers 1

get_memoryMethod · 0.95

Calls 6

get_scene_data_infoMethod · 0.95
submitMethod · 0.80
errorMethod · 0.65
infoMethod · 0.65

Tested by

no test coverage detected