# 知识资源

> 知识资源是供 AI 节点读取的受治理内容，例如分类体系、数据集或政策。发布时会记录一个编号版本，绑定关系显示它被用在哪里，Git Sync 可以把它保存在代码仓库中。

Source: https://docs.sommatic.ai/zh/ai/knowledge-resources/ (updated 2026-11-26)

知识资源是 AI 节点知道而模型本身不知道的东西：你用来分诊的类别、用来比对的登记表、决策必须遵循的政策。它在组织中只保存一份，有负责人和审核状态，所有需要它的节点都指向它。

## 资源类型

`resource_type` 说明内容是什么：

| `resource_type` | 典型内容                                         |
| --------------- | -------------------------------------------- |
| `text`          | 自由文本。                                        |
| `document`      | 文档或文件引用。                                     |
| `list`          | 一组取值。                                        |
| `taxonomy`      | 类别与子类别。                                      |
| `prompt`        | 结构化提示词块（`system`、`instructions`、`examples`）。 |
| `policy`        | 决策必须遵循的规则。                                   |
| `manual`        | 操作说明。                                        |
| `dataset`       | 小型结构化数据集。                                    |
| `reference`     | 指向外部或内部来源的引用。                                |

你可以从空白、文本、文件或结构化数据开始创建资源。

## 内容

`content` 保存实际内容，格式（`content.format`）为以下之一：`plain-text`、`markdown`、`json`、`file-reference`、`prompt-blocks` 或 `url`。

| 字段                | 用途                                                                                   |
| ----------------- | ------------------------------------------------------------------------------------ |
| `text`            | 纯文本或 Markdown 文本。                                                                    |
| `structured_data` | 用于列表、分类体系、规则或数据集的 JSON。                                                              |
| `file_ref`        | 已存储的文件：`file_name`、`mime_type`、`storage_key`、`document_uri`、`checksum`、`size_bytes`。 |
| `prompt_blocks`   | 类型为 `prompt` 时的 `system`、`instructions` 和 `examples`。                                |
| `url`             | 内容为引用时的链接。                                                                           |

除内容外，资源还包含：

- **治理**（`governance`）：负责的用户或团队、`visibility_scope`（`private`、`team`、`organization`）、`review_status`（`draft`、`reviewed`、`approved`、`rejected`）、`is_authoritative`，以及日期 `effective_from`、`effective_to` 和 `expires_at`。
- **能力**（`capabilities`）：`allowed_usage_modes`（`retrieval`、`context`、`instruction`、`routing`、`validation`、`few-shot`、`reference`）、`is_searchable`、`is_bindable`、`is_version_locked`。
- **来源**（`source`）：内容从哪里来，`sync_mode` 为 `manual`、`synced` 或 `imported`。
- `language`、`tags` 和 `git_binding`（由 Git Sync 填写）。

## 发布版本

资源的状态为 `draft`、`active` 或 `archived`。发布会做两件事：

1. 把当前 `content` 保存为下一个不可修改的版本快照（`1`、`2`、`3`……），可附带 `description`。
2. 把资源设为 `active`。

### 编辑资源

在控制台中打开 **Cognitive Assets → Knowledge Center**，再打开目标资源。在 **Knowledge Editor** 标签页中编辑并保存。

### 发布

在编辑器中发布。通过 API：`POST /cognitive-infrastructure/cognitive-assets/knowledge-resource/:id/publish`。

### 查看版本列表

`GET /cognitive-infrastructure/cognitive-assets/knowledge-resource/versions?search=<resource_id>` 返回每个快照的 `version`、`content`，以及来自 Git 时对应的提交。

> **注意: 节点读取的是当前内容**
>
> AI 节点运行时加载的是资源本身，而不是已发布的快照。保存的修改会立即作用于下一次运行。资源不是 `active` 状态时节点会给出警告，资源已删除时节点会失败。版本是你的历史记录和审计依据，保存前请先审阅。

## 在节点中使用

读取资源的节点提供 `knowledge_resource_id`，其选择器按节点接受的类型过滤：

| 节点                                                                                  | 期望的资源                       |
| ----------------------------------------------------------------------------------- | --------------------------- |
| [`ai.classify.triage`](https://docs.sommatic.ai/zh/nodes/ai.classify.triage.md)     | 包含分诊类别与子类别的 `taxonomy`（必填）。 |
| [`ai.classify.registry`](https://docs.sommatic.ai/zh/nodes/ai.classify.registry.md) | 用于比对分类的 `dataset`（必填）。      |
| [`ai.topics`](https://docs.sommatic.ai/zh/nodes/ai.topics.md)                       | 主题的 `taxonomy`。             |

## 绑定关系

绑定关系记录某个资源在哪里被使用。它包含 `resource_id`、`target_type`、`target_id`、`role` 和 `mode`：

| 字段            | 取值                                                                                           |
| ------------- | -------------------------------------------------------------------------------------------- |
| `target_type` | `project`、`workflow`、`workflow-node`、`agent-profile`、`app`、`conversation`、`report`、`anomaly` |
| `role`        | `knowledge`、`policy`、`instructions`、`dataset`、`template`、`reference`                         |
| `mode`        | `retrieval`、`context`、`both`、`instruction`、`routing`、`validation`                            |

在工作流 Studio 中保存草稿时，Sommatic AI 会让该工作流的绑定关系与节点保持一致：节点引用的每个资源对应一条绑定（`target_type: workflow`、`role: knowledge`、`mode: context`），不再有节点使用该资源时绑定会被移除。资源页面会列出它的绑定关系，修改前就能看到哪些工作流依赖它。

## 存放在 Git 中

知识资源与工作流一样可以通过 [Git Sync](https://docs.sommatic.ai/zh/git-sync.md) 同步。在仓库中，资源文件包含资源字段（`name`、`slug`、`resource_type`、`content` 等）以及头部 `{ "sommatic": { "kind": "knowledge-resource", "key": "…", "schema_version": "1.0" } }`，并在包清单的 `resources.knowledge` 中登记。

在资源页面的 **…** 菜单中，**Sync from Git…** 会把文件加载到编辑器（随后保存并发布），**Export for Git…** 会给出文件、清单条目和环境条目，可直接用于 Pull Request。从 Git 同步时可以同时发布，此时版本会记录其来源的仓库、分支和提交。

## 下一步

- [Git Sync](https://docs.sommatic.ai/zh/git-sync.md): 在 Pull Request 中审阅知识变更。
- [AI 节点](https://docs.sommatic.ai/zh/nodes/family/ai.md): 读取知识资源的节点。
- [API 参考](https://docs.sommatic.ai/zh/api/reference/cognitive-infrastructure.md): 资源、版本与绑定关系。
