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
}
請求欄位:
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
content | string | ✓ | 記憶內容 |
memory_type | string | ✓ | rule / fact / context |
importance | number | 0.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_type | string | 篩選類型:rule / fact / context |
page | number | 頁碼,預設 1 |
page_size | number | 每頁筆數,預設 20,最大 100 |
取得記憶詳情
GET /v1/memories/{id}
GET /v1/memories/mem-uuid
Authorization: Bearer sk-your-api-key
更新記憶
PATCH /v1/memories/{id}
{
"importance": 0.7
}
可更新的欄位:content、importance。
刪除記憶
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"
}
請求欄位:
| 欄位 | 類型 | 必填 | 說明 |
|---|---|---|---|
query | string | ✓ | 搜尋查詢 |
top_k | number | 回傳數量,預設 5 | |
min_similarity | number | 最低相似度門檻 | |
memory_type | string | 限定搜尋的記憶類型 |
回應:
{
"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
}
請求欄位:
| 欄位 | 類型 | 說明 |
|---|---|---|
messages | array | 對話訊息(與 text 擇一) |
text | string | 純文字(與 messages 擇一) |
deduplicate | boolean | 是否跳過與現有記憶重複的內容,預設 false |
注意: 此端點會呼叫 LLM 進行萃取,會消耗少量 Credits。
批次刪除
DELETE /v1/memories
{
"memory_type": "context"
}
刪除所有符合條件的記憶。
所需權限
| 操作 | 所需權限 |
|---|---|
| 讀取、搜尋 | memory.read |
| 新增、修改、刪除 | memory.write |
| 自動萃取 | memory.write |