feat: implement parent-child chunking strategy for enhanced context management
- Added support for parent-child chunking in the knowledge base, allowing for a two-level chunking strategy that improves context retrieval. - Introduced new configuration options for enabling parent-child chunking, including parent and child chunk sizes. - Updated relevant components and services to handle parent chunk data, ensuring proper linking and retrieval of child chunks. - Enhanced user interface elements to reflect the new chunking options and provide better user guidance. These changes significantly improve the knowledge extraction process by providing richer context through hierarchical chunking.
This commit is contained in:
@@ -296,7 +296,10 @@ const initFormData = (type: 'document' | 'faq' = 'document') => {
|
||||
chunkSize: 512,
|
||||
chunkOverlap: 100,
|
||||
separators: ['\n\n', '\n', '。', '!', '?', ';', ';'],
|
||||
parserEngineRules: undefined as any
|
||||
parserEngineRules: undefined as any,
|
||||
enableParentChild: false,
|
||||
parentChunkSize: 1024,
|
||||
childChunkSize: 256
|
||||
},
|
||||
storageProvider: 'local' as string,
|
||||
multimodalConfig: {
|
||||
@@ -373,7 +376,10 @@ const loadKBData = async () => {
|
||||
chunkSize: kb.chunking_config?.chunk_size || 512,
|
||||
chunkOverlap: kb.chunking_config?.chunk_overlap || 100,
|
||||
separators: kb.chunking_config?.separators || ['\n\n', '\n', '。', '!', '?', ';', ';'],
|
||||
parserEngineRules: kb.chunking_config?.parser_engine_rules || undefined
|
||||
parserEngineRules: kb.chunking_config?.parser_engine_rules || undefined,
|
||||
enableParentChild: kb.chunking_config?.enable_parent_child || false,
|
||||
parentChunkSize: kb.chunking_config?.parent_chunk_size || 1024,
|
||||
childChunkSize: kb.chunking_config?.child_chunk_size || 256
|
||||
},
|
||||
storageProvider: (kb.storage_config?.provider || 'local') as string,
|
||||
multimodalConfig: {
|
||||
@@ -503,6 +509,9 @@ const buildSubmitData = () => {
|
||||
chunk_overlap: formData.value.chunkingConfig.chunkOverlap,
|
||||
separators: formData.value.chunkingConfig.separators,
|
||||
enable_multimodal: formData.value.multimodalConfig.enabled,
|
||||
enable_parent_child: formData.value.chunkingConfig.enableParentChild,
|
||||
parent_chunk_size: formData.value.chunkingConfig.parentChunkSize,
|
||||
child_chunk_size: formData.value.chunkingConfig.childChunkSize,
|
||||
...(formData.value.chunkingConfig.parserEngineRules?.length
|
||||
? { parser_engine_rules: formData.value.chunkingConfig.parserEngineRules }
|
||||
: {})
|
||||
@@ -603,7 +612,10 @@ const handleSubmit = async () => {
|
||||
chunkSize: data.chunking_config.chunk_size,
|
||||
chunkOverlap: data.chunking_config.chunk_overlap,
|
||||
separators: data.chunking_config.separators,
|
||||
parserEngineRules: data.chunking_config.parser_engine_rules || undefined
|
||||
parserEngineRules: data.chunking_config.parser_engine_rules || undefined,
|
||||
enableParentChild: data.chunking_config.enable_parent_child || false,
|
||||
parentChunkSize: data.chunking_config.parent_chunk_size || 1024,
|
||||
childChunkSize: data.chunking_config.child_chunk_size || 256
|
||||
},
|
||||
multimodal: {
|
||||
enabled: !!data.vlm_config?.enabled
|
||||
|
||||
@@ -69,6 +69,64 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Parent-Child Chunking -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.chunking.parentChildLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.chunking.parentChildDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-switch
|
||||
v-model="localEnableParentChild"
|
||||
@change="handleParentChildChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Parent Chunk Size -->
|
||||
<div v-if="localEnableParentChild" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.chunking.parentChunkSizeLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.chunking.parentChunkSizeDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="slider-container">
|
||||
<t-slider
|
||||
v-model="localParentChunkSize"
|
||||
:min="256"
|
||||
:max="4096"
|
||||
:step="64"
|
||||
:marks="{ 256: '256', 1024: '1024', 2048: '2048', 4096: '4096' }"
|
||||
@change="handleParentChunkSizeChange"
|
||||
style="width: 200px;"
|
||||
/>
|
||||
<span class="value-display">{{ localParentChunkSize }} {{ $t('knowledgeEditor.chunking.characters') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Child Chunk Size -->
|
||||
<div v-if="localEnableParentChild" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('knowledgeEditor.chunking.childChunkSizeLabel') }}</label>
|
||||
<p class="desc">{{ $t('knowledgeEditor.chunking.childChunkSizeDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="slider-container">
|
||||
<t-slider
|
||||
v-model="localChildChunkSize"
|
||||
:min="64"
|
||||
:max="1024"
|
||||
:step="32"
|
||||
:marks="{ 64: '64', 256: '256', 512: '512', 1024: '1024' }"
|
||||
@change="handleChildChunkSizeChange"
|
||||
style="width: 200px;"
|
||||
/>
|
||||
<span class="value-display">{{ localChildChunkSize }} {{ $t('knowledgeEditor.chunking.characters') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -87,6 +145,9 @@ interface ChunkingConfig {
|
||||
chunkOverlap: number
|
||||
separators: string[]
|
||||
parserEngineRules?: ParserEngineRule[]
|
||||
enableParentChild: boolean
|
||||
parentChunkSize: number
|
||||
childChunkSize: number
|
||||
}
|
||||
|
||||
interface Props {
|
||||
@@ -102,6 +163,9 @@ const emit = defineEmits<{
|
||||
const localChunkSize = ref(props.config.chunkSize)
|
||||
const localChunkOverlap = ref(props.config.chunkOverlap)
|
||||
const localSeparators = ref([...props.config.separators])
|
||||
const localEnableParentChild = ref(props.config.enableParentChild ?? false)
|
||||
const localParentChunkSize = ref(props.config.parentChunkSize || 1024)
|
||||
const localChildChunkSize = ref(props.config.childChunkSize || 256)
|
||||
const { t } = useI18n()
|
||||
|
||||
const separatorOptions = computed(() => [
|
||||
@@ -119,18 +183,27 @@ watch(() => props.config, (newConfig) => {
|
||||
localChunkSize.value = newConfig.chunkSize
|
||||
localChunkOverlap.value = newConfig.chunkOverlap
|
||||
localSeparators.value = [...newConfig.separators]
|
||||
localEnableParentChild.value = newConfig.enableParentChild ?? false
|
||||
localParentChunkSize.value = newConfig.parentChunkSize || 1024
|
||||
localChildChunkSize.value = newConfig.childChunkSize || 256
|
||||
}, { deep: true })
|
||||
|
||||
const handleChunkSizeChange = () => { emitUpdate() }
|
||||
const handleChunkOverlapChange = () => { emitUpdate() }
|
||||
const handleSeparatorsChange = () => { emitUpdate() }
|
||||
const handleParentChildChange = () => { emitUpdate() }
|
||||
const handleParentChunkSizeChange = () => { emitUpdate() }
|
||||
const handleChildChunkSizeChange = () => { emitUpdate() }
|
||||
|
||||
const emitUpdate = () => {
|
||||
emit('update:config', {
|
||||
chunkSize: localChunkSize.value,
|
||||
chunkOverlap: localChunkOverlap.value,
|
||||
separators: localSeparators.value,
|
||||
parserEngineRules: props.config.parserEngineRules
|
||||
parserEngineRules: props.config.parserEngineRules,
|
||||
enableParentChild: localEnableParentChild.value,
|
||||
parentChunkSize: localParentChunkSize.value,
|
||||
childChunkSize: localChildChunkSize.value
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user