Skip to content

Commit

Permalink
v4.6.6-search test adapt diff search mode (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Jan 3, 2024
1 parent c766a0e commit 13b1072
Show file tree
Hide file tree
Showing 57 changed files with 1,101 additions and 612 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"prettier.prettierPath": "./node_modules/prettier",
"i18n-ally.localesPaths": [
"projects/app/public/locales",
"projects/home/public/locales"
],
"i18n-ally.enabledParsers": ["json"],
"i18n-ally.keystyle": "nested",
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,47 @@ https://github.com/labring/FastGPT/assets/15308462/7d3a38df-eb0e-4388-9250-2409b
<img src="https://img.shields.io/badge/-返回顶部-7d09f1.svg" alt="#" align="right">
</a>

## 💡 功能
## 💡 RoadMap

`1` 强大的可视化编排,轻松构建 AI 应用
`1` 应用编排能力
- [x] 提供简易模式,无需操作编排
- [x] 对话下一步指引
- [x] 工作流编排
- [x] 对话下一步指引
- [x] 源文件引用追踪
- [x] 模块封装,实现多级复用
- [x] 混合检索 & 重排
- [ ] 自查询规划
- [ ] 嵌入 [Laf](https://github.com/labring/laf),实现在线编写 HTTP 模块
- [ ] 混合检索 & 重排
- [ ] 插件封装功能

`2` 丰富的知识库预处理
`2` 知识库能力
- [x] 多库复用,混用
- [x] chunk 记录修改和删除
- [x] 支持知识库单独设置向量模型
- [x] 源文件存储
- [x] 支持手动输入,直接分段,QA 拆分导入
- [x] 支持 pdf、word、txt、md 等常用文件,支持 url 读取、CSV 批量导入
- [ ] 支持 HTML、csv、PPT、Excel 导入
- [ ] 支持文件阅读器
- [ ] 支持差异性文件同步
- [ ] 更多的数据预处理方案

`3` 多种效果测试渠道
`3` 应用调试能力
- [x] 知识库单点搜索测试
- [x] 对话时反馈引用并可修改与删除
- [x] 完整上下文呈现
- [x] 完整模块中间值呈现
- [ ] 高级编排 DeBug 模式

`4` OpenAPI
`4` OpenAPI 接口
- [x] completions 接口 (对齐 GPT 接口)
- [ ] 知识库 CRUD
- [ ] 对话 CRUD

`5` 运营功能
`5` 运营能力
- [x] 免登录分享窗口
- [x] Iframe 一键嵌入
- [x] 聊天窗口嵌入支持自定义 Icon,默认打开,拖拽等功能
- [x] 统一查阅对话记录,并对数据进行标注

<a href="#readme">
Expand Down
24 changes: 24 additions & 0 deletions docSite/content/docs/development/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,27 @@ weight: 708
}
}
```

## 特殊模型

### ReRank 接入

请使用 4.6.6-alpha 以上版本,配置文件中的 `reRankModels` 为重排模型,虽然是数组,不过目前仅有第1个生效。

1. [部署 ReRank 模型](/docs/development/custom-models/reranker/)
1. 找到 FastGPT 的配置文件中的 `reRankModels`, 4.6.6 以前是 `ReRankModels`
2. 修改对应的值:(记得去掉注释)

```json
{
"reRankModels": [
{
"model": "bge-reranker-base", // 随意
"name": "检索重排-base", // 随意
"inputPrice": 0,
"requestUrl": "{{host}}/api/v1/rerank",
"requestAuth": "安全凭证,已自动补 Bearer"
}
]
}
```
64 changes: 64 additions & 0 deletions docSite/content/docs/development/custom-models/reranker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: '接入 ReRank 重排模型'
description: '接入 ReRank 重排模型'
icon: 'sort'
draft: false
toc: true
weight: 910
---

## 推荐配置

推荐配置如下:

{{< table "table-hover table-striped-columns" >}}
| 类型 | 内存 | 显存 | 硬盘空间 | 启动命令 |
|------|---------|---------|----------|--------------------------|
| base | >=4GB | >=3GB | >=8GB | python app.py |
{{< /table >}}

## 部署

### 环境要求

- Python 3.10.11
- CUDA 11.7
- 科学上网环境

### 源码部署

1. 根据上面的环境配置配置好环境,具体教程自行 GPT;
2. 下载 [python 文件](app.py)
3. 在命令行输入命令 `pip install -r requirments.txt`
4. 按照[https://huggingface.co/BAAI/bge-reranker-base](https://huggingface.co/BAAI/bge-reranker-base)下载模型仓库到app.py同级目录
5. 添加环境变量 `export ACCESS_TOKEN=XXXXXX` 配置 token,这里的 token 只是加一层验证,防止接口被人盗用,默认值为 `ACCESS_TOKEN`
6. 执行命令 `python app.py`

然后等待模型下载,直到模型加载完毕为止。如果出现报错先问 GPT。

启动成功后应该会显示如下地址:

![](/imgs/chatglm2.png)

> 这里的 `http://0.0.0.0:6006` 就是连接地址。
### docker 部署

+ 镜像名: `luanshaotong/reranker:v0.1`
+ 端口号: 6006
+ 大小:约8GB

**设置安全凭证(即oneapi中的渠道密钥)**
```
ACCESS_TOKEN=mytoken
```

**运行命令示例**

```sh
docker run -d --name reranker -p 6006:6006 -e ACCESS_TOKEN=mytoken luanshaotong/reranker:v0.1
```

## 接入 FastGPT

参考 [ReRank模型接入](/docs/development/configuration/#rerank-接入),host 变量为部署的域名。
32 changes: 19 additions & 13 deletions docSite/content/docs/development/openapi/dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ A2:

## 搜索测试

{{< tabs tabTotal="2" >}}
{{< tabs tabTotal="3" >}}
{{< tab tabName="请求示例" >}}
{{< markdownify >}}

Expand All @@ -168,18 +168,33 @@ curl --location --request POST 'https://api.fastgpt.in/api/core/dataset/searchTe
--data-raw '{
"datasetId": "知识库的ID",
"text": "导演是谁",
"rarank": true,
"limit": 20
"limit": 5000,
"similarity": 0,
"searchMode": "embedding",
"usingReRank": false
}'
```

{{< /markdownify >}}
{{< /tab >}}

{{< tab tabName="参数说明" >}}
{{< markdownify >}}

- datasetId - 知识库ID
- text - 需要测试的文本
- limit - 最大 tokens 数量
- similarity - 最低相关度(0~1,可选)
- searchMode - 搜索模式:embedding | fullTextRecall | mixedRecall
- usingReRank - 使用重排

{{< /markdownify >}}
{{< /tab >}}

{{< tab tabName="响应示例" >}}
{{< markdownify >}}

返回 top k 结果, limit 为预估条数,会按每条数据 800 tokens 的长度进行预估,20条也就是返回 16000 tokens 长度的数据,最多测试 30000 tokens 的数据
返回 top k 结果, limit 为最大 Tokens 数量,最多 20000 tokens。

```bash
{
Expand All @@ -190,15 +205,6 @@ curl --location --request POST 'https://api.fastgpt.in/api/core/dataset/searchTe
"id": "65599c54a5c814fb803363cb",
"q": "你是谁",
"a": "我是FastGPT助手",
"indexes": [
{
"defaultIndex": true,
"type": "qa",
"dataId": "3645952",
"text": "你是谁\n我是FastGPT助手",
"_id": "65599c5588271af95b019862"
}
],
"datasetId": "6554684f7f9ed18a39a4d15c",
"collectionId": "6556cd795e4b663e770bb66d",
"sourceName": "GBT 15104-2021 装饰单板贴面人造板.pdf",
Expand Down
25 changes: 17 additions & 8 deletions docSite/content/docs/development/qa.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@ draft: false
images: []
---

## 错误排查方式

遇到问题先按下面方式排查。

1. `docker ps -a` 查看所有容器运行状态,检查是否全部 running,如有异常,尝试`docker logs 容器名`查看对应日志。
2. 不懂 docker 不要瞎改端口,只需要改`OPENAI_BASE_URL``CHAT_API_KEY`即可。
3. 容器都运行正常的,`docker logs 容器名` 查看报错日志
4. 无法解决时,可以找找[Issue](https://github.com/labring/FastGPT/issues),或新提 Issue,私有部署错误,务必提供详细的日志,否则很难排查。


## 通用问题

### insufficient_user_quota user quota is not enough

OneAPI 账号的余额不足,默认 root 用户只有 200 刀,可以手动修改。

### xxx渠道找不到

OneAPI 中没有配置该模型渠道。

### 页面中可以正常回复,API 报错

页面中是用 stream=true 模式,所以API也需要设置 stream=true 来进行测试。部分模型接口(国产居多)非 Stream 的兼容有点垃圾。

## Docker 部署常见问题

Expand Down Expand Up @@ -66,11 +83,3 @@ PG 数据库没有连接上/初始化失败,可以查看日志。FastGPT 会
mongo连接失败,检查
1. mongo 服务有没有起来(有些 cpu 不支持 AVX,无法用 mongo5,需要换成 mongo4.x,可以dockerhub找个最新的4.x,修改镜像版本,重新运行)
2. 环境变量(账号密码,注意host和port)


### 错误排查方式

遇到问题先按下面方式排查。

1. `docker ps -a` 查看所有容器运行状态,检查是否全部 running,如有异常,尝试`docker logs 容器名`查看对应日志。
2. 不懂 docker 不要瞎改端口,只需要改`OPENAI_BASE_URL``CHAT_API_KEY`即可。
11 changes: 5 additions & 6 deletions docSite/content/docs/development/upgrading/466.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ weight: 830

为了减少代码重复度,我们对配置文件做了一些修改:[点击查看最新的配置文件](/docs/development/configuration/)

## V4.6.6 更新说明


## V4.6.6 即将更新

1. UI 优化,未来将逐步替换新的UI设计。


1. 新增 - 搜索方式:分离向量语义检索,全文检索和重排,通过 RRF 进行排序合并。
2. 优化 - 问题分类提示词,id引导。测试国产商用 api 模型(百度阿里智谱讯飞)使用 Prompt 模式均可分类。
3. UI 优化,未来将逐步替换新的UI设计。
4. 查看 [FastGPT 2024 RoadMap](https://github.com/labring/FastGPT?tab=readme-ov-file#-%E5%9C%A8%E7%BA%BF%E4%BD%BF%E7%94%A8)
14 changes: 14 additions & 0 deletions packages/global/core/dataset/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,19 @@ export enum SearchScoreTypeEnum {
reRank = 'reRank',
rrf = 'rrf'
}
export const SearchScoreTypeMap = {
[SearchScoreTypeEnum.embedding]: {
label: 'core.dataset.search.score.embedding'
},
[SearchScoreTypeEnum.fullText]: {
label: 'core.dataset.search.score.fullText'
},
[SearchScoreTypeEnum.reRank]: {
label: 'core.dataset.search.score.reRank'
},
[SearchScoreTypeEnum.rrf]: {
label: 'core.dataset.search.score.rrf'
}
};

export const FolderAvatarSrc = '/imgs/files/folder.svg';
5 changes: 4 additions & 1 deletion packages/global/core/dataset/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ export type DatasetFileSchema = {
};

/* ============= search =============== */
export type SearchDataResponseItemType = Omit<DatasetDataItemType, 'isOwner' | 'canWrite'> & {
export type SearchDataResponseItemType = Omit<
DatasetDataItemType,
'indexes' | 'isOwner' | 'canWrite'
> & {
score: { type: `${SearchScoreTypeEnum}`; value: number; index: number }[];
// score: number;
};
2 changes: 1 addition & 1 deletion packages/global/core/module/template/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const Input_Template_History: FlowNodeInputItemType = {

export const Input_Template_UserChatInput: FlowNodeInputItemType = {
key: ModuleInputKeyEnum.userChatInput,
type: FlowNodeInputTypeEnum.target,
type: FlowNodeInputTypeEnum.hidden,
label: 'core.module.input.label.user question',
required: true,
valueType: ModuleIOValueTypeEnum.string,
Expand Down
8 changes: 8 additions & 0 deletions packages/global/core/module/template/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { ModuleOutputKeyEnum } from '../constants';
import { FlowNodeOutputTypeEnum } from '../node/constant';
import { ModuleIOValueTypeEnum } from '../constants';

export const Output_Template_UserChatInput: FlowNodeOutputItemType = {
key: ModuleOutputKeyEnum.userChatInput,
label: 'core.module.input.label.user question',
type: FlowNodeOutputTypeEnum.hidden,
valueType: ModuleIOValueTypeEnum.string,
targets: []
};

export const Output_Template_Finish: FlowNodeOutputItemType = {
key: ModuleOutputKeyEnum.finish,
label: 'core.module.output.label.running done',
Expand Down
3 changes: 2 additions & 1 deletion packages/global/core/module/template/system/aiChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Input_Template_UserChatInput
} from '../input';
import { chatNodeSystemPromptTip } from '../tip';
import { Output_Template_Finish } from '../output';
import { Output_Template_Finish, Output_Template_UserChatInput } from '../output';

export const AiChatModule: FlowModuleTemplateType = {
id: FlowNodeTypeEnum.chatNode,
Expand Down Expand Up @@ -131,6 +131,7 @@ export const AiChatModule: FlowModuleTemplateType = {
Input_Template_UserChatInput
],
outputs: [
Output_Template_UserChatInput,
{
key: ModuleOutputKeyEnum.history,
label: '新的上下文',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Input_Template_Switch,
Input_Template_UserChatInput
} from '../input';
import { Output_Template_UserChatInput } from '../output';

export const ClassifyQuestionModule: FlowModuleTemplateType = {
id: FlowNodeTypeEnum.classifyQuestion,
Expand Down Expand Up @@ -72,6 +73,7 @@ export const ClassifyQuestionModule: FlowModuleTemplateType = {
}
],
outputs: [
Output_Template_UserChatInput,
// custom output
{
key: 'wqre',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Input_Template_Switch,
Input_Template_UserChatInput
} from '../input';
import { Output_Template_UserChatInput } from '../output';

export const AiCFR: FlowModuleTemplateType = {
id: FlowNodeTypeEnum.chatNode,
Expand Down Expand Up @@ -50,6 +51,7 @@ export const AiCFR: FlowModuleTemplateType = {
Input_Template_UserChatInput
],
outputs: [
Output_Template_UserChatInput,
{
key: ModuleOutputKeyEnum.text,
label: 'core.module.output.label.cfr result',
Expand Down
Loading

0 comments on commit 13b1072

Please sign in to comment.