Skip to content

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

Fix: Validate the value of the 'topn' field on the dataset configuration page when the 'auto keyword' feature of the extractor operator is enabled. (#20805)

balibabua1363151981d
diff --git a/web/src/components/pipeline-operator-tabs/parser-config-validation.test.ts b/web/src/components/pipeline-operator-tabs/parser-config-validation.test.ts
new file mode 100644
index 0000000000..00ec3ac9c9
--- /dev/null
+++ b/web/src/components/pipeline-operator-tabs/parser-config-validation.test.ts
@@ -0,0 +1,52 @@
+import i18n from '@/locales/config';
+import { z } from 'zod';
+import { addParserConfigIssues } from './parser-config-validation';
+
+// The operator form schemas reach @/routes via navigate-hooks, which builds a
+// browser router at import time and crashes outside a browser.
+jest.mock('@/routes', () => ({ Routes: {} }));
+
+type CollectedIssue = {
+ path: (string | number)[];
+ message?: string;
+ code?: string;
+};
+
+function collectIssues(parserConfig: Record<string, any> | undefined) {
+ const issues: CollectedIssue[] = [];
+ const ctx = {
+ addIssue: (issue: CollectedIssue) => {
+ issues.push(issue);
+ },
+ };
+ addParserConfigIssues(parserConfig, ctx as never, i18n.t);
+ return issues;
+}
+
+describe('addParserConfigIssues: extractor toggles', () => {
+ it('re-paths an enabled keywords group with top_n 0 onto parser_config', () => {
+ const issues = collectIssues({
+ 'Extractor:abc': { keywords: { enabled: true, top_n: 0 } },
+ });
+ expect(issues).toEqual([
+ {
+ path: ['parser_config', 'Extractor:abc', 'keywords', 'top_n'],
+ message: i18n.t('flow.extractorKeywordsTopNMissing'),
+ code: z.ZodIssueCode.custom,
+ },
+ ]);
+ });
+
+ it('flags a tags group without a tag file', () => {
+ const issues = collectIssues({
+ 'Extractor:abc': { tags: { enabled: true, top_n: 3 } },
+ });
+ expect(issues.map((x) => x.path.join('.'))).toEqual([
+ 'parser_config.Extractor:abc.tags.tag_file_id',
+ ]);
+ });
+
+ it('accepts the untouched defaults (every group switched off)', () => {
+ expect(collectIssues({ 'Extractor:abc': {} })).toEqual([]);
+ });
+});
diff --git a/web/src/components/pipeline-operator-tabs/parser-config-validation.ts b/web/src/components/pipeline-operator-tabs/parser-config-validation.ts
index 7e1b9a3cb2..5ac70cd0a4 100644
--- a/web/src/components/pipeline-operator-tabs/parser-config-validation.ts
+++ b/web/src/components/pipeline-operator-tabs/parser-config-validation.ts
@@ -18,7 +18,7 @@ import { Operator } from '@/constants/agent';
import {
initialCompilationValues,
initialGeneralChunkerValues,
- initialGoExtractorValues,
+ initialExtractorValues,
initialParserValues,
initialTitleChunkerValues,
initialTokenChunkerValues,
@@ -71,7 +71,7 @@ function getOperatorInitialValues(operatorType: Operator) {
case Operator.ManualChunker:
return initialTitleChunkerValues;
case Operator.Extractor:
- return initialGoExtractorValues;
+ return initialExtractorValues;
case Operator.Compiler:
return initialCompilationValues;
case Operator.Tokenizer:
diff --git a/web/src/pages/agent/constant/pipeline.tsx b/web/src/pages/agent/constant/pipeline.tsx
index ca4620c314..2367222ec4 100644
--- a/web/src/pages/agent/constant/pipeline.tsx
+++ b/web/src/pages/agent/constant/pipeline.tsx
@@ -365,20 +365,9 @@ export const initialTitleChunkerValues = {
groupRules: cloneDeep(originalRules),
};
-// Defaults for the Python backend extractor (legacy flat fields).
+// Defaults for the extractor: the LLM settings plus the nested per-feature
+// groups the Go schema reads (schema.ExtractorParam).
export const initialExtractorValues = {
- ...initialLlmBaseValues,
- field_name: ContextGeneratorFieldName.Summary,
- auto_tags: 1,
- tag_file_id: '',
- outputs: {
- chunks: { type: 'Array<Object>', value: [] },
- },
-};
-
-// Defaults for the Go backend extractor: the LLM settings plus the nested
-// per-feature groups the Go schema reads (schema.ExtractorParam).
-export const initialGoExtractorValues = {
...initialLlmBaseValues,
keywords: {
enabled: false,
@@ -410,7 +399,7 @@ export const initialGoExtractorValues = {
};
export function getInitialExtractorValues() {
- return initialGoExtractorValues;
+ return initialExtractorValues;
}
export const initialCompilationValues = {
diff --git a/web/src/pages/agent/form/extractor-form/go-form.tsx b/web/src/pages/agent/form/extractor-form/go-form.tsx
deleted file mode 100644
index 16d11c8229..0000000000
--- a/web/src/pages/agent/form/extractor-form/go-form.tsx
+++ /dev/null
@@ -1,459 +0,0 @@
-/*
- * Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import {
- AutoKeywordsFormField,
- AutoQuestionsFormField,
-} from '@/components/auto-keywords-form-field';
-import { Collapse } from '@/components/collapse';
-import { LargeModelFormField } from '@/components/large-model-form-field';
-import { LlmSettingSchema } from '@/components/llm-setting-items/next';
-import { useSyncExternalFormErrors } from '@/components/pipeline-operator-tabs/use-sync-external-form-errors';
-import { RAGFlowFormItem } from '@/components/ragflow-form';
-import { SliderInputFormField } from '@/components/slider-input-form-field';
-import { AsyncTreeSelect } from '@/components/ui/async-tree-select';
-import { Button } from '@/components/ui/button';
-import { Card } from '@/components/ui/card';
-import { Form } from '@/components/ui/form';
-import { Switch } from '@/components/ui/switch';
-import { Textarea } from '@/components/ui/textarea';
-import { FormLayout } from '@/constants/form';
-import { RAGFlowNodeType } from '@/interfaces/database/agent';
-import { MetadataType } from '@/pages/dataset/components/metedata/constant';
-import {
- useManageMetadata,
- util,
-} from '@/pages/dataset/components/metedata/hooks/use-manage-modal';
-import {
- IBuiltInMetadataItem,
- IMetaDataReturnJSONSettings,
-} from '@/pages/dataset/components/metedata/interface';
-import { ManageMetadataModal } from '@/pages/dataset/components/metedata/manage-modal';
-import { transformExtractorConfigToForm } from '@/utils/pipeline-operator';
-import { zodResolver } from '@hookform/resolvers/zod';
-import { Settings } from 'lucide-react';
-import { memo, useCallback, useEffect, useMemo } from 'react';
-import { useForm, useFormContext, useWatch } from 'react-hook-form';
-import { useTranslation } from 'react-i18next';
-import { z } from 'zod';
-import { initialGoExtractorValues } from '../../constant/pipeline';
-import { useOwnerTenantId } from '../../context';
-import { useFormChangeCallback } from '../../hooks/use-form-change-callback';
-import { useWatchFormChange } from '../../hooks/use-watch-form-change';
-import { INextOperatorForm } from '../../interface';
-import { buildOutputList } from '../../utils/build-output-list';
-import { FormWrapper } from '../components/form-wrapper';
-import { Output } from '../components/output';
-import { canSelectTagFile, useTagFileTree } from './use-tag-file-tree';
-
-export const FormSchema = z.object({
- keywords: z
- .object({
- enabled: z.union([z.number(), z.boolean()]).optional(),
- top_n: z.number().optional(),
- system_prompt: z.string().optional(),
- })
- .optional(),
- questions: z
- .object({
- enabled: z.union([z.number(), z.boolean()]).optional(),
- top_n: z.number().optional(),
- system_prompt: z.string().optional(),
- })
- .optional(),
- tags: z
- .object({
- enabled: z.union([z.number(), z.boolean()]).optional(),
- top_n: z.number().optional(),
- tag_file_id: z.string().optional(),
- })
- .optional(),
- summary: z
- .object({
- enabled: z.union([z.number(), z.boolean()]).optional(),
- system_prompt: z.string().optional(),
- })
- .optional(),
- // Matches schema.ExtractorParam.Metadata on the Go side
- // (internal/ingestion/component/schema/extractor.go).
- metadata: z
- .object({
- enabled: z.union([z.number(), z.boolean()]).optional(),
- metadata: z.any().optional(),
- built_in_metadata: z.any().optional(),
- })
- .optional(),
- ...LlmSettingSchema,
- // No required mark on the model field — an LLM is optional for extraction.
- llm_id: z.string().optional(),
-});
-
-export type ExtractorFormSchemaType = z.infer<typeof FormSchema>;
-
-// The summary/metadata enable switches live in the Collapse header
-// (rightContent); the metadata section body only carries the field-schema
-// editor (custom + built-in metadata).
-function ExtractorMetadataContent() {
- const { t } = useTranslation();
- const form = useFormContext<ExtractorFormSchemaType>();
- const {
- manageMetadataVisible,
- showManageMetadataModal,
- hideManageMetadataModal,
- tableData,
- config: metadataConfig,
- } = useManageMetadata();
-
- const handleOpen = useCallback(() => {
- showManageMetadataModal({
- metadata: util.metaDataSettingJSONToMetaDataTableData(
- form.getValues('metadata.metadata') || [],
- ),
- isCanAdd: true,
- type: MetadataType.Setting,
- builtInMetadata: form.getValues('metadata.built_in_metadata') || [],
- });
- }, [form, showManageMetadataModal]);
-
- const handleSave = useCallback(
- (data?: {
- metadata?: IMetaDataReturnJSONSettings;
- builtInMetadata?: IBuiltInMetadataItem[];
- }) => {
- form.setValue('metadata.metadata', data?.metadata || [], {
- shouldDirty: true,
- });
- form.setValue('metadata.built_in_metadata', data?.builtInMetadata || [], {
- shouldDirty: true,
- });
- form.setValue('metadata.enabled', true, { shouldDirty: true });
- },
- [form],
- );
-
- return (
- <>
- <div>
- <Button
- type="button"
- variant="ghost"
- onClick={handleOpen}
- data-testid="extractor-metadata-open-modal-btn"
- >
- <div className="flex items-center gap-2">
- <Settings />
- {t('knowledgeConfiguration.settings')}
- </div>
- </Button>
- </div>
- {manageMetadataVisible && (
- <ManageMetadataModal
- title={t('knowledgeDetails.metadata.metadataGenerationSettings')}
- visible={manageMetadataVisible}
- hideModal={hideManageMetadataModal}
- tableData={tableData}
- isCanAdd={metadataConfig.isCanAdd}
- isDeleteSingleValue={metadataConfig.isDeleteSingleValue}
- type={metadataConfig.type}
- otherData={metadataConfig.record}
- isShowDescription
- isShowValueSwitch
- isVerticalShowValue={false}
- isLocalSave
- builtInMetadata={metadataConfig.builtInMetadata}
- secondTitle={metadataConfig.secondTitle}
- success={handleSave}
- />
- )}
- </>
- );
-}
-
-const outputList = buildOutputList(initialGoExtractorValues.outputs);
-
-const useNormalizedExtractorFormValues = (node?: RAGFlowNodeType) => {
- return useMemo(() => {
- const raw = (node?.data?.form as Record<string, any>) || {};
- return {
- ...initialGoExtractorValues,
- ...transformExtractorConfigToForm(raw),
- };
- }, [node?.data?.form]);
-};
-
-const GoExtractorForm = ({
- node,
- onValuesChange,
- hideOutputs,
- externalErrors,
-}: INextOperatorForm) => {
- const defaultValues = useNormalizedExtractorFormValues(node);
- const { t } = useTranslation();
-
- const form = useForm<ExtractorFormSchemaType>({
- defaultValues,
- resolver: zodResolver(FormSchema),
- mode: 'onChange',
- });
-
- useSyncExternalFormErrors(form, externalErrors);
-
- useWatchFormChange(node?.id, form);
- useFormChangeCallback(form, onValuesChange);
-
- const ownerTenantId = useOwnerTenantId();
-
- const tagFileId = useWatch({
- control: form.control,
- name: 'tags.tag_file_id',
- });
- const { treeData, loadData } = useTagFileTree(tagFileId);
-
- const keywordsEnabledRaw = useWatch({
- control: form.control,
- name: 'keywords.enabled',
- });
- const questionsEnabledRaw = useWatch({
- control: form.control,
- name: 'questions.enabled',
- });
- const tagsEnabledRaw = useWatch({
- control: form.control,
- name: 'tags.enabled',
- });
- const summaryEnabledRaw = useWatch({
- control: form.control,
- name: 'summary.enabled',
- });
- const metadataEnabledRaw = useWatch({
- control: form.control,
- name: 'metadata.enabled',
- });
- const keywordsEnabled =
- keywordsEnabledRaw === true || keywordsEnabledRaw === 1;
- const questionsEnabled =
- questionsEnabledRaw === true || questionsEnabledRaw === 1;
- const tagsEnabled = tagsEnabledRaw === true || tagsEnabledRaw === 1;
- const summaryEnabled = summaryEnabledRaw === true || summaryEnabledRaw === 1;
- const metadataEnabled =
- metadataEnabledRaw === true || metadataEnabledRaw === 1;
-
- useEffect(() => {
- if (!form.getValues('keywords.system_prompt')) {
- form.setValue(
- 'keywords.system_prompt',
- t('flow.prompts.system.keywords'),
- );
- }
- if (!form.getValues('questions.system_prompt')) {
- form.setValue(
- 'questions.system_prompt',
- t('flow.prompts.system.questions'),
- );
- }
- if (!form.getValues('summary.system_prompt')) {
- form.setValue('summary.system_prompt', t('flow.prompts.system.summary'));
- }
- }, [form, t]);
-
- const handleKeywordsSwitch = useCallback(
- (checked: boolean) => {
- form.setValue('keywords.enabled', checked, { shouldDirty: true });
- },
- [form],
- );
-
- const handleQuestionsSwitch = useCallback(
- (checked: boolean) => {
- form.setValue('questions.enabled', checked, { shouldDirty: true });
- },
- [form],
- );
-
- const handleTagsSwitch = useCallback(
- (checked: boolean) => {
- form.setValue('tags.enabled', checked, { shouldDirty: true });
- },
- [form],
- );
-
- const handleSummarySwitch = useCallback(
- (checked: boolean) => {
- form.setValue('summary.enabled', checked, { shouldDirty: true });
- },
- [form],
- );
-
- const handleMetadataSwitch = useCallback(
- (checked: boolean) => {
- form.setValue('metadata.enabled', checked, { shouldDirty: true });
- },
- [form],
- );
-
- return (
- <Form {...form}>
- <FormWrapper>
- <LargeModelFormField
- ownerTenantId={ownerTenantId}
- ></LargeModelFormField>
-
- <div className="space-y-4">
- <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">
- <Collapse
- title={t('flow.keywords')}
- defaultOpen
- rightContent={
- <Switch
- checked={keywordsEnabled}
- onCheckedChange={handleKeywordsSwitch}
- data-testid="extractor-keywords-switch"
- />
- }
- >
- <div className="space-y-4">
- <AutoKeywordsFormField name="keywords.top_n" />
- <RAGFlowFormItem
- label={t('flow.systemPrompt')}
- name="keywords.system_prompt"
- >
- <Textarea
- placeholder={t('flow.messagePlaceholder')}
- rows={18}
- resize="vertical"
- />
- </RAGFlowFormItem>
- </div>
- </Collapse>
- </Card>
-
- <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">
- <Collapse
- title={t('flow.questions')}
- defaultOpen
- rightContent={
- <Switch
- checked={questionsEnabled}
- onCheckedChange={handleQuestionsSwitch}
- data-testid="extractor-questions-switch"
- />
- }
- >
- <div className="space-y-4">
- <AutoQuestionsFormField name="questions.top_n" />
- <RAGFlowFormItem
- label={t('flow.systemPrompt')}
- name="questions.system_prompt"
- >
- <Textarea
- placeholder={t('flow.messagePlaceholder')}
- resize="vertical"
- rows={18}
- />
- </RAGFlowFormItem>
- </div>
- </Collapse>
- </Card>
-
- <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">
- <Collapse
- title={t('flow.tags') || t('knowledgeDetails.autoTags')}
- defaultOpen
- rightContent={
- <Switch
- checked={tagsEnabled}
- onCheckedChange={handleTagsSwitch}
- data-testid="extractor-tags-switch"
- />
- }
- >
- <div className="space-y-4">
- <SliderInputFormField
- name="tags.top_n"
- label={t('knowledgeDetails.autoTags')}
- min={0}
- max={10}
- defaultValue={0}
- layout={FormLayout.Vertical}
- integer
- />
- <RAGFlowFormItem
- label={t('flow.tagFile')}
- name="tags.tag_file_id"
- >
- {(field) => (
- <AsyncTreeSelect
- treeData={treeData}
- value={field.value}
- onChange={field.onChange}
- loadData={loadData}
- canSelect={canSelectTagFile}
- />
- )}
- </RAGFlowFormItem>
- </div>
- </Collapse>
- </Card>
-
- <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">
- <Collapse
- title={t('flow.summary')}
- defaultOpen
- rightContent={
- <Switch
- checked={summaryEnabled}
- onCheckedChange={handleSummarySwitch}
- data-testid="extractor-summary-switch"
- />
- }
- >
- <RAGFlowFormItem
- label={t('flow.systemPrompt')}
- name="summary.system_prompt"
- >
- <Textarea
- placeholder={t('flow.messagePlaceholder')}
- resize="vertical"
- rows={18}
- />
- </RAGFlowFormItem>
- </Collapse>
- </Card>
-
- <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">
- <Collapse
- title={t('flow.metadata')}
- defaultOpen
- rightContent={
- <Switch
- checked={metadataEnabled}
- onCheckedChange={handleMetadataSwitch}
- data-testid="extractor-metadata-switch"
- />
- }
- >
- <ExtractorMetadataContent />
- </Collapse>
- </Card>
- </div>
-
- {!hideOutputs && <Output list={outputList}></Output>}
- </FormWrapper>
- </Form>
- );
-};
-
-export default memo(GoExtractorForm);
diff --git a/web/src/pages/agent/form/extractor-form/index.tsx b/web/src/pages/agent/form/extractor-form/index.tsx
index 99a8c5fad3..281fbcadf1 100644
--- a/web/src/pages/agent/form/extractor-form/index.tsx
+++ b/web/src/pages/agent/form/extractor-form/index.tsx
@@ -1,3 +1,417 @@
-export { default } from './go-form';
-export { FormSchema } from './go-form';
-export type { ExtractorFormSchemaType } from './go-form';
+/*
+ * Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import {
+ AutoKeywordsFormField,
+ AutoQuestionsFormField,
+} from '@/components/auto-keywords-form-field';
+import { Collapse } from '@/components/collapse';
+import { LargeModelFormField } from '@/components/large-model-form-field';
+import { useSyncExternalFormErrors } from '@/components/pipeline-operator-tabs/use-sync-external-form-errors';
+import { RAGFlowFormItem } from '@/components/ragflow-form';
+import { SliderInputFormField } from '@/components/slider-input-form-field';
+import { AsyncTreeSelect } from '@/components/ui/async-tree-select';
+import { Button } from '@/components/ui/button';
+import { Card } from '@/components/ui/card';
+import { Form } from '@/components/ui/form';
+import { Switch } from '@/components/ui/switch';
+import { Textarea } from '@/components/ui/textarea';
+import { FormLayout } from '@/constants/form';
+import { RAGFlowNodeType } from '@/interfaces/database/agent';
+import { MetadataType } from '@/pages/dataset/components/metedata/constant';
+import {
+ useManageMetadata,
+ util,
+} from '@/pages/dataset/components/metedata/hooks/use-manage-modal';
+import {
+ IBuiltInMetadataItem,
+ IMetaDataReturnJSONSettings,
+} from '@/pages/dataset/components/metedata/interface';
+import { ManageMetadataModal } from '@/pages/dataset/components/metedata/manage-modal';
+import { transformExtractorConfigToForm } from '@/utils/pipeline-operator';
+import { zodResolver } from '@hookform/resolvers/zod';
+import { Settings } from 'lucide-react';
+import { memo, useCallback, useEffect, useMemo } from 'react';
+import { useForm, useFormContext, useWatch } from 'react-hook-form';
+import { useTranslation } from 'react-i18next';
+import { initialExtractorValues } from '../../constant/pipeline';
+import { useOwnerTenantId } from '../../context';
+import { useFormChangeCallback } from '../../hooks/use-form-change-callback';
+import { useWatchFormChange } from '../../hooks/use-watch-form-change';
+import { INextOperatorForm } from '../../interface';
+import { buildOutputList } from '../../utils/build-output-list';
+import { FormWrapper } from '../components/form-wrapper';
+import { Output } from '../components/output';
+import { ExtractorFormSchemaType, FormSchema } from './schema';
+import { canSelectTagFile, useTagFileTree } from './use-tag-file-tree';
+
+// The summary/metadata enable switches live in the Collapse header
+// (rightContent); the metadata section body only carries the field-schema
+// editor (custom + built-in metadata).
+function ExtractorMetadataContent() {
+ const { t } = useTranslation();
+ const form = useFormContext<ExtractorFormSchemaType>();
+ const {
+ manageMetadataVisible,
+ showManageMetadataModal,
+ hideManageMetadataModal,
+ tableData,
+ config: metadataConfig,
+ } = useManageMetadata();
+
+ const handleOpen = useCallback(() => {
+ showManageMetadataModal({
+ metadata: util.metaDataSettingJSONToMetaDataTableData(
+ form.getValues('metadata.metadata') || [],
+ ),
+ isCanAdd: true,
+ type: MetadataType.Setting,
+ builtInMetadata: form.getValues('metadata.built_in_metadata') || [],
+ });
+ }, [form, showManageMetadataModal]);
+
+ const handleSave = useCallback(
+ (data?: {
+ metadata?: IMetaDataReturnJSONSettings;
+ builtInMetadata?: IBuiltInMetadataItem[];
+ }) => {
+ form.setValue('metadata.metadata', data?.metadata || [], {
+ shouldDirty: true,
+ });
+ form.setValue('metadata.built_in_metadata', data?.builtInMetadata || [], {
+ shouldDirty: true,
+ });
+ form.setValue('metadata.enabled', true, { shouldDirty: true });
+ },
+ [form],
+ );
+
+ return (
+ <>
+ <div>
+ <Button
+ type="button"
+ variant="ghost"
+ onClick={handleOpen}
+ data-testid="extractor-metadata-open-modal-btn"
+ >
+ <div className="flex items-center gap-2">
+ <Settings />
+ {t('knowledgeConfiguration.settings')}
+ </div>
+ </Button>
+ </div>
+ {manageMetadataVisible && (
+ <ManageMetadataModal
+ title={t('knowledgeDetails.metadata.metadataGenerationSettings')}
+ visible={manageMetadataVisible}
+ hideModal={hideManageMetadataModal}
+ tableData={tableData}
+ isCanAdd={metadataConfig.isCanAdd}
+ isDeleteSingleValue={metadataConfig.isDeleteSingleValue}
+ type={metadataConfig.type}
+ otherData={metadataConfig.record}
+ isShowDescription
+ isShowValueSwitch
+ isVerticalShowValue={false}
+ isLocalSave
+ builtInMetadata={metadataConfig.builtInMetadata}
+ secondTitle={metadataConfig.secondTitle}
+ success={handleSave}
+ />
+ )}
+ </>
+ );
+}
+
+const outputList = buildOutputList(initialExtractorValues.outputs);
+
+const useNormalizedExtractorFormValues = (node?: RAGFlowNodeType) => {
+ return useMemo(() => {
+ const raw = (node?.data?.form as Record<string, any>) || {};
+ return {
+ ...initialExtractorValues,
+ ...transformExtractorConfigToForm(raw),
+ };
+ }, [node?.data?.form]);
+};
+
+const ExtractorForm = ({
+ node,
+ onValuesChange,
+ hideOutputs,
+ externalErrors,
+}: INextOperatorForm) => {
+ const defaultValues = useNormalizedExtractorFormValues(node);
+ const { t } = useTranslation();
+
+ const form = useForm<ExtractorFormSchemaType>({
+ defaultValues,
+ resolver: zodResolver(FormSchema),
+ mode: 'onChange',
+ });
+
+ useSyncExternalFormErrors(form, externalErrors);
+
+ useWatchFormChange(node?.id, form);
+ useFormChangeCallback(form, onValuesChange);
+
+ const ownerTenantId = useOwnerTenantId();
+
+ const tagFileId = useWatch({
+ control: form.control,
+ name: 'tags.tag_file_id',
+ });
+ const { treeData, loadData } = useTagFileTree(tagFileId);
+
+ const keywordsEnabledRaw = useWatch({
+ control: form.control,
+ name: 'keywords.enabled',
+ });
+ const questionsEnabledRaw = useWatch({
+ control: form.control,
+ name: 'questions.enabled',
+ });
+ const tagsEnabledRaw = useWatch({
+ control: form.control,
+ name: 'tags.enabled',
+ });
+ const summaryEnabledRaw = useWatch({
+ control: form.control,
+ name: 'summary.enabled',
+ });
+ const metadataEnabledRaw = useWatch({
+ control: form.control,
+ name: 'metadata.enabled',
+ });
+ const keywordsEnabled =
+ keywordsEnabledRaw === true || keywordsEnabledRaw === 1;
+ const questionsEnabled =
+ questionsEnabledRaw === true || questionsEnabledRaw === 1;
+ const tagsEnabled = tagsEnabledRaw === true || tagsEnabledRaw === 1;
+ const summaryEnabled = summaryEnabledRaw === true || summaryEnabledRaw === 1;
+ const metadataEnabled =
+ metadataEnabledRaw === true || metadataEnabledRaw === 1;
+
+ useEffect(() => {
+ if (!form.getValues('keywords.system_prompt')) {
+ form.setValue(
+ 'keywords.system_prompt',
+ t('flow.prompts.system.keywords'),
+ );
+ }
+ if (!form.getValues('questions.system_prompt')) {
+ form.setValue(
+ 'questions.system_prompt',
+ t('flow.prompts.system.questions'),
+ );
+ }
+ if (!form.getValues('summary.system_prompt')) {
+ form.setValue('summary.system_prompt', t('flow.prompts.system.summary'));
+ }
+ }, [form, t]);
+
+ const handleKeywordsSwitch = useCallback(
+ (checked: boolean) => {
+ form.setValue('keywords.enabled', checked, { shouldDirty: true });
+ },
+ [form],
+ );
+
+ const handleQuestionsSwitch = useCallback(
+ (checked: boolean) => {
+ form.setValue('questions.enabled', checked, { shouldDirty: true });
+ },
+ [form],
+ );
+
+ const handleTagsSwitch = useCallback(
+ (checked: boolean) => {
+ form.setValue('tags.enabled', checked, { shouldDirty: true });
+ },
+ [form],
+ );
+
+ const handleSummarySwitch = useCallback(
+ (checked: boolean) => {
+ form.setValue('summary.enabled', checked, { shouldDirty: true });
+ },
+ [form],
+ );
+
+ const handleMetadataSwitch = useCallback(
+ (checked: boolean) => {
+ form.setValue('metadata.enabled', checked, { shouldDirty: true });
+ },
+ [form],
+ );
+
+ return (
+ <Form {...form}>
+ <FormWrapper>
+ <LargeModelFormField
+ ownerTenantId={ownerTenantId}
+ ></LargeModelFormField>
+
+ <div className="space-y-4">
+ <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">
+ <Collapse
+ title={t('flow.keywords')}
+ defaultOpen
+ rightContent={
+ <Switch
+ checked={keywordsEnabled}
+ onCheckedChange={handleKeywordsSwitch}
+ data-testid="extractor-keywords-switch"
+ />
+ }
+ >
+ <div className="space-y-4">
+ <AutoKeywordsFormField name="keywords.top_n" />
+ <RAGFlowFormItem
+ label={t('flow.systemPrompt')}
+ name="keywords.system_prompt"
+ >
+ <Textarea
+ placeholder={t('flow.messagePlaceholder')}
+ rows={18}
+ resize="vertical"
+ />
+ </RAGFlowFormItem>
+ </div>
+ </Collapse>
+ </Card>
+
+ <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">
+ <Collapse
+ title={t('flow.questions')}
+ defaultOpen
+ rightContent={
+ <Switch
+ checked={questionsEnabled}
+ onCheckedChange={handleQuestionsSwitch}
+ data-testid="extractor-questions-switch"
+ />
+ }
+ >
+ <div className="space-y-4">
+ <AutoQuestionsFormField name="questions.top_n" />
+ <RAGFlowFormItem
+ label={t('flow.systemPrompt')}
+ name="questions.system_prompt"
+ >
+ <Textarea
+ placeholder={t('flow.messagePlaceholder')}
+ resize="vertical"
+ rows={18}
+ />
+ </RAGFlowFormItem>
+ </div>
+ </Collapse>
+ </Card>
+
+ <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">
+ <Collapse
+ title={t('flow.tags') || t('knowledgeDetails.autoTags')}
+ defaultOpen
+ rightContent={
+ <Switch
+ checked={tagsEnabled}
+ onCheckedChange={handleTagsSwitch}
+ data-testid="extractor-tags-switch"
+ />
+ }
+ >
+ <div className="space-y-4">
+ <SliderInputFormField
+ name="tags.top_n"
+ label={t('knowledgeDetails.autoTags')}
+ min={0}
+ max={10}
+ defaultValue={0}
+ layout={FormLayout.Vertical}
+ integer
+ />
+ <RAGFlowFormItem
+ label={t('flow.tagFile')}
+ name="tags.tag_file_id"
+ >
+ {(field) => (
+ <AsyncTreeSelect
+ treeData={treeData}
+ value={field.value}
+ onChange={field.onChange}
+ loadData={loadData}
+ canSelect={canSelectTagFile}
+ />
+ )}
+ </RAGFlowFormItem>
+ </div>
+ </Collapse>
+ </Card>
+
+ <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">
+ <Collapse
+ title={t('flow.summary')}
+ defaultOpen
+ rightContent={
+ <Switch
+ checked={summaryEnabled}
+ onCheckedChange={handleSummarySwitch}
+ data-testid="extractor-summary-switch"
+ />
+ }
+ >
+ <RAGFlowFormItem
+ label={t('flow.systemPrompt')}
+ name="summary.system_prompt"
+ >
+ <Textarea
+ placeholder={t('flow.messagePlaceholder')}
+ resize="vertical"
+ rows={18}
+ />
+ </RAGFlowFormItem>
+ </Collapse>
+ </Card>
+
+ <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">
+ <Collapse
+ title={t('flow.metadata')}
+ defaultOpen
+ rightContent={
+ <Switch
+ checked={metadataEnabled}
+ onCheckedChange={handleMetadataSwitch}
+ data-testid="extractor-metadata-switch"
+ />
+ }
+ >
+ <ExtractorMetadataContent />
+ </Collapse>
+ </Card>
+ </div>
+
+ {!hideOutputs && <Output list={outputList}></Output>}
+ </FormWrapper>
+ </Form>
+ );
+};
+
+export default memo(ExtractorForm);
+
+export { FormSchema } from './schema';
+export type { ExtractorFormSchemaType } from './schema';
diff --git a/web/src/pages/agent/form/extractor-form/schema.test.ts b/web/src/pages/agent/form/extractor-form/schema.test.ts
new file mode 100644
index 0000000000..397bff3818
--- /dev/null
+++ b/web/src/pages/agent/form/extractor-form/schema.test.ts
@@ -0,0 +1,67 @@
+import i18n from '@/locales/config';
+import { FormSchema } from './schema';
+
+// LlmSettingSchema's module chain reaches @/routes via navigate-hooks, which
+// builds a browser router at import time and crashes outside a browser.
+jest.mock('@/routes', () => ({ Routes: {} }));
+
+const issuePaths = (data: Record<string, any>) => {
+ const result = FormSchema.safeParse(data);
+ return result.success
+ ? []
+ : result.error.issues.map((issue) => issue.path.join('.'));
+};
+
+describe('extractor FormSchema extraction toggles', () => {
+ it('passes with every group switched off and top_n 0 (defaults)', () => {
+ const result = FormSchema.safeParse({
+ keywords: { enabled: false, top_n: 0 },
+ questions: { enabled: false, top_n: 0 },
+ tags: { enabled: false, top_n: 0, tag_file_id: '' },
+ });
+ expect(result.success).toBe(true);
+ });
+
+ it('requires keywords.top_n >= 1 when keywords is enabled', () => {
+ expect(issuePaths({ keywords: { enabled: true, top_n: 0 } })).toContain(
+ 'keywords.top_n',
+ );
+ const result = FormSchema.safeParse({
+ keywords: { enabled: true, top_n: 0 },
+ });
+ expect(result.success).toBe(false);
+ if (!result.success) {
+ expect(result.error.issues[0].message).toBe(
+ i18n.t('flow.extractorKeywordsTopNMissing'),
+ );
+ }
+ });
+
+ it('treats numeric 1 as enabled for questions', () => {
+ expect(issuePaths({ questions: { enabled: 1 } })).toContain(
+ 'questions.top_n',
+ );
+ });
+
+ it('requires tags.top_n >= 1 and a tag file when tags is enabled', () => {
+ expect(issuePaths({ tags: { enabled: true, top_n: 0 } })).toEqual(
+ expect.arrayContaining(['tags.top_n', 'tags.tag_file_id']),
+ );
+ expect(issuePaths({ tags: { enabled: true, top_n: 3 } })).toEqual([
+ 'tags.tag_file_id',
+ ]);
+ expect(
+ FormSchema.safeParse({
+ tags: { enabled: true, top_n: 3, tag_file_id: 'tag-1' },
+ }).success,
+ ).toBe(true);
+ });
+
+ it('ignores legacy groups without an enabled key', () => {
+ const result = FormSchema.safeParse({
+ keywords: { top_n: 3 },
+ questions: { top_n: 2 },
+ });
+ expect(result.success).toBe(true);
+ });
+});
diff --git a/web/src/pages/agent/form/extractor-form/schema.ts b/web/src/pages/agent/form/extractor-form/schema.ts
new file mode 100644
index 0000000000..c30a569f72
--- /dev/null
+++ b/web/src/pages/agent/form/extractor-form/schema.ts
@@ -0,0 +1,93 @@
+import { LlmSettingSchema } from '@/components/llm-setting-items/next';
+import i18n from '@/locales/config';
+import { z } from 'zod';
+
+// A group switch persists as a boolean from the form UI but as 0/1 in
+// legacy saved configs; the form UI normalizes with the same check.
+const isGroupEnabled = (v: number | boolean | undefined) =>
+ v === true || v === 1;
+
+export const FormSchema = z
+ .object({
+ keywords: z
+ .object({
+ enabled: z.union([z.number(), z.boolean()]).optional(),
+ top_n: z.number().optional(),
+ system_prompt: z.string().optional(),
+ })
+ .optional(),
+ questions: z
+ .object({
+ enabled: z.union([z.number(), z.boolean()]).optional(),
+ top_n: z.number().optional(),
+ system_prompt: z.string().optional(),
+ })
+ .optional(),
+ tags: z
+ .object({
+ enabled: z.union([z.number(), z.boolean()]).optional(),
+ top_n: z.number().optional(),
+ tag_file_id: z.string().optional(),
+ })
+ .optional(),
+ summary: z
+ .object({
+ enabled: z.union([z.number(), z.boolean()]).optional(),
+ system_prompt: z.string().optional(),
+ })
+ .optional(),
+ // Matches schema.ExtractorParam.Metadata on the Go side
+ // (internal/ingestion/component/schema/extractor.go).
+ metadata: z
+ .object({
+ enabled: z.union([z.number(), z.boolean()]).optional(),
+ metadata: z.any().optional(),
+ built_in_metadata: z.any().optional(),
+ })
+ .optional(),
+ ...LlmSettingSchema,
+ // No required mark on the model field — an LLM is optional for extraction.
+ llm_id: z.string().optional(),
+ })
+ .superRefine((data, ctx) => {
+ // Same enabled-with-nothing-to-extract rules as the canvas checklist
+ // (pages/agent/utils/canvas-checklist.ts): a group switched on with
+ // top_n < 1 fails the Go canvas build at parse time, and tags without
+ // a tag file silently skip — catch both at save time instead.
+ if (isGroupEnabled(data.keywords?.enabled)) {
+ if (!(Number(data.keywords?.top_n) > 0)) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ['keywords', 'top_n'],
+ message: i18n.t('flow.extractorKeywordsTopNMissing'),
+ });
+ }
+ }
+ if (isGroupEnabled(data.questions?.enabled)) {
+ if (!(Number(data.questions?.top_n) > 0)) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ['questions', 'top_n'],
+ message: i18n.t('flow.extractorQuestionsTopNMissing'),
+ });
+ }
+ }
+ if (isGroupEnabled(data.tags?.enabled)) {
+ if (!(Number(data.tags?.top_n) > 0)) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ['tags', 'top_n'],
+ message: i18n.t('flow.extractorTagsTopNMissing'),
+ });
+ }
+ if (!data.tags?.tag_file_id) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ path: ['tags', 'tag_file_id'],
+ message: i18n.t('flow.extractorTagFileMissing'),
+ });
+ }
+ }
+ });
+
+export type ExtractorFormSchemaType = z.infer<typeof FormSchema>;
diff --git a/web/src/pages/agent/form/extractor-form/use-switch-prompt.ts b/web/src/pages/agent/form/extractor-form/use-switch-prompt.ts
deleted file mode 100644
index d950af2460..0000000000
--- a/web/src/pages/agent/form/extractor-form/use-switch-prompt.ts
+++ /dev/null
@@ -1,83 +0,0 @@
-import { useSetModalState } from '@/hooks/common-hooks';
-import { useCallback, useRef } from 'react';
-import { useTranslation } from 'react-i18next';
-
-type SwitchPromptField = 'field_name' | 'sys_prompt' | 'prompts';
-
-// The Python canvas Extractor has no top_n input and sends sys_prompt to the
-// LLM verbatim, so its keyword and question prompts pin the {{ topn }}
-// placeholder to fixed counts.
-const pythonCanvasTopN: Record<string, number> = { keywords: 5, questions: 3 };
-
-type SwitchPromptForm = {
- getValues(name: 'field_name'): string;
- setValue(
- name: SwitchPromptField,
- value: string,
- options?: { shouldDirty?: boolean; shouldValidate?: boolean },
- ): void;
-};
-
-export function useSwitchPrompt(form: SwitchPromptForm) {
- const { visible, showModal, hideModal } = useSetModalState();
- const { t } = useTranslation();
- const previousFieldNames = useRef<string[]>([form.getValues('field_name')]);
-
- const setPromptValue = useCallback(
- (field: SwitchPromptField, key: string, value: string) => {
- const prompt = t(`flow.prompts.${key}.${value}`);
- form.setValue(
- field,
- Object.hasOwn(pythonCanvasTopN, value)
- ? prompt.replace(
- /\{\{\s*topn\s*\}\}/g,
- String(pythonCanvasTopN[value]),
- )
- : prompt,
- {
- shouldDirty: true,
- shouldValidate: true,
- },
- );
- },
- [form, t],
- );
-
- const handleFieldNameChange = useCallback(
- (value: string) => {
- if (value) {
- const names = previousFieldNames.current;
- if (names.length > 1) {
- names.shift();
- }
- names.push(value);
- showModal();
- }
- },
- [showModal],
- );
-
- const confirmSwitch = useCallback(() => {
- const value = form.getValues('field_name');
- setPromptValue('sys_prompt', 'system', value);
- setPromptValue('prompts', 'user', value);
- }, [form, setPromptValue]);
-
- const cancelSwitch = useCallback(() => {
- const previousValue = previousFieldNames.current.at(-2);
- if (previousValue) {
- form.setValue('field_name', previousValue, {
- shouldDirty: true,
- shouldValidate: true,
- });
- }
- }, [form]);
-
- return {
- handleFieldNameChange,
- confirmSwitch,
- hideModal,
- visible,
- cancelSwitch,
- };
-}
diff --git a/web/src/pages/agent/utils.ts b/web/src/pages/agent/utils.ts
index 2a053badc1..832850d7dd 100644
--- a/web/src/pages/agent/utils.ts
+++ b/web/src/pages/agent/utils.ts
@@ -492,7 +492,7 @@ export const LlmSettingParamKeys = [
// the transitional "metadata_config", ...). Accept them as read
// fallbacks — flat "metadata" is an array, which distinguishes it from
// the group object — but never re-emit them.
-function transformExtractorParamsGo(
+export function transformExtractorParams(
params: ExtractorFormSchemaType,
): Record<string, any> {
const raw = params as Record<string, any>;
@@ -582,12 +582,6 @@ function transformExtractorParamsGo(
};
}
-export function transformExtractorParams(
- params: ExtractorFormSchemaType,
-): Record<string, any> {
- return transformExtractorParamsGo(params);
-}
-
// The Compiler reads the compilation template group plus the same LLM runtime
// settings as the Extractor; display-only fields like outputs are dropped.
export function transformCompilationParams(
diff --git a/web/src/utils/pipeline-operator.ts b/web/src/utils/pipeline-operator.ts
index 1d7ce7dfec..6d88b7ed40 100644
--- a/web/src/utils/pipeline-operator.ts
+++ b/web/src/utils/pipeline-operator.ts
@@ -19,7 +19,7 @@ import { DSL, RAGFlowNodeType } from '@/interfaces/database/agent';
import {
getInitialExtractorValues,
initialCompilationValues,
- initialGoExtractorValues,
+ initialExtractorValues,
initialGeneralChunkerValues,
initialParserValues,
initialTitleChunkerValues,
@@ -121,9 +121,17 @@ function transformLevelsToRules(
.filter((rule) => rule !== null);
}
-// Base normalization: flatten the DSL prompts array into the form's single
-// field. The Go transform below builds on top of this.
-function transformExtractorConfigToFormPython(
+/**
+ * Converts Extractor config from API/DSL format to form format: flattens the
+ * DSL prompts array into the form's single field and normalizes the nested
+ * per-feature groups the extractor schema reads (schema.ExtractorParam).
+ * Legacy flat keys (auto_keywords, keywords_sys_prompt, enable_summary, ...)
+ * are accepted as read fallbacks and never re-emitted.
+ *
+ * DSL: { prompts: [{ content: "text", role: "user" }] }
+ * Form: { prompts: "text" }
+ */
+export function transformExtractorConfigToForm(
config: Record<string, any> | undefined,
): Record<string, any> {
if (!config) return {};
@@ -133,17 +141,6 @@ function transformExtractorConfigToFormPython(
result.prompts = config.prompts[0]?.content ?? '';
}
- return result;
-}
-
-// Go form: additionally normalize the nested per-feature groups the Go
-// extractor schema reads (schema.ExtractorParam).
-function transformExtractorConfigToFormGo(
- config: Record<string, any> | undefined,
-): Record<string, any> {
- const result = transformExtractorConfigToFormPython(config);
- if (!config) return result;
-
const isSummaryEnabled =
config.summary?.enabled !== undefined
? Boolean(config.summary?.enabled)
@@ -170,15 +167,13 @@ function transformExtractorConfigToFormGo(
const keywordsTopN =
config.keywords?.top_n ??
config.auto_keywords ??
- initialGoExtractorValues.keywords.top_n;
+ initialExtractorValues.keywords.top_n;
const questionsTopN =
config.questions?.top_n ??
config.auto_questions ??
- initialGoExtractorValues.questions.top_n;
+ initialExtractorValues.questions.top_n;
const tagsTopN =
- config.tags?.top_n ??
- config.auto_tags ??
- initialGoExtractorValues.tags.top_n;
+ config.tags?.top_n ?? config.auto_tags ?? initialExtractorValues.tags.top_n;
result.keywords = {
enabled:
@@ -220,7 +215,7 @@ function transformExtractorConfigToFormGo(
metadataGroup?.built_in_metadata ?? config.built_in_metadata ?? [],
};
// Drop the historical keys so they don't linger in form state and get
- // re-emitted into the DSL on save — the Go extractor only reads the group.
+ // re-emitted into the DSL on save — the extractor only reads the group.
delete result.metadata_config;
delete result.enable_metadata;
delete result.built_in_metadata;
@@ -228,17 +223,6 @@ function transformExtractorConfigToFormGo(
return result;
}
-/**
- * Converts Extractor config from API/DSL format to form format.
- * DSL: { prompts: [{ content: "text", role: "user" }] }
- * Form: { prompts: "text" }
- */
-export function transformExtractorConfigToForm(
- config: Record<string, any> | undefined,
-): Record<string, any> {
- return transformExtractorConfigToFormGo(config);
-}
-
/**
* Converts TokenChunker config from API/DSL format to form format.
* DSL: { delimiters: ["\n"], overlapped_percent: 0.1, table_context_size: 10, image_context_size: 20 }