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

Function main

examples/mem_feedback/example_feedback.py:153–244  ·  view source on GitHub ↗

Main program flow: 1. Initialize components. 2. Simulate a conversation scenario and existing (possibly incorrect) memory. 3. Receive user feedback (correct memory). 4. Process feedback and update memory store. 5. Display processing results.

()

Source from the content-addressed store, hash-verified

151
152
153def main():
154 """
155 Main program flow:
156 1. Initialize components.
157 2. Simulate a conversation scenario and existing (possibly incorrect) memory.
158 3. Receive user feedback (correct memory).
159 4. Process feedback and update memory store.
160 5. Display processing results.
161 """
162 # Load dotenv in main to avoid affecting module import order
163 from dotenv import load_dotenv
164
165 load_dotenv()
166
167 # Lazy import to avoid E402
168 from memos.mem_feedback.utils import make_mem_item
169
170 feedback_server, memory_manager, embedder = init_components()
171 print("-" * 50)
172 print("Initialization Done. Processing Feedback...")
173 print("-" * 50)
174
175 # 1. Simulate Chat History
176 # Simulate a conversation between user and assistant, where the assistant's response contains a statement about user preferences.
177 history = [
178 {"role": "user", "content": "我喜欢什么水果,不喜欢什么水果"},
179 {"role": "assistant", "content": "你喜欢苹果,不喜欢香蕉"},
180 ]
181
182 # 2. Simulate Initial Memory
183 # We manually add a memory to the database, representing what the system currently believes to be a "fact".
184 # This memory content is "你喜欢苹果,不喜欢香蕉", which we will later correct via feedback.
185 mem_text = "你喜欢苹果,不喜欢香蕉"
186 memory_manager.add(
187 [
188 make_mem_item(
189 mem_text,
190 user_id="user_id_001",
191 user_name="cube_id_001_0115",
192 session_id="session_id",
193 tags=["fact"],
194 key="food_preference",
195 sources=[{"type": "chat"}],
196 background="init from chat history",
197 embedding=embedder.embed([mem_text])[
198 0
199 ], # Generate embedding for subsequent retrieval
200 info={
201 "user_id": "user_id_001",
202 "user_name": "cube_id_001_0115",
203 "session_id": "session_id",
204 },
205 )
206 ],
207 user_name="cube_id_001_0115",
208 mode="sync",
209 )
210

Callers 1

Calls 5

make_mem_itemFunction · 0.90
init_componentsFunction · 0.70
embedMethod · 0.65
addMethod · 0.45
process_feedbackMethod · 0.45

Tested by

no test coverage detected