feat: add reparse functionality for knowledge documents
- Introduced a new API function `reparseKnowledge` to trigger the re-parsing of knowledge documents. - Updated the KnowledgeBase component to include a user interface option for document re-parsing, with confirmation prompts and status messages. - Added corresponding translations for the reparse feature in both English and Chinese locales. These changes enhance the document management capabilities by allowing users to rebuild knowledge documents, improving the overall user experience.
This commit is contained in:
@@ -98,6 +98,10 @@ export function updateManualKnowledge(id: string, data: { title: string; content
|
||||
return put(`/api/v1/knowledge/manual/${id}`, data);
|
||||
}
|
||||
|
||||
export function reparseKnowledge(id: string) {
|
||||
return post(`/api/v1/knowledge/${id}/reparse`);
|
||||
}
|
||||
|
||||
export function delKnowledgeDetails(id: string) {
|
||||
return del(`/api/v1/knowledge/${id}`);
|
||||
}
|
||||
|
||||
@@ -189,6 +189,11 @@ export default {
|
||||
// Additional translations for KnowledgeBase.vue
|
||||
newSession: 'New Chat',
|
||||
editDocument: 'Edit Document',
|
||||
rebuildDocument: 'Rebuild Document',
|
||||
rebuildConfirm: 'Rebuild document "{fileName}"? This will clear existing chunks and parse it again.',
|
||||
rebuildSubmitted: 'Rebuild task submitted',
|
||||
rebuildFailed: 'Rebuild failed. Please try again later',
|
||||
rebuildInProgress: 'This document is currently being parsed. Please try again later',
|
||||
draft: 'Draft',
|
||||
draftTip: 'Temporarily saved and not included in retrieval',
|
||||
untitledDocument: 'Untitled Document',
|
||||
|
||||
@@ -189,6 +189,11 @@ export default {
|
||||
totalSize: "总大小",
|
||||
newSession: "新会话",
|
||||
editDocument: "编辑文档",
|
||||
rebuildDocument: "重建知识",
|
||||
rebuildConfirm: '确认重建文档"{fileName}"?该操作会清理现有分块并重新解析。',
|
||||
rebuildSubmitted: "重建任务已提交",
|
||||
rebuildFailed: "重建失败,请稍后再试",
|
||||
rebuildInProgress: "当前文档正在解析中,请稍后重试",
|
||||
draft: "草稿",
|
||||
draftTip: "暂存内容,未参与检索",
|
||||
untitledDocument: "未命名文档",
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
uploadKnowledgeFile,
|
||||
createKnowledgeFromURL,
|
||||
listKnowledgeBases,
|
||||
reparseKnowledge,
|
||||
} from "@/api/knowledge-base/index";
|
||||
import FAQEntryManager from './components/FAQEntryManager.vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
@@ -1171,6 +1172,33 @@ const handleManualEdit = (index: number, item: KnowledgeCard) => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleKnowledgeReparse = async (index: number, item: KnowledgeCard) => {
|
||||
if (isFAQ.value) return;
|
||||
if (!canEdit.value) return;
|
||||
if (!item?.id) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.messages.missingId'));
|
||||
return;
|
||||
}
|
||||
if (item.parse_status === 'pending' || item.parse_status === 'processing') {
|
||||
MessagePlugin.info(t('knowledgeBase.rebuildInProgress'));
|
||||
return;
|
||||
}
|
||||
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;
|
||||
try {
|
||||
await reparseKnowledge(item.id);
|
||||
MessagePlugin.success(t('knowledgeBase.rebuildSubmitted'));
|
||||
loadKnowledgeFiles(kbId.value);
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('knowledgeBase.rebuildFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
const handleScroll = () => {
|
||||
if (isFAQ.value) return;
|
||||
const element = knowledgeScroll.value;
|
||||
@@ -1586,6 +1614,10 @@ async function createNewSession(value: string): Promise<void> {
|
||||
<t-icon class="icon" name="edit" />
|
||||
<span>{{ t('knowledgeBase.editDocument') }}</span>
|
||||
</div>
|
||||
<div class="card-menu-item" @click.stop="handleKnowledgeReparse(index, item)">
|
||||
<t-icon class="icon" name="refresh" />
|
||||
<span>{{ t('knowledgeBase.rebuildDocument') }}</span>
|
||||
</div>
|
||||
<div class="card-menu-item danger" @click.stop="delCard(index, item)">
|
||||
<t-icon class="icon" name="delete" />
|
||||
<span>{{ t('knowledgeBase.deleteDocument') }}</span>
|
||||
|
||||
Reference in New Issue
Block a user