> ## 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/search
```

使用自然语言在项目中搜索记忆。可以按用户筛选结果、设置分数阈值限制，并可选择重排序以获得更高的相关性。

<Note>
  **所需权限：** [`project:mem_search`](/zh/features/team-collaboration/permission-reference#搜索事实) · `instance`
</Note>

### 路径参数

<ParamField path="id" type="string" required>
  项目 ID
</ParamField>

### 请求体

<ParamField body="query" type="string" required>
  搜索查询文本
</ParamField>

<ParamField body="user_id" type="string" required>
  按用户 ID 筛选
</ParamField>

<ParamField body="top_k" type="integer" default="10">
  返回的最大结果数（1–1000）
</ParamField>

<ParamField body="threshold" type="number" default="0.3">
  最低相似度分数阈值。低于此分数的结果将被过滤掉。
</ParamField>

<ParamField body="rerank" type="boolean" default="false">
  是否应用重排序以提高结果相关性
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://app.memorylake.ai/openapi/memorylake/api/v2/projects/proj-a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6/memories/search' \
    -H 'Authorization: Bearer sk_xxxxxx' \
    -H 'Content-Type: application/json' \
    -d '{
      "query": "What restaurants were recommended?",
      "user_id": "user-abc123",
      "top_k": 10,
      "threshold": 0.3,
      "rerank": false
    }'
  ```
</RequestExample>

### 响应

<ResponseField name="data" type="object">
  <Expandable title="搜索结果">
    <ResponseField name="results" type="array">
      按相关性排序的匹配记忆列表

      <Expandable title="记忆结果">
        <ResponseField name="id" type="string">记忆 ID</ResponseField>
        <ResponseField name="content" type="string">记忆内容</ResponseField>
        <ResponseField name="user_id" type="string">关联的用户 ID</ResponseField>
        <ResponseField name="created_at" type="string">创建时间戳</ResponseField>
        <ResponseField name="updated_at" type="string">最后更新时间戳</ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json Success (200) theme={null}
  {
    "success": true,
    "data": {
      "results": [
        {
          "id": "mem-123",
          "content": "User prefers Hangzhou cuisine restaurants",
          "user_id": "user-abc123",
          "created_at": "2024-01-15T10:00:00Z",
          "updated_at": "2024-01-15T10:00:00Z"
        }
      ]
    }
  }
  ```
</ResponseExample>
