CreateOpenVikingCollection 用于在您的账号下创建 OpenViking 库。创建时,需要指定库名称、库版本,并分别配置 VLM 模型和 Embedding 模型。首次接入可直接参考本文的“请求示例”,替换库名称、模型 API Key 和模型接入点 ID 后调用。
注意
创建库为异步操作。接口返回 Success: true 仅表示创建请求已受理,不代表库已就绪。
创建后,请使用返回的 ResourceID 调用 GetOpenVikingCollection,轮询 Result.Status。
库状态流转:INIT(初始化中)→ READY(就绪)或 FAILED(初始化失败)。
说明
使用接口创建库暂不支持指定数据库服务的结算方式,仅支持使用火山余额结算,不能配置使用 AgentPlan 个人版或企业版结算。如果希望创建 AgentPlan 结算的数据库,或修改数据库结算方式,请登录控制台操作。见 计费说明。
EndpointID。注意区分两类凭证:
凭证 | 用途 | 填写位置 |
|---|---|---|
火山引擎 AK/SK | 对创建库接口进行签名鉴权 | 用于生成请求签名,不填入模型配置 |
模型 API Key | 供 OpenViking 调用 VLM、Embedding 模型(通过 AgentPlan,CodingPlan,或方舟推理接入点) | 请求体中的 |
Action | CreateOpenVikingCollection |
|---|---|
请求方法 | POST |
Content-Type | application/json |
字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| string | 是 | 自定义库名,以字母开头,仅含字母/数字/ |
| string | 是 | 库版本,枚举: |
| object | 是 | VLM 模型配置(见「模型配置」) |
| object | 是 | Embedding 模型配置(见「模型配置」) |
| string | 否 | 项目名,默认 |
| string | 否 | 描述,≤65535 字符 |
| string | 否 | 语言配置,枚举 |
配置 OpenViking Context 记忆抽取、知识解析和摘要生成的 VLM 模型和向量化的 Embedding 模型。
字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| string | 是 | 模型名,当前仅支持固定值:
|
| string | 否 | 模型版本 |
| array[Credentials] | 推荐 | 有序凭证列表(支持多凭证 failover),模型调用时,使用Credentials配置的顺序请求,支持 AgentPlan,CodingPlan 和 方舟模型推理接入点。 |
可配置模型使用什么渠道接入和结算,支持配置多个,按列表顺序优先消耗。
字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| string | 是 | 模型凭证来源,列表内不可重复,枚举值: |
| string | 条件必填 | 填入模型接入方式的API Key。 |
| string | 条件必填 | Source为 |
字段 | 类型 | 说明 |
|---|---|---|
| string | 新建库 ID |
| bool | 是否成功 |
HTTP 状态码 | 错误码 | 说明 |
|---|---|---|
400 |
| 请求参数非法、User 已存在,或者不支持显式设置 User MemoryPolicy |
400 |
| 缺少必填参数 |
401 |
| 请求签名缺失或无效 |
403 |
| 身份校验失败 |
403 |
| 当前账号无权操作该 OpenViking 库 |
429 |
| User 数量或创建频率超过配额,或触发限流 |
500 |
| 服务内部错误 |
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="CreateOpenVikingCollection",#action替换为当前操作 body={ "Name": "my_collection", "Version": "enterprise", "Project": "default", "Description": "示例库", "VLM": { "ModelName": "doubao-seed-2.0-lite", "Credentials":[ { "Source":"agentplan", "APIKey":"your-eagentplan-api-key" }, { "Source":"volcengine", "EndpointID": "your-endpoint-id", "APIKey":"your-endpoint-api-key" } ] }, "Embedding": { "ModelName": "doubao-embedding-vision", "Credentials":[ { "Source":"agentplan", "APIKey":"your-eagentplan-api-key" }, { "Source":"volcengine", "EndpointID": "your-endpoint-id", "APIKey":"your-endpoint-api-key" } ] } } ) print("req http status code: ", http_code) print("req result: \n", result_json)
{ "ResponseMetadata": { "RequestId": "202506091030001A2B3C4D5E6F", "Action": "CreateOpenVikingCollection", "Version": "2025-06-09", "Service": "vikingdb", "Region": "cn-beijing" }, "Result": { "ResourceID": "ov-20250609abcde--1", "Success": true } }