mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: enhance form layout and add dynamic selection for chunk size, patterns, and limits
This commit is contained in:
parent
4b417edbbf
commit
a8c4e48e31
|
|
@ -35,13 +35,38 @@ class DocumentSplitNodeSerializer(serializers.Serializer):
|
|||
required=False, label=_("document name relate problem reference"), child=serializers.CharField(), default=[]
|
||||
)
|
||||
limit = serializers.IntegerField(required=False, label=_("limit"), default=4096)
|
||||
limit_type = serializers.ChoiceField(
|
||||
choices=['custom', 'referencing'], required=False, label=_("document name relate problem type"),
|
||||
default='custom'
|
||||
)
|
||||
limit_reference = serializers.ListField(
|
||||
required=False, label=_("limit reference"), child=serializers.CharField(), default=[]
|
||||
)
|
||||
chunk_size = serializers.IntegerField(required=False, label=_("chunk size"), default=256)
|
||||
chunk_size_type = serializers.ChoiceField(
|
||||
choices=['custom', 'referencing'], required=False, label=_("chunk size type"), default='custom'
|
||||
)
|
||||
chunk_size_reference = serializers.ListField(
|
||||
required=False, label=_("chunk size reference"), child=serializers.CharField(), default=[]
|
||||
)
|
||||
patterns = serializers.ListField(
|
||||
required=False, label=_("patterns"), child=serializers.CharField(), default=[]
|
||||
)
|
||||
patterns_type = serializers.ChoiceField(
|
||||
choices=['custom', 'referencing'], required=False, label=_("patterns type"), default='custom'
|
||||
)
|
||||
patterns_reference = serializers.ListField(
|
||||
required=False, label=_("patterns reference"), child=serializers.CharField(), default=[]
|
||||
)
|
||||
with_filter = serializers.BooleanField(
|
||||
required=False, label=_("with filter"), default=False
|
||||
)
|
||||
with_filter_type = serializers.ChoiceField(
|
||||
choices=['custom', 'referencing'], required=False, label=_("with filter type"), default='custom'
|
||||
)
|
||||
with_filter_reference = serializers.ListField(
|
||||
required=False, label=_("with filter reference"), child=serializers.CharField(), default=[]
|
||||
)
|
||||
|
||||
|
||||
class IDocumentSplitNode(INode):
|
||||
|
|
@ -59,5 +84,7 @@ class IDocumentSplitNode(INode):
|
|||
def execute(self, document_list, knowledge_id, split_strategy, paragraph_title_relate_problem_type,
|
||||
paragraph_title_relate_problem, paragraph_title_relate_problem_reference,
|
||||
document_name_relate_problem_type, document_name_relate_problem,
|
||||
document_name_relate_problem_reference, limit, chunk_size, patterns, with_filter, **kwargs) -> NodeResult:
|
||||
document_name_relate_problem_reference, limit, limit_type, limit_reference, chunk_size, chunk_size_type,
|
||||
chunk_size_reference, patterns, patterns_type, patterns_reference, with_filter, with_filter_type,
|
||||
with_filter_reference, **kwargs) -> NodeResult:
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -44,11 +44,23 @@ class BaseDocumentSplitNode(IDocumentSplitNode):
|
|||
def execute(self, document_list, knowledge_id, split_strategy, paragraph_title_relate_problem_type,
|
||||
paragraph_title_relate_problem, paragraph_title_relate_problem_reference,
|
||||
document_name_relate_problem_type, document_name_relate_problem,
|
||||
document_name_relate_problem_reference, limit, chunk_size, patterns, with_filter, **kwargs) -> NodeResult:
|
||||
document_name_relate_problem_reference, limit, limit_type, limit_reference, chunk_size, chunk_size_type,
|
||||
chunk_size_reference, patterns, patterns_type, patterns_reference, with_filter, with_filter_type,
|
||||
with_filter_reference, **kwargs) -> NodeResult:
|
||||
self.context['knowledge_id'] = knowledge_id
|
||||
file_list = self.workflow_manage.get_reference_field(document_list[0], document_list[1:])
|
||||
paragraph_list = []
|
||||
file_list = self.get_reference_content(document_list)
|
||||
|
||||
# 处理引用类型的参数
|
||||
if patterns_type == 'referencing':
|
||||
patterns = self.get_reference_content(patterns_reference)
|
||||
if limit_type == 'referencing':
|
||||
limit = self.get_reference_content(limit_reference)
|
||||
if chunk_size_type == 'referencing':
|
||||
chunk_size = self.get_reference_content(chunk_size_reference)
|
||||
if with_filter_type == 'referencing':
|
||||
with_filter = self.get_reference_content(with_filter_reference)
|
||||
|
||||
paragraph_list = []
|
||||
for doc in file_list:
|
||||
get_buffer = FileBufferHandle().get_buffer
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
:label="$t('views.workflow.nodes.documentSplitNode.splitStrategy.label')"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: $t('views.workflow.nodes.documentSplitNode.splitStrategy.required'),
|
||||
message: $t('views.workflow.nodes.documentSplitNode.splitStrategy.requiredMessage'),
|
||||
trigger: 'change'
|
||||
}"
|
||||
>
|
||||
|
|
@ -52,45 +52,79 @@
|
|||
</el-form-item>
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
<div class="flex">
|
||||
<span>子分块长度</span>
|
||||
<el-tooltip
|
||||
effect="dark"
|
||||
placement="top"
|
||||
>
|
||||
<template #content>
|
||||
核心目标是平衡检索精度与召回效率 <br/>
|
||||
•避免过短拆分:单块<50 字易导致语义碎片化,检索时可能因缺少上下文无法匹配查询意图<br/>
|
||||
•避免过长拆分:单块>500 字会增加冗余信息,降低检索精准度,且占用更多存储和计算资源
|
||||
</template>
|
||||
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
|
||||
</el-tooltip>
|
||||
<div class="flex-between">
|
||||
<span>
|
||||
<span>子分块长度</span>
|
||||
<el-tooltip
|
||||
effect="dark"
|
||||
placement="right"
|
||||
>
|
||||
<template #content>
|
||||
核心目标是平衡检索精度与召回效率 <br/>
|
||||
•避免过短拆分:单块<50 字易导致语义碎片化,检索时可能因缺少上下文无法匹配查询意图<br/>
|
||||
•避免过长拆分:单块>500 字会增加冗余信息,降低检索精准度,且占用更多存储和计算资源
|
||||
</template>
|
||||
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
|
||||
</el-tooltip>
|
||||
</span>
|
||||
<el-select v-model="form_data.chunk_size_type" size="small" style="width: 100px">
|
||||
<el-option
|
||||
:label="$t('views.workflow.nodes.searchDocumentNode.custom')"
|
||||
value="custom"
|
||||
/>
|
||||
<el-option
|
||||
:label="$t('views.workflow.variable.Referencing')"
|
||||
value="referencing"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
</template>
|
||||
<el-input-number
|
||||
v-if="form_data.chunk_size_type === 'custom'"
|
||||
v-model="form_data.chunk_size"
|
||||
show-input
|
||||
:min="50"
|
||||
:max="100000"
|
||||
/>
|
||||
<NodeCascader
|
||||
v-else
|
||||
ref="nodeCascaderRef4"
|
||||
:nodeModel="nodeModel"
|
||||
class="w-full"
|
||||
:placeholder="$t('views.chatLog.documentPlaceholder')"
|
||||
v-model="form_data.chunk_size_reference"
|
||||
/>
|
||||
</el-form-item>
|
||||
<div v-if="form_data.split_strategy === 'custom'">
|
||||
<div class="set-rules__form">
|
||||
<div class="form-item mb-16">
|
||||
<div class="title flex align-center mb-8">
|
||||
<span style="margin-right: 4px">{{
|
||||
$t('views.document.setRules.patterns.label')
|
||||
}}</span>
|
||||
<el-tooltip
|
||||
effect="dark"
|
||||
:content="$t('views.document.setRules.patterns.tooltip')"
|
||||
placement="right"
|
||||
>
|
||||
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
|
||||
</el-tooltip>
|
||||
<div class="flex-between">
|
||||
<div class="title flex align-center mb-8">
|
||||
<span style="margin-right: 4px">
|
||||
{{ $t('views.document.setRules.patterns.label') }}
|
||||
</span>
|
||||
<el-tooltip
|
||||
effect="dark"
|
||||
:content="$t('views.document.setRules.patterns.tooltip')"
|
||||
placement="right"
|
||||
>
|
||||
<AppIcon iconName="app-warning" class="app-warning-icon"></AppIcon>
|
||||
</el-tooltip>
|
||||
</div>
|
||||
<el-select v-model="form_data.patterns_type" size="small" style="width: 100px">
|
||||
<el-option
|
||||
:label="$t('views.workflow.nodes.searchDocumentNode.custom')"
|
||||
value="custom"
|
||||
/>
|
||||
<el-option
|
||||
:label="$t('views.workflow.variable.Referencing')"
|
||||
value="referencing"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
<div @click.stop>
|
||||
<el-select
|
||||
v-if="form_data.patterns_type === 'custom'"
|
||||
v-model="form_data.patterns"
|
||||
multiple
|
||||
:reserve-keyword="false"
|
||||
|
|
@ -107,25 +141,74 @@
|
|||
>
|
||||
</el-option>
|
||||
</el-select>
|
||||
<NodeCascader
|
||||
v-else
|
||||
ref="nodeCascaderRef5"
|
||||
:nodeModel="nodeModel"
|
||||
class="w-full"
|
||||
:placeholder="$t('views.chatLog.documentPlaceholder')"
|
||||
v-model="form_data.patterns_reference"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item mb-16">
|
||||
<div class="title mb-8">
|
||||
{{ $t('views.document.setRules.limit.label') }}
|
||||
<div class="flex-between">
|
||||
<div class="title mb-8">
|
||||
{{ $t('views.document.setRules.limit.label') }}
|
||||
</div>
|
||||
<el-select v-model="form_data.limit_type" size="small" style="width: 100px">
|
||||
<el-option
|
||||
:label="$t('views.workflow.nodes.searchDocumentNode.custom')"
|
||||
value="custom"
|
||||
/>
|
||||
<el-option
|
||||
:label="$t('views.workflow.variable.Referencing')"
|
||||
value="referencing"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
<el-slider
|
||||
v-if="form_data.limit_type === 'custom'"
|
||||
v-model="form_data.limit"
|
||||
show-input
|
||||
:show-input-controls="false"
|
||||
:min="50"
|
||||
:max="100000"
|
||||
/>
|
||||
<NodeCascader
|
||||
v-else
|
||||
ref="nodeCascaderRef6"
|
||||
:nodeModel="nodeModel"
|
||||
class="w-full"
|
||||
:placeholder="$t('views.chatLog.documentPlaceholder')"
|
||||
v-model="form_data.limit_reference"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-item mb-16">
|
||||
<div class="title mb-8">
|
||||
{{ $t('views.document.setRules.with_filter.label') }}
|
||||
<div class="flex-between">
|
||||
<div class="title mb-8">
|
||||
{{ $t('views.document.setRules.with_filter.label') }}
|
||||
</div>
|
||||
<el-select v-model="form_data.with_filter_type" size="small" style="width: 100px">
|
||||
<el-option
|
||||
:label="$t('views.workflow.nodes.searchDocumentNode.custom')"
|
||||
value="custom"
|
||||
/>
|
||||
<el-option
|
||||
:label="$t('views.workflow.variable.Referencing')"
|
||||
value="referencing"
|
||||
/>
|
||||
</el-select>
|
||||
</div>
|
||||
<el-switch size="small" v-model="form_data.with_filter" />
|
||||
<el-switch v-if="form_data.with_filter_type === 'custom'" size="small" v-model="form_data.with_filter" />
|
||||
<NodeCascader
|
||||
v-else
|
||||
ref="nodeCascaderRef7"
|
||||
:nodeModel="nodeModel"
|
||||
class="w-full"
|
||||
:placeholder="$t('views.chatLog.documentPlaceholder')"
|
||||
v-model="form_data.with_filter_reference"
|
||||
/>
|
||||
<div style="margin-top: 4px">
|
||||
<el-text type="info">
|
||||
{{ $t('views.document.setRules.with_filter.text') }}
|
||||
|
|
@ -240,9 +323,17 @@ const form = {
|
|||
document_name_relate_problem: false,
|
||||
document_name_relate_problem_reference: [],
|
||||
limit: 4096,
|
||||
limit_type: 'custom',
|
||||
limit_reference: [],
|
||||
chunk_size: 256,
|
||||
chunk_size_type: 'custom',
|
||||
chunk_size_reference: [],
|
||||
patterns: [],
|
||||
with_filter: false
|
||||
patterns_type: 'custom',
|
||||
patterns_reference: [],
|
||||
with_filter: false,
|
||||
with_filter_type: 'custom',
|
||||
with_filter_reference: []
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue