feat: 完善文档分块参数配置
- 支持自定义正则匹配内容保留开关及配置持久化 - 约束分块重叠长度始终小于分块长度 - 补充中英文交互文案
This commit is contained in:
@@ -720,6 +720,9 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
if (config.getMdSplitterLevel() == null || config.getMdSplitterLevel() <= 0) {
|
||||
config.setMdSplitterLevel(RagDefaults.MD_SPLITTER_LEVEL);
|
||||
}
|
||||
if (config.getRetainRegexMatch() == null) {
|
||||
config.setRetainRegexMatch(Boolean.FALSE);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -742,6 +745,10 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
config.setChunkSize(asInteger(rawProfile.get("chunkSize"), config.getChunkSize()));
|
||||
config.setOverlapSize(asInteger(rawProfile.get("overlapSize"), config.getOverlapSize()));
|
||||
config.setRegex(asString(rawProfile.get("regex")));
|
||||
if (rawProfile.containsKey("retainRegexMatch")) {
|
||||
config.setRetainRegexMatch(
|
||||
asBoolean(rawProfile.get("retainRegexMatch"), false));
|
||||
}
|
||||
config.setRowsPerChunk(asInteger(rawProfile.get("rowsPerChunk"), config.getRowsPerChunk()));
|
||||
config.setMdSplitterLevel(asInteger(rawProfile.get("mdSplitterLevel"), config.getMdSplitterLevel()));
|
||||
return config;
|
||||
@@ -763,6 +770,9 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
if (StringUtil.hasText(source.getRegex())) {
|
||||
target.setRegex(source.getRegex());
|
||||
}
|
||||
if (source.getRetainRegexMatch() != null) {
|
||||
target.setRetainRegexMatch(source.getRetainRegexMatch());
|
||||
}
|
||||
if (source.getRowsPerChunk() != null) {
|
||||
target.setRowsPerChunk(source.getRowsPerChunk());
|
||||
}
|
||||
@@ -777,6 +787,8 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
||||
map.put("chunkSize", strategyConfig.getChunkSize());
|
||||
map.put("overlapSize", strategyConfig.getOverlapSize());
|
||||
map.put("regex", strategyConfig.getRegex());
|
||||
map.put("retainRegexMatch", Boolean.TRUE.equals(
|
||||
strategyConfig.getRetainRegexMatch()));
|
||||
map.put("rowsPerChunk", strategyConfig.getRowsPerChunk());
|
||||
map.put("mdSplitterLevel", strategyConfig.getMdSplitterLevel());
|
||||
return map;
|
||||
|
||||
@@ -159,6 +159,9 @@
|
||||
"chunkSize": "SegmentLength",
|
||||
"overlapSize": "SegmentOverlap",
|
||||
"regex": "RegularExpression",
|
||||
"regexMatchHandling": "Matched content",
|
||||
"retainRegexMatch": "Keep in next chunk",
|
||||
"discardRegexMatch": "Discard",
|
||||
"document": "Document",
|
||||
"simpleDocumentSplitter": "SimpleDocumentSplitter",
|
||||
"simpleTokenizeSplitter": "SimpleTokenizeSplitter",
|
||||
|
||||
@@ -159,6 +159,9 @@
|
||||
"chunkSize": "分段长度",
|
||||
"overlapSize": "分段重叠",
|
||||
"regex": "正则表达式",
|
||||
"regexMatchHandling": "匹配内容处理",
|
||||
"retainRegexMatch": "保留到下一分块",
|
||||
"discardRegexMatch": "不保留",
|
||||
"document": "文档",
|
||||
"simpleDocumentSplitter": "简单文档分割器",
|
||||
"simpleTokenizeSplitter": "简单分词器",
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
ElOption,
|
||||
ElSelect,
|
||||
ElSlider,
|
||||
ElSwitch,
|
||||
} from 'element-plus';
|
||||
|
||||
import { api } from '#/api/request';
|
||||
@@ -88,6 +89,7 @@ const createDefaultFormState = () => ({
|
||||
mdSplitterLevel: 2,
|
||||
overlapSize: 128,
|
||||
regex: '',
|
||||
retainRegexMatch: false,
|
||||
rowsPerChunk: 10,
|
||||
strategyCode: 'AUTO',
|
||||
});
|
||||
@@ -154,6 +156,10 @@ const showLengthSettings = (strategyCode?: string) =>
|
||||
const showOverlapSettings = (strategyCode?: string) =>
|
||||
['AUTO', 'PARAGRAPH_LENGTH'].includes(strategyCode || '');
|
||||
|
||||
const maxOverlapSize = computed(() =>
|
||||
Math.max(0, Number(formState.chunkSize || 0) - 1),
|
||||
);
|
||||
|
||||
const clearPreviewTimer = () => {
|
||||
if (!previewDebounceTimer) {
|
||||
return;
|
||||
@@ -388,6 +394,15 @@ watch(
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
() => formState.chunkSize,
|
||||
() => {
|
||||
if (formState.overlapSize > maxOverlapSize.value) {
|
||||
formState.overlapSize = maxOverlapSize.value;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
formState,
|
||||
() => {
|
||||
@@ -456,7 +471,7 @@ watch(
|
||||
>
|
||||
<ElSlider
|
||||
v-model="formState.overlapSize"
|
||||
:max="512"
|
||||
:max="Math.min(512, maxOverlapSize)"
|
||||
:min="0"
|
||||
show-input
|
||||
/>
|
||||
@@ -484,6 +499,20 @@ watch(
|
||||
>
|
||||
<ElInput v-model="formState.regex" />
|
||||
</ElFormItem>
|
||||
|
||||
<ElFormItem
|
||||
v-if="formState.strategyCode === 'CUSTOM_REGEX'"
|
||||
:label="$t('documentCollection.splitterDoc.regexMatchHandling')"
|
||||
class="workbench__form-full"
|
||||
>
|
||||
<ElSwitch
|
||||
v-model="formState.retainRegexMatch"
|
||||
:active-text="$t('documentCollection.splitterDoc.retainRegexMatch')"
|
||||
:inactive-text="
|
||||
$t('documentCollection.splitterDoc.discardRegexMatch')
|
||||
"
|
||||
/>
|
||||
</ElFormItem>
|
||||
</div>
|
||||
</ElForm>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user