根据 conversation_id,同时获取短期和长期记忆,且可直接拼接到对话模型的 prompt 内使用。包括:1)该 conversation_id 下最近 N 轮原始消息;2)该 conversation_id 下的事件记忆,全部返回;3)该 conversation 外的事件记忆,通过检索返回;4)用户画像记忆,通过检索返回
URL | /api/memory/get_context | 统一资源标识符 |
|---|---|---|
请求方法 | POST | 客户端对记忆库服务器请求的操作类型 |
请求头 | Content-Type: application/json | 请求消息类型 |
Authorization: HMAC-SHA256 *** | 基于AK/SK生成的签名信息 |
参数名称 | 参数类型 | 是否必须 | 参数说明 |
|---|---|---|---|
collection_name | String | 否 | 目标记忆库的名称。 |
project_name | String | 否 | 记忆库所属项目。 |
resource_id | String | 否 | 记忆库唯一的资源id。可选择直接传resource_id,或同时传collection_name和project_name作为记忆库的唯一标识。 |
conversation_id | String | 是 | 当前对话会话ID。长度要求: [1, 128],只能使用英文字母、数字、下划线,并以英文字母开头。 |
query | String | 是 | 用户的检索查询语句。 |
event_search_config | Object | 否 | 事件记忆的检索设置。 |
profile_search_config | Object | 否 | 画像记忆的检索设置。 |
说明:
参数名称 | 参数类型 | 参数说明 |
|---|---|---|
code | Integer | 状态码,0表示成功,其他表示错误。 |
message | String | 返回信息。 |
data | Object | 返回的详细检索结果。 |
request_id | String | 标识每个请求的唯一ID。 |
import os import requests import json API_KEY = os.getenv("MEMORY_API_KEY", "your_key") url = "https://api-knowledgebase.mlp.cn-beijing.volces.com/api/memory/profile/search" headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } data = { "collection_name": "test", "conversation_id": "conversation_001", "query": "天气", "event_search_config":{ "filter": { "user_id": "user_01", "memory_type": ["event_v1"] }, "limit": 10 } "profile_search_config":{ "filter": { "user_id": "user_01", "memory_type": ["profile_v1"] }, "limit": 1 } } response = requests.post(url, headers=headers, data=json.dumps(data)) print("Status Code:", response.status_code) print("Response:", response.text)