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

# 检索对话记忆 - POST /v1/workspaces/:workspace_id/chat-memories/search

> 通过 POST /v1/workspaces/:workspace_id/chat-memories/search 分层检索对话记忆，带预算控制。最小角色 viewer。

在工作空间的分层对话记忆中做语义检索，并返回命中结果与字符预算（用于把记忆注入上下文时控制长度）。

## 接口

```http theme={null}
POST /v1/workspaces/:workspace_id/chat-memories/search
```

## 认证

`Authorization: Bearer <jwt>` 或 `X-API-Key <sk_...>`。最小角色：**viewer**。

## 路径参数

<ParamField path="workspace_id" type="string" required>
  工作空间 id。
</ParamField>

## 请求体

<ParamField body="query" type="string">
  检索文本，省略时回退到查询参数 `query`。
</ParamField>

<ParamField body="max_items" type="integer">
  返回的最大记忆条数。
</ParamField>

<ParamField body="max_chars" type="integer">
  返回内容的最大字符数预算。
</ParamField>

## 响应

<ResponseField name="hits" type="array">
  命中记忆数组，每项含 `content` 等字段。
</ResponseField>

<ResponseField name="budget" type="object">
  预算统计。

  <Expandable title="budget">
    <ResponseField name="items" type="integer">
      实际返回的条数。
    </ResponseField>

    <ResponseField name="chars" type="integer">
      返回内容的总字符数。
    </ResponseField>
  </Expandable>
</ResponseField>

## 示例

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://memo.ariacompute.cn/v1/workspaces/ws_01a2b3c4d5e6/chat-memories/search \
    -H "Authorization: Bearer <jwt>" \
    -H "Content-Type: application/json" \
    -d '{"query":"用户的身份与偏好","max_items":10,"max_chars":2000}'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "hits": [
      {
        "id": "cm_01a2b3c4d5e6",
        "content": "用户是开发者，关注定价与集成。",
        "layer": 3,
        "kind": "persona"
      }
    ],
    "budget": { "items": 1, "chars": 18 }
  }
  ```
</ResponseExample>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.