Skip to content

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

Fix: Retrieve the frontend code of the extractor operator for the Python version. (#18481)

balibabu808f21646260
diff --git a/web/src/pages/agent/constant/pipeline.tsx b/web/src/pages/agent/constant/pipeline.tsx
index 86f4de16cc..d27c237ac8 100644
--- a/web/src/pages/agent/constant/pipeline.tsx
+++ b/web/src/pages/agent/constant/pipeline.tsx
@@ -1,5 +1,6 @@
import { ParseDocumentType } from '@/components/layout-recognize-form-field';
import { initialLlmBaseValues, Operator } from '@/constants/agent';
+import { isGoBackend } from '@/utils/backend-runtime';
import { cloneDeep } from 'lodash';
export enum FileType {
@@ -92,6 +93,13 @@ export const InitialOutputFormatMap = {
[FileType.Audio]: AudioOutputFormat.Text,
};
+export enum ContextGeneratorFieldName {
+ Summary = 'summary',
+ Keywords = 'keywords',
+ Questions = 'questions',
+ Metadata = 'metadata',
+}
+
export const FileId = 'File'; // BeginId
export enum TokenizerSearchMethod {
@@ -342,7 +350,20 @@ export const initialTitleChunkerValues = {
groupRules: cloneDeep(originalRules),
};
+// Defaults for the Python backend extractor (legacy flat fields).
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 (nested per-feature configs plus
+// legacy flat fields, which the Go schema still accepts).
+export const initialGoExtractorValues = {
...initialLlmBaseValues,
keywords: {
top_n: 0,
@@ -382,6 +403,10 @@ export const initialExtractorValues = {
},
};
+export function getInitialExtractorValues() {
+ return isGoBackend() ? initialGoExtractorValues : initialExtractorValues;
+}
+
export const initialCompilationValues = {
compilation_template_group_id: '',
llm_id: '',
diff --git a/web/src/pages/agent/form/extractor-form/go-form.tsx b/web/src/pages/agent/form/extractor-form/go-form.tsx
new file mode 100644
index 0000000000..4b64c19e9e
--- /dev/null
+++ b/web/src/pages/agent/form/extractor-form/go-form.tsx
@@ -0,0 +1,429 @@
+/*
+ * 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 { LargeModelFormField } from '@/components/large-model-form-field';
+import { LlmSettingSchema } from '@/components/llm-setting-items/next';
+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 { Form } from '@/components/ui/form';
+import { Switch } from '@/components/ui/switch';
+import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
+import { FormLayout } from '@/constants/form';
+import { RAGFlowNodeType } from '@/interfaces/database/agent';
+import { PromptEditor } from '@/pages/agent/form/components/prompt-editor';
+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 { zodResolver } from '@hookform/resolvers/zod';
+import { Settings } from 'lucide-react';
+import { memo, useCallback, useEffect, useMemo, useState } from 'react';
+import { useForm, useFormContext } 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 { transformExtractorConfigToForm } from '@/utils/pipeline-operator';
+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({
+ top_n: z.number().optional(),
+ system_prompt: z.string().optional(),
+ })
+ .optional(),
+ questions: z
+ .object({
+ top_n: z.number().optional(),
+ system_prompt: z.string().optional(),
+ })
+ .optional(),
+ tags: z
+ .object({
+ 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(),
+ metadata_config: z
+ .object({
+ enabled: z.union([z.number(), z.boolean()]).optional(),
+ metadata: z.any().optional(),
+ built_in_metadata: z.any().optional(),
+ })
+ .optional(),
+
+ // Legacy flat fields for backward compatibility
+ field_name: z.string().optional(),
+ sys_prompt: z.string().optional(),
+ prompts: z.string().optional(),
+ keywords_sys_prompt: z.string().optional(),
+ questions_sys_prompt: z.string().optional(),
+ auto_keywords: z.number().optional(),
+ auto_questions: z.number().optional(),
+ auto_tags: z.number().optional(),
+ tag_file_id: z.string().optional(),
+ enable_summary: z.union([z.number(), z.boolean()]).optional(),
+ enable_metadata: z.number().optional(),
+ metadata: z.any().optional(),
+ built_in_metadata: z.any().optional(),
+ ...LlmSettingSchema,
+});
+
+export type ExtractorFormSchemaType = z.infer<typeof FormSchema>;
+
+enum ExtractorSubTab {
+ Keywords = 'keywords',
+ Questions = 'questions',
+ Tags = 'tags',
+ Summary = 'summary',
+ Metadata = 'metadata',
+}
+
+// ExtractorAutoMetadata mirrors Python's dataset "Auto metadata" control: an
+// enable_metadata switch plus a field-schema editor (custom + built-in).
+// Values are stored on the node params (enable_metadata / metadata /
+// built_in_metadata) and drive the Go extractor's runEnableMetadata.
+function ExtractorAutoMetadata() {
+ 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_config.metadata') ||
+ form.getValues('metadata') ||
+ [],
+ ),
+ isCanAdd: true,
+ type: MetadataType.Setting,
+ builtInMetadata:
+ form.getValues('metadata_config.built_in_metadata') ||
+ form.getValues('built_in_metadata') ||
+ [],
+ });
+ }, [form, showManageMetadataModal]);
+
+ const handleSave = useCallback(
+ (data?: {
+ metadata?: IMetaDataReturnJSONSettings;
+ builtInMetadata?: IBuiltInMetadataItem[];
+ }) => {
+ const metaList = data?.metadata || [];
+ const builtInList = data?.builtInMetadata || [];
+ form.setValue('metadata_config.metadata', metaList, {
+ shouldDirty: true,
+ });
+ form.setValue('metadata_config.built_in_metadata', builtInList, {
+ shouldDirty: true,
+ });
+ form.setValue('metadata_config.enabled', true, { shouldDirty: true });
+ // Also keep flat fields for backward compatibility
+ form.setValue('metadata', metaList, { shouldDirty: true });
+ form.setValue('built_in_metadata', builtInList, { shouldDirty: true });
+ form.setValue('enable_metadata', 1, { shouldDirty: true });
+ },
+ [form],
+ );
+
+ return (
+ <>
+ <RAGFlowFormItem
+ label={t('knowledgeConfiguration.autoMetadata')}
+ name="metadata_config.enabled"
+ >
+ {(field) => (
+ <div className="flex items-center justify-between">
+ <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>
+ <Switch
+ checked={field.value === 1 || field.value === true}
+ onCheckedChange={(checked) => {
+ field.onChange(checked);
+ form.setValue('enable_metadata', checked ? 1 : 0, {
+ shouldDirty: true,
+ });
+ }}
+ data-testid="extractor-metadata-switch"
+ />
+ </div>
+ )}
+ </RAGFlowFormItem>
+ {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}
+ 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,
+}: INextOperatorForm) => {
+ const defaultValues = useNormalizedExtractorFormValues(node);
+ const { t } = useTranslation();
+
+ const form = useForm<ExtractorFormSchemaType>({
+ defaultValues,
+ resolver: zodResolver(FormSchema),
+ });
+
+ useEffect(() => {
+ form.reset(defaultValues);
+ }, [defaultValues, form]);
+
+ const [activeTab, setActiveTab] = useState<ExtractorSubTab>(
+ ExtractorSubTab.Keywords,
+ );
+
+ useWatchFormChange(node?.id, form);
+ useFormChangeCallback(form, onValuesChange);
+
+ const ownerTenantId = useOwnerTenantId();
+
+ const tagFileIdWatch =
+ form.watch('tags.tag_file_id') || form.watch('tag_file_id');
+ const { treeData, loadData } = useTagFileTree(tagFileIdWatch);
+
+ 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 handleTabChange = useCallback((tab: string) => {
+ setActiveTab(tab as ExtractorSubTab);
+ }, []);
+
+ return (
+ <Form {...form}>
+ <FormWrapper>
+ <LargeModelFormField
+ ownerTenantId={ownerTenantId}
+ ></LargeModelFormField>
+
+ <Tabs
+ value={activeTab}
+ onValueChange={handleTabChange}
+ className="w-full"
+ >
+ <TabsList className="w-full justify-start">
+ <TabsTrigger value={ExtractorSubTab.Keywords}>
+ {t('flow.keywords')}
+ </TabsTrigger>
+ <TabsTrigger value={ExtractorSubTab.Questions}>
+ {t('flow.questions')}
+ </TabsTrigger>
+ <TabsTrigger value={ExtractorSubTab.Tags}>
+ {t('flow.tags') || t('knowledgeDetails.autoTags')}
+ </TabsTrigger>
+ <TabsTrigger value={ExtractorSubTab.Summary}>
+ {t('flow.summary')}
+ </TabsTrigger>
+ <TabsTrigger value={ExtractorSubTab.Metadata}>
+ {t('flow.metadata')}
+ </TabsTrigger>
+ </TabsList>
+
+ <TabsContent
+ value={ExtractorSubTab.Keywords}
+ className="space-y-4 pt-2"
+ >
+ <AutoKeywordsFormField name="keywords.top_n" />
+ <RAGFlowFormItem
+ label={t('flow.systemPrompt')}
+ name="keywords.system_prompt"
+ >
+ <PromptEditor
+ placeholder={t('flow.messagePlaceholder')}
+ showToolbar={false}
+ showMergePath={false}
+ />
+ </RAGFlowFormItem>
+ </TabsContent>
+
+ <TabsContent
+ value={ExtractorSubTab.Questions}
+ className="space-y-4 pt-2"
+ >
+ <AutoQuestionsFormField name="questions.top_n" />
+ <RAGFlowFormItem
+ label={t('flow.systemPrompt')}
+ name="questions.system_prompt"
+ >
+ <PromptEditor
+ placeholder={t('flow.messagePlaceholder')}
+ showToolbar={false}
+ showMergePath={false}
+ />
+ </RAGFlowFormItem>
+ </TabsContent>
+
+ <TabsContent value={ExtractorSubTab.Tags} className="space-y-4 pt-2">
+ <SliderInputFormField
+ name="tags.top_n"
+ label={t('knowledgeDetails.autoTags')}
+ min={0}
+ max={10}
+ defaultValue={0}
+ layout={FormLayout.Vertical}
+ />
+ <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>
+ </TabsContent>
+
+ <TabsContent
+ value={ExtractorSubTab.Summary}
+ className="space-y-4 pt-2"
+ >
+ <RAGFlowFormItem
+ label={t('flow.enableSummary')}
+ name="summary.enabled"
+ horizontal
+ valueClassName="w-auto flex justify-end"
+ >
+ {(field) => (
+ <Switch
+ checked={field.value === 1 || field.value === true}
+ onCheckedChange={(checked) => {
+ field.onChange(checked);
+ form.setValue('field_name', checked ? 'summary' : '', {
+ shouldDirty: true,
+ });
+ form.setValue('enable_summary', checked ? 1 : 0, {
+ shouldDirty: true,
+ });
+ }}
+ data-testid="extractor-summary-switch"
+ />
+ )}
+ </RAGFlowFormItem>
+ <RAGFlowFormItem
+ label={t('flow.systemPrompt')}
+ name="summary.system_prompt"
+ >
+ <PromptEditor
+ placeholder={t('flow.messagePlaceholder')}
+ showToolbar={false}
+ showMergePath={false}
+ />
+ </RAGFlowFormItem>
+ </TabsContent>
+
+ <TabsContent
+ value={ExtractorSubTab.Metadata}
+ className="space-y-4 pt-2"
+ >
+ <ExtractorAutoMetadata />
+ </TabsContent>
+ </Tabs>
+
+ {!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 0eae00437e..19209af2eb 100644
--- a/web/src/pages/agent/form/extractor-form/index.tsx
+++ b/web/src/pages/agent/form/extractor-form/index.tsx
@@ -15,414 +15,30 @@
*/
import {
- AutoKeywordsFormField,
- AutoQuestionsFormField,
-} from '@/components/auto-keywords-form-field';
-import { LargeModelFormField } from '@/components/large-model-form-field';
-import { LlmSettingSchema } from '@/components/llm-setting-items/next';
-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 { Form } from '@/components/ui/form';
-import { Switch } from '@/components/ui/switch';
-import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
-import { FormLayout } from '@/constants/form';
-import { RAGFlowNodeType } from '@/interfaces/database/agent';
-import { PromptEditor } from '@/pages/agent/form/components/prompt-editor';
-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 { zodResolver } from '@hookform/resolvers/zod';
-import { Settings } from 'lucide-react';
-import { memo, useCallback, useEffect, useMemo, useState } from 'react';
-import { useForm, useFormContext } from 'react-hook-form';
-import { useTranslation } from 'react-i18next';
-import { z } from 'zod';
-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';
+ getBackendLanguage,
+ subscribeBackendLanguage,
+} from '@/utils/backend-runtime';
+import { memo, useSyncExternalStore } from 'react';
import { INextOperatorForm } from '../../interface';
-import { buildOutputList } from '../../utils/build-output-list';
-import { transformExtractorConfigToForm } from '@/utils/pipeline-operator';
-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({
- top_n: z.number().optional(),
- system_prompt: z.string().optional(),
- })
- .optional(),
- questions: z
- .object({
- top_n: z.number().optional(),
- system_prompt: z.string().optional(),
- })
- .optional(),
- tags: z
- .object({
- 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(),
- metadata_config: z
- .object({
- enabled: z.union([z.number(), z.boolean()]).optional(),
- metadata: z.any().optional(),
- built_in_metadata: z.any().optional(),
- })
- .optional(),
-
- // Legacy flat fields for backward compatibility
- field_name: z.string().optional(),
- sys_prompt: z.string().optional(),
- prompts: z.string().optional(),
- keywords_sys_prompt: z.string().optional(),
- questions_sys_prompt: z.string().optional(),
- auto_keywords: z.number().optional(),
- auto_questions: z.number().optional(),
- auto_tags: z.number().optional(),
- tag_file_id: z.string().optional(),
- enable_summary: z.union([z.number(), z.boolean()]).optional(),
- enable_metadata: z.number().optional(),
- metadata: z.any().optional(),
- built_in_metadata: z.any().optional(),
- ...LlmSettingSchema,
-});
-
-export type ExtractorFormSchemaType = z.infer<typeof FormSchema>;
-
-enum ExtractorSubTab {
- Keywords = 'keywords',
- Questions = 'questions',
- Tags = 'tags',
- Summary = 'summary',
- Metadata = 'metadata',
-}
-
-// ExtractorAutoMetadata mirrors Python's dataset "Auto metadata" control: an
-// enable_metadata switch plus a field-schema editor (custom + built-in).
-// Values are stored on the node params (enable_metadata / metadata /
-// built_in_metadata) and drive the Go extractor's runEnableMetadata.
-function ExtractorAutoMetadata() {
- 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_config.metadata') ||
- form.getValues('metadata') ||
- [],
- ),
- isCanAdd: true,
- type: MetadataType.Setting,
- builtInMetadata:
- form.getValues('metadata_config.built_in_metadata') ||
- form.getValues('built_in_metadata') ||
- [],
- });
- }, [form, showManageMetadataModal]);
-
- const handleSave = useCallback(
- (data?: {
- metadata?: IMetaDataReturnJSONSettings;
- builtInMetadata?: IBuiltInMetadataItem[];
- }) => {
- const metaList = data?.metadata || [];
- const builtInList = data?.builtInMetadata || [];
- form.setValue('metadata_config.metadata', metaList, {
- shouldDirty: true,
- });
- form.setValue('metadata_config.built_in_metadata', builtInList, {
- shouldDirty: true,
- });
- form.setValue('metadata_config.enabled', true, { shouldDirty: true });
- // Also keep flat fields for backward compatibility
- form.setValue('metadata', metaList, { shouldDirty: true });
- form.setValue('built_in_metadata', builtInList, { shouldDirty: true });
- form.setValue('enable_metadata', 1, { shouldDirty: true });
- },
- [form],
- );
-
- return (
- <>
- <RAGFlowFormItem
- label={t('knowledgeConfiguration.autoMetadata')}
- name="metadata_config.enabled"
- >
- {(field) => (
- <div className="flex items-center justify-between">
- <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>
- <Switch
- checked={field.value === 1 || field.value === true}
- onCheckedChange={(checked) => {
- field.onChange(checked);
- form.setValue('enable_metadata', checked ? 1 : 0, {
- shouldDirty: true,
- });
- }}
- data-testid="extractor-metadata-switch"
- />
- </div>
- )}
- </RAGFlowFormItem>
- {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}
- builtInMetadata={metadataConfig.builtInMetadata}
- secondTitle={metadataConfig.secondTitle}
- success={handleSave}
- />
- )}
- </>
+import GoExtractorForm from './go-form';
+import LegacyExtractorForm from './legacy-form';
+
+export { FormSchema } from './go-form';
+export type { ExtractorFormSchemaType } from './go-form';
+
+// The Go backend supports the modularized extractor config (per-feature
+// sub-tabs with nested params), while the Python backend only understands the
+// legacy flat fields — pick the matching form per backend.
+const ExtractorForm = (props: INextOperatorForm) => {
+ const backendLanguage = useSyncExternalStore(
+ subscribeBackendLanguage,
+ getBackendLanguage,
);
-}
-
-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,
-}: INextOperatorForm) => {
- const defaultValues = useNormalizedExtractorFormValues(node);
- const { t } = useTranslation();
-
- const form = useForm<ExtractorFormSchemaType>({
- defaultValues,
- resolver: zodResolver(FormSchema),
- });
-
- useEffect(() => {
- form.reset(defaultValues);
- }, [defaultValues, form]);
-
- const [activeTab, setActiveTab] = useState<ExtractorSubTab>(
- ExtractorSubTab.Keywords,
- );
-
- useWatchFormChange(node?.id, form);
- useFormChangeCallback(form, onValuesChange);
-
- const ownerTenantId = useOwnerTenantId();
-
- const tagFileIdWatch =
- form.watch('tags.tag_file_id') || form.watch('tag_file_id');
- const { treeData, loadData } = useTagFileTree(tagFileIdWatch);
-
- 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 handleTabChange = useCallback((tab: string) => {
- setActiveTab(tab as ExtractorSubTab);
- }, []);
-
- return (
- <Form {...form}>
- <FormWrapper>
- <LargeModelFormField
- ownerTenantId={ownerTenantId}
- ></LargeModelFormField>
-
- <Tabs
- value={activeTab}
- onValueChange={handleTabChange}
- className="w-full"
- >
- <TabsList className="w-full justify-start">
- <TabsTrigger value={ExtractorSubTab.Keywords}>
- {t('flow.keywords')}
- </TabsTrigger>
- <TabsTrigger value={ExtractorSubTab.Questions}>
- {t('flow.questions')}
- </TabsTrigger>
- <TabsTrigger value={ExtractorSubTab.Tags}>
- {t('flow.tags') || t('knowledgeDetails.autoTags')}
- </TabsTrigger>
- <TabsTrigger value={ExtractorSubTab.Summary}>
- {t('flow.summary')}
- </TabsTrigger>
- <TabsTrigger value={ExtractorSubTab.Metadata}>
- {t('flow.metadata')}
- </TabsTrigger>
- </TabsList>
-
- <TabsContent
- value={ExtractorSubTab.Keywords}
- className="space-y-4 pt-2"
- >
- <AutoKeywordsFormField name="keywords.top_n" />
- <RAGFlowFormItem
- label={t('flow.systemPrompt')}
- name="keywords.system_prompt"
- >
- <PromptEditor
- placeholder={t('flow.messagePlaceholder')}
- showToolbar={false}
- showMergePath={false}
- />
- </RAGFlowFormItem>
- </TabsContent>
-
- <TabsContent
- value={ExtractorSubTab.Questions}
- className="space-y-4 pt-2"
- >
- <AutoQuestionsFormField name="questions.top_n" />
- <RAGFlowFormItem
- label={t('flow.systemPrompt')}
- name="questions.system_prompt"
- >
- <PromptEditor
- placeholder={t('flow.messagePlaceholder')}
- showToolbar={false}
- showMergePath={false}
- />
- </RAGFlowFormItem>
- </TabsContent>
-
- <TabsContent value={ExtractorSubTab.Tags} className="space-y-4 pt-2">
- <SliderInputFormField
- name="tags.top_n"
- label={t('knowledgeDetails.autoTags')}
- min={0}
- max={10}
- defaultValue={0}
- layout={FormLayout.Vertical}
- />
- <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>
- </TabsContent>
-
- <TabsContent
- value={ExtractorSubTab.Summary}
- className="space-y-4 pt-2"
- >
- <RAGFlowFormItem
- label={t('flow.enableSummary')}
- name="summary.enabled"
- horizontal
- valueClassName="w-auto flex justify-end"
- >
- {(field) => (
- <Switch
- checked={field.value === 1 || field.value === true}
- onCheckedChange={(checked) => {
- field.onChange(checked);
- form.setValue('field_name', checked ? 'summary' : '', {
- shouldDirty: true,
- });
- form.setValue('enable_summary', checked ? 1 : 0, {
- shouldDirty: true,
- });
- }}
- data-testid="extractor-summary-switch"
- />
- )}
- </RAGFlowFormItem>
- <RAGFlowFormItem
- label={t('flow.systemPrompt')}
- name="summary.system_prompt"
- >
- <PromptEditor
- placeholder={t('flow.messagePlaceholder')}
- showToolbar={false}
- showMergePath={false}
- />
- </RAGFlowFormItem>
- </TabsContent>
-
- <TabsContent
- value={ExtractorSubTab.Metadata}
- className="space-y-4 pt-2"
- >
- <ExtractorAutoMetadata />
- </TabsContent>
- </Tabs>
- {!hideOutputs && <Output list={outputList}></Output>}
- </FormWrapper>
- </Form>
+ return backendLanguage === 'go' ? (
+ <GoExtractorForm {...props} />
+ ) : (
+ <LegacyExtractorForm {...props} />
);
};
diff --git a/web/src/pages/agent/form/extractor-form/legacy-form.tsx b/web/src/pages/agent/form/extractor-form/legacy-form.tsx
new file mode 100644
index 0000000000..afd2a79d2e
--- /dev/null
+++ b/web/src/pages/agent/form/extractor-form/legacy-form.tsx
@@ -0,0 +1,127 @@
+import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog';
+import { LargeModelFormField } from '@/components/large-model-form-field';
+import { LlmSettingSchema } from '@/components/llm-setting-items/next';
+import { SelectWithSearch } from '@/components/originui/select-with-search';
+import { RAGFlowFormItem } from '@/components/ragflow-form';
+import { Form } from '@/components/ui/form';
+import { PromptEditor } from '@/pages/agent/form/components/prompt-editor';
+import { buildOptions } from '@/utils/form';
+import { zodResolver } from '@hookform/resolvers/zod';
+import { memo } from 'react';
+import { useForm } from 'react-hook-form';
+import { useTranslation } from 'react-i18next';
+import { z } from 'zod';
+import {
+ ContextGeneratorFieldName,
+ initialExtractorValues,
+} from '../../constant/pipeline';
+import { useOwnerTenantId } from '../../context';
+import { useBuildNodeOutputOptions } from '../../hooks/use-build-options';
+import { useFormChangeCallback } from '../../hooks/use-form-change-callback';
+import { useFormValues } from '../../hooks/use-form-values';
+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 { useSwitchPrompt } from './use-switch-prompt';
+
+// Python-backend extractor form: the Python Extractor component only reads
+// the legacy flat fields (field_name / sys_prompt / prompts), so this form
+// is kept unchanged from before the Go modularization.
+const FormSchema = z.object({
+ field_name: z.string(),
+ sys_prompt: z.string(),
+ prompts: z.string().optional(),
+ auto_tags: z.number().optional(),
+ tag_file_id: z.string().optional(),
+ ...LlmSettingSchema,
+});
+
+type ExtractorFormSchemaType = z.infer<typeof FormSchema>;
+
+const outputList = buildOutputList(initialExtractorValues.outputs);
+
+const LegacyExtractorForm = ({
+ node,
+ onValuesChange,
+ hideOutputs,
+}: INextOperatorForm) => {
+ const defaultValues = useFormValues(initialExtractorValues, node);
+ const { t } = useTranslation();
+
+ const form = useForm<ExtractorFormSchemaType>({
+ defaultValues,
+ resolver: zodResolver(FormSchema),
+ // mode: 'onChange',
+ });
+
+ const promptOptions = useBuildNodeOutputOptions(node?.id);
+
+ const options = buildOptions(ContextGeneratorFieldName, t, 'flow');
+
+ const {
+ handleFieldNameChange,
+ confirmSwitch,
+ hideModal,
+ visible,
+ cancelSwitch,
+ } = useSwitchPrompt(form);
+
+ useWatchFormChange(node?.id, form);
+ useFormChangeCallback(form, onValuesChange);
+
+ const ownerTenantId = useOwnerTenantId();
+
+ return (
+ <Form {...form}>
+ <FormWrapper>
+ <LargeModelFormField
+ ownerTenantId={ownerTenantId}
+ ></LargeModelFormField>
+
+ <RAGFlowFormItem label={t('flow.fieldName')} name="field_name">
+ {(field) => (
+ <SelectWithSearch
+ onChange={(value) => {
+ field.onChange(value);
+ handleFieldNameChange(value);
+ }}
+ value={field.value}
+ placeholder={t('dataFlowPlaceholder')}
+ options={options}
+ ></SelectWithSearch>
+ )}
+ </RAGFlowFormItem>
+
+ <RAGFlowFormItem label={t('flow.systemPrompt')} name="sys_prompt">
+ <PromptEditor
+ placeholder={t('flow.messagePlaceholder')}
+ showToolbar={true}
+ baseOptions={promptOptions}
+ ></PromptEditor>
+ </RAGFlowFormItem>
+
+ <RAGFlowFormItem label={t('flow.userPrompt')} name="prompts">
+ <PromptEditor
+ showToolbar={true}
+ baseOptions={promptOptions}
+ ></PromptEditor>
+ </RAGFlowFormItem>
+
+ {!hideOutputs && <Output list={outputList}></Output>}
+ </FormWrapper>
+ {visible && (
+ <ConfirmDeleteDialog
+ title={t('flow.switchPromptMessage')}
+ open
+ onOpenChange={hideModal}
+ onOk={confirmSwitch}
+ onCancel={cancelSwitch}
+ ></ConfirmDeleteDialog>
+ )}
+ </Form>
+ );
+};
+
+export default memo(LegacyExtractorForm);
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
new file mode 100644
index 0000000000..1efe7b409c
--- /dev/null
+++ b/web/src/pages/agent/form/extractor-form/use-switch-prompt.ts
@@ -0,0 +1,68 @@
+import { useSetModalState } from '@/hooks/common-hooks';
+import { useCallback, useRef } from 'react';
+import { useTranslation } from 'react-i18next';
+
+type SwitchPromptField = 'field_name' | 'sys_prompt' | 'prompts';
+
+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) => {
+ form.setValue(field, t(`flow.prompts.${key}.${value}`), {
+ 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/hooks/use-add-node.ts b/web/src/pages/agent/hooks/use-add-node.ts
index cc9b6dfd45..6716af54d8 100644
--- a/web/src/pages/agent/hooks/use-add-node.ts
+++ b/web/src/pages/agent/hooks/use-add-node.ts
@@ -23,7 +23,7 @@ import {
initialDuckValues,
initialEmailValues,
initialExeSqlValues,
- initialExtractorValues,
+ getInitialExtractorValues,
initialGithubValues,
initialGoogleScholarValues,
initialGoogleValues,
@@ -182,7 +182,7 @@ export const useInitializeOperatorParams = () => {
[Operator.TokenChunker]: initialTokenChunkerValues,
[Operator.TitleChunker]: initialTitleChunkerValues,
[Operator.Extractor]: {
- ...initialExtractorValues,
+ ...getInitialExtractorValues(),
llm_id: llmId,
sys_prompt: t('flow.prompts.system.summary'),
prompts: t('flow.prompts.user.summary'),
diff --git a/web/src/pages/agent/utils.ts b/web/src/pages/agent/utils.ts
index b432f1a565..df562376bf 100644
--- a/web/src/pages/agent/utils.ts
+++ b/web/src/pages/agent/utils.ts
@@ -399,7 +399,15 @@ export function transformTitleChunkerParams(
};
}
-export function transformExtractorParams(params: ExtractorFormSchemaType) {
+export function transformExtractorParams(
+ params: ExtractorFormSchemaType,
+): Record<string, any> {
+ // The Python extractor only reads the legacy flat fields; the nested
+ // per-feature configs below are Go-only.
+ if (!isGoBackend()) {
+ return { ...params, prompts: [{ content: params.prompts, role: 'user' }] };
+ }
+
const isMetadataEnabled =
params.metadata_config?.enabled !== undefined
? Boolean(params.metadata_config?.enabled)
diff --git a/web/src/pages/agent/utils/tests/extractor-transform.test.ts b/web/src/pages/agent/utils/tests/extractor-transform.test.ts
index 800a3b35d4..0ea79d055d 100644
--- a/web/src/pages/agent/utils/tests/extractor-transform.test.ts
+++ b/web/src/pages/agent/utils/tests/extractor-transform.test.ts
@@ -1,7 +1,17 @@
import { transformExtractorConfigToForm } from '@/utils/pipeline-operator';
import { transformExtractorParams } from '../../utils';
+let mockIsGoBackend = true;
+jest.mock('@/utils/backend-runtime', () => ({
+ isGoBackend: () => mockIsGoBackend,
+ getBackendLanguage: () => (mockIsGoBackend ? 'go' : 'python'),
+}));
+
describe('Extractor parameter transformations & precedence', () => {
+ beforeEach(() => {
+ mockIsGoBackend = true;
+ });
+
describe('transformExtractorParams', () => {
it('synchronizes nested modular configs to flat fields and preserves nested objects', () => {
const input: any = {
@@ -112,4 +122,52 @@ describe('Extractor parameter transformations & precedence', () => {
expect(result.tags.top_n).toBe(1);
});
});
+
+ describe('python backend keeps the legacy flat shape', () => {
+ beforeEach(() => {
+ mockIsGoBackend = false;
+ });
+
+ it('transformExtractorParams only wraps prompts, without nested configs', () => {
+ const input: any = {
+ field_name: 'summary',
+ sys_prompt: 'sys',
+ prompts: 'user prompt',
+ auto_keywords: 3,
+ auto_questions: 2,
+ auto_tags: 1,
+ tag_file_id: 'tag-1',
+ llm_id: 'gpt-4',
+ };
+
+ const result = transformExtractorParams(input);
+
+ expect(result).toEqual({
+ ...input,
+ prompts: [{ content: 'user prompt', role: 'user' }],
+ });
+ expect(result).not.toHaveProperty('keywords');
+ expect(result).not.toHaveProperty('questions');
+ expect(result).not.toHaveProperty('tags');
+ expect(result).not.toHaveProperty('summary');
+ expect(result).not.toHaveProperty('metadata_config');
+ });
+
+ it('transformExtractorConfigToForm only unwraps prompts, without nested configs', () => {
+ const config = {
+ prompts: [{ content: 'user prompt', role: 'user' }],
+ auto_keywords: 4,
+ auto_tags: 1,
+ };
+
+ const result = transformExtractorConfigToForm(config);
+
+ expect(result.prompts).toBe('user prompt');
+ expect(result).not.toHaveProperty('keywords');
+ expect(result).not.toHaveProperty('summary');
+ expect(result).not.toHaveProperty('metadata_config');
+ expect(result).not.toHaveProperty('enable_summary');
+ expect(result).not.toHaveProperty('enable_metadata');
+ });
+ });
});
diff --git a/web/src/utils/pipeline-operator.ts b/web/src/utils/pipeline-operator.ts
index efaac7b69d..df9023ed37 100644
--- a/web/src/utils/pipeline-operator.ts
+++ b/web/src/utils/pipeline-operator.ts
@@ -17,7 +17,8 @@
import { Operator } from '@/constants/agent';
import { DSL, RAGFlowNodeType } from '@/interfaces/database/agent';
import {
- initialExtractorValues,
+ getInitialExtractorValues,
+ initialGoExtractorValues,
initialParserValues,
initialTitleChunkerValues,
initialTokenChunkerValues,
@@ -29,6 +30,7 @@ import {
transformTitleChunkerParams,
transformTokenChunkerParams,
} from '@/pages/agent/utils';
+import { isGoBackend } from '@/utils/backend-runtime';
import { cloneDeep, isEmpty } from 'lodash';
export const FileNodeId = 'File';
@@ -96,6 +98,12 @@ export function transformExtractorConfigToForm(
result.prompts = config.prompts[0]?.content ?? '';
}
+ // The nested per-feature configs are Go-only; the Python extractor form
+ // consumes the legacy flat fields as-is.
+ if (!isGoBackend()) {
+ return result;
+ }
+
const isSummaryEnabled =
config.summary?.enabled !== undefined
? Boolean(config.summary?.enabled)
@@ -110,7 +118,7 @@ export function transformExtractorConfigToForm(
top_n:
config.keywords?.top_n ??
config.auto_keywords ??
- initialExtractorValues.keywords.top_n,
+ initialGoExtractorValues.keywords.top_n,
system_prompt:
config.keywords?.system_prompt ?? config.keywords_sys_prompt ?? '',
};
@@ -118,7 +126,7 @@ export function transformExtractorConfigToForm(
top_n:
config.questions?.top_n ??
config.auto_questions ??
- initialExtractorValues.questions.top_n,
+ initialGoExtractorValues.questions.top_n,
system_prompt:
config.questions?.system_prompt ?? config.questions_sys_prompt ?? '',
};
@@ -126,7 +134,7 @@ export function transformExtractorConfigToForm(
top_n:
config.tags?.top_n ??
config.auto_tags ??
- initialExtractorValues.tags.top_n,
+ initialGoExtractorValues.tags.top_n,
tag_file_id: config.tags?.tag_file_id ?? config.tag_file_id ?? '',
};
result.summary = {
@@ -337,7 +345,7 @@ function normalizeOperatorForm(
};
case Operator.Extractor:
return {
- ...cloneDeep(initialExtractorValues),
+ ...cloneDeep(getInitialExtractorValues()),
...rawForm,
};
case Operator.Tokenizer: