Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(web): restore auto-metadata checkbox in reparse dialog (#21346)

chanx395ee73a6594
diff --git a/web/src/pages/dataset/dataset/parsing-status-cell.test.tsx b/web/src/pages/dataset/dataset/parsing-status-cell.test.tsx
index 511ead3ae5..863a5c775d 100644
--- a/web/src/pages/dataset/dataset/parsing-status-cell.test.tsx
+++ b/web/src/pages/dataset/dataset/parsing-status-cell.test.tsx
@@ -181,7 +181,7 @@ describe('ParsingStatusCell', () => {
renderCell({
ingestion_status: IngestionTaskStatus.COMPLETED,
chunk_count: 0,
- parser_config: { enable_metadata: true },
+ parser_config: {},
});
fireEvent.click(screen.getByTestId('document-parse-toggle'));
@@ -189,4 +189,32 @@ describe('ParsingStatusCell', () => {
expect(mockRunDocumentByIds).toHaveBeenCalledTimes(1);
expect(mockShowReparseDialog).not.toHaveBeenCalled();
});
+
+ it('asks for confirmation on a chunkless document when auto-metadata can be applied', () => {
+ renderCell({
+ ingestion_status: IngestionTaskStatus.COMPLETED,
+ chunk_count: 0,
+ parser_config: { enable_metadata: true },
+ });
+
+ fireEvent.click(screen.getByTestId('document-parse-toggle'));
+
+ expect(mockShowReparseDialog).toHaveBeenCalledTimes(1);
+ expect(mockRunDocumentByIds).not.toHaveBeenCalled();
+ });
+
+ it('detects auto-metadata in the pipeline parser config shape', () => {
+ renderCell({
+ ingestion_status: IngestionTaskStatus.COMPLETED,
+ chunk_count: 0,
+ parser_config: {
+ 'Extractor:AutoExtractDefault': { metadata: { enabled: true } },
+ },
+ });
+
+ fireEvent.click(screen.getByTestId('document-parse-toggle'));
+
+ expect(mockShowReparseDialog).toHaveBeenCalledTimes(1);
+ expect(mockRunDocumentByIds).not.toHaveBeenCalled();
+ });
});
diff --git a/web/src/pages/dataset/dataset/parsing-status-cell.tsx b/web/src/pages/dataset/dataset/parsing-status-cell.tsx
index 3340fe2dbd..7974b4c3a6 100644
--- a/web/src/pages/dataset/dataset/parsing-status-cell.tsx
+++ b/web/src/pages/dataset/dataset/parsing-status-cell.tsx
@@ -26,6 +26,7 @@ import { useHandleRunDocumentByIds } from './use-run-document';
import {
getDocumentParserLabel,
getDocumentRunningStatus,
+ isAutoMetadataEnabled,
isDocumentProcessing,
isDocumentStopping,
} from './utils';
@@ -136,10 +137,12 @@ export function ParsingStatusCell({
handleRunDocumentByIds(record, isRunning, option);
};
- // Existing chunks are always dropped server-side on re-ingest, so the
- // confirmation is only needed when there are existing chunks; otherwise, and
- // always when cancelling a run, the action fires straight away.
- const needsParseConfirm = !isRunning && !isZeroChunk;
+ const autoMetadataEnabled = isAutoMetadataEnabled(record?.parser_config);
+
+ // The confirmation only offers real choices when there are existing chunks to
+ // drop or auto-metadata to re-apply. Otherwise, and always when cancelling a
+ // run, the action fires straight away.
+ const needsParseConfirm = !isRunning && (!isZeroChunk || autoMetadataEnabled);
const handleParseClick = () => {
if (needsParseConfirm) {
@@ -263,6 +266,8 @@ export function ParsingStatusCell({
)}
{reparseDialogVisible && (
<ReparseDialog
+ chunk_num={chunk_count}
+ enable_metadata={autoMetadataEnabled}
handleOperationIconClick={handleOperationIconClick}
visible={reparseDialogVisible}
hideModal={hideReparseDialogModal}
diff --git a/web/src/pages/dataset/dataset/reparse-dialog.tsx b/web/src/pages/dataset/dataset/reparse-dialog.tsx
index 665136121b..5816d597dd 100644
--- a/web/src/pages/dataset/dataset/reparse-dialog.tsx
+++ b/web/src/pages/dataset/dataset/reparse-dialog.tsx
@@ -1,31 +1,71 @@
import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog';
-import { DynamicForm, DynamicFormRef } from '@/components/dynamic-form';
+import {
+ DynamicForm,
+ DynamicFormRef,
+ FormFieldConfig,
+ FormFieldType,
+} from '@/components/dynamic-form';
+import { Checkbox } from '@/components/ui/checkbox';
import { DialogProps } from '@radix-ui/react-dialog';
-import { memo, useCallback, useRef } from 'react';
+import { memo, useCallback, useEffect, useRef, useState } from 'react';
+import { ControllerRenderProps } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
export const ReparseDialog = memo(
({
handleOperationIconClick,
+ chunk_num,
+ enable_metadata = false,
visible = true,
hideModal,
}: DialogProps & {
+ chunk_num: number;
handleOperationIconClick: (options?: {
delete: boolean;
apply_kb: boolean;
}) => void;
+ enable_metadata?: boolean;
visible: boolean;
hideModal: () => void;
}) => {
+ const [defaultValues, setDefaultValues] = useState<any>(null);
+ const [fields, setFields] = useState<FormFieldConfig[]>([]);
const { t } = useTranslation();
- // Existing chunks are always dropped on re-ingest, so the dialog only
- // needs a plain confirmation with no checkboxes. Seed delete: true so the
- // click payload keeps the drop behavior.
- const defaultValues = {
- delete: true,
- apply_kb: false,
- };
+ useEffect(() => {
+ // delete has no checkbox in this dialog; seed it so the payload keeps
+ // dropping existing chunks (the backend skips re-parse when delete is
+ // false and the previous task completed).
+ setDefaultValues({
+ delete: true,
+ apply_kb: false,
+ });
+ const applyKBField = {
+ name: 'apply_kb',
+ label: '',
+ type: FormFieldType.Checkbox,
+ defaultValue: false,
+ render: (fieldProps: ControllerRenderProps) => (
+ <div className="flex items-center text-text-secondary p-5 border border-border-button rounded-lg">
+ <Checkbox
+ {...fieldProps}
+ checked={fieldProps.value}
+ onCheckedChange={(checked: boolean) => {
+ fieldProps.onChange(checked);
+ }}
+ />
+ <span className="ml-2">
+ {t('knowledgeDetails.applyAutoMetadataSettings')}
+ </span>
+ </div>
+ ),
+ };
+ if (enable_metadata) {
+ setFields([applyKBField]);
+ } else {
+ setFields([]);
+ }
+ }, [t, enable_metadata]);
const formCallbackRef = useRef<DynamicFormRef>(null);
@@ -60,7 +100,11 @@ export const ReparseDialog = memo(
open={visible}
okButtonText={t('common.confirm')}
content={{
- title: t(`knowledgeDetails.clearChunksReparseTip`),
+ title: t(
+ chunk_num > 0
+ ? `knowledgeDetails.clearChunksReparseTip`
+ : `knowledgeDetails.parseFileTip`,
+ ),
node: (
<div>
<DynamicForm.Root
@@ -68,7 +112,7 @@ export const ReparseDialog = memo(
console.log('submit', data);
}}
ref={formCallbackRef}
- fields={[]}
+ fields={fields}
defaultValues={defaultValues}
></DynamicForm.Root>
</div>
diff --git a/web/src/pages/dataset/dataset/utils.ts b/web/src/pages/dataset/dataset/utils.ts
index 05057233dc..086accac4a 100644
--- a/web/src/pages/dataset/dataset/utils.ts
+++ b/web/src/pages/dataset/dataset/utils.ts
@@ -421,6 +421,39 @@ export function getSavedParserConfig(
};
}
+/**
+ * Whether auto-metadata generation is switched on for the config a document
+ * actually runs with. Accepts both shapes a document row can carry: the
+ * pipeline shape (an Extractor operator node whose `metadata` group owns the
+ * enabled flag, matching transformExtractorConfigToForm's precedence) and the
+ * legacy flat shape (a top-level `enable_metadata`).
+ */
+export function isAutoMetadataEnabled(
+ parserConfig: Record<string, any> | undefined,
+): boolean {
+ if (!parserConfig) {
+ return false;
+ }
+ const extractor = Object.entries(parserConfig).find(
+ ([operatorId]) => getOperatorType(operatorId) === Operator.Extractor,
+ )?.[1];
+ if (extractor) {
+ const group =
+ extractor.metadata !== undefined && !Array.isArray(extractor.metadata)
+ ? extractor.metadata
+ : extractor.metadata_config;
+ if (group?.enabled !== undefined) {
+ return Boolean(group.enabled);
+ }
+ return (
+ extractor.enable_metadata === 1 || extractor.enable_metadata === true
+ );
+ }
+ return (
+ parserConfig.enable_metadata === 1 || parserConfig.enable_metadata === true
+ );
+}
+
export function findParserGap(
fileType: FileType | undefined,
config: SavedParserConfig,