feat(knowledge): add batch reparse capability

This commit introduces the Batch Reparse feature for the Knowledge Base.
Users can now select multiple documents and trigger a re-parsing pipeline in batches, streamlining the recovery from parse failures.
This commit is contained in:
jw_mac
2026-06-25 21:03:11 +08:00
committed by lyingbug
parent 5f2ca6c975
commit a14c1d87aa
5 changed files with 168 additions and 5 deletions
+9 -1
View File
@@ -120,7 +120,7 @@ export function updateKnowledgeBase(id: string, data: {
};
}
}) {
return put(`/api/v1/knowledge-bases/${id}` , data);
return put(`/api/v1/knowledge-bases/${id}`, data);
}
export function rebuildKBIndex(kbId: string) {
@@ -481,3 +481,11 @@ export function knowledgeSemanticSearch(data: {
}) {
return post('/api/v1/knowledge-search', data);
}
export function batchReparseKnowledge(kbId: string, ids: string[], processConfig?: any) {
return post(`/api/v1/knowledge/batch-reparse`, {
kb_id: kbId,
ids,
process_config: processConfig
});
}
+33 -3
View File
@@ -36,6 +36,7 @@ import {
reparseKnowledge,
cancelKnowledgeParse,
batchDeleteKnowledge,
batchReparseKnowledge,
getKnowledgeSpans,
getKnowledgeDetails,
} from "@/api/knowledge-base/index";
@@ -60,7 +61,7 @@ import { formatFileSize } from '@/utils/files';
import { useMarqueeSelect } from '@/hooks/useMarqueeSelect';
import type { ParserEngineInfo } from '@/api/system';
const route = useRoute();
const { t } = useI18n();
const { t, te } = useI18n();
const kbId = computed(() => (route.params as any).kbId as string || '');
const kbInfo = ref<any>(null);
const uploadSourceRef = ref<InstanceType<typeof KbUploadSourceDropdown> | null>(null);
@@ -415,6 +416,35 @@ watch(viewMode, (v) => {
const selectedIds = ref<Set<string>>(new Set());
let lastSelectedIndex = -1;
const batchDeleting = ref(false);
const batchReparsing = ref(false);
const confirmBatchReparse = async () => {
if (batchReparsing.value || selectedIds.value.size === 0) return;
const ids = Array.from(selectedIds.value);
batchReparsing.value = true;
try {
const res: any = await batchReparseKnowledge(kbId.value, ids);
if (res?.success) {
if (res.partial && res.failed_ids && res.failed_ids.length > 0) {
MessagePlugin.warning(`部分重构任务提交成功,失败 ${res.failed_ids.length} 个`);
} else {
const successMsg = te('knowledgeBase.batchReparseSuccess')
? t('knowledgeBase.batchReparseSuccess', { count: ids.length })
: `已提交 ${ids.length} 个重构任务`;
MessagePlugin.success(successMsg);
}
clearSelection();
batchMode.value = false;
loadKnowledgeFiles(kbId.value);
} else {
MessagePlugin.error(res?.message || '批量重建失败');
}
} catch (e: any) {
MessagePlugin.error(e?.message || '批量重建失败');
} finally {
batchReparsing.value = false;
}
};
const selectedTagId = ref<string>('');
const tagList = ref<any[]>([]);
@@ -2607,9 +2637,9 @@ async function createNewSession(value: string): Promise<void> {
</template>
</div>
<div class="doc-batch-bar-anchor" v-show="batchMode || selectedIds.size > 0">
<DocumentBatchBar :count="selectedIds.size" :loading="batchDeleting"
<DocumentBatchBar :count="selectedIds.size" :loading="batchDeleting || batchReparsing"
:visible="batchMode || selectedIds.size > 0" @cancel="handleBatchCancel"
@delete="confirmBatchDelete" />
@delete="confirmBatchDelete" @reparse="confirmBatchReparse" />
</div>
</div>
</div>
@@ -12,9 +12,10 @@ defineProps<{
const emit = defineEmits<{
(e: 'cancel'): void;
(e: 'delete'): void;
(e: 'reparse'): void;
}>();
const { t } = useI18n();
const { t, te } = useI18n();
</script>
<template>
@@ -39,6 +40,27 @@ const { t } = useI18n();
</t-button>
</div>
<div class="batch-bar-actions">
<t-popconfirm
theme="warning"
:content="te('knowledgeBase.overviewDescReparse') ? t('knowledgeBase.overviewDescReparse') : '确认后现有内容将被清除并重新解析该文档'"
:confirm-btn="{ content: te('knowledgeBase.confirmReparse') ? t('knowledgeBase.confirmReparse') : '确认并重新解析', theme: 'warning' }"
:cancel-btn="{ content: t('common.cancel') }"
placement="top"
@confirm="emit('reparse')"
>
<t-button
theme="default"
variant="outline"
size="small"
:disabled="count === 0"
:loading="loading"
@click.stop
>
<template #icon><t-icon name="refresh" size="14px" /></template>
{{ t('knowledgeBase.rebuildDocument') }}
</t-button>
</t-popconfirm>
<t-popconfirm
theme="warning"
:content="t('knowledgeBase.confirmBatchDeleteDocument', { count })"