From 2aadd61fcc5078f58efd1a862545c5eba4297d40 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Tue, 9 Jun 2026 20:34:16 +0800 Subject: [PATCH] feat: implement reparse functionality with process configuration support - Enhanced the `reparseKnowledge` function to accept optional process configuration overrides, allowing users to adjust parsing settings during reparse operations. - Updated the frontend components to integrate reparse capabilities, including the `UploadConfirmDialog` and `KnowledgeBase` views, providing a user-friendly interface for confirming reparse actions. - Added new localization strings for reparse confirmation and process configuration details in multiple languages. - Modified the backend API to handle reparse requests with optional configuration, ensuring proper validation and persistence of overrides. - Introduced new types and interfaces to manage reparse-specific data structures in the store, improving type safety and clarity in the codebase. --- frontend/src/api/knowledge-base/index.ts | 4 +- frontend/src/components/UploadConfirmHost.vue | 1 + .../knowledge-processing-timeline.vue | 92 ++++++++++++++++++- frontend/src/i18n/locales/en-US.ts | 21 +++++ frontend/src/i18n/locales/ko-KR.ts | 21 +++++ frontend/src/i18n/locales/ru-RU.ts | 21 +++++ frontend/src/i18n/locales/zh-CN.ts | 21 +++++ frontend/src/stores/uploadConfirm.ts | 14 ++- .../src/views/knowledge/KnowledgeBase.vue | 63 ++++++++++--- .../components/UploadConfirmDialog.vue | 65 +++++++++++++ .../application/service/knowledge_process.go | 26 +++++- .../service/knowledge_process_config.go | 19 ++++ internal/handler/knowledge.go | 18 +++- internal/types/interfaces/knowledge.go | 8 +- 14 files changed, 371 insertions(+), 23 deletions(-) diff --git a/frontend/src/api/knowledge-base/index.ts b/frontend/src/api/knowledge-base/index.ts index 9ffdad3f..2c54e659 100644 --- a/frontend/src/api/knowledge-base/index.ts +++ b/frontend/src/api/knowledge-base/index.ts @@ -251,8 +251,8 @@ export function updateManualKnowledge( return put(`/api/v1/knowledge/manual/${id}`, data); } -export function reparseKnowledge(id: string) { - return post(`/api/v1/knowledge/${id}/reparse`); +export function reparseKnowledge(id: string, data?: { process_config?: KnowledgeProcessOverrides }) { + return post(`/api/v1/knowledge/${id}/reparse`, data); } export function cancelKnowledgeParse(id: string) { diff --git a/frontend/src/components/UploadConfirmHost.vue b/frontend/src/components/UploadConfirmHost.vue index 81724ab0..1e257935 100644 --- a/frontend/src/components/UploadConfirmHost.vue +++ b/frontend/src/components/UploadConfirmHost.vue @@ -21,6 +21,7 @@ const handleCancel = () => { :files="uploadConfirmStore.files" :urls="uploadConfirmStore.urls" :manual-preview="uploadConfirmStore.manual" + :reparse-preview="uploadConfirmStore.reparse" :accept-file-types="uploadConfirmStore.acceptFileTypes" :supported-file-types="uploadConfirmStore.supportedFileTypes" @confirm="handleConfirm" diff --git a/frontend/src/components/knowledge-processing-timeline.vue b/frontend/src/components/knowledge-processing-timeline.vue index 20676f82..26ec782f 100644 --- a/frontend/src/components/knowledge-processing-timeline.vue +++ b/frontend/src/components/knowledge-processing-timeline.vue @@ -2,8 +2,9 @@ import { ref, reactive, onMounted, onBeforeUnmount, watch, computed, nextTick } from 'vue' import { MessagePlugin } from 'tdesign-vue-next' import { useI18n } from 'vue-i18n' -import { getKnowledgeSpans, reparseKnowledge, cancelKnowledgeParse } from '@/api/knowledge-base/index' +import { getKnowledgeSpans, reparseKnowledge, cancelKnowledgeParse, getKnowledgeDetails } from '@/api/knowledge-base/index' import { knowledgeSpansPayloadHasTrace } from '@/utils/knowledgeTrace' +import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess' interface SpanNode { span_id?: string @@ -92,6 +93,7 @@ const STAGES = ['docreader', 'chunking', 'embedding', 'multimodal', 'postprocess const POLL_INTERVAL_MS = 2000 const data = ref(null) +const processOverrides = ref(null) const loading = ref(false) const refreshing = ref(false) const selectedAttempt = ref(undefined) @@ -519,8 +521,21 @@ function onKeydown(ev: KeyboardEvent) { } } +async function fetchProcessOverrides() { + if (props.compact || !props.knowledgeId) return + try { + const res: any = await getKnowledgeDetails(props.knowledgeId) + if (res?.success && res.data) { + processOverrides.value = res.data.metadata?.process_overrides ?? null + } + } catch { + processOverrides.value = null + } +} + onMounted(() => { fetchSpans() + fetchProcessOverrides() // One permanent interval for the entire component lifetime. The // tick decides whether to actually fetch — no clearing, no // re-arming, no watchers wired into it. If this interval ever @@ -1290,6 +1305,46 @@ const stageBreakdown = computed(() => { pct: typeof s.duration_ms === 'number' && s.duration_ms > 0 ? Math.min(100, (s.duration_ms / total) * 100) : 0, })) }) + +// Human-readable summary of the per-upload parse overrides stored in +// knowledge.metadata.process_overrides. Empty overrides → KB defaults. +const processConfigLines = computed(() => { + const o = processOverrides.value + if (!o) return [t('knowledgeStages.processConfig.kbDefault')] + const k = (s: string) => `knowledgeStages.processConfig.${s}` + const onOff = (v: boolean) => (v ? t(k('on')) : t(k('off'))) + const lines: string[] = [] + + const cc = o.chunking_config + if (cc) { + const parts: string[] = [] + if (cc.chunk_size != null) parts.push(t(k('chunkSize'), { n: cc.chunk_size })) + if (cc.enable_parent_child != null) { + parts.push(cc.enable_parent_child ? t(k('parentChildOn')) : t(k('parentChildOff'))) + } + if (parts.length) lines.push(`${t(k('chunking'))}: ${parts.join(' · ')}`) + } + + const rules = o.parser_engine_rules || cc?.parser_engine_rules + if (rules?.length) { + lines.push(`${t(k('parser'))}: ${rules.map(r => `${r.file_types.join('/')}→${r.engine}`).join(', ')}`) + } + + const mm = o.vlm_config?.enabled ?? o.enable_multimodel + if (mm != null) lines.push(`${t(k('multimodal'))}: ${onOff(mm)}`) + + if (o.asr_config?.enabled != null) lines.push(`${t(k('asr'))}: ${onOff(o.asr_config.enabled)}`) + + const qg = o.question_generation_config + if (qg?.enabled != null) { + lines.push(`${t(k('question'))}: ${qg.enabled ? t(k('questionOn'), { n: qg.question_count ?? 3 }) : t(k('off'))}`) + } + + const graph = o.graph_enabled ?? o.extract_config?.enabled + if (graph != null) lines.push(`${t(k('graph'))}: ${onOff(graph)}`) + + return lines.length ? lines : [t('knowledgeStages.processConfig.kbDefault')] +})