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

Method get_memory

src/memos/mem_reader/simple_struct.py:479–532  ·  view source on GitHub ↗

Extract and classify memory content from scene_data. For dictionaries: Use LLM to summarize pairs of Q&A For file paths: Use chunker to split documents and LLM to summarize each chunk Args: scene_data: List of dialogue information or document paths

(
        self,
        scene_data: SceneDataInput,
        type: str,
        info: dict[str, Any],
        mode: str = "fine",
        user_name: str | None = None,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

477 return chat_read_nodes
478
479 def get_memory(
480 self,
481 scene_data: SceneDataInput,
482 type: str,
483 info: dict[str, Any],
484 mode: str = "fine",
485 user_name: str | None = None,
486 **kwargs,
487 ) -> list[list[TextualMemoryItem]]:
488 """
489 Extract and classify memory content from scene_data.
490 For dictionaries: Use LLM to summarize pairs of Q&A
491 For file paths: Use chunker to split documents and LLM to summarize each chunk
492
493 Args:
494 scene_data: List of dialogue information or document paths
495 type: (Deprecated) not supported in the future. Type of scene_data: ['doc', 'chat']
496 info: Dictionary containing user_id and session_id.
497 Must be in format: {"user_id": "1111", "session_id": "2222"}
498 Optional parameters:
499 - topic_chunk_size: Size for large topic chunks (default: 1024)
500 - topic_chunk_overlap: Overlap for large topic chunks (default: 100)
501 - chunk_size: Size for small chunks (default: 256)
502 - chunk_overlap: Overlap for small chunks (default: 50)
503 mode: mem-reader mode, fast for quick process while fine for
504 better understanding via calling llm
505 user_name: tha user_name would be inserted later into the
506 database, may be used in recall.
507 Returns:
508 list[list[TextualMemoryItem]] containing memory content with summaries as keys and original text as values
509 Raises:
510 ValueError: If scene_data is empty or if info dictionary is missing required fields
511 """
512 if not scene_data:
513 raise ValueError("scene_data is empty")
514
515 # Validate info dictionary format
516 if not isinstance(info, dict):
517 raise ValueError("info must be a dictionary")
518
519 required_fields = {"user_id", "session_id"}
520 missing_fields = required_fields - set(info.keys())
521 if missing_fields:
522 raise ValueError(f"info dictionary is missing required fields: {missing_fields}")
523
524 if not all(isinstance(info[field], str) for field in required_fields):
525 raise ValueError("user_id and session_id must be strings")
526
527 # Backward compatibility, after coercing scene_data, we only tackle
528 # with standard scene_data type: MessagesType
529 standard_scene_data = coerce_scene_data(scene_data, type)
530 return self._read_memory(
531 standard_scene_data, type, info, mode, user_name=user_name, **kwargs
532 )
533
534 def rewrite_memories(
535 self, messages: list[dict], memory_list: list[TextualMemoryItem], user_only: bool = True

Callers 1

run_simple_readerFunction · 0.95

Calls 5

_read_memoryMethod · 0.95
coerce_scene_dataFunction · 0.90
setFunction · 0.85
allFunction · 0.85
keysMethod · 0.45

Tested by

no test coverage detected