reset_memory.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import sys, subprocess, requests, time
  2. CHROMA_V2 = "http://192.168.0.200:8001/api/v2/tenants/default_tenant/databases/default_database"
  3. CONTAINER = "mem0server"
  4. COMPOSE_FILE = "/home/lucky/mem0server/docker-compose.yml"
  5. MEM0_SQLITE = "/root/.mem0/history.db"
  6. name = sys.argv[1]
  7. # 1. Wipe and recreate Chroma collection
  8. requests.delete(f"{CHROMA_V2}/collections/{name}")
  9. requests.post(f"{CHROMA_V2}/collections", json={"name": name})
  10. print(f"chroma reset: {name}")
  11. # 2. Verify entry count is 0
  12. col = requests.get(f"{CHROMA_V2}/collections/{name}").json()
  13. col_id = col.get("id")
  14. count = requests.get(f"{CHROMA_V2}/collections/{col_id}/count").json()
  15. print(f"chroma verified: {name} → {count} entries")
  16. # 3. Delete mem0 SQLite
  17. subprocess.run(["docker", "exec", CONTAINER, "rm", "-f", MEM0_SQLITE])
  18. print(f"removed sqlite: {MEM0_SQLITE}")
  19. # 4. Restart
  20. subprocess.run(["docker", "compose", "-f", COMPOSE_FILE, "restart", CONTAINER])
  21. print("restarting...")
  22. # 5. Wait for health
  23. online = False
  24. for i in range(15):
  25. time.sleep(2)
  26. try:
  27. r = requests.get("http://192.168.0.200:8420/health", timeout=2)
  28. if r.ok:
  29. online = True
  30. break
  31. except:
  32. pass
  33. print(f" waiting... ({(i+1)*2}s)")
  34. if online:
  35. print(f"server back online ✓")
  36. else:
  37. print("server did not come back — check: docker logs mem0server")