全部產品
Search
文件中心

Tablestore:記憶儲存API

更新時間:Jul 10, 2026

通過 HTTP JSON 協議直接調用記憶儲存服務,覆蓋記憶庫管理、長期記憶讀寫、短期記憶與審計查詢、記憶整理(Dream)任務,適用於無 SDK 的自訂整合情境。

介面列表

按功能分類,全部介面如下。

記憶庫管理

介面

說明

CreateMemoryStore

建立記憶庫。

GetMemoryStore

擷取記憶庫詳情。

UpdateMemoryStore

更新記憶庫描述。

DeleteMemoryStore

刪除記憶庫。

ListMemoryStores

列出記憶庫。

長期記憶

介面

說明

AddMemories

寫入對話訊息或文本,並產生長期記憶。

SearchMemories

檢索長期記憶。

ListMemories

列出長期記憶。

GetMemory

擷取單條長期記憶。

UpdateMemory

更新單條長期記憶。

DeleteMemory

刪除單條長期記憶。

短期記憶與審計

介面

說明

ListMemoryStoreMessages

查詢短期記憶,即原始會話訊息。

ListMemoryStoreRequests

查詢記憶程式庫要求審計記錄。

非同步任務與 Scope

介面

說明

GetMemoryTask

查詢非同步抽取任務狀態與結果。

ListMemoryTasks

列出非同步抽取任務。

ListMemoryStoreScopes

列出記憶庫中已存在的 Scope。

記憶整理(Dream)

介面

說明

CreateMemoryDreamTask

建立記憶整理任務。

GetMemoryDreamTask

查詢記憶整理任務進度。

ListMemoryDreamTasks

列出記憶整理任務。

ListMemoryDreamActions

列出整理任務產生的動作(提案)。

ApplyMemoryDreamActions

應用整理動作提案。

CancelMemoryDreamTask

取消記憶整理任務。

通用對象

記憶庫介面在請求和響應中複用以下資料結構。

Scope

Scope 表示記憶資料的歸屬層級,由四級欄位組成。

欄位

類型

說明

appId

string

應用標識。

tenantId

string

租戶或使用者標識。

agentId

string

Agent 標識。

runId

string

會話、運行或任務標識。

不同介面對 Scope 欄位的必填性和萬用字元 * 支援規則不同。

情境

必要欄位

萬用字元 * 規則

寫入(AddMemories

appId

其他欄位為空白時補 __default__,不允許使用 *

檢索長期記憶(SearchMemories

appIdtenantId

agentIdrunId 可使用 *

查詢短期記憶(ListMemoryStoreMessages

四級 Scope 全部必填

不允許使用 *

擷取、更新、刪除單條長期記憶(GetMemoryUpdateMemoryDeleteMemory

四級 Scope 全部必填

不允許使用 *

列表查詢(ListMemoriesListMemoryStoreRequests

appId

支援按層級使用 *

樣本:

{
  "appId": "app-001",
  "tenantId": "user-001",
  "agentId": "assistant",
  "runId": "session-001"
}

Message

AddMemories 介面的 messages 欄位使用以下結構。

欄位

類型

必填

說明

role

string

訊息角色,例如 userassistantsystem

content

string

訊息內容。

messageId

string

訊息 ID,最長 256 個字元。

timestamp

string

RFC3339 格式時間。

metadata

object

訊息級中繼資料,鍵和值均為字串。

Metadata

Metadata 為字串索引值對,用於附加業務標籤。在檢索介面中,Metadata 用於字串索引值的精確匹配過濾。

限制項

取值

單次請求最多鍵數

16 個

鍵長度上限

64 個字元

值長度上限

1024 個字元

樣本:

{
  "source": "chat",
  "topic": "preference"
}

CreateMemoryStore

建立一個記憶庫。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱,只能包含字母、數字和底線,最長 32 個字元。

description

string

記憶庫描述,最長 1024 個字元。

extractInstructions

string

記憶庫自訂抽取指令,最長 4096 個字元。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "description": "Agent 長期記憶庫",
  "extractInstructions": "重點關注使用者的飲食偏好與出行習慣"
}

GetMemoryStore

擷取記憶庫詳情。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

請求樣本

{
  "memoryStoreName": "agent_memory"
}

UpdateMemoryStore

更新記憶庫描述。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

description

string

新描述,最長 1024 個字元。

extractInstructions

string

新的自訂抽取指令,最長 4096 個字元;傳Null 字元串清除,不傳保持不變。

DeleteMemoryStore

刪除記憶庫。

警告

刪除記憶庫會一併刪除該記憶庫下的全部資料,操作無法復原。生產環境請謹慎執行。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

ListMemoryStores

列出記憶庫。

請求參數

欄位

類型

必填

說明

limit

int

返回數量。

nextToken

string

下一頁標記。

AddMemories

寫入對話訊息或文本。服務儲存原始訊息作為短期記憶,並從輸入中提取長期記憶。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

目標記憶庫名稱。

scope

object

Scope。寫入時 appId 必填,不允許使用萬用字元 *

messages

array

text 二選一

對話訊息數組,最多 20 條;總內容長度不超過 32000 個字元。

text

string

messages 二選一

常值內容,最長 32000 個字元。

metadata

object

寫入級中繼資料,最多 16 個鍵,鍵最長 64 個字元,值最長 1024 個字元。

sync

boolean

是否同步等待記憶抽取完成,預設 false

各項上限的完整說明,請參見 限制與注意事項

請求樣本:寫入訊息

{
  "memoryStoreName": "agent_memory",
  "scope": {
    "appId": "app-001",
    "tenantId": "user-001",
    "agentId": "assistant",
    "runId": "session-001"
  },
  "messages": [
    {
      "role": "user",
      "content": "我喜歡喝咖啡"
    },
    {
      "role": "assistant",
      "content": "好的,我記住了"
    }
  ],
  "metadata": {
    "source": "chat"
  },
  "sync": true
}

請求樣本:寫入文本

{
  "memoryStoreName": "agent_memory",
  "scope": {
    "appId": "app-001",
    "tenantId": "user-001"
  },
  "text": "使用者喜歡喝咖啡,偏好簡潔的回答風格"
}

響應欄位

欄位

說明

requestId

請求 ID。

status

請求狀態。非同步寫入通常返回 running

acceptedMessages

接收的訊息數量。

scope

實際寫入使用的 Scope。

memoryStoreName

記憶庫名稱。

memcellsCreated

同步寫入時返回,表示建立的記憶片段數量。

unitsCreated

同步寫入時返回,表示建立的長期記憶單元數量。

SearchMemories

檢索長期記憶。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

目標記憶庫名稱。

query

string

查詢文本。

scope

object

Scope。檢索時 appIdtenantId 必填,agentIdrunId 可使用萬用字元 *

topK

int

返回數量,預設 10,取值範圍 1~50

includeEvidence

boolean

是否在結果中附帶短期記憶源證據(evidence 欄位),預設 false

minSimilarity

float

相似性過濾閾值,取值範圍 0~1,預設 0(不過濾);大於 0 時過濾掉歸一化餘弦相似性低於該值的結果。

enableRerank

boolean

是否啟用 Rerank,預設 true

metadata

object

中繼資料精確匹配過濾條件,鍵和值均為字串。

topK 取值上限的完整說明,請參見 限制與注意事項

請求樣本

{
  "memoryStoreName": "agent_memory",
  "scope": {
    "appId": "app-001",
    "tenantId": "user-001",
    "agentId": "*",
    "runId": "*"
  },
  "query": "使用者喜歡什麼飲品",
  "topK": 5,
  "enableRerank": true,
  "includeEvidence": true,
  "metadata": {
    "source": "chat"
  }
}

響應欄位

欄位

說明

results

檢索結果清單。

results[].unit

長期記憶單元,欄位定義見下表。

results[].score

相關性分數。

results[].similarity

查詢與記憶的歸一化餘弦相似性(0~1),用於 minSimilarity 過濾。

results[].source

命中來源,例如 vectorvector+text

evidence

includeEvidence=true 時返回的短期記憶源證據列表;無可用證據時為 []。元素結構與 results 類似,但僅包含 unitscoresource,不含 similarity

scope

查詢使用的 Scope。

memoryStoreName

記憶庫名稱。

results[].unit 內部欄位如下。

欄位

說明

id

長期記憶單元 ID。

conversation_key

關聯的會話鍵。

scope

記憶所屬 Scope,對象包含 appIdtenantIdagentIdrunId 四個欄位。

memcell_id

記憶片段 ID。

unit_type

記憶單元類型。

text

記憶文本。

search_text

用於檢索的文本。

source_turn_ids

來源訊息 ID 列表。

type_label

類型標籤。

date_bucket

日期分桶。

metadata_json

中繼資料,JSON 字串。

deleted

是否已刪除。

created_at

建立時間。

salience

顯著性分數。

version

版本號碼。

ListMemories

列出長期記憶。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

scope

object

Scope。appIdtenantId 必填,agentIdrunId 可使用萬用字元 *

limit

int

返回數量。

nextToken

string

下一頁標記。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "scope": {
    "appId": "app-001",
    "tenantId": "*",
    "agentId": "*",
    "runId": "*"
  },
  "limit": 20
}

GetMemory

擷取單條長期記憶。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

memoryId

string

記憶 ID。

scope

object

完整 Scope,4 欄位全部必填,不允許使用萬用字元 *

UpdateMemory

更新單條長期記憶。textmetadata 至少提供一個。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

memoryId

string

記憶 ID。

scope

object

完整 Scope,4 欄位全部必填,不允許使用萬用字元 *

text

string

新記憶文本。

metadata

object

新中繼資料。

DeleteMemory

刪除單條長期記憶。

警告

刪除單條長期記憶為無法復原操作。生產環境請謹慎執行。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

memoryId

string

記憶 ID。

scope

object

完整 Scope,4 欄位全部必填,不允許使用萬用字元 *

ListMemoryStoreMessages

查詢短期記憶,即原始會話訊息。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

scope

object

完整 Scope,4 欄位全部必填,不允許使用萬用字元 *

limit

int

返回數量。

nextToken

string

下一頁標記。

minTimestamp

string

最小時間,RFC3339 格式。

maxTimestamp

string

最大時間,RFC3339 格式。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "scope": {
    "appId": "app-001",
    "tenantId": "user-001",
    "agentId": "assistant",
    "runId": "session-001"
  },
  "limit": 100
}

響應樣本

{
  "session": {
    "scope": { "appId": "app-001", "tenantId": "user-001", "agentId": "assistant", "runId": "session-001" },
    "messages": [
      {
        "messageId": "d0d9dd778a27e8cde773a243a5bab13c",
        "role": "user",
        "speaker": "user",
        "content": "[10:00 AM on 13 May, 2026] 我以後出差都優先訂靠窗座位",
        "timestamp": "2026-05-13T10:00:00Z",
        "metadata": { "channel": "chat", "source": "chat" }
      }
    ]
  }
}

記憶庫存在但該 Scope 暫無訊息時,返回 200 與空的 messages 列表。

ListMemoryStoreRequests

查詢記憶程式庫要求審計記錄。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

scope

object

Scope,可按層級使用萬用字元 *

operation

string

操作名稱,例如 AddMemoriesSearchMemories

limit

int

返回數量。

nextToken

string

下一頁標記。

minTimestamp

string

最小時間,RFC3339 格式。

maxTimestamp

string

最大時間,RFC3339 格式。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "scope": {
    "appId": "app-001",
    "tenantId": "*",
    "agentId": "*",
    "runId": "*"
  },
  "operation": "AddMemories",
  "limit": 50
}

響應欄位

欄位

說明

requestId

請求 ID。

operation

操作名稱。

scope

請求使用的 Scope。

requestSummary

請求摘要。

responseStatus

響應狀態。

latencyMs

處理耗時,單位毫秒。

targetId

操作目標 ID,例如記憶 ID。

createdAt

記錄建立時間。

GetMemoryTask

查詢非同步抽取任務的狀態與結果,傳入 AddMemories 返回的 requestId

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

requestId

string

AddMemories 返回的請求 ID。

scope

object

校正任務歸屬的 Scope,可按層級使用 *

請求樣本

{
  "memoryStoreName": "agent_memory",
  "requestId": "4b41a912f8c8a66202896e880a505d4a"
}

響應樣本

{
  "memoryStoreName": "agent_memory",
  "task": {
    "requestId": "4b41a912f8c8a66202896e880a505d4a",
    "eventType": "ingest",
    "memoryStoreName": "agent_memory",
    "conversationKey": "app-001/user-001/assistant/session-001",
    "scope": { "appId": "app-001", "tenantId": "user-001", "agentId": "assistant", "runId": "session-001" },
    "status": "completed",
    "acceptedMessages": 2,
    "derivedMemcellId": "b1bb4faec235b0d55bc8830da8ffa9f2",
    "derivedUnitIds": ["88432eb9d28e0787791625da916d6a20", "480230ab0806e88fd69e0804599552a4"],
    "createdAt": "2026-06-17T07:19:59.962Z",
    "updatedAt": "2026-06-17T07:20:08.749Z",
    "finishedAt": "2026-06-17T07:20:08.749Z"
  }
}

任務狀態 status 取值:queuedrunningcompletedfailedneeds_reconcile。首次寫入後任務索引建立期間,本介面可能返回 409 CONFLICTingest task index is still building, please retry shortly),稍後重試即可。

ListMemoryTasks

列出非同步抽取任務。響應在 tasks 數組中返回任務對象,元素結構與 GetMemoryTask 響應中的 task 一致。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

scope

object

Scope,可按層級使用 *

status

string

任務狀態過濾:queuedrunningcompletedfailedneeds_reconcile

limit

int

返回數量,預設 50,最大 100

nextToken

string

下一頁標記。

minTimestamp

string

最小時間,Unix 毫秒時間戳記(不支援 RFC3339)。

maxTimestamp

string

最大時間,Unix 毫秒時間戳記(不支援 RFC3339)。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "scope": { "appId": "app-001", "tenantId": "user-001", "agentId": "assistant", "runId": "session-001" },
  "limit": 5
}

ListMemoryStoreScopes

列出記憶庫中已存在的 Scope,可查看某應用或租戶下有哪些 Agent 和會話產生過記憶。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

scope

object

Scope,可按層級使用 *

limit

int

返回數量,預設 100,最大 100

nextToken

string

下一頁標記。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "scope": { "appId": "app-001", "tenantId": "*", "agentId": "*", "runId": "*" },
  "limit": 10
}

響應樣本

{
  "memoryStoreName": "agent_memory",
  "scope": { "appId": "app-001", "tenantId": "*", "agentId": "*", "runId": "*" },
  "scopes": [
    { "appId": "app-001", "tenantId": "user-001", "agentId": "__default__", "runId": "__default__" },
    { "appId": "app-001", "tenantId": "user-001", "agentId": "assistant", "runId": "session-001" }
  ]
}

CreateMemoryDreamTask

建立記憶整理(Dream)任務,對已寫入記憶進行二次提煉、歸併與技能/畫像提取。任務非同步執行。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

scopes

array

待整理的 Scope 列表,最多 20 個。

taskType

string

任務類型:memory(預設)、skillprofile

applyMode

string

應用模式:proposal(預設,僅產生提案)、safe_auto(自動應用安全動作)。僅 taskType=memory 支援。

scopeOutputMode

string

整理結果歸屬:preserve_scope(預設)、promote_scope

confidenceThresholds

object

各動作的自動應用信賴度閾值,鍵為 addupdatemerge,值取值範圍 0~1

minTimestamp / maxTimestamp

string

整理的時間範圍,Unix 毫秒時間戳記(不支援 RFC3339)。

maxSessions / maxMessages / maxMemories

int

輸入規模上限,取值範圍見限制文檔。

expandedScopeLimit

int

Scope 展開上限,0~1000

instructions

string

自訂整理指令,最長 4000 個字元。

incremental

boolean

是否增量整理,預設 false(全量);為 true 時從上次成功位置繼續處理。

clientToken

string

等冪 Token。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "scopes": [ { "appId": "app-001", "tenantId": "user-001" } ],
  "taskType": "memory",
  "applyMode": "proposal"
}

響應樣本

{
  "memoryStoreName": "agent_memory",
  "dreamId": "2a528008111f5dc3500c73fd965089f7",
  "status": "queued",
  "createdAt": "2026-06-17T07:21:25.329Z"
}

GetMemoryDreamTask

查詢記憶整理任務的進度與結果概覽。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

dreamId

string

整理任務 ID。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "dreamId": "2a528008111f5dc3500c73fd965089f7"
}

響應樣本

{
  "memoryStoreName": "agent_memory",
  "dreamId": "2a528008111f5dc3500c73fd965089f7",
  "taskType": "memory",
  "applyMode": "proposal",
  "scopeOutputMode": "preserve_scope",
  "status": "completed",
  "actions": { "total": 2, "proposed": 2, "applied": 0, "skipped": 0, "failed": 0 },
  "input": { "scopes": [ { "appId": "app-001", "tenantId": "user-001", "agentId": "__default__", "runId": "__default__" } ], "sessionCount": 1, "messageCount": 1, "memoryCount": 2, "incremental": false },
  "lastError": "",
  "createdAt": "2026-06-17T07:21:25.329Z",
  "updatedAt": "2026-06-17T07:21:32.276Z",
  "finishedAt": "2026-06-17T07:21:32.276Z"
}

任務狀態 status 取值:queuedrunningplanningapplyingcompletedcompleted_with_failuresfailedcancelled

ListMemoryDreamTasks

列出記憶整理任務。響應在 tasks 數組中返回任務對象,包含 dreamIdstatustaskTypeactionCountproposedCountconfidenceThresholdscreatedAt 等欄位。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

scope

object

Scope,可按層級使用 *

status

string

任務狀態過濾。

limit

int

返回數量,預設 50,最大 100

nextToken

string

下一頁標記。

minTimestamp / maxTimestamp

string

時間範圍,Unix 毫秒時間戳記(不支援 RFC3339)。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "scope": { "appId": "app-001", "tenantId": "*", "agentId": "*", "runId": "*" },
  "limit": 10
}

ListMemoryDreamActions

列出整理任務產生的動作(提案)。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

dreamId

string

整理任務 ID(與 scope 二選一)。

scope

object

按 Scope 查詢(與 dreamId 二選一),此時 actionType 必填且僅支援 EMIT_SKILLEMIT_PROFILE

status

string

動作狀態過濾:proposedappliedskippedfailed

action

string

動作類型過濾:ADDUPDATEDELETEMERGENOOP

minConfidence / maxConfidence

float

信賴度過濾,0~1

orderBy

string

排序:created_at_asc(預設)、created_at_descconfidence_desc

limit

int

返回數量,預設 100,最大 100

nextToken

string

下一頁標記。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "dreamId": "2a528008111f5dc3500c73fd965089f7",
  "limit": 20
}

響應樣本

{
  "memoryStoreName": "agent_memory",
  "dreamId": "2a528008111f5dc3500c73fd965089f7",
  "actions": [
    {
      "dreamId": "2a528008111f5dc3500c73fd965089f7",
      "actionId": "968768529cdfde8d56686a71e1c28227",
      "action": "UPDATE",
      "status": "proposed",
      "targetScope": { "appId": "app-001", "tenantId": "user-001", "agentId": "__default__", "runId": "__default__" },
      "targetMemoryId": "d16fd038835d89ae8586f7814e5256c1",
      "newMemory": { "text": "User prefers concise responses.", "unitType": "atomic_fact" },
      "reason": "改寫為更準確的 atomic_fact 表述。",
      "confidence": 0.95,
      "createdAt": "2026-06-17T07:21:32.161Z"
    }
  ]
}

兩種查詢模式互斥:按 dreamId 查詢該任務下所有動作;按 scope + actionType(僅 EMIT_SKILLEMIT_PROFILE)查詢該範圍內累積產生的技能或畫像。

ApplyMemoryDreamActions

應用記憶整理任務產生的提案動作(applyMode=proposal 時)。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

dreamId

string

整理任務 ID。

actionIds

array

待應用的動作 ID 列表,不可為空白,單次最多 100 個。

applier

string

應用者標識,記錄在審計中。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "dreamId": "2a528008111f5dc3500c73fd965089f7",
  "actionIds": ["968768529cdfde8d56686a71e1c28227", "a0f4715245920ea7b6a34c1828c6f1ae"]
}

響應樣本

{
  "memoryStoreName": "agent_memory",
  "dreamId": "2a528008111f5dc3500c73fd965089f7",
  "applied": 2,
  "failed": 0,
  "results": [
    { "actionId": "968768529cdfde8d56686a71e1c28227", "status": "applied", "memoryId": "bd14a67ed215c114896325d912c8fa71" },
    { "actionId": "a0f4715245920ea7b6a34c1828c6f1ae", "status": "applied", "memoryId": "fa253856113f78d51a3b84a1fdf2d110" }
  ]
}

EMIT_SKILLEMIT_PROFILE 動作由整理任務直接寫入,沒有手動 apply 流程,混入此類動作 ID 會被拒絕。actionIds 為空白數組時返回 403。

CancelMemoryDreamTask

取消尚未完成的記憶整理任務。

請求參數

欄位

類型

必填

說明

memoryStoreName

string

記憶庫名稱。

dreamId

string

整理任務 ID。

請求樣本

{
  "memoryStoreName": "agent_memory",
  "dreamId": "2a528008111f5dc3500c73fd965089f7"
}

響應樣本

{
  "memoryStoreName": "agent_memory",
  "dreamId": "2a528008111f5dc3500c73fd965089f7",
  "status": "cancelled",
  "taskType": "memory"
}

僅可取消未完成的任務;已進入終態(completedfailedcancelled)的任務,響應仍返回 200,status 保持原值,任務本身不做處理。