上下文加载 · Schema 检索 API (0.1.3)

Download OpenAPI specification:

Context Loader(服务名 agent-retrieval)的 Schema 探索入口:把一句自然语言 映射到知识网络里的概念(对象类 / 关系类 / 行动类 / 指标类),供 Agent 据此决定下一步调哪个查询接口。

两个端点的分工:

端点 定位 建议
POST /kn/search_schema 标准契约,Schema-only 新接入方用这个
POST /kn/kn_search 兼容壳,吸收旧字段;可选开语义实例召回 仅存量调用方

search_schema 固定为 Schema-only:不返回实例数据,也不承担实例检索。 kn_search 默认同样只回 Schema,只有显式传 only_schema: false 时才在概念命中的 基础上做一轮语义实例召回,并把命中实例放在 nodes 里。参与召回的只有 condition_operations 里带 match / knn / == 的属性——没建索引的对象类不出实例。

拿到概念后,实例数据也可以走 object-instance.yaml、instance-subgraph.yaml, 或 data-access.yaml 的 run_sql。

响应格式:本模块所有端点都支持 ?response_format=toon,返回 application/toon(同构数组压成表格,比 JSON 省 token);默认 json。

认证:Authorization: Bearer <token>,token 为 OAuth access token 或用户自助 签发的 AppKey(bak_ 前缀)。账户身份由服务端从凭据解析,调用方不需要也 不应该自己传 x-account-id。

SchemaSearch

探索知识网络 Schema

统一的 Schema 探索入口。适用于还不确定该继续调用哪个 query_* / find_* / get_* 接口时,先探索相关概念。

**写 SQL 时注意 include_columns**:data_properties[].name 是逻辑名, 物理列名在 mapped_field 里,二者可以不同(同一份资源可被多个对象类以不同 逻辑名映射)。要用 run_sql 直查时置 include_columns=true 拿物理列名。

Authorizations:
OAuth2AppKey
query Parameters
response_format
string
Default: "json"
Enum: "json" "toon"

响应格式。toon 返回 application/toon,同构数组压成表格,省 token。

header Parameters
x-kn-id
string

知识网络 ID 的 header 形式,供无法改请求体的调用方(如 MCP 客户端固定 注入 header)使用;与请求体的 kn_id 二选一,请求体优先。

Request Body schema: application/json
required
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 /mcp/proxy/.../call. A verified disabled capture policy admits business calls without this context because no Conversation or Interaction IDs are issued. A verified Trace Core infrastructure outage also admits unrecorded REST execution after a bounded, read-only availability probe.

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:

  • conversation_id: obtained from the Context Loader MCP tool bkn_start_interaction on the first turn
  • interaction_id: obtained from the Context Loader MCP tool bkn_start_interaction

These handles are available only through the provenance MCP tool above. The BKN Trace Core session APIs under /api/agent-observability/v1 accept gateway credentials only from trusted in-cluster services. They do not accept OAuth tokens or bak_ AppKeys; direct external calls receive 401 permission_denied. Context Loader derives the Operation idempotency identity on the server from request correlation, tool name, and normalized input. Callers must not submit operation_key. Network retries should reuse bkn-request-id or provide a stable X-OpenBKN-Client-Invocation-Id for the same logical call. This hint is used only for idempotency and has no role in identity, authorization, or data-isolation decisions.

query
required
string

用户查询问题或关键词。

kn_id
string

知识网络 ID。与 x-kn-id 头二选一,本字段优先。

object (SearchSchemaScope)

Schema 探索范围。不传时四类概念全开。四个开关不能同时为 false,否则返回 400。

search_scope 只约束响应输出,不阻断系统内部用相关线索辅助召回。

max_concepts
integer >= 1
Default: 10

每类概念的候选规模上限。

schema_brief
boolean
Default: false

是否只返回精简 Schema;默认返回相对完整的 Schema。

enable_rerank
boolean
Default: true

是否对关系类做精排。

rerank_model
string

覆盖本次请求的精排小模型名。运维 / 高级用户的逃生口,留空走部署级默认 (concept_search_config.rerank_model)。不建议由 Agent 自行选择模型名。

include_columns
boolean
Default: false

是否在每个对象类的 data_properties 上附带物理列名(取自 mapped_field)。 写 run_sql 需要物理列名时置 true;默认 false 以保持响应精简。

enum_query
string

按显示名或编码检索枚举项,多个词用空格隔开,任一词命中即返回。用于没有展开的枚举: 超过展开上限(默认 50 项)的大字典,以及精简模式下的所有枚举。不传时这些枚举只给 value_type 与 enum_count。命中超过展开上限时只列前面一部分,另给 enum_match_count 表示命中总数。

Responses

Request samples

Content type
application/json
Example
{
  • "kn_id": "kn_medical",
  • "query": "最近半年哪些药品的不良反应上报最多"
}

Response samples

Content type
{
  • "object_types": [
    ],
  • "relation_types": [
    ],
  • "action_types": [
    ],
  • "metric_types": [
    ],
  • "nodes": [
    ],
  • "message": "string"
}

探索知识网络 Schema(兼容接口)

兼容历史 kn_search 调用方式的接口。底层与 search_schema 共用同一套逻辑, 默认输出同样收敛为 Schema 结果。

兼容边界:

  • only_schema 缺省按 true 处理,行为与 search_schema 一致;显式传 false 才额外做语义实例召回,命中实例放在 nodes,无命中时给 message;
  • 实例召回失败不影响本次调用:降级为只回 Schema,不报错;
  • retrieval_config 里只有 concept_retrieval.top_k、 concept_retrieval.schema_brief 会被吸收,其余字段被忽略。

只要 Schema 的新接入方请直接用 POST /kn/search_schema。

Authorizations:
OAuth2AppKey
query Parameters
response_format
string
Default: "json"
Enum: "json" "toon"

响应格式。toon 返回 application/toon,同构数组压成表格,省 token。

Request Body schema: application/json
required
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 /mcp/proxy/.../call. A verified disabled capture policy admits business calls without this context because no Conversation or Interaction IDs are issued. A verified Trace Core infrastructure outage also admits unrecorded REST execution after a bounded, read-only availability probe.

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:

  • conversation_id: obtained from the Context Loader MCP tool bkn_start_interaction on the first turn
  • interaction_id: obtained from the Context Loader MCP tool bkn_start_interaction

These handles are available only through the provenance MCP tool above. The BKN Trace Core session APIs under /api/agent-observability/v1 accept gateway credentials only from trusted in-cluster services. They do not accept OAuth tokens or bak_ AppKeys; direct external calls receive 401 permission_denied. Context Loader derives the Operation idempotency identity on the server from request correlation, tool name, and normalized input. Callers must not submit operation_key. Network retries should reuse bkn-request-id or provide a stable X-OpenBKN-Client-Invocation-Id for the same logical call. This hint is used only for idempotency and has no role in identity, authorization, or data-isolation decisions.

query
required
string

用户查询问题或关键词。

kn_id
required
string

知识网络 ID。

object (KnSearchScope)

kn_search 的检索范围。只有 concept_groups 生效——本接口从不按概念类型过滤 响应,需要按类型裁剪请用 search_schema 的 search_scope。

object or null

检索参数。concept_retrieval 下仅 top_k 与 schema_brief 被吸收; semantic_instance_retrieval 下的实例召回参数生效,其中与相关性直接相关的是:

  • instance_rerank_mode:off(默认)/ on / shadow。shadow 调模型但不改 顺序,只记录两个序的差异,用于在改默认值之前取证。
  • min_reranker_score:相关性闸门。低于该分的实例被丢弃;一条都不达标时返回空, 并在 message 里说明最高分是多少。传 0(默认)则沿用部署配置 instance_search_config.min_reranker_score,后者为 0 时闸门关闭。

闸门自带模型:设了 min_reranker_score 就会为本次查询开启精排——融合分表达的是 通道一致性而非绝对相关度(某通道第一名恒得 1.0),只有精排分能回答「这批到底相不相关」。 代价是每次实例查询多一次模型调用。

阈值不可跨部署照抄:实测两套自有环境上,「明显相关」的精排分一套在 0.16 量级、 另一套在 0.74 量级。校准方法是各跑几条该网络答得上和答不上的 query,取两段分数之间的值。

精排不可用、或模型对所有候选给出同一个分数时,闸门不过滤并在 message 里说明—— 没有判断就不能假装筛过。

only_schema
boolean
Default: true

缺省 true,只回 Schema。传 false 时在概念命中的基础上做一轮语义实例 召回,结果放在 nodes。只有 condition_operations 含 match / knn / == 的属性参与召回,因此没建索引的对象类不会出实例。

enable_rerank
boolean
Default: true

是否对关系类做精排。

rerank_model
string

覆盖精排小模型名;留空走部署级默认。

include_columns
boolean
Default: false

是否附带物理列名。

enum_query
string

按显示名或编码检索未展开枚举的枚举项。

Responses

Request samples

Content type
application/json
{
  • "kn_id": "kn_medical",
  • "query": "药品不良反应",
  • "only_schema": true,
  • "retrieval_config": {
    }
}

Response samples

Content type
{
  • "object_types": [
    ],
  • "relation_types": [
    ],
  • "action_types": [
    ],
  • "metric_types": [
    ],
  • "nodes": [
    ],
  • "message": "string"
}