> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fetchhive.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Write to Knowledge Base

> 配置一个将内容写入现有知识库的工作流步骤——从自定义文本、文档或抓取的网站

# Write to Knowledge Base

当你希望工作流步骤向某个知识库添加新内容时,请使用 **Write to Knowledge Base**。每次运行都会创建一个新的知识库条目,以便完整保留写入历史。

## 配置

| 选项                     | 是否必填           | 说明                                                                                                        |
| ---------------------- | -------------- | --------------------------------------------------------------------------------------------------------- |
| Name                   | 否              | 步骤在工作流画布中的标签。                                                                                             |
| Knowledge Base         | 是              | 在 **Knowledge Base** 中选择的目标知识库。                                                                           |
| Write Mode             | 是              | **Text**、**Document** 或 **Scrape** 之一。                                                                    |
| Content                | 是(Text 模式)     | 要嵌入的文本。此字段通过 **Insert Variable** 支持工作流变量。                                                                 |
| Document URL           | 是(Document 模式) | 要提取并嵌入的文档 URL。通过 **Insert Variable** 支持工作流变量。                                                             |
| Website URL            | 是(Scrape 模式)   | 要抓取的 URL。                                                                                                 |
| Chunking Strategy      | 否              | **Default** 使用确定性的、按段落和句子感知的分块策略。**Advanced** 使用相同的分块器,并允许你手动设置 **Max Chunk Length** 和 **Chunk Overlap**。 |
| Remove Email Addresses | 否              | 启用时,在嵌入之前从内容中剥离电子邮件地址。                                                                                    |
| Remove Phone Numbers   | 否              | 启用时,在嵌入之前从内容中剥离电话号码。                                                                                      |
| When the step fails    | 否              | 控制此步骤失败时工作流应 **Terminate Workflow** 还是 **Continue**。                                                      |

### Write Mode

**Text** — 直接在 **Content** 中输入原始文本,或使用 `{{step_n.output}}` 接入先前步骤的输出。

**Document** — 在 **Document URL** 中输入文档 URL,或使用 **Insert Variable** 传入先前步骤的 URL(例如媒体库资源 URL)。内容会自动提取并嵌入到知识库中。

**Scrape** — 在 **Website URL** 中输入 URL。Fetch Hive 会抓取页面并嵌入提取的文本。

### Chunking Strategy

对于大多数用例,将 **Chunking Strategy** 保留为 **Default**。Fetch Hive 会尽可能保留段落和句子边界,仅在单个单元过大时才回退到硬切分。切换到 **Advanced** 以精确控制内容的切分方式:

* **Max Chunk Length** — 每个分块的最大字符数(默认 500)。
* **Chunk Overlap** — 相邻分块之间共享的字符数(默认 50)。重叠有助于在分块边界保留上下文。

### PII 移除

启用 **Remove Email Addresses** 和/或 **Remove Phone Numbers** 可在内容嵌入和存储之前从中编辑这些值。

## 输出

此步骤返回写入操作的摘要:

```json theme={null}
{
  "knowledge_base_item_id": "...",
  "knowledge_base_id": "...",
  "chunk_count": 12,
  "status": "completed",
  "write_mode": "custom_text"
}
```

在后续步骤中引用输出:

```text theme={null}
{{step_2.output}}
{{step_2.output.chunk_count}}
```

## 费用

此步骤每次运行消耗 **1 task**。

## 示例

从 **Search steps...** 的 **Knowledge Base** 分组中添加 **Write to Knowledge Base**。

将 **Knowledge Base** 设置为目标知识库。

选择 **Write Mode**。对于总结网络文章的管道,选择 **Scrape** 并将 **Website URL** 设置为 `{{step_1.output.url}}`。

除非需要精确控制分块大小,否则将 **Chunking Strategy** 保留为 **Default**。

如果抓取的内容可能包含个人数据,请启用 **Remove Email Addresses**。

点击步骤标题中的 **Run** 来测试写入,然后查看 **Output** 以确认分块数和条目 ID。

{/* Add screenshot: Write to Knowledge Base settings with Scrape mode and Advanced chunking */}

## 备注

* 每次运行都会创建一个**新的**知识库条目。早前运行写入的条目不会被覆盖,因此完整的写入历史会保留在知识库中。
* 该步骤会在运行之前验证是否已选择知识库且所选模式的必填输入是否存在。
* 分块和 PII 移除在内容嵌入之前应用。

另见:[Search Knowledge Base](./search-knowledge-base)、[创建和编辑](../../creating-and-editing)、[测试与迭代](../../testing-and-iteration) 和 [错误处理](../../error-handling)
