-
Notifications
You must be signed in to change notification settings - Fork 6.3k
feat:优化全文索引,增加datasetId作为联合索引 #4970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
增加DatasetID作为联合索引的字段,用于优化全文索引效率
TestGru AssignmentSummary
Tip You can |
Preview mcp_server Image: |
补充:以下是同一个数据库,同一个搜索词的慢查询日志 索引优化后
索引优化前
|
Preview sandbox Image: |
Preview fastgpt Image: |
datasetId 无法支持 $in 模式,如果是多个知识库会导致需要多次查找,并且无法得到正确分数 |
🚨 BugBot failed to runRemote branch not found for this Pull Request. It may have been merged or deleted (requestId: serverGenReqId_da2d575b-9d48-4ae5-9194-b411e8239cfa). |
Preview mcp_server Image: |
Preview sandbox Image: |
Preview fastgpt Image: |
@c121914yu 这个优化对于全文查询性能优化明显,特别是数据库中知识库比较多的时候。是否可以考虑在查询时使用其他方式,能够使得datasetId加入到索引中,有效减少扫描文件数量和数据量大小 |
我这边的应用,在执行的时候发现问题:每次查询时,扫描的数据数量几乎为整个知识库(整个DB)的文本数量,而不是单个DataSet的文本数量。进一步查询发现,此处的索引未针对datasetID字段做联合索引,导致所有的全文检索扫描都会对比所有文本。
通过将datasetId字段加入联合索引,并在本地进行测试后,测试结论如下:
以下是针对10w左右数据量的一个dataset进行查询的前后对比。


增加DatasetID作为联合索引的字段,用于优化全文索引效率。优化效果如下:
以下是索引优化前后,慢SQL日志对比

经过上述对比,可见文档扫描数量和数据检索数量都有大幅下降。
该优化对于1个TeamID下有很多知识库,但是目标查询知识库占总知识库文本数量较低的查询优化效果更明显。