You need to enable JavaScript to run this app.
向量数据库VikingDB

向量数据库VikingDB

复制全文
记忆检索
获取上下文-GetContext
复制全文
获取上下文-GetContext

接口概述

根据 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
画像记忆的检索设置。

说明:

  • 检索画像:user_id 和 assistant_id 至少填写一个,也可同时填写。

响应消息
参数名称
参数类型
参数说明
code
Integer
状态码,0表示成功,其他表示错误。
message
String
返回信息。
data
Object
返回的详细检索结果。
request_id
String
标识每个请求的唯一ID。

示例代码

Python请求

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)
最近更新时间:2026.03.16 17:42:55
这个页面对您有帮助吗?
有用
有用
无用
无用