> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memorylake.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 添加记忆

> 提交对话以提取并存储记忆

```
POST /openapi/memorylake/api/v2/projects/{id}/memories
```

向项目提交一段用户与助手的对话。系统会自动从消息中提取结构化记忆并异步存储。响应包含一个事件 ID，可用于跟踪处理进度。

<Note>
  **所需权限：** [`project:mem_add`](/zh/features/team-collaboration/permission-reference#通过-api-添加事实（仅-api）) · `instance`
</Note>

### 路径参数

<ParamField path="id" type="string" required>
  项目 ID（格式：`proj-{uuid}`）
</ParamField>

### 请求体

<ParamField body="messages" type="array" required>
  表示对话的消息对象数组。每条消息包含 `role`（`user` 或 `assistant`）和 `content`。
</ParamField>

<ParamField body="user_id" type="string">
  与此记忆关联的用户唯一标识符
</ParamField>

<ParamField body="chat_session_id" type="string">
  聊天会话的唯一标识符
</ParamField>

<ParamField body="infer" type="boolean" default="true">
  是否从消息中推断记忆，还是直接存储消息。默认为 `true`（推断模式）。
</ParamField>

<ParamField body="metadata" type="object">
  附加的任意元数据键值对
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://app.memorylake.ai/openapi/memorylake/api/v2/projects/proj-a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/memories' \
    -H 'Authorization: Bearer sk_xxxxxx' \
    -H 'Content-Type: application/json' \
    -d '{
      "messages": [
        {"role": "user", "content": "What restaurants do you recommend in Hangzhou?"},
        {"role": "assistant", "content": "I recommend trying Grandma'\''s Kitchen for Hangzhou cuisine and Green Tea Restaurant for a modern take on local dishes."}
      ],
      "user_id": "user-abc123",
      "chat_session_id": "session-abc123",
      "infer": true
    }'
  ```
</RequestExample>

### 响应

<ResponseField name="data" type="object">
  <Expandable title="添加记忆结果">
    <ResponseField name="results" type="array">
      异步处理结果数组

      <Expandable title="结果条目">
        <ResponseField name="message" type="string">状态消息</ResponseField>
        <ResponseField name="status" type="string">处理状态（例如 `PENDING`）</ResponseField>
        <ResponseField name="event_id" type="string">用于跟踪处理进度的事件 ID</ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "success": true,
    "message": "Operation completed successfully",
    "data": {
      "results": [
        {
          "message": "Memory processing has been queued for background execution",
          "status": "PENDING",
          "event_id": "97ba056d-df1b-4236-886a-4db825f29227"
        }
      ]
    }
  }
  ```
</ResponseExample>
