This commit is contained in:
Archer
2023-10-30 13:26:42 +08:00
committed by GitHub
parent 008d0af010
commit 60ee160131
216 changed files with 4429 additions and 2229 deletions

1
docSite/.zhlintignore Normal file
View File

@@ -0,0 +1 @@
*.html

6
docSite/.zhlintrc Normal file
View File

@@ -0,0 +1,6 @@
{
"preset": "default",
"rules": {
"adjustedFullWidthPunctuation": ""
}
}

View File

@@ -3,7 +3,7 @@
## 本地运行
1. 安装 go 语言环境。
2. 安装 hugo。 [二进制下载](https://github.com/gohugoio/hugo/releases/tag/v0.117.0),注意需要安装 extended 版本。
2. 安装 hugo。[二进制下载](https://github.com/gohugoio/hugo/releases/tag/v0.117.0),注意需要安装 extended 版本。
3. cd docSite
4. hugo serve
5. 访问 http://localhost:1313

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 865 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 574 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 731 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 671 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 KiB

View File

@@ -4,7 +4,7 @@ description: 'FastGPT V4.5.1 更新'
icon: 'upgrade'
draft: false
toc: true
weight: 839
weight: 838
---
## 执行初始化 API

View File

@@ -0,0 +1,15 @@
---
title: 'V4.5.2'
description: 'FastGPT V4.5.2 更新'
icon: 'upgrade'
draft: false
toc: true
weight: 837
---
## 功能介绍
### Fast GPT V4.5.2
1. 新增 - 模块插件,允许自行组装插件进行模块复用。
2. 优化 - 知识库引用提示。

View File

@@ -39,16 +39,18 @@ weight: 310
```
{{% alert icon="🍅" context="success" %}}
Tips: 可以通过点击上下文按键查看完整的
Tips: 可以通过点击上下文按键查看完整的上下文组成,便于调试。
{{% /alert %}}
## 引用模板和提示词设计
引用模板和引用提示词通常是成对出现,引用提示词依赖引用模板。
FastGPT 知识库采用 QA 对(不一定都是问答格式,仅代表两个变量)的格式存储,在转义成字符串时候会根据**引用模板**来进行格式化。知识库包含 3 个变量: q, a, file_id, index, source可以通过 {{q}} {{a}} {{file_id}} {{index}} {{source}} 按需引入。下面一个模板例子:
FastGPT 知识库采用 QA 对(不一定都是问答格式,仅代表两个变量)的格式存储,在转义成字符串时候会根据**引用模板**来进行格式化。知识库包含多个可用变量: q, a, sourceId数据的ID, index(第n个数据), source(数据的集合名、文件名)score(距离得分0-1) 可以通过 {{q}} {{a}} {{sourceId}} {{index}} {{source}} {{score}} 按需引入。下面一个模板例子:
**引用模板**
可以通过 [知识库结构讲解](/docs/use-cases/datasetEngine/) 了解详细的知识库的结构。
### 引用模板
```
{instruction:"{{q}}",output:"{{a}}",source:"{{source}}"}
@@ -62,7 +64,7 @@ FastGPT 知识库采用 QA 对(不一定都是问答格式,仅代表两个变
{instruction:"电影《铃芽之旅》的编剧是谁22",output:"新海诚是本片的编剧。",source:"手动输入"}
```
**引用提示词**
### 引用提示词
引用模板需要和引用提示词一起使用,提示词中可以写引用模板的格式说明以及对话的要求等。可以使用 {{quote}} 来使用 **引用模板**,使用 {{question}} 来引入问题。例如:
@@ -91,4 +93,42 @@ FastGPT 知识库采用 QA 对(不一定都是问答格式,仅代表两个变
2. 使用背景知识回答问题。
3. 背景知识无法回答问题时,你可以礼貌的的回答用户问题。
我的问题是:"{{question}}"
```
```
### 总结
引用模板规定了搜索出来的内容如何组成一句话,其由 q,a,index,source 多个变量组成。
引用提示词由`引用模板``提示词`组成,提示词通常是对引用模板的一个描述,加上对模型的要求。
## 引用模板和提示词设计 示例
### 通用模板与问答模板对比
我们通过一组`你是谁`的手动数据,对通用模板与问答模板的效果进行对比。此处特意打了个搞笑的答案,通用模板下 GPT35 就变得不那么听话了,而问答模板下 GPT35 依然能够回答正确。这是由于结构化的提示词,在大语言模型中具有更强的引导作用。
{{% alert icon="🍅" context="success" %}}
Tips: 建议根据不同的场景每种知识库仅选择1类数据类型这样有利于充分发挥提示词的作用。
{{% /alert %}}
| 通用模板配置及效果 | 问答模板配置及效果 |
| --- | --- |
| ![](/imgs/datasetprompt1.png) | ![](/imgs/datasetprompt2.png) |
| ![](/imgs/datasetprompt3.png) | ![](/imgs/datasetprompt5.png) |
| ![](/imgs/datasetprompt4.png) | ![](/imgs/datasetprompt6.png) |
### 严格模板
使用非严格模板,我们随便询问一个不在知识库中的内容,模型通常会根据其自身知识进行回答。
| 非严格模板效果 | 选择严格模板 | 严格模板效果 |
| --- | --- | --- |
| ![](/imgs/datasetprompt7.png) | ![](/imgs/datasetprompt8.png) |![](/imgs/datasetprompt9.png) |
### 提示词设计思路
1. 使用序号进行不同要求描述。
2. 使用首先、然后、最后等词语进行描述。
3. 列举不同场景的要求时尽量完整不要遗漏。例如背景知识完全可以回答、背景知识可以回答一部分、背景知识与问题无关3种场景都说明清楚。
4. 巧用结构化提示,例如在问答模板中,利用了`instruction``output`,清楚的告诉模型,`output`是一个预期的答案。
5. 标点符号正确且完整。

View File

@@ -0,0 +1,83 @@
---
title: "知识库结构讲解"
description: "本节会介绍 FastGPT 知识库结构设计,理解其 QA 的存储格式和检索格式,以便更好的构建知识库。这篇介绍主要以使用为主,详细原理不多介绍。"
icon: "dataset"
draft: false
toc: true
weight: 311
---
# 理解向量
FastGPT 采用了 RAG 中的 Embedding 方案构建知识库,要使用好 FastGPT 需要简单的理解`Embedding`向量是如何工作的及其特点。
人类的文字、图片、视频等媒介是无法直接被计算机理解的,要想让计算机理解两段文字是否有相似性、相关性,通常需要将它们转成计算机可以理解的语言,向量是其中的一种方式。
向量可以简单理解为一个数字数组,两个向量之间可以通过数学公式得出一个`距离`,距离越小代表两个向量的相似度越大。从而映射到文字、图片、视频等媒介上,可以用来判断两个媒介之间的相似度。向量搜索便是利用了这个原理。
而由于文字是有多种类型,并且拥有成千上万种组合方式,因此在转成向量进行相似度匹配时,很难保障其精确性。在向量方案构建的知识库中,通常使用`topk`召回的方式,也就是查找前`k`个最相似的内容,丢给大模型去做更进一步的`语义判断``逻辑推理``归纳总结`,从而实现知识库问答。因此,在知识库问答中,向量搜索的环节是最为重要的。
影响向量搜索精度的因素非常多,主要包括:向量模型的质量、数据的质量(长度,完整性,多样性)、检索器的精度(速度与精度之间的取舍)。与数据质量对应的就是检索词的质量。
检索器的精度比较容易解决,向量模型的训练略复杂,因此数据和检索词质量优化成了一个重要的环节。
# FastGPT 中向量的结构设计
FastGPT 采用了 `PostgresSQL``PG Vector` 插件作为向量检索器,索引为`HNSW`。且`PostgresSQL`仅用于向量检索,`MongoDB`用于其他数据的存取。
`PostgresSQL`的表中,设置一个 `index` 字段用于存储向量、一个 `q` 字段用于存储向量对应的内容,以及一个 `a` 字段用于检索映射。之所以取字段为 `qa` 是由于一些历史缘故,无需完全解为 “问答对” 的格式。在实际使用过程中,可以利用`q``a`的组合,对检索后的内容做进一步的声明,提高大模型的理解力(注意,这里不直接提高搜索精度)。
目前,提高向量搜索的精度,主要可以通过几种途径:
1. 精简`q`的内容,减少向量内容的长度:当`q`的内容更少,更准确时,检索精度自然会提高。但与此同时,会牺牲一定的检索范围,适合答案较为严格的场景。
2. 更好分词分段:当一段话的结构和语义是完整的,并且是单一的,精度也会提高。因此,许多系统都会优化分词器,尽可能的保障每组数据的完整性。
3. 多样性文本:为一段内容增加关键词、摘要、相似问题等描述性信息,可以使得该内容的向量具有更大的检索覆盖范围。
4. 优化检索词:在实际使用过程中,用户的问题通常是模糊的或是缺失的,并不一定是完整清晰的问题。因此优化用户的问题(检索词)很大程度上也可以提高精度。
5. 微调向量模型:由于市面上直接使用的向量模型都是通用型模型,在特定领域的检索精度并不高,因此微调向量模型可以很大程度上提高专业领域的检索效果。
# FastGPT 构建知识库方案
在 FastGPT 中,整个知识库由库、集合和数据 3 部分组成。集合可以简单理解为一个`文件`。一个`库`中可以包含多个`集合`,一个`集合`中可以包含多组`数据`。最小的搜索单位是`库`,也就是说,知识库搜索时,是对整个`库`进行搜索,而集合仅是为了对数据进行分类管理,与搜索效果无关。(起码目前还是)
| 库 | 集合 | 数据 |
| --- | --- | --- |
| ![](/imgs/datasetEngine1.png) | ![](/imgs/datasetEngine2.png) | ![](/imgs/datasetEngine3.png) |
## 导入数据方案1 - 直接分段导入
选择文件导入时,可以选择直接分段方案。直接分段会利用`句子分词器`对文本进行一定长度拆分,最终分割中多组的`q`。如果使用了直接分段方案,我们建议在`应用`设置`引用提示词`时,使用`通用模板`即可,无需选择`问答模板`
| 交互 | 结果 |
| --- | --- |
| ![](/imgs/datasetEngine4.png) | ![](/imgs/datasetEngine5.png) |
## 导入数据方案2 - QA导入
选择文件导入时可以选择QA拆分方案。仍然需要使用到`句子分词器`对文本进行拆分,但长度比直接分段大很多。在导入后,会先调用`大模型`对分段进行学习,并给出一些`问题``答案`,最终问题和答案会一起被存储到`q`中。注意,新版的 FastGPT 为了提高搜索的范围,不再将问题和答案分别存储到 qa 中。
| 交互 | 结果 |
| --- | --- |
| ![](/imgs/datasetEngine6.png) | ![](/imgs/datasetEngine7.png) |
## 导入数据方案3 - 手动录入
在 FastGPT 中,你可以在任何一个`集合`中点击右上角的`插入`手动录入知识点,或者使用`标注`功能手动录入。被搜索的内容为`q`,补充内容(可选)为`a`
| | | |
| --- | --- | --- |
| ![](/imgs/datasetEngine8.png) | ![](/imgs/datasetEngine9.png) | ![](/imgs/datasetEngine10.png) |
## 导入数据方案4 - CSV录入
有些数据较为独特,可能需要单独的进行预处理分割后再导入 FastGPT此时可以选择 csv 导入,可批量的将处理好的数据导入。
![](/imgs/datasetEngine11.png)
## 导入数据方案5 - API导入
参考[FastGPT OpenAPI使用](/docs/development/openapi/#知识库添加数据)。
# QA的组合与引用提示词构建
参考[引用模板与引用提示词示例](/docs/use-cases/ai_settings/#示例)

View File

@@ -4,7 +4,7 @@ description: "通过与 OpenAI 兼容的 API 对接第三方应用"
icon: "model_training"
draft: false
toc: true
weight: 311
weight: 312
---
## 获取 API 秘钥

View File

@@ -86,7 +86,7 @@ weight: 142
{
"key": "history",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"type": "source",
"targets": [
{
@@ -210,14 +210,14 @@ weight: 142
"type": "target",
"label": "引用内容",
"description": "对象数组格式,结构:\n [{q:'问题',a:'回答'}]",
"valueType": "kb_quote",
"valueType": "datasetQuote",
"connected": false
},
{
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{

View File

@@ -132,7 +132,7 @@ export default async function (ctx: FunctionContext) {
{
"key": "history",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"type": "source",
"targets": [
{
@@ -179,7 +179,7 @@ export default async function (ctx: FunctionContext) {
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -410,14 +410,14 @@ export default async function (ctx: FunctionContext) {
"key": "quoteQA",
"type": "target",
"label": "引用内容",
"valueType": "kb_quote",
"valueType": "datasetQuote",
"connected": false
},
{
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{

View File

@@ -131,7 +131,7 @@ HTTP 模块允许你调用任意 POST 类型的 HTTP 接口,从而实验一些
{
"key": "history",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"type": "source",
"targets": [
{
@@ -174,7 +174,7 @@ HTTP 模块允许你调用任意 POST 类型的 HTTP 接口,从而实验一些
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -413,7 +413,7 @@ HTTP 模块允许你调用任意 POST 类型的 HTTP 接口,从而实验一些
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -630,7 +630,7 @@ HTTP 模块允许你调用任意 POST 类型的 HTTP 接口,从而实验一些
"label": "引用内容",
"description": "始终返回数组,如果希望搜索结果为空时执行额外操作,需要用到上面的两个输入以及目标模块的触发器",
"type": "source",
"valueType": "kb_quote",
"valueType": "datasetQuote",
"targets": [
{
"moduleId": "bjfklc",
@@ -729,14 +729,14 @@ HTTP 模块允许你调用任意 POST 类型的 HTTP 接口,从而实验一些
"key": "quoteQA",
"type": "target",
"label": "引用内容",
"valueType": "kb_quote",
"valueType": "datasetQuote",
"connected": true
},
{
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -831,7 +831,7 @@ HTTP 模块允许你调用任意 POST 类型的 HTTP 接口,从而实验一些
{
"key": "history",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"type": "source",
"targets": [
{
@@ -874,7 +874,7 @@ HTTP 模块允许你调用任意 POST 类型的 HTTP 接口,从而实验一些
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -1006,7 +1006,7 @@ HTTP 模块允许你调用任意 POST 类型的 HTTP 接口,从而实验一些
{
"key": "history",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"type": "source",
"targets": [
{

View File

@@ -83,7 +83,7 @@ weight: 144
{
"key": "history",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"type": "source",
"targets": [
{
@@ -189,7 +189,7 @@ weight: 144
"label": "引用内容",
"description": "始终返回数组,如果希望搜索结果为空时执行额外操作,需要用到上面的两个输入以及目标模块的触发器",
"type": "source",
"valueType": "kb_quote",
"valueType": "datasetQuote",
"targets": [
{
"moduleId": "ol82hp",
@@ -291,14 +291,14 @@ weight: 144
"type": "target",
"label": "引用内容",
"description": "对象数组格式,结构:\n [{q:'问题',a:'回答'}]",
"valueType": "kb_quote",
"valueType": "datasetQuote",
"connected": true
},
{
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -389,7 +389,7 @@ weight: 144
{
"key": "history",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"type": "source",
"targets": [
{
@@ -432,7 +432,7 @@ weight: 144
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{

View File

@@ -245,7 +245,7 @@ PS2配置中的问题分类还包含着“联网搜索”这个是另一
{
"key": "history",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"type": "source",
"targets": [
{
@@ -300,7 +300,7 @@ PS2配置中的问题分类还包含着“联网搜索”这个是另一
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -427,7 +427,7 @@ PS2配置中的问题分类还包含着“联网搜索”这个是另一
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -713,14 +713,14 @@ PS2配置中的问题分类还包含着“联网搜索”这个是另一
"type": "custom",
"label": "引用内容",
"description": "对象数组格式,结构:\n [{q:'问题',a:'回答'}]",
"valueType": "kb_quote",
"valueType": "datasetQuote",
"connected": false
},
{
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -871,14 +871,14 @@ PS2配置中的问题分类还包含着“联网搜索”这个是另一
"type": "custom",
"label": "引用内容",
"description": "对象数组格式,结构:\n [{q:'问题',a:'回答'}]",
"valueType": "kb_quote",
"valueType": "datasetQuote",
"connected": false
},
{
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -1085,14 +1085,14 @@ PS2配置中的问题分类还包含着“联网搜索”这个是另一
"type": "custom",
"label": "引用内容",
"description": "对象数组格式,结构:\n [{q:'问题',a:'回答'}]",
"valueType": "kb_quote",
"valueType": "datasetQuote",
"connected": false
},
{
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -1162,7 +1162,7 @@ PS2配置中的问题分类还包含着“联网搜索”这个是另一
{
"key": "history",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"type": "source",
"targets": [
{
@@ -1205,7 +1205,7 @@ PS2配置中的问题分类还包含着“联网搜索”这个是另一
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{
@@ -1452,14 +1452,14 @@ PS2配置中的问题分类还包含着“联网搜索”这个是另一
"type": "custom",
"label": "引用内容",
"description": "对象数组格式,结构:\n [{q:'问题',a:'回答'}]",
"valueType": "kb_quote",
"valueType": "datasetQuote",
"connected": false
},
{
"key": "history",
"type": "target",
"label": "聊天记录",
"valueType": "chat_history",
"valueType": "chatHistory",
"connected": true
},
{