Lukas Goldschmidt 2 dias atrás
pai
commit
89f104a6e9
2 arquivos alterados com 89 adições e 23 exclusões
  1. 71 12
      mem0server.py
  2. 18 11
      reset_memory.py

+ 71 - 12
mem0server.py

@@ -47,20 +47,79 @@ PROMPTS = {
     # Used by /memories — conversational, user-centric recall for OpenClaw.
     "conversational": {
         "fact_extraction": """
-You are a personal memory assistant. Extract concise, standalone facts about
-the user from the conversation below. Write each fact as a single sentence
-starting with "User" — for example:
-  - "User is interested in generative music."
-  - "User is familiar with Python async patterns."
-  - "User prefers dark mode interfaces."
-Only extract facts that are clearly stated or strongly implied. Ignore filler,
-greetings, and opinions the user is uncertain about.
+You are an intelligent system that extracts useful long-term memory
+from a conversation.
+
+Your goal is to identify information that could help future interactions.
+
+Extract facts that describe:
+
+1. User preferences
+2. Important decisions
+3. Ongoing projects
+4. Tools or technologies being used
+5. Goals or plans
+6. Constraints or requirements
+7. Discoveries or conclusions
+8. Important context about tasks
+
+Ignore:
+- greetings
+- casual conversation
+- general world knowledge
+- temporary statements
+
+Return the result in JSON format:
+
+{
+ "facts": [
+   "fact 1",
+   "fact 2"
+ ]
+}
+
+Only include information that may be useful later.
+If nothing important is present return:
+
+{"facts": []}
+
 """.strip(),
         "update_memory": """
-You manage a long-term memory database for a personal AI assistant.
-You receive existing memories and new information. Update, merge, or add
-memories as needed. Keep each memory as a single concise sentence starting
-with "User". Remove duplicates and outdated facts.
+
+You manage a long-term memory database.
+
+You receive:
+1. existing stored memories
+2. new extracted facts
+
+For each fact decide whether to:
+
+ADD
+Create a new memory if it contains useful new information.
+
+UPDATE
+Modify an existing memory if the new fact refines or corrects it.
+
+DELETE
+Remove a memory if it is clearly outdated or incorrect.
+
+NONE
+Ignore the fact if it is redundant or trivial.
+
+Guidelines:
+
+- Prefer updating over adding duplicates
+- Keep memories concise
+- Avoid storing repeated information
+- Preserve important context
+
+Return JSON list:
+
+[
+ { "event": "ADD", "text": "..." },
+ { "event": "UPDATE", "id": "...", "text": "..." }
+]
+
 """.strip(),
     },
 

+ 18 - 11
reset_memory.py

@@ -1,16 +1,23 @@
-# reset_memory.py
-import sys
-import requests
-
-base = "http://192.168.0.200:8001/api/v1"
-mem0_base = "http://192.168.0.200:8420"
+import sys, subprocess, requests, os
 
+chroma_base = "http://192.168.0.200:8001/api/v1"
 name = sys.argv[1]
-requests.delete(f"{base}/collections/{name}")
-requests.post(f"{base}/collections", json={"name": name})
-print(f"collection reset: {name}")
 
-# Bounce the mem0 server so it re-acquires the fresh collection
-import subprocess
+# 1. Reset Chroma collection
+requests.delete(f"{chroma_base}/collections/{name}")
+requests.post(f"{chroma_base}/collections", json={"name": name})
+print(f"chroma collection reset: {name}")
+
+# 2. Wipe mem0's SQLite so integer IDs don't drift from UUIDs
+result = subprocess.run(
+    ["docker", "exec", "mem0server", "find", "/", "-name", "*.db"],
+    capture_output=True, text=True
+)
+for path in result.stdout.strip().splitlines():
+    if "mem0" in path.lower():
+        subprocess.run(["docker", "exec", "mem0server", "rm", "-f", path])
+        print(f"removed sqlite: {path}")
+
+# 3. Restart so mem0 reinitialises cleanly
 subprocess.run(["docker", "compose", "restart", "mem0server"])
 print("mem0server restarted")