1# 安装:pip install memorysync2# 使用 API key 认证时,end_user_id 为必填项。3import os4from memorysync import MemorySyncClient5 6client = MemorySyncClient(7 api_key=os.getenv("MEMORYSYNC_API_KEY", "your-api-key-here"),8 base_url="https://api.memorysync.io",9 end_user_id="user_42",10)11 12# 保存一条记忆。source 标记来源;tags 用于召回时过滤;13# importance 是 0..1 的提示值,供排序器使用。14client.add(15 "Customer asked about churn drivers in the enterprise plan.",16 source="api",17 tags=["billing", "churn"],18 importance=0.8,19)20 21# 语义召回。22# k = 返回排名最高的记忆数量(1-50,默认 5)。23hits = client.query("How can we reduce churn for enterprise users?", k=5)24for m in hits.memories:25 print(m.id, m.score, m.text)