Download OpenAPI specification:
批量求一批对象实例的逻辑属性(指标 metric 或算子 operator)值。
逻辑属性不直接存在于数据源里,需要带参数计算,而参数往往藏在用户的自然语言里
(「最近一年」→ 时间窗、「按省份」→ 分析维度)。本接口先用大模型把 query
翻译成各属性的 dynamic_params,再批量取值,省掉调用方自己拼参数的工作。
对象类有哪些逻辑属性、各自需要什么参数,看
kn-explore.yaml 的 get_object_types 返回的
logic_properties[].parameters。
同一份文件里还有 POST /kn/query_metric:类级指标、或没绑到任何逻辑属性的
指标走它,直接按 metric_id 与 MetricDefinition 的口径取数。两条路的分工是
「实例 + 已绑逻辑属性 → logic-property-resolver,其余 → query_metric」;
已建模的指标一律不该用 run_sql 重写口径。指标清单来自 get_object_types
返回的 related_metrics。
认证:Authorization: Bearer <token>(OAuth access token 或 bak_ AppKey)。
query 的质量决定成败:参数由大模型从 query(必要时加
additional_context)里推断。查询里要含时间范围、统计维度等业务上下文,
否则会因缺参失败。
缺参返回 400,不是空结果:模型判定必需的 input 参数无法从查询推出时,
返回 400,details 里是 MISSING_INPUT_PARAMS 及逐属性的缺失说明。补上
上下文重试即可。
与之区分的是 500 DYNAMIC_PARAMS_GENERATION_FAILED:那是大模型或依赖服务
故障,不是调用方少给信息,重试或查服务状态。
结果与入参对齐:datas 与 _instance_identities 顺序一一对应,每项含
主键和本次请求的 properties。
| response_format | string Default: "json" Enum: "json" "toon" 响应格式。 |
object (BKNContext) BKN Trace business-provenance context identifying the business
conversation and interaction to which this call belongs. Required on
MCP business tools and REST execution APIs while capture is enabled
and Trace Core is available;
optional on REST reads and Naming it makes the call managed: the service records an Operation under that interaction and attempts to return a receipt and capture evidence. Omitting it entirely, or sending an empty object, makes an eligible REST read or proxy call ad hoc. Only those two shapes are ad hoc — one id without the other, or a misspelt field, is refused rather than quietly downgraded. Both required child fields are server-issued handles and must not be invented by the caller:
These handles are available only through the provenance MCP tool above.
The BKN Trace Core session APIs under | |
| kn_id required | string 知识网络 ID。 |
| ot_id required | string 对象类 ID。 |
| query required | string 用户查询。需要包含时间范围、统计维度、业务上下文,用于生成
|
required | Array of objects 对象实例标识数组,必须从上游取,不可自拼:先调
|
| properties required | Array of strings 要求值的逻辑属性名列表( |
| additional_context | string 补充上下文,如 timezone、instant、step 或对象属性,帮助模型生成更准的
|
| llm_model | string 覆盖用于生成动态参数的大模型;留空走系统默认大模型。 |
object (ResolveOptions) 高级选项。 |
{- "kn_id": "kn_medical",
- "ot_id": "ot_company",
- "query": "最近一年这些药企的药品上市数量和经营健康度",
- "_instance_identities": [
- {
- "company_id": "company_000001"
}, - {
- "company_id": "company_000002"
}
], - "properties": [
- "approved_drug_count",
- "business_health_score"
]
}{- "datas": [
- { }
], - "debug": {
- "dynamic_params": { },
- "agent_info": { },
- "now_ms": 0,
- "warnings": [
- "string"
], - "trace_id": "string"
}
}按已建模指标自身的口径计算取数,是 OT-first 指标路径的第 3 步:
search_schema / get_kn_detail 锁定对象类 → get_object_types 从
related_metrics 里选定 metric_id → 本接口计算。
与 logic-property-resolver 的分工:实例级、且已绑到逻辑属性的指标走那条
(它会先用大模型推参数);类级指标、或未绑逻辑属性的指标走本接口,参数
由调用方显式给出,不经大模型。
time 在指标没有时间维度(related_metrics[].time_dimension 为空)时可整体
省略。给了就要自洽:**省略 instant 等同于 instant=false(序列查询),
必须带 step**;instant=true 取单点(此时 step 被下游忽略);
start 与 end 要么都给要么都不给。step 大小写不敏感。
这些规则在本服务就地校验并返回 400,规则逐条对齐 ontology-query 的
validateMetricQueryRequest——本地比下游严会把合法调用误拒,比下游松只是
把同一个错误延后。
请求体与 ontology-query 的 MetricQueryRequestBody 同构;响应只保留结果序列,
不回带指标定义(related_metrics 里已经有了)。
| response_format | string Default: "json" Enum: "json" "toon" 响应格式。 |
| x-kn-id | string 知识网络 ID 的请求头写法;请求体里给了 |
| kn_id required | string 知识网络 ID。也可用 |
| metric_id required | string 指标 ID,取自 |
object (MetricTimeWindow) 时间窗。指标没有时间维度时可整体省略;给了就要自洽(见接口说明)。 | |
object 过滤条件,结构与 | |
| analysis_dimensions | Array of strings 分析维度(按维度拆分结果)。取值须来自
|
Array of objects 结果排序。 | |
object 对聚合结果过滤。 | |
| limit | integer 返回条数上限。 |
| fill_null | boolean Default: false 区间查询时,无数据的步长点是否补空。仅对序列查询有效,且必须同时给
|
{- "kn_id": "kn_supplychain",
- "metric_id": "metric_product_total"
}{- "kn_id": "string",
- "metric_id": "string",
- "datas": [
- {
- "labels": {
- "property1": "string",
- "property2": "string"
}, - "times": [
- null
], - "time_strs": [
- "string"
], - "values": [
- null
], - "growth_values": [
- null
], - "growth_rates": [
- null
], - "proportions": [
- null
]
}
], - "overall_ms": 0
}