MemoryOS 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of MemoryOS might be problematic. Click here for more details.

Files changed (114) hide show
  1. {memoryos-0.2.0.dist-info → memoryos-0.2.2.dist-info}/METADATA +67 -26
  2. memoryos-0.2.2.dist-info/RECORD +169 -0
  3. memoryos-0.2.2.dist-info/entry_points.txt +3 -0
  4. memos/__init__.py +1 -1
  5. memos/api/config.py +562 -0
  6. memos/api/context/context.py +147 -0
  7. memos/api/context/dependencies.py +90 -0
  8. memos/api/exceptions.py +28 -0
  9. memos/api/mcp_serve.py +502 -0
  10. memos/api/product_api.py +35 -0
  11. memos/api/product_models.py +163 -0
  12. memos/api/routers/__init__.py +1 -0
  13. memos/api/routers/product_router.py +386 -0
  14. memos/chunkers/sentence_chunker.py +8 -2
  15. memos/cli.py +113 -0
  16. memos/configs/embedder.py +27 -0
  17. memos/configs/graph_db.py +132 -3
  18. memos/configs/internet_retriever.py +6 -0
  19. memos/configs/llm.py +47 -0
  20. memos/configs/mem_cube.py +1 -1
  21. memos/configs/mem_os.py +5 -0
  22. memos/configs/mem_reader.py +9 -0
  23. memos/configs/mem_scheduler.py +107 -7
  24. memos/configs/mem_user.py +58 -0
  25. memos/configs/memory.py +5 -4
  26. memos/dependency.py +52 -0
  27. memos/embedders/ark.py +92 -0
  28. memos/embedders/factory.py +4 -0
  29. memos/embedders/sentence_transformer.py +8 -2
  30. memos/embedders/universal_api.py +32 -0
  31. memos/graph_dbs/base.py +11 -3
  32. memos/graph_dbs/factory.py +4 -0
  33. memos/graph_dbs/nebular.py +1364 -0
  34. memos/graph_dbs/neo4j.py +333 -124
  35. memos/graph_dbs/neo4j_community.py +300 -0
  36. memos/llms/base.py +9 -0
  37. memos/llms/deepseek.py +54 -0
  38. memos/llms/factory.py +10 -1
  39. memos/llms/hf.py +170 -13
  40. memos/llms/hf_singleton.py +114 -0
  41. memos/llms/ollama.py +4 -0
  42. memos/llms/openai.py +67 -1
  43. memos/llms/qwen.py +63 -0
  44. memos/llms/vllm.py +153 -0
  45. memos/log.py +1 -1
  46. memos/mem_cube/general.py +77 -16
  47. memos/mem_cube/utils.py +109 -0
  48. memos/mem_os/core.py +251 -51
  49. memos/mem_os/main.py +94 -12
  50. memos/mem_os/product.py +1220 -43
  51. memos/mem_os/utils/default_config.py +352 -0
  52. memos/mem_os/utils/format_utils.py +1401 -0
  53. memos/mem_reader/simple_struct.py +18 -10
  54. memos/mem_scheduler/base_scheduler.py +441 -40
  55. memos/mem_scheduler/general_scheduler.py +249 -248
  56. memos/mem_scheduler/modules/base.py +14 -5
  57. memos/mem_scheduler/modules/dispatcher.py +67 -4
  58. memos/mem_scheduler/modules/misc.py +104 -0
  59. memos/mem_scheduler/modules/monitor.py +240 -50
  60. memos/mem_scheduler/modules/rabbitmq_service.py +319 -0
  61. memos/mem_scheduler/modules/redis_service.py +32 -22
  62. memos/mem_scheduler/modules/retriever.py +167 -23
  63. memos/mem_scheduler/modules/scheduler_logger.py +255 -0
  64. memos/mem_scheduler/mos_for_test_scheduler.py +140 -0
  65. memos/mem_scheduler/schemas/__init__.py +0 -0
  66. memos/mem_scheduler/schemas/general_schemas.py +43 -0
  67. memos/mem_scheduler/{modules/schemas.py → schemas/message_schemas.py} +63 -61
  68. memos/mem_scheduler/schemas/monitor_schemas.py +329 -0
  69. memos/mem_scheduler/utils/__init__.py +0 -0
  70. memos/mem_scheduler/utils/filter_utils.py +176 -0
  71. memos/mem_scheduler/utils/misc_utils.py +61 -0
  72. memos/mem_user/factory.py +94 -0
  73. memos/mem_user/mysql_persistent_user_manager.py +271 -0
  74. memos/mem_user/mysql_user_manager.py +500 -0
  75. memos/mem_user/persistent_factory.py +96 -0
  76. memos/mem_user/persistent_user_manager.py +260 -0
  77. memos/mem_user/user_manager.py +4 -4
  78. memos/memories/activation/item.py +29 -0
  79. memos/memories/activation/kv.py +10 -3
  80. memos/memories/activation/vllmkv.py +219 -0
  81. memos/memories/factory.py +2 -0
  82. memos/memories/textual/base.py +1 -1
  83. memos/memories/textual/general.py +43 -97
  84. memos/memories/textual/item.py +5 -33
  85. memos/memories/textual/tree.py +22 -12
  86. memos/memories/textual/tree_text_memory/organize/conflict.py +9 -5
  87. memos/memories/textual/tree_text_memory/organize/manager.py +26 -18
  88. memos/memories/textual/tree_text_memory/organize/redundancy.py +25 -44
  89. memos/memories/textual/tree_text_memory/organize/relation_reason_detector.py +50 -48
  90. memos/memories/textual/tree_text_memory/organize/reorganizer.py +81 -56
  91. memos/memories/textual/tree_text_memory/retrieve/internet_retriever.py +6 -3
  92. memos/memories/textual/tree_text_memory/retrieve/internet_retriever_factory.py +2 -0
  93. memos/memories/textual/tree_text_memory/retrieve/recall.py +0 -1
  94. memos/memories/textual/tree_text_memory/retrieve/reranker.py +2 -2
  95. memos/memories/textual/tree_text_memory/retrieve/retrieval_mid_structs.py +2 -0
  96. memos/memories/textual/tree_text_memory/retrieve/searcher.py +52 -28
  97. memos/memories/textual/tree_text_memory/retrieve/task_goal_parser.py +42 -15
  98. memos/memories/textual/tree_text_memory/retrieve/utils.py +11 -7
  99. memos/memories/textual/tree_text_memory/retrieve/xinyusearch.py +62 -58
  100. memos/memos_tools/dinding_report_bot.py +422 -0
  101. memos/memos_tools/notification_service.py +44 -0
  102. memos/memos_tools/notification_utils.py +96 -0
  103. memos/parsers/markitdown.py +8 -2
  104. memos/settings.py +3 -1
  105. memos/templates/mem_reader_prompts.py +66 -23
  106. memos/templates/mem_scheduler_prompts.py +126 -43
  107. memos/templates/mos_prompts.py +87 -0
  108. memos/templates/tree_reorganize_prompts.py +85 -30
  109. memos/vec_dbs/base.py +12 -0
  110. memos/vec_dbs/qdrant.py +46 -20
  111. memoryos-0.2.0.dist-info/RECORD +0 -128
  112. memos/mem_scheduler/utils.py +0 -26
  113. {memoryos-0.2.0.dist-info → memoryos-0.2.2.dist-info}/LICENSE +0 -0
  114. {memoryos-0.2.0.dist-info → memoryos-0.2.2.dist-info}/WHEEL +0 -0
@@ -1,7 +1,5 @@
1
1
  SIMPLE_STRUCT_MEM_READER_PROMPT = """You are a memory extraction expert.
2
-
3
2
  Your task is to extract memories from the perspective of user, based on a conversation between user and assistant. This means identifying what user would plausibly remember — including their own experiences, thoughts, plans, or relevant statements and actions made by others (such as assistant) that impacted or were acknowledged by user.
4
-
5
3
  Please perform:
6
4
  1. Identify information that reflects user's experiences, beliefs, concerns, decisions, plans, or reactions — including meaningful input from assistant that user acknowledged or responded to.
7
5
  2. Resolve all time, person, and event references clearly:
@@ -18,6 +16,7 @@ For example, write "The user felt exhausted..." instead of "I felt exhausted..."
18
16
  - Include all key experiences, thoughts, emotional responses, and plans — even if they seem minor.
19
17
  - Prioritize completeness and fidelity over conciseness.
20
18
  - Do not generalize or skip details that could be personally meaningful to user.
19
+ 5. Please avoid any content that violates national laws and regulations or involves politically sensitive information in the memories you extract.
21
20
 
22
21
  Return a single valid JSON object with the following structure:
23
22
 
@@ -35,7 +34,7 @@ Return a single valid JSON object with the following structure:
35
34
  }
36
35
 
37
36
  Language rules:
38
- - The `key`, `value`, `tags`, `summary` fields must match the language of the input conversation.
37
+ - The `key`, `value`, `tags`, `summary` fields must match the mostly used language of the input conversation. **如果输入是中文,请输出中文**
39
38
  - Keep `memory_type` in English.
40
39
 
41
40
  Example:
@@ -66,33 +65,63 @@ Output:
66
65
  "summary": "Tom is currently focused on managing a new project with a tight schedule. After a team meeting on June 25, 2025, he realized the original deadline of December 15 might not be feasible due to backend delays. Concerned about insufficient testing time, he welcomed Jerry’s suggestion of proposing an extension. Tom plans to raise the idea of shifting the deadline to January 5, 2026 in the next morning’s meeting. His actions reflect both stress about timelines and a proactive, team-oriented problem-solving approach."
67
66
  }
68
67
 
68
+ Another Example in Chinese (注意: 当user的语言为中文时,你就需要也输出中文):
69
+ {
70
+ "memory list": [
71
+ {
72
+ "key": "项目会议",
73
+ "memory_type": "LongTermMemory",
74
+ "value": "在2025年6月25日下午3点,Tom与团队开会讨论了新项目,涉及时间表,并提出了对12月15日截止日期可行性的担忧。",
75
+ "tags": ["项目", "时间表", "会议", "截止日期"]
76
+ },
77
+ ...
78
+ ],
79
+ "summary": "Tom 目前专注于管理一个进度紧张的新项目..."
80
+ }
81
+
82
+ Always respond in the same language as the conversation.
83
+
69
84
  Conversation:
70
85
  ${conversation}
71
86
 
72
87
  Your Output:"""
73
88
 
74
- SIMPLE_STRUCT_DOC_READER_PROMPT = """
75
- You are an expert text analyst for a search and retrieval system. Your task is to process a document chunk and generate a single, structured JSON object.
76
- The input is a single piece of text: `[DOCUMENT_CHUNK]`.
77
- You must generate a single JSON object with two top-level keys: `summary` and `tags`.
78
- 1. `summary`:
79
- - A dense, searchable summary of the ENTIRE `[DOCUMENT_CHUNK]`.
80
- - The purpose is for semantic search embedding.
81
- - A clear and accurate sentence that comprehensively summarizes the main points, arguments, and information within the `[DOCUMENT_CHUNK]`.
82
- - The goal is to create a standalone overview that allows a reader to fully understand the essence of the chunk without reading the original text.
83
- - The summary should be **no more than 50 words**.
84
- 2. `tags`:
85
- - A concise list of **3 to 5 high-level, summative tags**.
86
- - **Each tag itself should be a short phrase, ideally 2 to 4 words long.**
87
- - These tags must represent the core abstract themes of the text, suitable for broad categorization.
88
- - **Crucially, prioritize abstract concepts** over specific entities or phrases mentioned in the text. For example, prefer "Supply Chain Resilience" over "Reshoring Strategies".
89
-
90
- Here is the document chunk to process:
91
- `[DOCUMENT_CHUNK]`
89
+ SIMPLE_STRUCT_DOC_READER_PROMPT = """You are an expert text analyst for a search and retrieval system.
90
+ Your task is to process a document chunk and generate a single, structured JSON object.
91
+
92
+ Please perform:
93
+ 1. Identify key information that reflects factual content, insights, decisions, or implications from the documents — including any notable themes, conclusions, or data points. Allow a reader to fully understand the essence of the chunk without reading the original text.
94
+ 2. Resolve all time, person, location, and event references clearly:
95
+ - Convert relative time expressions (e.g., “last year,” “next quarter”) into absolute dates if context allows.
96
+ - Clearly distinguish between event time and document time.
97
+ - If uncertainty exists, state it explicitly (e.g., “around 2024,” “exact date unclear”).
98
+ - Include specific locations if mentioned.
99
+ - Resolve all pronouns, aliases, and ambiguous references into full names or identities.
100
+ - Disambiguate entities with the same name if applicable.
101
+ 3. Always write from a third-person perspective, referring to the subject or content clearly rather than using first-person ("I", "me", "my").
102
+ 4. Do not omit any information that is likely to be important or memorable from the document summaries.
103
+ - Include all key facts, insights, emotional tones, and plans even if they seem minor.
104
+ - Prioritize completeness and fidelity over conciseness.
105
+ - Do not generalize or skip details that could be contextually meaningful.
106
+
107
+ Return a single valid JSON object with the following structure:
108
+
109
+ Return valid JSON:
110
+ {
111
+ "key": <string, a concise title of the `value` field>,
112
+ "memory_type": "LongTermMemory",
113
+ "value": <A clear and accurate paragraph that comprehensively summarizes the main points, arguments, and information within the document chunk — written in English if the input memory items are in English, or in Chinese if the input is in Chinese>,
114
+ "tags": <A list of relevant thematic keywords (e.g., ["deadline", "team", "planning"])>
115
+ }
116
+
117
+ Language rules:
118
+ - The `key`, `value`, `tags`, `summary` fields must match the mostly used language of the input document summaries. **如果输入是中文,请输出中文**
119
+ - Keep `memory_type` in English.
120
+
121
+ Document chunk:
92
122
  {chunk_text}
93
123
 
94
- Produce ONLY the JSON object as your response.
95
- """
124
+ Your Output:"""
96
125
 
97
126
  SIMPLE_STRUCT_MEM_READER_EXAMPLE = """Example:
98
127
  Conversation:
@@ -122,4 +151,18 @@ Output:
122
151
  "summary": "Tom is currently focused on managing a new project with a tight schedule. After a team meeting on June 25, 2025, he realized the original deadline of December 15 might not be feasible due to backend delays. Concerned about insufficient testing time, he welcomed Jerry’s suggestion of proposing an extension. Tom plans to raise the idea of shifting the deadline to January 5, 2026 in the next morning’s meeting. His actions reflect both stress about timelines and a proactive, team-oriented problem-solving approach."
123
152
  }
124
153
 
154
+ Another Example in Chinese (注意: 当user的语言为中文时,你就需要也输出中文):
155
+ {
156
+ "memory list": [
157
+ {
158
+ "key": "项目会议",
159
+ "memory_type": "LongTermMemory",
160
+ "value": "在2025年6月25日下午3点,Tom与团队开会讨论了新项目,涉及时间表,并提出了对12月15日截止日期可行性的担忧。",
161
+ "tags": ["项目", "时间表", "会议", "截止日期"]
162
+ },
163
+ ...
164
+ ],
165
+ "summary": "Tom 目前专注于管理一个进度紧张的新项目..."
166
+ }
167
+
125
168
  """
@@ -1,65 +1,148 @@
1
- INTENT_RECOGNIZING_PROMPT = """You are a user intent recognizer, and your task is to determine whether the user's current question has been satisfactorily answered.
2
-
3
- You will receive the following information:
4
-
5
- The user’s current question list (q_list), arranged in chronological order (currently contains only one question);
6
- The memory information currently present in the system’s workspace (working_memory_list), i.e., the currently known contextual clues.
7
- Your tasks are:
8
-
9
- Determine whether the user is satisfied with the existing answer;
10
-
11
- If the user is satisfied, explain the reason and return:
12
-
13
- "trigger_retrieval": false
14
- If the user is not satisfied, meaning the system's answer did not meet their actual needs, please return:
15
-
16
- "trigger_retrieval": true
17
- "missing_evidence": ["Information you infer is missing and needs to be supplemented, such as specific experiences of someone, health records, etc."]
18
- Please return strictly according to the following JSON format:
19
-
1
+ INTENT_RECOGNIZING_PROMPT = """
2
+ # User Intent Recognition Task
3
+
4
+ ## Role
5
+ You are an advanced intent analysis system that evaluates answer satisfaction and identifies information gaps.
6
+
7
+ ## Input Analysis
8
+ You will receive:
9
+ 1. User's question list (chronological order)
10
+ 2. Current system knowledge (working memory)
11
+
12
+ ## Evaluation Criteria
13
+ Consider these satisfaction factors:
14
+ 1. Answer completeness (covers all aspects of the question)
15
+ 2. Evidence relevance (directly supports the answer)
16
+ 3. Detail specificity (contains necessary granularity)
17
+ 4. Personalization (tailored to user's context)
18
+
19
+ ## Decision Framework
20
+ 1. Mark as satisfied ONLY if:
21
+ - All question aspects are addressed
22
+ - Supporting evidence exists in working memory
23
+ - No apparent gaps in information
24
+
25
+ 2. Mark as unsatisfied if:
26
+ - Any question aspect remains unanswered
27
+ - Evidence is generic/non-specific
28
+ - Personal context is missing
29
+
30
+ ## Output Specification
31
+ Return JSON with:
32
+ - "trigger_retrieval": Boolean (true if more evidence needed)
33
+ - "missing_evidences": List of specific evidence types required
34
+
35
+ ## Response Format
20
36
  {{
21
- "trigger_retrieval": true or false,
22
- "missing_evidence": ["The missing evidence needed for the next step of retrieval and completion"]
37
+ "trigger_retrieval": <boolean>,
38
+ "missing_evidences": [
39
+ "<evidence_type_1>",
40
+ "<evidence_type_2>"
41
+ ]
23
42
  }}
24
- The user's question list is:
43
+
44
+ ## Evidence Type Examples
45
+ - Personal medical history
46
+ - Recent activity logs
47
+ - Specific measurement data
48
+ - Contextual details about [topic]
49
+ - Temporal information (when something occurred)
50
+
51
+ ## Current Task
52
+ User Questions:
25
53
  {q_list}
26
54
 
27
- The memory information currently present in the system’s workspace is:
55
+ Working Memory Contents:
28
56
  {working_memory_list}
29
- """
30
57
 
31
- MEMORY_RERANKEING_PROMPT = """You are a memory sorter. Your task is to reorder the evidence according to the user's question, placing the evidence that best supports the user's query as close to the front as possible.
32
-
33
- Please return the newly reordered memory sequence according to the query in the following format, which must be in JSON:
58
+ ## Required Output
59
+ Please provide your analysis in the specified JSON format:
60
+ """
34
61
 
62
+ MEMORY_RERANKING_PROMPT = """
63
+ # Memory Reranking Task
64
+
65
+ ## Role
66
+ You are an intelligent memory reorganization system. Your primary function is to analyze and optimize the ordering of memory evidence based on relevance to recent user queries.
67
+
68
+ ## Task Description
69
+ Reorganize the provided memory evidence list by:
70
+ 1. Analyzing the semantic relationship between each evidence item and the user's queries
71
+ 2. Calculating relevance scores
72
+ 3. Sorting evidence in descending order of relevance
73
+ 4. Maintaining all original items (no additions or deletions)
74
+
75
+ ## Temporal Priority Rules
76
+ - Query recency matters: Index 0 is the MOST RECENT query
77
+ - Evidence matching recent queries gets higher priority
78
+ - For equal relevance scores: Favor items matching newer queries
79
+
80
+ ## Input Format
81
+ - Queries: Recent user questions/requests (list)
82
+ - Current Order: Existing memory sequence (list of strings with indices)
83
+
84
+ ## Output Requirements
85
+ Return a JSON object with:
86
+ - "new_order": The reordered indices (array of integers)
87
+ - "reasoning": Brief explanation of your ranking logic (1-2 sentences)
88
+
89
+ ## Processing Guidelines
90
+ 1. Prioritize evidence that:
91
+ - Directly answers query questions
92
+ - Contains exact keyword matches
93
+ - Provides contextual support
94
+ - Shows temporal relevance (newer > older)
95
+ 2. For ambiguous cases, maintain original relative ordering
96
+
97
+ ## Scoring Priorities (Descending Order)
98
+ 1. Direct matches to newer queries
99
+ 2. Exact keyword matches in recent queries
100
+ 3. Contextual support for recent topics
101
+ 4. General relevance to older queries
102
+
103
+ ## Example
104
+ Input queries: ["[0] python threading", "[1] data visualization"]
105
+ Input order: ["[0] syntax", "[1] matplotlib", "[2] threading"]
106
+
107
+ Output:
35
108
  {{
36
- "new_order": [...]
109
+ "new_order": [2, 1, 0],
110
+ "reasoning": "Threading (2) prioritized for matching newest query, followed by matplotlib (1) for older visualization query",
37
111
  }}
38
- Now the user's question is:
39
- {query}
40
112
 
41
- The current order is:
42
- {current_order}"""
113
+ ## Current Task
114
+ Queries: {queries} (recency-ordered)
115
+ Current order: {current_order}
43
116
 
44
- FREQ_DETECTING_PROMPT = """You are a memory frequency monitor. Your task is to check which memories in the activation memory list appear in the given answer, and increment their count by 1 for each occurrence.
117
+ Please provide your reorganization:
118
+ """
119
+
120
+ QUERY_KEYWORDS_EXTRACTION_PROMPT = """
121
+ ## Role
122
+ You are an intelligent keyword extraction system. Your task is to identify and extract the most important words or short phrases from user queries.
45
123
 
46
- Please return strictly according to the following JSON format:
124
+ ## Instructions
125
+ - They have to be single words or short phrases that make sense.
126
+ - Only nouns (naming words) or verbs (action words) are allowed.
127
+ - Don't include stop words (like "the", "is") or adverbs (words that describe verbs, like "quickly").
128
+ - Keep them as the smallest possible units that still have meaning.
47
129
 
48
- [
49
- {{"memory": ..., "count": ...}}, {{"memory": ..., "count": ...}}, ...
50
- ]
130
+ ## Example
131
+ - Input Query: "What breed is Max?"
132
+ - Output Keywords (list of string): ["breed", "Max"]
51
133
 
52
- The answer is:
53
- {answer}
134
+ ## Current Task
135
+ - Query: {query}
136
+ - Output Format: A Json list of keywords.
54
137
 
55
- The activation memory list is:
56
- {activation_memory_freq_list}
138
+ Answer:
57
139
  """
58
140
 
141
+
59
142
  PROMPT_MAPPING = {
60
143
  "intent_recognizing": INTENT_RECOGNIZING_PROMPT,
61
- "memory_reranking": MEMORY_RERANKEING_PROMPT,
62
- "freq_detecting": FREQ_DETECTING_PROMPT,
144
+ "memory_reranking": MEMORY_RERANKING_PROMPT,
145
+ "query_keywords_extraction": QUERY_KEYWORDS_EXTRACTION_PROMPT,
63
146
  }
64
147
 
65
148
  MEMORY_ASSEMBLY_TEMPLATE = """The retrieved memories are listed as follows:\n\n {memory_text}"""
@@ -61,3 +61,90 @@ Please synthesize these answers into a comprehensive response that:
61
61
  3. Provides clear reasoning and connections
62
62
  4. Is well-structured and easy to understand
63
63
  5. Maintains a natural conversational tone"""
64
+
65
+ MEMOS_PRODUCT_BASE_PROMPT = (
66
+ "You are a knowledgeable and helpful AI assistant with access to user memories. "
67
+ "When responding to user queries, you should reference relevant memories using the provided memory IDs. "
68
+ "Use the reference format: [1-n:memoriesID] "
69
+ "where refid is a sequential number starting from 1 and increments for each reference in your response, "
70
+ "and memoriesID is the specific memory ID provided in the available memories list. "
71
+ "For example: [1:abc123], [2:def456], [3:ghi789], [4:jkl101], [5:mno112] "
72
+ "Do not use connect format like [1:abc123,2:def456]"
73
+ "Only reference memories that are directly relevant to the user's question. "
74
+ "Make your responses natural and conversational while incorporating memory references when appropriate."
75
+ )
76
+
77
+ MEMOS_PRODUCT_ENHANCE_PROMPT = """
78
+ # Memory-Enhanced AI Assistant Prompt
79
+
80
+ You are a knowledgeable and helpful AI assistant with access to two types of memory sources:
81
+
82
+ ## Memory Types
83
+ - **PersonalMemory**: User-specific memories and information stored from previous interactions
84
+ - **OuterMemory**: External information retrieved from the internet and other sources
85
+
86
+ ## Memory Reference Guidelines
87
+
88
+ ### Reference Format
89
+ When citing memories in your responses, use the following format:
90
+ - `[refid:memoriesID]` where:
91
+ - `refid` is a sequential number starting from 1 and incrementing for each reference
92
+ - `memoriesID` is the specific memory ID from the available memories list
93
+
94
+ ### Reference Examples
95
+ - Correct: `[1:abc123]`, `[2:def456]`, `[3:ghi789]`, `[4:jkl101]`, `[5:mno112]`
96
+ - Incorrect: `[1:abc123,2:def456]` (do not use connected format)
97
+
98
+ ## Response Guidelines
99
+
100
+ ### Memory Selection
101
+ - Intelligently choose which memories (PersonalMemory or OuterMemory) are most relevant to the user's query
102
+ - Only reference memories that are directly relevant to the user's question
103
+ - Prioritize the most appropriate memory type based on the context and nature of the query
104
+
105
+ ### Response Style
106
+ - Make your responses natural and conversational
107
+ - Seamlessly incorporate memory references when appropriate
108
+ - Ensure the flow of conversation remains smooth despite memory citations
109
+ - Balance factual accuracy with engaging dialogue
110
+
111
+ ## Key Principles
112
+ - Reference only relevant memories to avoid information overload
113
+ - Maintain conversational tone while being informative
114
+ - Use memory references to enhance, not disrupt, the user experience
115
+ """
116
+ QUERY_REWRITING_PROMPT = """
117
+ I'm in discussion with my friend about a question, and we have already talked about something before that. Please help me analyze the logic between the question and the former dialogue, and rewrite the question we are discussing about.
118
+
119
+ Requirements:
120
+ 1. First, determine whether the question is related to the former dialogue. If so, set "former_dialogue_related" to True.
121
+ 2. If "former_dialogue_related" is set to True, meaning the question is related to the former dialogue, rewrite the question according to the keyword in the dialogue and put it in the "rewritten_question" item. If "former_dialogue_related" is set to False, set "rewritten_question" to an empty string.
122
+ 3. If you decided to rewrite the question, keep in mind that the rewritten question needs to be concise and accurate.
123
+ 4. You must return ONLY a valid JSON object. Do not include any other text, explanations, or formatting.
124
+
125
+ Here are some examples:
126
+
127
+ Former dialogue:
128
+ ————How's the weather in ShangHai today?
129
+ ————It's great. The weather in Shanghai is sunny right now. The lowest temperature is 27℃, the highest temperature can reach 33℃, the air quality is excellent, the pm2.5 index is 13, the humidity is 60%, and the northerly wind is at level 1.
130
+ Current question: What should I wear today?
131
+ Answer: {{"former_dialogue_related": True, "rewritten_question": "Considering the weather in Shanghai today, what should I wear?"}}
132
+
133
+ Former dialogue:
134
+ ————I need a brief introduction to Oxford-Cambridge boat race.
135
+ ————The race originated from a challenge in 1829 between Charles Merivale of Cambridge University and Charles Wordsworth of Oxford University. Oxford won the first race. The event became an annual tradition in 1856, with interruptions only during the World Wars and the 2020 COVID-19 pandemic. The women's race was added in 1927. The team members are full-time students of the two universities, including both novice rowers and experienced athletes such as Olympic champions and world champions.
136
+ ————What is the international community's attitude towards the 2024 US election?
137
+ ————The international community approached the 2024 U.S. election with a blend of pragmatism, anxiety, and strategic recalibration. Allies sought to mitigate risks from Trump's policies while maintaining cooperation, while adversaries like China and Russia capitalized on perceived U.S. decline to advance their agendas. Developing nations increasingly resisted U.S. dominance, advocating for a multipolar world. Ultimately, the election underscored the need for global actors to adapt to a more fragmented and unpredictable international order shaped by U.S. domestic politics.
138
+ Current question: In March 2025, after a magnitude 7.9 earthquake struck Myanmar, what assistance did the Chinese government provide?
139
+ Answer: {{"former_dialogue_related": False, "rewritten_question": ""}}
140
+
141
+ Former dialogue:
142
+ ————I am an entry-level learner of large language models. Please recommend me three papers suitable for reading.
143
+ ————For an entry-level learner of large language models (LLMs), here are three foundational papers that provide essential insights into the core concepts, architectures, and advancements in the field: "Attention Is All You Need", "Improving Language Understanding by Generative Pre-Training (GPT-1)", and "BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding". These papers will equip you with the foundational knowledge needed to explore more advanced topics in LLMs, such as scaling laws, instruction tuning, and multi-modal learning.
144
+ Current question: Of these three papers, which one do you recommend I start reading?
145
+ Answer: {{"former_dialogue_related": True, "rewritten_question": "Among the three papers \"Attention Is All You Need\", \"Improving Language Understanding by Generative Pre-Training (GPT-1)\" and \"BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding\", which one do you recommend I start reading?"}}
146
+
147
+ Former dialogue:
148
+ {dialogue}
149
+ Current question: {query}
150
+ Answer:"""
@@ -2,32 +2,80 @@ REORGANIZE_PROMPT = """You are a memory clustering and summarization expert.
2
2
 
3
3
  Given the following child memory items:
4
4
 
5
- Keys:
6
- {joined_keys}
5
+ {memory_items_text}
6
+
7
+ Please perform:
8
+ 1. Identify information that reflects user's experiences, beliefs, concerns, decisions, plans, or reactions — including meaningful input from assistant that user acknowledged or responded to.
9
+ 2. Resolve all time, person, and event references clearly:
10
+ - Convert relative time expressions (e.g., “yesterday,” “next Friday”) into absolute dates using the message timestamp if possible.
11
+ - Clearly distinguish between event time and message time.
12
+ - If uncertainty exists, state it explicitly (e.g., “around June 2025,” “exact date unclear”).
13
+ - Include specific locations if mentioned.
14
+ - Resolve all pronouns, aliases, and ambiguous references into full names or identities.
15
+ - Disambiguate people with the same name if applicable.
16
+ 3. Always write from a third-person perspective, referring to user as
17
+ "The user" or by name if name mentioned, rather than using first-person ("I", "me", "my").
18
+ For example, write "The user felt exhausted..." instead of "I felt exhausted...".
19
+ 4. Do not omit any information that user is likely to remember.
20
+ - Include all key experiences, thoughts, emotional responses, and plans — even if they seem minor.
21
+ - Prioritize completeness and fidelity over conciseness.
22
+ - Do not generalize or skip details that could be personally meaningful to user.
23
+ 5. Summarize all child memory items into one memory item.
24
+
25
+ Language rules:
26
+ - The `key`, `value`, `tags`, `summary` fields must match the mostly used language of the input memory items. **如果输入是中文,请输出中文**
27
+ - Keep `memory_type` in English.
7
28
 
8
- Values:
9
- {joined_values}
29
+ Return valid JSON:
30
+ {
31
+ "key": <string, a concise title of the `value` field>,
32
+ "memory_type": <string, Either "LongTermMemory" or "UserMemory">,
33
+ "value": <A detailed, self-contained, and unambiguous memory statement, only contain detailed, unaltered information extracted and consolidated from the input `value` fields, do not include summary content — written in English if the input memory items are in English, or in Chinese if the input is in Chinese>,
34
+ "tags": <A list of relevant thematic keywords (e.g., ["deadline", "team", "planning"])>,
35
+ "summary": <a natural paragraph summarizing the above memories from user's perspective, only contain information from the input `summary` fields, 120–200 words, same language as the input>
36
+ }
10
37
 
11
- Backgrounds:
12
- {joined_backgrounds}
38
+ """
13
39
 
14
- Your task:
15
- - Generate a single clear English `key` (5–10 words max).
16
- - Write a detailed `value` that merges the key points into a single, complete, well-structured text. This must stand alone and convey what the user should remember.
17
- - Provide a list of 5–10 relevant English `tags`.
18
- - Write a short `background` note (50–100 words) covering any extra context, sources, or traceability info.
40
+ DOC_REORGANIZE_PROMPT = """You are a document summarization and knowledge extraction expert.
41
+
42
+ Given the following summarized document items:
43
+
44
+ {memory_items_text}
45
+
46
+ Please perform:
47
+ 1. Identify key information that reflects factual content, insights, decisions, or implications from the documents — including any notable themes, conclusions, or data points.
48
+ 2. Resolve all time, person, location, and event references clearly:
49
+ - Convert relative time expressions (e.g., “last year,” “next quarter”) into absolute dates if context allows.
50
+ - Clearly distinguish between event time and document time.
51
+ - If uncertainty exists, state it explicitly (e.g., “around 2024,” “exact date unclear”).
52
+ - Include specific locations if mentioned.
53
+ - Resolve all pronouns, aliases, and ambiguous references into full names or identities.
54
+ - Disambiguate entities with the same name if applicable.
55
+ 3. Always write from a third-person perspective, referring to the subject or content clearly rather than using first-person ("I", "me", "my").
56
+ 4. Do not omit any information that is likely to be important or memorable from the document summaries.
57
+ - Include all key facts, insights, emotional tones, and plans — even if they seem minor.
58
+ - Prioritize completeness and fidelity over conciseness.
59
+ - Do not generalize or skip details that could be contextually meaningful.
60
+ 5. Summarize all document summaries into one integrated memory item.
61
+
62
+ Language rules:
63
+ - The `key`, `value`, `tags`, `summary` fields must match the mostly used language of the input document summaries. **如果输入是中文,请输出中文**
64
+ - Keep `memory_type` in English.
19
65
 
20
66
  Return valid JSON:
21
- {{
22
- "key": "<concise topic>",
23
- "value": "<full memory text>",
24
- "tags": ["tag1", "tag2", ...],
25
- "background": "<extra context>"
26
- }}
67
+ {
68
+ "key": <string, a concise title of the `value` field>,
69
+ "memory_type": "LongTermMemory",
70
+ "value": <A detailed, self-contained, and unambiguous memory statement, only contain detailed, unaltered information extracted and consolidated from the input `value` fields, do not include summary content — written in English if the input memory items are in English, or in Chinese if the input is in Chinese>,
71
+ "tags": <A list of relevant thematic keywords (e.g., ["deadline", "team", "planning"])>,
72
+ "summary": <a natural paragraph summarizing the above memories from user's perspective, only contain information from the input `summary` fields, 120–200 words, same language as the input>
73
+ }
74
+
27
75
  """
28
76
 
29
- LOCAL_SUBCLUSTER_PROMPT = """
30
- You are a memory organization expert.
77
+
78
+ LOCAL_SUBCLUSTER_PROMPT = """You are a memory organization expert.
31
79
 
32
80
  You are given a cluster of memory items, each with an ID and content.
33
81
  Your task is to divide these into smaller, semantically meaningful sub-clusters.
@@ -36,21 +84,25 @@ Instructions:
36
84
  - Identify natural topics by analyzing common time, place, people, and event elements.
37
85
  - Each sub-cluster must reflect a coherent theme that helps retrieval.
38
86
  - Each sub-cluster should have 2–10 items. Discard singletons.
39
- - Each item ID must appear in exactly one sub-cluster.
87
+ - Each item ID must appear in exactly one sub-cluster or be discarded. No duplicates are allowed.
88
+ - All IDs in the output must be from the provided Memory items.
40
89
  - Return strictly valid JSON only.
41
90
 
42
91
  Example: If you have items about a project across multiple phases, group them by milestone, team, or event.
43
92
 
93
+ Language rules:
94
+ - The `key` fields must match the mostly used language of the clustered memories. **如果输入是中文,请输出中文**
95
+
44
96
  Return valid JSON:
45
- {{
97
+ {
46
98
  "clusters": [
47
- {{
48
- "ids": ["id1", "id2", ...],
49
- "theme": "<short label>"
50
- }},
99
+ {
100
+ "ids": ["<id1>", "<id2>", ...],
101
+ "key": "<string, a unique, concise memory title>"
102
+ },
51
103
  ...
52
104
  ]
53
- }}
105
+ }
54
106
 
55
107
  Memory items:
56
108
  {joined_scene}
@@ -70,7 +122,7 @@ Your task:
70
122
  Valid options:
71
123
  - CAUSE: One clearly leads to the other.
72
124
  - CONDITION: One happens only if the other condition holds.
73
- - RELATE_TO: They are semantically related by shared people, time, place, or event, but neither causes the other.
125
+ - RELATE: They are semantically related by shared people, time, place, or event, but neither causes the other.
74
126
  - CONFLICT: They logically contradict each other.
75
127
  - NONE: No clear useful connection.
76
128
 
@@ -84,7 +136,7 @@ Another Example:
84
136
  - Node 2: "The venue was booked for a wedding in August."
85
137
  Answer: CONFLICT
86
138
 
87
- Always respond with ONE word: [CAUSE | CONDITION | RELATE_TO | CONFLICT | NONE]
139
+ Always respond with ONE word, no matter what language is for the input nodes: [CAUSE | CONDITION | RELATE | CONFLICT | NONE]
88
140
  """
89
141
 
90
142
  INFER_FACT_PROMPT = """
@@ -125,13 +177,16 @@ Input Memories:
125
177
  - "Mary organized the 2023 sustainability summit in Berlin."
126
178
  - "Mary presented a keynote on renewable energy at the same summit."
127
179
 
180
+ Language rules:
181
+ - The `key`, `value`, `tags`, `background` fields must match the language of the input.
182
+
128
183
  Good Aggregate:
129
- {{
184
+ {
130
185
  "key": "Mary's Sustainability Summit Role",
131
186
  "value": "Mary organized and spoke at the 2023 sustainability summit in Berlin, highlighting renewable energy initiatives.",
132
187
  "tags": ["Mary", "summit", "Berlin", "2023"],
133
188
  "background": "Combined from multiple memories about Mary's activities at the summit."
134
- }}
189
+ }
135
190
 
136
191
  If you find NO useful higher-level concept, reply exactly: "None".
137
192
  """
memos/vec_dbs/base.py CHANGED
@@ -55,6 +55,10 @@ class BaseVecDB(ABC):
55
55
  def get_by_id(self, id: str) -> VecDBItem | None:
56
56
  """Get an item from the vector database."""
57
57
 
58
+ @abstractmethod
59
+ def get_by_ids(self, ids: list[str]) -> list[VecDBItem]:
60
+ """Get multiple items by their IDs."""
61
+
58
62
  @abstractmethod
59
63
  def get_by_filter(self, filter: dict[str, Any]) -> list[VecDBItem]:
60
64
  """
@@ -103,3 +107,11 @@ class BaseVecDB(ABC):
103
107
  @abstractmethod
104
108
  def delete(self, ids: list[str]) -> None:
105
109
  """Delete items from the vector database."""
110
+
111
+ @abstractmethod
112
+ def ensure_payload_indexes(self, fields: list[str]) -> None:
113
+ """
114
+ Create payload indexes for specified fields in the collection.
115
+ Args:
116
+ fields (list[str]): List of field names to index (as keyword).
117
+ """