Skip to content

Commit 8b78d0d

Browse files
authored
Merge pull request #190 from yxlvbubu-prog/patch-62
Update mem_recall.md
2 parents 5bd4f4b + fc9bd37 commit 8b78d0d

File tree

1 file changed

+8
-248
lines changed

1 file changed

+8
-248
lines changed
Lines changed: 8 additions & 248 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
---
2-
title: Memory Recall and Instruction Completion
3-
desc: "In MemOS, memory is not just about archiving information, but also about being dynamically retrieved when needed and transformed into executable input. This process is achieved through two closely connected steps: Memory Recall and Instruction Completion."
2+
title: Memory Recall
3+
desc: "In MemOS, memory is not just about archiving information, but also about being dynamically retrieved when needed and transformed into executable input."
44
---
55

66
## 1. Capability Overview
77

8-
### 1.1 Memory Recall
9-
108
Memory recall is responsible for quickly retrieving the most relevant memory fragments when the user initiates a new request.
119

1210
* **Role**: Ensures that the model does not start “from scratch” when generating responses, but instead integrates the user's history, preferences, and context.
@@ -16,272 +14,34 @@ Memory recall is responsible for quickly retrieving the most relevant memory fra
1614
* Traceable: Each memory is accompanied by its source, timestamp, and confidence level.
1715

1816
* Highly controllable: Developers have full control over which memories enter downstream logic.
19-
20-
21-
### 1.2 Instruction Completion (Coming Soon)
22-
23-
It is important to note that “facts” are not the same as “instructions.” If developers only obtain plaintext memory, they must write additional rules to translate this information into prompts that large models can directly execute.
24-
25-
:::note
26-
**The role of instruction completion** is to automatically generate instructions of different granularity based on recall results.
27-
:::
28-
29-
* **In most systems, developers can only get “memory facts” and then manually piece together prompts. This leads to several challenges:**
30-
31-
* Task awareness: The same memory may require different phrasing under different tasks;
32-
33-
* Personalization: User style and habits need to be instantly supplemented;
34-
35-
* Dynamic optimization: Different models require different optimal prompt formulations;
36-
37-
* Efficient compression: Redundancy must be removed to reduce token consumption.
38-
39-
40-
<br>
41-
42-
* **MemOS instruction completion helps developers cover this “last mile”:**
43-
44-
* Saves the cost of rules assembly and tuning;
45-
46-
* Ensures that recalled memories are effectively utilized;
47-
48-
* Provides three modes: matches / instruction / full_instruction, to meet different levels of control needs.
49-
50-
* Memory facts (matches): Recall relevant memories for the current query.
51-
52-
* Semi-finished instruction (instruction): Combine recalled memories with the user’s current question to form a basic prompt, upon which developers can add business logic.
53-
54-
* Full instruction (full_instruction): Based on the semi-finished version, integrate context, preferences, compliance constraints, etc., to generate a terminal prompt directly executable by the model.
55-
56-
57-
<br>
58-
59-
:::note
60-
Instruction completion works through both **offline chain** and **real-time chain**.
61-
:::
62-
63-
| **Chain** | **Description** |
64-
| --- | --- |
65-
| **Offline Chain** (Accumulation & Preparation) | Extract user preferences to form a profile.<br><br>Build a few-shot sample library.<br><br>Solidify long-term rules such as brand, compliance, and style. |
66-
| **Real-time Chain** (Dynamic Decision) | Select which memories and templates to activate based on task intent.<br><br>Resolve conflicts (e.g., “likes poetic openings” vs. “requires conciseness”).<br><br>Perform compression and degradation based on token budget and model characteristics. |
67-
68-
69-
## 2. Example (Try after instruction completion is launched) — Personalized Tutoring in AI Education
70-
71-
### 2.1 Historical Dialogue Input (Raw Material)
72-
73-
```json
74-
2025-06-10
75-
Student: Hello teacher, my name is Xiao Ming, I am in 9th grade
76-
Teacher: Hello Xiao Ming, nice to meet you
77-
……
78-
79-
2025-08-01
80-
Student: Teacher, I really can’t solve this problem, can you explain more clearly?
81-
Teacher: Sure, I will explain step by step.
82-
……
83-
84-
2025-09-03
85-
……
86-
Student: You just explained too long, I couldn’t keep up. Can you make it simpler?
87-
Teacher: Okay, I’ll tell you in a simpler way.
88-
……
89-
90-
2025-10-09
91-
Student: I still can’t distinguish between linear and quadratic functions…
92-
Teacher: The graph of a linear function is a straight line, while a quadratic function is a parabola. You need to remember this difference.
93-
……
94-
```
95-
96-
### 2.2 MemOS Instruction Preference Modeling (Offline Chain)
97-
98-
* **Preference Extraction**
99-
100-
* Likes step-by-step explanations (from “can you explain step by step”).
101-
102-
* Prefers concise answers (from “you just explained too long”).
103-
104-
* Easily confuses similar concepts (from “I still can’t distinguish between linear and quadratic functions”).
105-
106-
* **Few-shot Selection**: Pick dialogues with step-by-step, concise explanations, and concept clarification.
107-
108-
* **Strategy Summary**: Summarized as “step-by-step + concise + clarify common confusions”.
109-
110-
111-
```yaml
112-
user_teaching_template_u123:
113-
audience: "9th grade student"
114-
task: "Solve math problems"
115-
structure:
116-
- "Step-by-step explanation (3–4 steps)"
117-
- "Correct confusion between linear and quadratic functions when necessary"
118-
constraints:
119-
- "Keep explanations concise, not too long"
120-
- "Highlight key points, avoid lengthy formula derivations"
121-
122-
fewshot_examples_u123:
123-
- id: "fs-step-01"
124-
user: "Teacher, I really can’t solve this problem, can you explain more clearly?"
125-
assistant: "Sure, I will explain step by step…"
126-
tag: "Step-by-step explanation"
127-
128-
- id: "fs-brief-02"
129-
user: "You just explained too long, I couldn’t keep up. Can you make it simpler?"
130-
assistant: "Okay, I’ll tell you in a simpler way…"
131-
tag: "Concise expression"
132-
133-
- id: "fs-contrast-03"
134-
user: "I still can’t distinguish between linear and quadratic functions…"
135-
assistant: "The graph of a linear function is a straight line, while a quadratic function is a parabola. You need to remember this difference…"
136-
tag: "Concept clarification"
137-
```
138-
139-
### 2.3 Real-time Chain (Instruction Completion)
140-
141-
:::note{icon="ri:message-2-line"}
142-
User query: [Teacher, can you teach me how to solve this problem? 2x² - 3x - 5 = 0]
143-
:::
144-
145-
* **Recalled matches:** Only returns facts, unprocessed. Developers need to piece together the prompt and decide how to guide the student.
146-
147-
148-
```yaml
149-
matches:
150-
- value: "9th grade student"
151-
score: 0.95
152-
source: "Dialogue record#2025-06-10"
153-
154-
- value: "Prefers step-by-step explanations"
155-
score: 0.94
156-
source: "Dialogue record#2025-08-01"
157-
158-
- value: "Likes concise explanations"
159-
score: 0.92
160-
source: "Dialogue record#2025-09-03"
161-
162-
- value: "Confuses linear and quadratic functions"
163-
score: 0.90
164-
source: "Dialogue record#2025-10-09"
165-
166-
user_query: "Teacher, can you teach me how to solve this problem? 2x² - 3x - 5 = 0"
167-
```
168-
169-
<br>
170-
171-
* **Semi-finished instruction:** Translate facts into structured requirements: task / audience / steps / constraints
172-
173-
174-
```yaml
175-
instruction: |
176-
Task: Help student solve a quadratic equation problem
177-
Audience: 9th grade student
178-
Requirements:
179-
- Explain in 3–4 steps
180-
- Correct common confusion between linear/quadratic functions during explanation
181-
- Keep it concise, avoid lengthy derivations
182-
Note: If the question is incomplete, please ask for clarification first
183-
184-
user_query: "Teacher, can you teach me how to solve this problem? 2x² - 3x - 5 = 0"
185-
```
186-
187-
<br>
188-
189-
* **Full instruction:** Further refined from the semi-finished version
190-
191-
* Convert “often confuses” into explicit teaching action (must emphasize difference between quadratic and linear functions during explanation).
192-
193-
* Translate “prefers step-by-step explanations” into a clear problem-solving method (use step-by-step explanation).
194-
195-
* Rewrite “9th grade student” into the teaching role relationship (you are the math teacher of a 9th grade student).
196-
197-
* Select few-shot examples from historical dialogue and include them in the final instruction to help the model learn explanation and clarification patterns.
198-
199-
200-
> Semi-finished instructions are more structured for developer customization; full instructions are closer to natural language and directly executable by models.
201-
202-
```yaml
203-
final_prompt_to_model:
204-
- role: system
205-
content: |
206-
You are the math teacher of a 9th grade student.
207-
The student often confuses linear and quadratic functions, and prefers concise, step-by-step explanations.
208-
Please follow the style of the following historical examples:
209-
210-
[Example 1]
211-
Student: Teacher, I really can’t solve this problem, can you explain more clearly?
212-
Teacher: Sure, I will explain step by step.
213-
214-
[Example 2]
215-
Student: You just explained too long, I couldn’t keep up. Can you make it simpler?
216-
Teacher: Okay, I’ll tell you in a simpler way.
217-
218-
[Example 3]
219-
Student: I still can’t distinguish between linear and quadratic functions…
220-
Teacher: The graph of a linear function is a straight line, while a quadratic function is a parabola. You need to remember this difference.
221-
222-
Now please answer the student’s question: “Solve 2x² - 3x - 5 = 0.”
223-
Requirements:
224-
- Solve the problem step-by-step (3–4 steps);
225-
- Point out the difference between linear and quadratic functions during the explanation;
226-
- Keep the answer concise and clear, avoid lengthy derivations;
227-
- If the problem statement is incomplete, please ask for clarification first.
228-
- role: user
229-
content: "Teacher, can you teach me how to solve this problem? 2x² - 3x - 5 = 0"
230-
```
231-
232-
> Case Summary: In the “9th grade student solving quadratic equation” scenario, instruction completion provides the following benefits over returning raw memory only:
233-
234-
* **From facts to executable**
235-
236-
* Raw memory only has “student often confuses linear and quadratic functions,” developers must convert this into a teaching action.
237-
238-
* Instruction completion directly generates “must emphasize the key difference during explanation,” avoiding extra developer rules.
239-
240-
* **Context integration**
241-
242-
* Raw memory is fragmented; developers must decide how to place them into prompts.
243-
244-
* Instruction completion automatically merges memories with the user query into a coherent task description for direct model use.
245-
246-
* **Optimization and pruning**
247-
248-
* If developers directly concatenate memories, the result is often redundant or conflicting.
24917

250-
* Instruction completion compresses into concise step-by-step requirements, reducing token consumption and improving focus.
251-
252-
* **Robustness assurance**
18+
* **Features**:
25319

254-
* If developers only get memories, they must consider “what if the question is incomplete.”
20+
* Seamless recall: Users don’t need to repeat their previous choices or preferences.
25521

256-
* Instruction completion includes clarification strategies, making outputs more robust without reinventing the wheel.
22+
* Structured output: Separates factual and preference memories, making it easier for developers to control whether to inject them.
25723

25824

259-
## 3. Advanced: Deep Customization
25+
## 2. Advanced: Deep Customization
26026

26127
In MemOS, recall and completion are not achieved through a single path, but through combinations of multiple strategies and components. Different scenarios may require different configurations. This section lists the main steps and customizable points for you to flexibly choose according to business needs.
26228

26329
| **Layer** | **Customizable Points** | **Example** |
26430
| --- | --- | --- |
26531
| Memory Recall | Adjust recall strategy | Raise similarity threshold to only return memories with confidence ≥0.9 |
26632
| | Set filters | Only retrieve the last 30 days of conversations; only preference memories, not factual ones |
267-
| Semi-finished Instruction<br>instruction | Extend structured fields | Add extra fields such as “Output format: Markdown”, “Must include: Safety reminder” |
268-
| | Custom concatenation template | Replace default concatenation logic to generate semi-finished instructions with brand tone |
269-
| Full Instruction<br>full_instruction | Few-shot strategy | Replace default historical messages with your own example library, fix to 2 examples each time |
270-
| | Role and tone control | Force setting to “Financial Advisor”, output style as “formal professional” |
271-
| | Token cost optimization | Define compression rules: keep core preferences, prune redundant background information |
272-
| | Multi-model adaptation | For GPT output with LaTeX, for LLaMA output plain text, auto-switch |
27333
| Output Governance & Audit | Compliance fallback | Automatically prepend “Answer must comply with regulations” before completion |
27434
| | Logging & traceability | Record used memories and few-shot selection each call |
27535
| | A/B testing | Run two concatenation templates simultaneously, compare user satisfaction differences |
27636

27737

278-
## 4. Next Steps
38+
## 3. Next Steps
27939

28040
Learn more about MemOS core capabilities:
28141

28242
* [Memory Lifecycle Management](/overview/quick_start/mem_lifecycle)
28343

28444

285-
## 5. Contact Us
45+
## 4. Contact Us
28646

28747
<img src="https://cdn.memtensor.com.cn/img/1758685658684_nbhka4_compressed.png" alt="image" style="width:70%;">

0 commit comments

Comments
 (0)