You need to enable JavaScript to run this app.
文档中心
向量数据库VikingDB

向量数据库VikingDB

复制全文
下载 pdf
用户管理(Users)
UpdateOpenVikingUserMemoryPolicy - 更新 OpenViking User 记忆策略
复制全文
下载 pdf
UpdateOpenVikingUserMemoryPolicy - 更新 OpenViking User 记忆策略

概述

查询指定数据空间中某个 User 当前生效的记忆策略。

前置条件

完成 "数据库管理使用说明" 页面的 AK/SK 获取后,可调用本接口。当前库版本需为企业版(enterprise),调用者需具备管理员权限。

请求接口

Action

UpdateOpenVikingUserMemoryPolicy

请求方法

POST

Content-Type

application/json

请求参数

参数

类型

是否必填

说明

ResourceID

String

是

OpenViking 库 ID。

AccountID

String

否

User 所属的数据空间 ID,缺省为 default。

UserID

String

是

要更新的 User ID。

MemoryPolicy

Object

是

更新后的 User 记忆策略,不能传 null。

MemoryPolicy.MemoryTypes

Array of String

是

更新后允许抽取的记忆类型。支持传空数组。

MemoryPolicy

User 记忆策略使用以下结构:

{
  "MemoryTypes": [
    "profile",
    "preferences",
    "events",
    "entities",
    "cases",
    "trajectories",
    "experiences"
  ]
}

当前支持的记忆类型如下:

取值

说明

profile

用户画像与长期稳定信息。

preferences

用户偏好、习惯和倾向。

events

用户相关事件、决定和阶段性信息。

entities

用户提及的重要人物、组织、地点、产品等实体。

cases

Agent 任务案例。

trajectories

Agent 执行轨迹。

experiences

从任务执行中沉淀的 Agent 经验。

注意事项:

  • MemoryTypes 按集合处理,返回顺序不表示优先级。
  • 重复的记忆类型会被去重。
  • MemoryTypes: [] 表示该 User 不启用任何可配置的长期记忆类型;该设置不影响 Session 消息保存。
  • 未传 MemoryPolicy 创建 User 时,默认启用当前全部 7 种记忆类型。
  • User 记忆策略变更只影响后续 Session Commit,不会重新处理已经生成的记忆文件。
  • cases、trajectories 和 experiences 作为一组 Agent 自进化记忆生效。配置 experiences 时,系统会同时启用 cases 和 trajectories;未配置 experiences 时,这三种类型均不生效,不能单独开启其中一种。
  • Agent 自进化记忆除了需要在 User 策略中启用,还要求对应数据空间已开启 Agent 自进化。

响应参数

参数

类型

说明

UserID

String

User ID。

MemoryPolicy

Object

当前生效的 User 记忆策略。

MemoryPolicy.MemoryTypes

Array of String

当前允许抽取的记忆类型。

请求示例

Python 请求示例

import os
import datetime
import hashlib
import hmac
from urllib.parse import quote

import requests, json

def norm_query(params):
    query = ""
    for key in sorted(params.keys()):
        if type(params[key]) == list:
            for k in params[key]:
                query = (
                        query + quote(key, safe="-_.~") + "=" + quote(k, safe="-_.~") + "&"
                )
        else:
            query = (query + quote(key, safe="-_.~") + "=" + quote(params[key], safe="-_.~") + "&")
    query = query[:-1]
    return query.replace("+", "%20")

def hmac_sha256(key: bytes, content: str):
    return hmac.new(key, content.encode("utf-8"), hashlib.sha256).digest()

def hash_sha256(content: str):
    return hashlib.sha256(content.encode("utf-8")).hexdigest()

class ClientForConsoleApi:
    def __init__(self, ak, sk, host, region):
        self.ak = ak
        self.sk = sk
        self.host = host
        self.region = region
        self.service_code = "vikingdb"
        self.version = "2025-06-09"

    def request(self, method, action, body, query=None, header=None):
        if query is None:
            query = {}
        if header is None:
            header = {}
        credential = {
            "access_key_id": self.ak,
            "secret_access_key": self.sk,
            "service": self.service_code,
            "region": self.region,
        }
        request_param = {
            "body": json.dumps(body),
            "host": self.host,
            "path": "/",
            "method": method,
            "content_type": 'application/json',
            "date": datetime.datetime.utcnow(),
            "query": {"Action": action, "Version": self.version, **query},
        }
        if body is None:
            request_param["body"] = ""
        x_date = request_param["date"].strftime("%Y%m%dT%H%M%SZ")
        short_x_date = x_date[:8]
        x_content_sha256 = hash_sha256(request_param["body"])
        sign_result = {
            "Host": request_param["host"],
            "X-Content-Sha256": x_content_sha256,
            "X-Date": x_date,
            "Content-Type": request_param["content_type"],
        }
        signed_headers_str = ";".join(
            ["content-type", "host", "x-content-sha256", "x-date"]
        )
        canonical_request_str = "\n".join(
            [request_param["method"].upper(),
             request_param["path"],
             norm_query(request_param["query"]),
             "\n".join(
                 [
                     "content-type:" + request_param["content_type"],
                     "host:" + request_param["host"],
                     "x-content-sha256:" + x_content_sha256,
                     "x-date:" + x_date,
                 ]
             ),
             "",
             signed_headers_str,
             x_content_sha256,
             ]
        )

        hashed_canonical_request = hash_sha256(canonical_request_str)
        credential_scope = "/".join([short_x_date, credential["region"], credential["service"], "request"])
        string_to_sign = "\n".join(["HMAC-SHA256", x_date, credential_scope, hashed_canonical_request])

        k_date = hmac_sha256(credential["secret_access_key"].encode("utf-8"), short_x_date)
        k_region = hmac_sha256(k_date, credential["region"])
        k_service = hmac_sha256(k_region, credential["service"])
        k_signing = hmac_sha256(k_service, "request")
        signature = hmac_sha256(k_signing, string_to_sign).hex()

        sign_result["Authorization"] = "HMAC-SHA256 Credential={}, SignedHeaders={}, Signature={}".format(
            credential["access_key_id"] + "/" + credential_scope,
            signed_headers_str,
            signature,
        )
        header = {**header, **sign_result}
        r = requests.request(method=method,
                             url="https://{}{}".format(request_param["host"], request_param["path"]),
                             headers=header,
                             params=request_param["query"],
                             data=request_param["body"],
                             )
        return r.status_code, r.headers, r.json()

if __name__ == '__main__':
    client = ClientForConsoleApi(
        ak = "*",#替换为您的 AK
        sk ="*" ,#替换为您的 SK
        host="vikingdb.cn-beijing.volcengineapi.com", #替换为您所在地区的域名
        region="cn-beijing"
    )
    http_code, _, result_json = client.request(
        method="POST",
        action="UpdateOpenVikingUserMemoryPolicy",#action替换为当前操作
        body={
          "ResourceID": "ov-xxxxxxxxxxxxxxxx",
          "AccountID": "default",
          "UserID": "user_001",
          "MemoryPolicy": {
            "MemoryTypes": [
              "profile",
              "preferences",
              "events",
              "entities"
            ]
          }
}
    )
    print("req http status code: ", http_code)
    print("req result: \n", result_json)

响应示例
{
  "ResponseMetadata": {
    "RequestId": "20260904120000XXXXXXXXXXXXXXXX",
    "Action": "UpdateOpenVikingUserMemoryPolicy",
    "Version": "2025-06-09",
    "Service": "vikingdb",
    "Region": "cn-beijing"
  },
  "Result": {
    "UserID": "user_001",
    "MemoryPolicy": {
      "MemoryTypes": [
        "entities",
        "events",
        "preferences",
        "profile"
      ]
    }
  }
}

错误码

HTTP 状态码

错误码

说明

400

InvalidParameter

请求参数、AccountID、UserID 或 MemoryPolicy 非法。

403

AccessDenied

当前账号无权操作该 OpenViking 库。

404

ResourceNotExist

指定的库、数据空间或 User 不存在。

409

OperationConflict

当前存在冲突的更新操作。

412

FailedPrecondition

当前资源状态不允许更新。

500

InternalError

服务内部错误。

最近更新时间:2026.09.11 16:21:09
这个页面对您有帮助吗?
有用
有用
无用
无用