Files
memoryweave/scripts/migrate_openclaw.py
T
xiaowei 1b0e1a549c fix: 蒸馏引擎 + 命名空间隔离 + PassiveValidator + ephemeral清理
- 蒸馏引擎: LLM调用需LLM_API_KEY(不再复用API_KEY), 新增flush日志
- namespace三层: shared/hermes-main/openclaw-main 隔离, Rust IPC client-side过滤
- PassiveValidator: 蒸馏完成回调中加载已有记忆进行P1/P2/P3匹配
- ephemeral清理: currentUnixMS修复, AgentInfo.LastSeen, 定时扫描
- Go代理: goproxy.cn配置
- 图谱: 孤儿边自动补节点, namespace兼容, 多跳导航前缀修复
- 召回管道: shared namespace联合搜索, recall_count跟踪
2026-05-29 08:04:57 +08:00

89 lines
3.1 KiB
Python

"""OpenClaw LanceDB → 织忆 MemoryWeave 迁移脚本"""
import json, time, requests
import lancedb
OPENCLAW_DB = "/home/muc/.openclaw/memory-lancedb"
ZHIYI_URL = "http://localhost:7821"
ZHIYI_KEY = "zhiyi-dev-key-2026"
def log(msg):
print(f"[migrate-openclaw] {msg}", flush=True)
def main():
log(f"打开 OpenClaw LanceDB: {OPENCLAW_DB}")
db = lancedb.connect(OPENCLAW_DB)
table = db.open_table("memories")
total = table.count_rows()
log(f"共 {total} 条记忆")
# 用 to_arrow() 避免 pandas 依赖
arrow_table = table.to_arrow()
cols = arrow_table.column_names
success, fail = 0, 0
for i in range(arrow_table.num_rows):
row = {c: arrow_table.column(c)[i].as_py() for c in cols}
content = str(row.get("text", "")).strip()
if not content:
fail += 1
continue
category = str(row.get("category", "general"))
scope = str(row.get("scope", "openclaw"))
try:
resp = requests.post(
f"{ZHIYI_URL}/api/v1/commit",
headers={"X-API-Key": ZHIYI_KEY, "Content-Type": "application/json"},
json={
"content": content,
"category": category,
"namespace": "openclaw-main",
"agent_id": "openclaw-snowy",
"metadata": json.dumps({
"scope": scope,
"openclaw_id": str(row.get("id", "")),
"importance": row.get("importance", 0.5),
"timestamp": row.get("timestamp", 0),
}),
},
timeout=30,
)
if resp.status_code in (200, 201):
success += 1
else:
fail += 1
if resp.status_code == 429:
time.sleep(1)
# retry once
resp = requests.post(
f"{ZHIYI_URL}/api/v1/commit",
headers={"X-API-Key": ZHIYI_KEY, "Content-Type": "application/json"},
json={
"content": content,
"category": category,
"namespace": "openclaw-main",
"agent_id": "openclaw-snowy",
},
timeout=30,
)
if resp.status_code in (200, 201):
success += 1
fail -= 1
else:
print(f" FAIL[{resp.status_code}]: {content[:80]}...")
else:
print(f" FAIL[{resp.status_code}]: {content[:80]}...")
except Exception as e:
fail += 1
print(f" ERR: {content[:80]}... -> {e}")
if (success + fail) % 10 == 0:
log(f"进度: {success + fail}/{total} (成功={success}, 失败={fail})")
time.sleep(0.05) # 温和限流
log(f"完成: {total} 条, 成功={success}, 失败={fail}")
if __name__ == "__main__":
main()