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) {
|
if (config.getMdSplitterLevel() == null || config.getMdSplitterLevel() <= 0) {
|
||||||
config.setMdSplitterLevel(RagDefaults.MD_SPLITTER_LEVEL);
|
config.setMdSplitterLevel(RagDefaults.MD_SPLITTER_LEVEL);
|
||||||
}
|
}
|
||||||
|
if (config.getRetainRegexMatch() == null) {
|
||||||
|
config.setRetainRegexMatch(Boolean.FALSE);
|
||||||
|
}
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,6 +745,10 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
|||||||
config.setChunkSize(asInteger(rawProfile.get("chunkSize"), config.getChunkSize()));
|
config.setChunkSize(asInteger(rawProfile.get("chunkSize"), config.getChunkSize()));
|
||||||
config.setOverlapSize(asInteger(rawProfile.get("overlapSize"), config.getOverlapSize()));
|
config.setOverlapSize(asInteger(rawProfile.get("overlapSize"), config.getOverlapSize()));
|
||||||
config.setRegex(asString(rawProfile.get("regex")));
|
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.setRowsPerChunk(asInteger(rawProfile.get("rowsPerChunk"), config.getRowsPerChunk()));
|
||||||
config.setMdSplitterLevel(asInteger(rawProfile.get("mdSplitterLevel"), config.getMdSplitterLevel()));
|
config.setMdSplitterLevel(asInteger(rawProfile.get("mdSplitterLevel"), config.getMdSplitterLevel()));
|
||||||
return config;
|
return config;
|
||||||
@@ -763,6 +770,9 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
|||||||
if (StringUtil.hasText(source.getRegex())) {
|
if (StringUtil.hasText(source.getRegex())) {
|
||||||
target.setRegex(source.getRegex());
|
target.setRegex(source.getRegex());
|
||||||
}
|
}
|
||||||
|
if (source.getRetainRegexMatch() != null) {
|
||||||
|
target.setRetainRegexMatch(source.getRetainRegexMatch());
|
||||||
|
}
|
||||||
if (source.getRowsPerChunk() != null) {
|
if (source.getRowsPerChunk() != null) {
|
||||||
target.setRowsPerChunk(source.getRowsPerChunk());
|
target.setRowsPerChunk(source.getRowsPerChunk());
|
||||||
}
|
}
|
||||||
@@ -777,6 +787,8 @@ public class DocumentServiceImpl extends ServiceImpl<DocumentMapper, Document> i
|
|||||||
map.put("chunkSize", strategyConfig.getChunkSize());
|
map.put("chunkSize", strategyConfig.getChunkSize());
|
||||||
map.put("overlapSize", strategyConfig.getOverlapSize());
|
map.put("overlapSize", strategyConfig.getOverlapSize());
|
||||||
map.put("regex", strategyConfig.getRegex());
|
map.put("regex", strategyConfig.getRegex());
|
||||||
|
map.put("retainRegexMatch", Boolean.TRUE.equals(
|
||||||
|
strategyConfig.getRetainRegexMatch()));
|
||||||
map.put("rowsPerChunk", strategyConfig.getRowsPerChunk());
|
map.put("rowsPerChunk", strategyConfig.getRowsPerChunk());
|
||||||
map.put("mdSplitterLevel", strategyConfig.getMdSplitterLevel());
|
map.put("mdSplitterLevel", strategyConfig.getMdSplitterLevel());
|
||||||
return map;
|
return map;
|
||||||
|
|||||||
@@ -159,6 +159,9 @@
|
|||||||
"chunkSize": "SegmentLength",
|
"chunkSize": "SegmentLength",
|
||||||
"overlapSize": "SegmentOverlap",
|
"overlapSize": "SegmentOverlap",
|
||||||
"regex": "RegularExpression",
|
"regex": "RegularExpression",
|
||||||
|
"regexMatchHandling": "Matched content",
|
||||||
|
"retainRegexMatch": "Keep in next chunk",
|
||||||
|
"discardRegexMatch": "Discard",
|
||||||
"document": "Document",
|
"document": "Document",
|
||||||
"simpleDocumentSplitter": "SimpleDocumentSplitter",
|
"simpleDocumentSplitter": "SimpleDocumentSplitter",
|
||||||
"simpleTokenizeSplitter": "SimpleTokenizeSplitter",
|
"simpleTokenizeSplitter": "SimpleTokenizeSplitter",
|
||||||
|
|||||||
@@ -159,6 +159,9 @@
|
|||||||
"chunkSize": "分段长度",
|
"chunkSize": "分段长度",
|
||||||
"overlapSize": "分段重叠",
|
"overlapSize": "分段重叠",
|
||||||
"regex": "正则表达式",
|
"regex": "正则表达式",
|
||||||
|
"regexMatchHandling": "匹配内容处理",
|
||||||
|
"retainRegexMatch": "保留到下一分块",
|
||||||
|
"discardRegexMatch": "不保留",
|
||||||
"document": "文档",
|
"document": "文档",
|
||||||
"simpleDocumentSplitter": "简单文档分割器",
|
"simpleDocumentSplitter": "简单文档分割器",
|
||||||
"simpleTokenizeSplitter": "简单分词器",
|
"simpleTokenizeSplitter": "简单分词器",
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
ElOption,
|
ElOption,
|
||||||
ElSelect,
|
ElSelect,
|
||||||
ElSlider,
|
ElSlider,
|
||||||
|
ElSwitch,
|
||||||
} from 'element-plus';
|
} from 'element-plus';
|
||||||
|
|
||||||
import { api } from '#/api/request';
|
import { api } from '#/api/request';
|
||||||
@@ -88,6 +89,7 @@ const createDefaultFormState = () => ({
|
|||||||
mdSplitterLevel: 2,
|
mdSplitterLevel: 2,
|
||||||
overlapSize: 128,
|
overlapSize: 128,
|
||||||
regex: '',
|
regex: '',
|
||||||
|
retainRegexMatch: false,
|
||||||
rowsPerChunk: 10,
|
rowsPerChunk: 10,
|
||||||
strategyCode: 'AUTO',
|
strategyCode: 'AUTO',
|
||||||
});
|
});
|
||||||
@@ -154,6 +156,10 @@ const showLengthSettings = (strategyCode?: string) =>
|
|||||||
const showOverlapSettings = (strategyCode?: string) =>
|
const showOverlapSettings = (strategyCode?: string) =>
|
||||||
['AUTO', 'PARAGRAPH_LENGTH'].includes(strategyCode || '');
|
['AUTO', 'PARAGRAPH_LENGTH'].includes(strategyCode || '');
|
||||||
|
|
||||||
|
const maxOverlapSize = computed(() =>
|
||||||
|
Math.max(0, Number(formState.chunkSize || 0) - 1),
|
||||||
|
);
|
||||||
|
|
||||||
const clearPreviewTimer = () => {
|
const clearPreviewTimer = () => {
|
||||||
if (!previewDebounceTimer) {
|
if (!previewDebounceTimer) {
|
||||||
return;
|
return;
|
||||||
@@ -388,6 +394,15 @@ watch(
|
|||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => formState.chunkSize,
|
||||||
|
() => {
|
||||||
|
if (formState.overlapSize > maxOverlapSize.value) {
|
||||||
|
formState.overlapSize = maxOverlapSize.value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
formState,
|
formState,
|
||||||
() => {
|
() => {
|
||||||
@@ -456,7 +471,7 @@ watch(
|
|||||||
>
|
>
|
||||||
<ElSlider
|
<ElSlider
|
||||||
v-model="formState.overlapSize"
|
v-model="formState.overlapSize"
|
||||||
:max="512"
|
:max="Math.min(512, maxOverlapSize)"
|
||||||
:min="0"
|
:min="0"
|
||||||
show-input
|
show-input
|
||||||
/>
|
/>
|
||||||
@@ -484,6 +499,20 @@ watch(
|
|||||||
>
|
>
|
||||||
<ElInput v-model="formState.regex" />
|
<ElInput v-model="formState.regex" />
|
||||||
</ElFormItem>
|
</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>
|
</div>
|
||||||
</ElForm>
|
</ElForm>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user