Multimodal implementation of MemReader that inherits from SimpleStructMemReader.
| 32 | |
| 33 | |
| 34 | class MultiModalStructMemReader(SimpleStructMemReader): |
| 35 | """Multimodal implementation of MemReader that inherits from |
| 36 | SimpleStructMemReader.""" |
| 37 | |
| 38 | def __init__(self, config: MultiModalStructMemReaderConfig): |
| 39 | """ |
| 40 | Initialize the MultiModalStructMemReader with configuration. |
| 41 | |
| 42 | Args: |
| 43 | config: Configuration object for the reader |
| 44 | """ |
| 45 | from memos.configs.mem_reader import SimpleStructMemReaderConfig |
| 46 | from memos.llms.factory import LLMFactory |
| 47 | |
| 48 | # Extract direct_markdown_hostnames before converting to SimpleStructMemReaderConfig |
| 49 | direct_markdown_hostnames = getattr(config, "direct_markdown_hostnames", None) |
| 50 | |
| 51 | # oss |
| 52 | self.oss_config = getattr(config, "oss_config", None) |
| 53 | |
| 54 | # skills_dir |
| 55 | self.skills_dir_config = getattr(config, "skills_dir_config", None) |
| 56 | |
| 57 | # Create config_dict excluding direct_markdown_hostnames for SimpleStructMemReaderConfig |
| 58 | config_dict = config.model_dump(exclude_none=True) |
| 59 | config_dict.pop("direct_markdown_hostnames", None) |
| 60 | |
| 61 | simple_config = SimpleStructMemReaderConfig(**config_dict) |
| 62 | super().__init__(simple_config) |
| 63 | |
| 64 | self.memory_version_switch = getattr(config, "memory_version_switch", "off") |
| 65 | |
| 66 | # Image parser LLM (requires vision model) |
| 67 | # Falls back to general_llm if not configured (general_llm itself falls back to main llm) |
| 68 | self.image_parser_llm = ( |
| 69 | LLMFactory.from_config(config.image_parser_llm) |
| 70 | if config.image_parser_llm is not None |
| 71 | else self.general_llm |
| 72 | ) |
| 73 | # Initialize MultiModalParser for routing to different parsers |
| 74 | # Pass image_parser_llm for image parsing |
| 75 | self.multi_modal_parser = MultiModalParser( |
| 76 | embedder=self.embedder, |
| 77 | llm=self.llm, |
| 78 | image_parser_llm=self.image_parser_llm, |
| 79 | parser=None, |
| 80 | direct_markdown_hostnames=direct_markdown_hostnames, |
| 81 | ) |
| 82 | |
| 83 | def _embed_memory_items(self, items: list[TextualMemoryItem]) -> None: |
| 84 | """Compute embeddings for a list of memory items in-place. |
| 85 | |
| 86 | Attempts a single batch call first; falls back to per-item calls if the |
| 87 | batch fails. Errors are logged but never raised so callers always |
| 88 | continue normally. |
| 89 | """ |
| 90 | valid = [w for w in items if w and w.memory] |
| 91 | if not valid: |
no outgoing calls
no test coverage detected