feat: document batch operation tool add re-index operation (#30275)

This commit is contained in:
wangxiaolei 2025-12-29 10:03:15 +08:00 committed by GitHub
parent 44ab8a3376
commit 8b38e3f79d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 47 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import type { FC } from 'react'
import { RiArchive2Line, RiCheckboxCircleLine, RiCloseCircleLine, RiDeleteBinLine, RiDraftLine } from '@remixicon/react'
import { RiArchive2Line, RiCheckboxCircleLine, RiCloseCircleLine, RiDeleteBinLine, RiDraftLine, RiRefreshLine } from '@remixicon/react'
import { useBoolean } from 'ahooks'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
@ -17,6 +17,7 @@ type IBatchActionProps = {
onBatchDelete: () => Promise<void>
onArchive?: () => void
onEditMetadata?: () => void
onBatchReIndex?: () => void
onCancel: () => void
}
@ -28,6 +29,7 @@ const BatchAction: FC<IBatchActionProps> = ({
onArchive,
onBatchDelete,
onEditMetadata,
onBatchReIndex,
onCancel,
}) => {
const { t } = useTranslation()
@ -91,6 +93,16 @@ const BatchAction: FC<IBatchActionProps> = ({
<span className="px-0.5">{t(`${i18nPrefix}.archive`)}</span>
</Button>
)}
{onBatchReIndex && (
<Button
variant="ghost"
className="gap-x-0.5 px-3"
onClick={onBatchReIndex}
>
<RiRefreshLine className="size-4" />
<span className="px-0.5">{t(`${i18nPrefix}.reIndex`)}</span>
</Button>
)}
<Button
variant="ghost"
destructive

View File

@ -26,7 +26,7 @@ import { useDatasetDetailContextWithSelector as useDatasetDetailContext } from '
import useTimestamp from '@/hooks/use-timestamp'
import { ChunkingMode, DataSourceType, DocumentActionType } from '@/models/datasets'
import { DatasourceType } from '@/models/pipeline'
import { useDocumentArchive, useDocumentDelete, useDocumentDisable, useDocumentEnable } from '@/service/knowledge/use-document'
import { useDocumentArchive, useDocumentBatchRetryIndex, useDocumentDelete, useDocumentDisable, useDocumentEnable } from '@/service/knowledge/use-document'
import { asyncRunSafe } from '@/utils'
import { cn } from '@/utils/classnames'
import { formatNumber } from '@/utils/format'
@ -220,6 +220,7 @@ const DocumentList: FC<IDocumentListProps> = ({
const { mutateAsync: enableDocument } = useDocumentEnable()
const { mutateAsync: disableDocument } = useDocumentDisable()
const { mutateAsync: deleteDocument } = useDocumentDelete()
const { mutateAsync: retryIndexDocument } = useDocumentBatchRetryIndex()
const handleAction = (actionName: DocumentActionType) => {
return async () => {
@ -250,6 +251,22 @@ const DocumentList: FC<IDocumentListProps> = ({
}
}
const handleBatchReIndex = async () => {
const [e] = await asyncRunSafe<CommonResponse>(retryIndexDocument({ datasetId, documentIds: selectedIds }))
if (!e) {
onSelectedIdChange([])
Toast.notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
onUpdate()
}
else {
Toast.notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') })
}
}
const hasErrorDocumentsSelected = useMemo(() => {
return localDocs.some(doc => selectedIds.includes(doc.id) && doc.display_status === 'error')
}, [localDocs, selectedIds])
const getFileExtension = useCallback((fileName: string): string => {
if (!fileName)
return ''
@ -447,6 +464,7 @@ const DocumentList: FC<IDocumentListProps> = ({
onBatchDisable={handleAction(DocumentActionType.disable)}
onBatchDelete={handleAction(DocumentActionType.delete)}
onEditMetadata={showEditModal}
onBatchReIndex={hasErrorDocumentsSelected ? handleBatchReIndex : undefined}
onCancel={() => {
onSelectedIdChange([])
}}

View File

@ -170,6 +170,7 @@ const translation = {
enable: 'Enable',
disable: 'Disable',
archive: 'Archive',
reIndex: 'Re-index',
delete: 'Delete',
cancel: 'Cancel',
},

View File

@ -170,6 +170,7 @@ const translation = {
enable: '启用',
disable: '禁用',
archive: '归档',
reIndex: '重新索引',
delete: '删除',
cancel: '取消',
},

View File

@ -7,7 +7,7 @@ import {
} from '@tanstack/react-query'
import { normalizeStatusForQuery } from '@/app/components/datasets/documents/status-filter'
import { DocumentActionType } from '@/models/datasets'
import { del, get, patch } from '../base'
import { del, get, patch, post } from '../base'
import { pauseDocIndexing, resumeDocIndexing } from '../datasets'
import { useInvalid } from '../use-base'
@ -163,3 +163,15 @@ export const useDocumentResume = () => {
},
})
}
export const useDocumentBatchRetryIndex = () => {
return useMutation({
mutationFn: ({ datasetId, documentIds }: { datasetId: string, documentIds: string[] }) => {
return post<CommonResponse>(`/datasets/${datasetId}/retry`, {
body: {
document_ids: documentIds,
},
})
},
})
}