跳至主要内容

Memory API

建立記憶

POST /v1/memories

POST /v1/memories
Authorization: Bearer sk-your-api-key
Content-Type: application/json
{
"content": "使用者偏好繁體中文回覆,技術術語保留英文",
"memory_type": "rule",
"importance": 0.9
}

請求欄位:

欄位類型必填說明
contentstring記憶內容
memory_typestringrule / fact / context
importancenumber0.0 – 1.0,越高越優先注入,預設 0.5

回應:

{
"success": true,
"data": {
"id": "mem-uuid",
"content": "使用者偏好繁體中文回覆,技術術語保留英文",
"memory_type": "rule",
"importance": 0.9,
"created_at": "2026-05-08T12:00:00Z"
}
}

列出記憶

GET /v1/memories

查詢參數:

參數類型說明
memory_typestring篩選類型:rule / fact / context
pagenumber頁碼,預設 1
page_sizenumber每頁筆數,預設 20,最大 100

取得記憶詳情

GET /v1/memories/{id}

GET /v1/memories/mem-uuid
Authorization: Bearer sk-your-api-key

更新記憶

PATCH /v1/memories/{id}

{
"importance": 0.7
}

可更新的欄位:contentimportance


刪除記憶

DELETE /v1/memories/{id}

DELETE /v1/memories/mem-uuid
Authorization: Bearer sk-your-api-key

語義搜尋

POST /v1/memories/search

{
"query": "使用者語言偏好",
"top_k": 5,
"min_similarity": 0.3,
"memory_type": "rule"
}

請求欄位:

欄位類型必填說明
querystring搜尋查詢
top_knumber回傳數量,預設 5
min_similaritynumber最低相似度門檻
memory_typestring限定搜尋的記憶類型

回應:

{
"success": true,
"data": {
"results": [
{
"id": "mem-uuid",
"content": "使用者偏好繁體中文回覆",
"memory_type": "rule",
"importance": 0.9,
"score": 0.9521
}
]
}
}

自動萃取記憶

POST /v1/memories/extract

讓 LLM 從文字或對話中自動識別並儲存值得記住的資訊。

{
"messages": [
{ "role": "user", "content": "我用 React 19 + TypeScript,後端是 Go" },
{ "role": "assistant", "content": "了解,之後範例會用這個 stack" }
],
"deduplicate": true
}

也可以傳純文字(text 欄位):

{
"text": "使用者使用 Python 3.12,偏好 async 模式",
"deduplicate": true
}

請求欄位:

欄位類型說明
messagesarray對話訊息(與 text 擇一)
textstring純文字(與 messages 擇一)
deduplicateboolean是否跳過與現有記憶重複的內容,預設 false

注意: 此端點會呼叫 LLM 進行萃取,會消耗少量 Credits。


批次刪除

DELETE /v1/memories

{
"memory_type": "context"
}

刪除所有符合條件的記憶。


所需權限

操作所需權限
讀取、搜尋memory.read
新增、修改、刪除memory.write
自動萃取memory.write