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.
- {memoryos-0.2.0.dist-info → memoryos-0.2.2.dist-info}/METADATA +67 -26
- memoryos-0.2.2.dist-info/RECORD +169 -0
- memoryos-0.2.2.dist-info/entry_points.txt +3 -0
- memos/__init__.py +1 -1
- memos/api/config.py +562 -0
- memos/api/context/context.py +147 -0
- memos/api/context/dependencies.py +90 -0
- memos/api/exceptions.py +28 -0
- memos/api/mcp_serve.py +502 -0
- memos/api/product_api.py +35 -0
- memos/api/product_models.py +163 -0
- memos/api/routers/__init__.py +1 -0
- memos/api/routers/product_router.py +386 -0
- memos/chunkers/sentence_chunker.py +8 -2
- memos/cli.py +113 -0
- memos/configs/embedder.py +27 -0
- memos/configs/graph_db.py +132 -3
- memos/configs/internet_retriever.py +6 -0
- memos/configs/llm.py +47 -0
- memos/configs/mem_cube.py +1 -1
- memos/configs/mem_os.py +5 -0
- memos/configs/mem_reader.py +9 -0
- memos/configs/mem_scheduler.py +107 -7
- memos/configs/mem_user.py +58 -0
- memos/configs/memory.py +5 -4
- memos/dependency.py +52 -0
- memos/embedders/ark.py +92 -0
- memos/embedders/factory.py +4 -0
- memos/embedders/sentence_transformer.py +8 -2
- memos/embedders/universal_api.py +32 -0
- memos/graph_dbs/base.py +11 -3
- memos/graph_dbs/factory.py +4 -0
- memos/graph_dbs/nebular.py +1364 -0
- memos/graph_dbs/neo4j.py +333 -124
- memos/graph_dbs/neo4j_community.py +300 -0
- memos/llms/base.py +9 -0
- memos/llms/deepseek.py +54 -0
- memos/llms/factory.py +10 -1
- memos/llms/hf.py +170 -13
- memos/llms/hf_singleton.py +114 -0
- memos/llms/ollama.py +4 -0
- memos/llms/openai.py +67 -1
- memos/llms/qwen.py +63 -0
- memos/llms/vllm.py +153 -0
- memos/log.py +1 -1
- memos/mem_cube/general.py +77 -16
- memos/mem_cube/utils.py +109 -0
- memos/mem_os/core.py +251 -51
- memos/mem_os/main.py +94 -12
- memos/mem_os/product.py +1220 -43
- memos/mem_os/utils/default_config.py +352 -0
- memos/mem_os/utils/format_utils.py +1401 -0
- memos/mem_reader/simple_struct.py +18 -10
- memos/mem_scheduler/base_scheduler.py +441 -40
- memos/mem_scheduler/general_scheduler.py +249 -248
- memos/mem_scheduler/modules/base.py +14 -5
- memos/mem_scheduler/modules/dispatcher.py +67 -4
- memos/mem_scheduler/modules/misc.py +104 -0
- memos/mem_scheduler/modules/monitor.py +240 -50
- memos/mem_scheduler/modules/rabbitmq_service.py +319 -0
- memos/mem_scheduler/modules/redis_service.py +32 -22
- memos/mem_scheduler/modules/retriever.py +167 -23
- memos/mem_scheduler/modules/scheduler_logger.py +255 -0
- memos/mem_scheduler/mos_for_test_scheduler.py +140 -0
- memos/mem_scheduler/schemas/__init__.py +0 -0
- memos/mem_scheduler/schemas/general_schemas.py +43 -0
- memos/mem_scheduler/{modules/schemas.py → schemas/message_schemas.py} +63 -61
- memos/mem_scheduler/schemas/monitor_schemas.py +329 -0
- memos/mem_scheduler/utils/__init__.py +0 -0
- memos/mem_scheduler/utils/filter_utils.py +176 -0
- memos/mem_scheduler/utils/misc_utils.py +61 -0
- memos/mem_user/factory.py +94 -0
- memos/mem_user/mysql_persistent_user_manager.py +271 -0
- memos/mem_user/mysql_user_manager.py +500 -0
- memos/mem_user/persistent_factory.py +96 -0
- memos/mem_user/persistent_user_manager.py +260 -0
- memos/mem_user/user_manager.py +4 -4
- memos/memories/activation/item.py +29 -0
- memos/memories/activation/kv.py +10 -3
- memos/memories/activation/vllmkv.py +219 -0
- memos/memories/factory.py +2 -0
- memos/memories/textual/base.py +1 -1
- memos/memories/textual/general.py +43 -97
- memos/memories/textual/item.py +5 -33
- memos/memories/textual/tree.py +22 -12
- memos/memories/textual/tree_text_memory/organize/conflict.py +9 -5
- memos/memories/textual/tree_text_memory/organize/manager.py +26 -18
- memos/memories/textual/tree_text_memory/organize/redundancy.py +25 -44
- memos/memories/textual/tree_text_memory/organize/relation_reason_detector.py +50 -48
- memos/memories/textual/tree_text_memory/organize/reorganizer.py +81 -56
- memos/memories/textual/tree_text_memory/retrieve/internet_retriever.py +6 -3
- memos/memories/textual/tree_text_memory/retrieve/internet_retriever_factory.py +2 -0
- memos/memories/textual/tree_text_memory/retrieve/recall.py +0 -1
- memos/memories/textual/tree_text_memory/retrieve/reranker.py +2 -2
- memos/memories/textual/tree_text_memory/retrieve/retrieval_mid_structs.py +2 -0
- memos/memories/textual/tree_text_memory/retrieve/searcher.py +52 -28
- memos/memories/textual/tree_text_memory/retrieve/task_goal_parser.py +42 -15
- memos/memories/textual/tree_text_memory/retrieve/utils.py +11 -7
- memos/memories/textual/tree_text_memory/retrieve/xinyusearch.py +62 -58
- memos/memos_tools/dinding_report_bot.py +422 -0
- memos/memos_tools/notification_service.py +44 -0
- memos/memos_tools/notification_utils.py +96 -0
- memos/parsers/markitdown.py +8 -2
- memos/settings.py +3 -1
- memos/templates/mem_reader_prompts.py +66 -23
- memos/templates/mem_scheduler_prompts.py +126 -43
- memos/templates/mos_prompts.py +87 -0
- memos/templates/tree_reorganize_prompts.py +85 -30
- memos/vec_dbs/base.py +12 -0
- memos/vec_dbs/qdrant.py +46 -20
- memoryos-0.2.0.dist-info/RECORD +0 -128
- memos/mem_scheduler/utils.py +0 -26
- {memoryos-0.2.0.dist-info → memoryos-0.2.2.dist-info}/LICENSE +0 -0
- {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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
1.
|
|
79
|
-
|
|
80
|
-
-
|
|
81
|
-
-
|
|
82
|
-
-
|
|
83
|
-
-
|
|
84
|
-
|
|
85
|
-
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
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 = """
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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":
|
|
22
|
-
"
|
|
37
|
+
"trigger_retrieval": <boolean>,
|
|
38
|
+
"missing_evidences": [
|
|
39
|
+
"<evidence_type_1>",
|
|
40
|
+
"<evidence_type_2>"
|
|
41
|
+
]
|
|
23
42
|
}}
|
|
24
|
-
|
|
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
|
-
|
|
55
|
+
Working Memory Contents:
|
|
28
56
|
{working_memory_list}
|
|
29
|
-
"""
|
|
30
57
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
42
|
-
{
|
|
113
|
+
## Current Task
|
|
114
|
+
Queries: {queries} (recency-ordered)
|
|
115
|
+
Current order: {current_order}
|
|
43
116
|
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
]
|
|
130
|
+
## Example
|
|
131
|
+
- Input Query: "What breed is Max?"
|
|
132
|
+
- Output Keywords (list of string): ["breed", "Max"]
|
|
51
133
|
|
|
52
|
-
|
|
53
|
-
{
|
|
134
|
+
## Current Task
|
|
135
|
+
- Query: {query}
|
|
136
|
+
- Output Format: A Json list of keywords.
|
|
54
137
|
|
|
55
|
-
|
|
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":
|
|
62
|
-
"
|
|
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}"""
|
memos/templates/mos_prompts.py
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
{
|
|
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
|
-
|
|
12
|
-
{joined_backgrounds}
|
|
38
|
+
"""
|
|
13
39
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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":
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
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
|
-
|
|
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
|
-
"
|
|
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
|
-
-
|
|
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 |
|
|
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
|
+
"""
|