feat(knowledge): implement knowledge item rebuild confirmation dialog and enhance chunk processing options

- Added a confirmation dialog for rebuilding knowledge items in the KnowledgeBase component.
- Introduced new state variables to manage the rebuild process and item selection.
- Enhanced the processChunks function to support question generation options based on configuration.
- Updated the knowledge service to handle question generation settings during document processing.
This commit is contained in:
wizardchen
2026-03-23 19:21:46 +08:00
committed by lyingbug
parent 0e01a8ca64
commit b02e3f1dbb
2 changed files with 59 additions and 9 deletions
+38 -7
View File
@@ -167,6 +167,8 @@ const onVisibleChange = (visible: boolean) => {
let isCardDetails = ref(false);
let timeout: ReturnType<typeof setInterval> | null = null;
let delDialog = ref(false)
let rebuildDialog = ref(false)
let rebuildKnowledgeItem = ref<KnowledgeCard>({ id: '', parse_status: '' })
let knowledge = ref<KnowledgeCard>({ id: '', parse_status: '' })
let knowledgeIndex = ref(-1)
let knowledgeScroll = ref()
@@ -1299,7 +1301,7 @@ const handleManualEdit = (index: number, item: KnowledgeCard) => {
});
};
const handleKnowledgeReparse = async (index: number, item: KnowledgeCard) => {
const handleKnowledgeReparse = (index: number, item: KnowledgeCard) => {
if (isFAQ.value) return;
if (!canEdit.value) return;
if (!item?.id) {
@@ -1313,10 +1315,14 @@ const handleKnowledgeReparse = async (index: number, item: KnowledgeCard) => {
if (cardList.value[index]) {
cardList.value[index].isMore = false;
}
const confirm = window.confirm(
t('knowledgeBase.rebuildConfirm', { fileName: item.file_name || item.title || '' }) as string,
);
if (!confirm) return;
rebuildKnowledgeItem.value = item;
rebuildDialog.value = true;
};
const rebuildConfirm = async () => {
rebuildDialog.value = false;
const item = rebuildKnowledgeItem.value;
if (!item?.id) return;
try {
await reparseKnowledge(item.id);
MessagePlugin.success(t('knowledgeBase.rebuildSubmitted'));
@@ -1736,7 +1742,7 @@ async function createNewSession(value: string): Promise<void> {
@click.stop="openMore(index)"
:class="[moreIndex == index ? 'active-more' : '']"
>
<img class="more" src="@/assets/img/more.png" alt="" />
<img class="more-icon" src="@/assets/img/more.png" alt="" />
</div>
<template #content>
<!-- Normal menu -->
@@ -1956,6 +1962,31 @@ async function createNewSession(value: string): Promise<void> {
</div>
</t-dialog>
<!-- 重建知识确认弹窗 -->
<t-dialog
v-model:visible="rebuildDialog"
dialogClassName="del-knowledge"
:closeBtn="false"
:cancelBtn="null"
:confirmBtn="null"
>
<div class="circle-wrap">
<div class="header">
<img class="circle-img" src="@/assets/img/circle.png" alt="" />
<span class="circle-title">{{ t('knowledgeBase.rebuildDocument') }}</span>
</div>
<span class="del-circle-txt">
{{ t('knowledgeBase.rebuildConfirm', { fileName: rebuildKnowledgeItem.file_name || rebuildKnowledgeItem.title || '' }) }}
</span>
<div class="circle-btn">
<span class="circle-btn-txt" @click="rebuildDialog = false">{{ t('common.cancel') }}</span>
<span class="circle-btn-txt confirm" @click="rebuildConfirm">
{{ t('common.confirm') }}
</span>
</div>
</div>
</t-dialog>
<!-- URL 导入对话框 -->
<t-dialog
v-model:visible="urlDialogVisible"
@@ -3187,7 +3218,7 @@ async function createNewSession(value: string): Promise<void> {
background: var(--td-component-stroke);
}
.more {
.more-icon {
width: 14px;
height: 14px;
}
+21 -2
View File
@@ -1344,7 +1344,15 @@ func (s *knowledgeService) processDocumentFromPassage(ctx context.Context,
start = end
}
// Process and store chunks
s.processChunks(ctx, kb, knowledge, chunks)
var opts ProcessChunksOptions
if kb.QuestionGenerationConfig != nil && kb.QuestionGenerationConfig.Enabled {
opts.EnableQuestionGeneration = true
opts.QuestionCount = kb.QuestionGenerationConfig.QuestionCount
if opts.QuestionCount <= 0 {
opts.QuestionCount = 3
}
}
s.processChunks(ctx, kb, knowledge, chunks, opts)
}
// ProcessChunksOptions contains options for processing chunks
@@ -6848,6 +6856,13 @@ func (s *knowledgeService) triggerManualProcessing(ctx context.Context,
EnableMultimodel: kb.IsMultimodalEnabled() && len(resolvedImages) > 0,
StoredImages: resolvedImages,
}
if kb.QuestionGenerationConfig != nil && kb.QuestionGenerationConfig.Enabled {
opts.EnableQuestionGeneration = true
opts.QuestionCount = kb.QuestionGenerationConfig.QuestionCount
if opts.QuestionCount <= 0 {
opts.QuestionCount = 3
}
}
if kb.ChunkingConfig.EnableParentChild {
parentCfg, childCfg := buildParentChildConfigs(kb.ChunkingConfig, chunkCfg)
@@ -7473,7 +7488,11 @@ func (s *knowledgeService) ProcessDocument(ctx context.Context, t *asynq.Task) e
})
start = end
}
s.processChunks(ctx, kb, knowledge, passageChunks)
passageOpts := ProcessChunksOptions{
EnableQuestionGeneration: payload.EnableQuestionGeneration,
QuestionCount: payload.QuestionCount,
}
s.processChunks(ctx, kb, knowledge, passageChunks, passageOpts)
return nil
} else {
// File import