RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Feat: List all file type parsing configurations for the parser operator. (#19050)
balibabued9fdb9d7884
diff --git a/web/src/locales/en.ts b/web/src/locales/en.tsindex 376a0901db..159e79bb6e 100644--- a/web/src/locales/en.ts+++ b/web/src/locales/en.ts@@ -3386,7 +3386,6 @@ This process aggregates variables from multiple branches into a single variablecompilerDescription:'Compiles document chunks using knowledge compilation templates into structured artifacts.',outputFormat: 'Output format',- fileFormats: 'File type',fileFormatOptions: {pdf: 'PDF',spreadsheet: 'Spreadsheet',@@ -3402,7 +3401,6 @@ This process aggregates variables from multiple branches into a single variablevideo: 'Video',},fields: 'Field',- addParser: 'Add Parser',rule: 'Rule',addRule: 'Add rule',group: 'Group',diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.tsindex df67d82a04..a3f2bf95b2 100644--- a/web/src/locales/zh.ts+++ b/web/src/locales/zh.ts@@ -2945,7 +2945,6 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 Rcompiler: '编译器',compilerDescription: '使用知识编译模板将文档块编译为知识工件。',outputFormat: '输出格式',- fileFormats: '文件类型',fileFormatOptions: {pdf: 'PDF',spreadsheet: '表格',@@ -2961,7 +2960,6 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取 Entities 和 Rvideo: '视频',},fields: '字段',- addParser: '增加解析器',rule: '规则',addRule: '增加规则',addRegularExpressions: '增加正则表达式',diff --git a/web/src/pages/agent/canvas/node/parser-node.tsx b/web/src/pages/agent/canvas/node/parser-node.tsxindex 96a83050a3..0b0904dcd2 100644--- a/web/src/pages/agent/canvas/node/parser-node.tsx+++ b/web/src/pages/agent/canvas/node/parser-node.tsx@@ -1,15 +1,14 @@-import { NodeCollapsible } from '@/components/collapse';import { BaseNode } from '@/interfaces/database/agent';import { NodeProps, Position } from '@xyflow/react';import { memo } from 'react';import { useTranslation } from 'react-i18next';import { NodeHandleId } from '../../constant';import { ParserFormSchemaType } from '../../form/parser-form';-import { LabelCard } from './card';import { CommonHandle } from './handle';import { LeftHandleStyle, RightHandleStyle } from './handle-icon';import NodeHeader from './node-header';import { NodeWrapper } from './node-wrapper';+import { LabelCard } from './card';function ParserNode({id,@@ -18,6 +17,11 @@ function ParserNode({selected,}: NodeProps<BaseNode<ParserFormSchemaType>>) {const { t } = useTranslation();++ const fileFormats = (data.form?.setups ?? [])+ .map((setup) => setup.fileFormat)+ .filter((format): format is string => typeof format === 'string');+return (<NodeWrapper selected={selected} id={id}><CommonHandle@@ -38,18 +42,15 @@ function ParserNode({isConnectableEnd={false}></CommonHandle><NodeHeader id={id} name={data.name} label={data.label}></NodeHeader>-- <NodeCollapsible items={data.form?.setups}>- {(x, idx) => (- <LabelCard- key={idx}- className="flex flex-col text-text-primary gap-1"- >- <span className="text-text-secondary">Parser {idx + 1}</span>- {t(`flow.fileFormatOptions.${x.fileFormat}`)}- </LabelCard>- )}- </NodeCollapsible>+ {fileFormats.length > 0 && (+ <LabelCard className="flex flex-wrap gap-2">+ {fileFormats.map((format, index) => (+ <span key={index} className="italic text-text-secondary">+ {t(`flow.fileFormatOptions.${format}`)}+ </span>+ ))}+ </LabelCard>+ )}</NodeWrapper>);}diff --git a/web/src/pages/agent/constant/pipeline.tsx b/web/src/pages/agent/constant/pipeline.tsxindex 170f5018a1..9c916a4285 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 { ModelTypeToField } from '@/constants/llm';import { pickByBackend } from '@/utils/backend-variant';import { cloneDeep } from 'lodash';@@ -78,19 +79,12 @@ export const OutputFormatMap = {[FileType.Audio]: AudioOutputFormat,};-export const InitialOutputFormatMap = {- [FileType.PDF]: PdfOutputFormat.Json,- [FileType.Spreadsheet]: SpreadsheetOutputFormat.Html,- [FileType.Image]: ImageOutputFormat.Json,- [FileType.Email]: EmailOutputFormat.Text,- [FileType.TextMarkdown]: TextMarkdownOutputFormat.Text,- [FileType.Code]: TextJsonOutputFormat.Json,- [FileType.Html]: TextJsonOutputFormat.Json,- [FileType.Doc]: DocxOutputFormat.Json,- [FileType.Docx]: DocxOutputFormat.Json,- [FileType.PowerPoint]: PptOutputFormat.Json,- [FileType.Video]: VideoOutputFormat.Text,- [FileType.Audio]: AudioOutputFormat.Text,+// The video parser defaults to the tenant's VLM model and the audio parser to+// the ASR model, keyed by the useFetchDefaultModelDictionary fields. A file+// type without a configured tenant default keeps its empty model id.+export const FileTypeDefaultModelFieldMap: Partial<Record<FileType, string>> = {+ [FileType.Video]: ModelTypeToField.vision,+ [FileType.Audio]: ModelTypeToField.asr,};export enum ContextGeneratorFieldName {@@ -256,6 +250,16 @@ export const initialParserValues = {parse_method: ParseDocumentType.DeepDOC,preprocess: PreprocessValue.main_content,},+ {+ fileFormat: FileType.Video,+ output_format: VideoOutputFormat.Text,+ vlm: { llm_id: '' },+ },+ {+ fileFormat: FileType.Audio,+ output_format: AudioOutputFormat.Text,+ vlm: { 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.tsxindex 3fb55f59fe..4fa05b35f1 100644--- a/web/src/pages/agent/form/extractor-form/go-form.tsx+++ b/web/src/pages/agent/form/extractor-form/go-form.tsx@@ -26,6 +26,7 @@ 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';@@ -270,28 +271,90 @@ const GoExtractorForm = ({></LargeModelFormField><div className="space-y-4">- <Collapse title={t('flow.keywords')} defaultOpen>- <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"+ <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">+ <Collapse title={t('flow.keywords')} defaultOpen>+ <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>+ <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+ >+ <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>- </div>- </Collapse>+ <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>- <Collapse title={t('flow.questions')} defaultOpen>- <div className="space-y-4">- <AutoQuestionsFormField name="questions.top_n" />+ <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"+ />+ }+ ><RAGFlowFormItemlabel={t('flow.systemPrompt')}- name="questions.system_prompt"+ name="summary.system_prompt"><Textareaplaceholder={t('flow.messagePlaceholder')}@@ -299,76 +362,24 @@ const GoExtractorForm = ({rows={18}/></RAGFlowFormItem>- </div>- </Collapse>+ </Collapse>+ </Card>- <Collapse- title={t('flow.tags') || t('knowledgeDetails.autoTags')}- defaultOpen- >- <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>-- <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"+ <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"+ />+ }>- <Textarea- placeholder={t('flow.messagePlaceholder')}- resize="vertical"- rows={18}- />- </RAGFlowFormItem>- </Collapse>-- <Collapse- title={t('flow.metadata')}- defaultOpen- rightContent={- <Switch- checked={metadataEnabled}- onCheckedChange={handleMetadataSwitch}- data-testid="extractor-metadata-switch"- />- }- >- <ExtractorMetadataContent />- </Collapse>+ <ExtractorMetadataContent />+ </Collapse>+ </Card></div>{!hideOutputs && <Output list={outputList}></Output>}diff --git a/web/src/pages/agent/form/parser-form/index.tsx b/web/src/pages/agent/form/parser-form/index.tsxindex 6db355f7cb..b8ae01004c 100644--- a/web/src/pages/agent/form/parser-form/index.tsx+++ b/web/src/pages/agent/form/parser-form/index.tsx@@ -1,32 +1,15 @@-import {- SelectWithSearch,- SelectWithSearchFlagOptionType,-} from '@/components/originui/select-with-search';+import { Collapse } from '@/components/collapse';import { useSyncExternalFormErrors } from '@/components/pipeline-operator-tabs/use-sync-external-form-errors';-import { RAGFlowFormItem } from '@/components/ragflow-form';-import { BlockButton, Button } from '@/components/ui/button';+import { Card } from '@/components/ui/card';import { Form } from '@/components/ui/form';-import { Separator } from '@/components/ui/separator';-import { cn } from '@/lib/utils';+import { useFetchDefaultModelDictionary } from '@/hooks/use-llm-request';import i18n from '@/locales/config';-import { buildOptions } from '@/utils/form';import { zodResolver } from '@hookform/resolvers/zod';-import { useHover } from 'ahooks';-import { Trash2 } from 'lucide-react';-import { memo, useCallback, useEffect, useMemo, useRef } from 'react';-import {- useFieldArray,- UseFieldArrayRemove,- useForm,- useFormContext,-} from 'react-hook-form';+import { memo, useMemo } from 'react';+import { useFieldArray, useForm, useFormContext } from 'react-hook-form';import { useTranslation } from 'react-i18next';import { z } from 'zod';-import {- FileType,- InitialOutputFormatMap,- initialParserValues,-} from '../../constant/pipeline';+import { FileType, initialParserValues } from '../../constant/pipeline';import { useFormChangeCallback } from '../../hooks/use-form-change-callback';import { useFormValues } from '../../hooks/use-form-values';import { useWatchFormChange } from '../../hooks/use-watch-form-change';@@ -43,7 +26,7 @@ import {HtmlFormFields,TextMarkdownFormFields,} from './text-html-form-fields';-import { buildFieldNameWithPrefix, getInitialParseMethod } from './utils';+import { withDefaultParserModels } from './utils';import { AudioFormFields, VideoFormFields } from './video-form-fields';import { WordFormFields } from './word-form-fields';@@ -66,9 +49,6 @@ const FileFormatWidgetMap = {type ParserItemProps = {name: string;index: number;- fieldLength: number;- remove: UseFieldArrayRemove;- fileFormatOptions: SelectWithSearchFlagOptionType[];};const SetupSchema = z@@ -138,52 +118,12 @@ export const FormSchema = z.object({export type ParserFormSchemaType = z.infer<typeof FormSchema>;-function ParserItem({- name,- index,- fieldLength,- remove,- fileFormatOptions,-}: ParserItemProps) {+function ParserItem({ name, index }: ParserItemProps) {const { t } = useTranslation();const form = useFormContext<ParserFormSchemaType>();- const ref = useRef(null);- const isHovering = useHover(ref);const prefix = `${name}.${index}`;const fileFormat = form.watch(`setups.${index}.fileFormat`);- const prevFileFormatRef = useRef(fileFormat);-- useEffect(() => {- if (!fileFormat || prevFileFormatRef.current === fileFormat) {- return;- }- prevFileFormatRef.current = fileFormat;-- form.setValue(- `setups.${index}.output_format`,- InitialOutputFormatMap[fileFormat as FileType],- { shouldDirty: true, shouldValidate: true, shouldTouch: true },- );- form.setValue(- `setups.${index}.parse_method`,- getInitialParseMethod(fileFormat as FileType),- { shouldDirty: true, shouldValidate: true, shouldTouch: true },- );- }, [fileFormat, form, index]);-- const values = form.getValues();- const parserList = values.setups.slice(); // Adding, deleting, or modifying the parser array will not change the reference.-- const filteredFileFormatOptions = useMemo(() => {- const otherFileFormatList = parserList- .filter((_, idx) => idx !== index)- .map((x) => x.fileFormat);-- return fileFormatOptions.filter((x) => {- return !otherFileFormatList.includes(x.value);- });- }, [fileFormatOptions, index, parserList]);const Widget =typeof fileFormat === 'string' && fileFormat in FileFormatWidgetMap@@ -191,43 +131,22 @@ function ParserItem({: () => <></>;return (- <section- className={cn('space-y-5 py-2.5 rounded-md', {- 'bg-state-error-5': isHovering,- })}- >- <div className="flex justify-between items-center">- <span className="text-text-primary text-sm font-medium">- Parser {index + 1}- </span>- {index > 0 && (- <Button variant={'ghost'} onClick={() => remove(index)} ref={ref}>- <Trash2 />- </Button>- )}- </div>- <RAGFlowFormItem- name={buildFieldNameWithPrefix(`fileFormat`, prefix)}- label={t('flow.fileFormats')}- >- {(field) => (- <SelectWithSearch- value={field.value}- onChange={field.onChange}- options={filteredFileFormatOptions}- ></SelectWithSearch>- )}- </RAGFlowFormItem>- <Widget prefix={prefix} fileType={fileFormat as FileType}></Widget>+ <Card as="section" className="bg-bg-card px-5 py-2.5 border-none">+ {/* The file format is fixed per parser item; keep it registered so it is+ still submitted with the form. */}+ <input type="hidden" {...form.register(`setups.${index}.fileFormat`)} />+ <Collapse title={t(`flow.fileFormatOptions.${fileFormat}`)} defaultOpen>+ <div className="space-y-5">+ <Widget prefix={prefix} fileType={fileFormat as FileType}></Widget>+ </div>+ </Collapse><div className="hidden"><OutputFormatFormFieldprefix={prefix}fileType={fileFormat as FileType}/></div>-- {index < fieldLength - 1 && <Separator />}- </section>+ </Card>);}@@ -237,64 +156,38 @@ const ParserForm = ({hideOutputs,externalErrors,}: INextOperatorForm) => {- const { t } = useTranslation();- const defaultValues = useFormValues(initialParserValues, node);-- const FileFormatOptions = buildOptions(FileType, t, 'flow.fileFormatOptions');+ const defaultModelDictionary = useFetchDefaultModelDictionary();+ const formValues = useFormValues(initialParserValues, node);+ const defaultValues = useMemo(+ () => withDefaultParserModels(formValues, defaultModelDictionary),+ [formValues, defaultModelDictionary],+ );const form = useForm<z.infer<typeof FormSchema>>({defaultValues,resolver: zodResolver(FormSchema),mode: 'onChange',- shouldUnregister: true,});useSyncExternalFormErrors(form, externalErrors);const name = 'setups';- const { fields, remove, append } = useFieldArray({+ const { fields } = useFieldArray({name,control: form.control,});- const add = useCallback(() => {- append({- fileFormat: null,- output_format: '',- parse_method: '',- lang: '',- fields: [],- vlm: { llm_id: '' },- table_result_type: '',- markdown_image_response_type: '',- remove_header_footer: false,- // preprocess: [],- });- }, [append]);-useWatchFormChange(node?.id, form);useFormChangeCallback(form, onValuesChange);return (<Form {...form}>- <form className="px-5">+ <form className="space-y-5 px-5">{fields.map((field, index) => {return (- <ParserItem- key={field.id}- name={name}- index={index}- fieldLength={fields.length}- remove={remove}- fileFormatOptions={FileFormatOptions}- ></ParserItem>+ <ParserItem key={field.id} name={name} index={index}></ParserItem>);})}- {fields.length < FileFormatOptions.length && (- <BlockButton onClick={add} type="button" className="mt-2.5">- {t('flow.addParser')}- </BlockButton>- )}</form>{!hideOutputs && (<div className="p-5">diff --git a/web/src/pages/agent/form/parser-form/utils.ts b/web/src/pages/agent/form/parser-form/utils.tsindex bcc15e5c76..d840f757dd 100644--- a/web/src/pages/agent/form/parser-form/utils.ts+++ b/web/src/pages/agent/form/parser-form/utils.ts@@ -1,6 +1,7 @@import { ParseDocumentType } from '@/components/layout-recognize-form-field';import {FileType,+ FileTypeDefaultModelFieldMap,ImageParseMethod,initialParserValues,} from '../../constant/pipeline';@@ -9,6 +10,28 @@ export function buildFieldNameWithPrefix(name: string, prefix: string) {return `${prefix}.${name}`;}+export function withDefaultParserModels(+ formValues: Record<string, any>,+ defaultModelDictionary: Record<string, string>,+) {+ const setups = formValues?.setups;+ if (!Array.isArray(setups)) {+ return formValues;+ }++ return {+ ...formValues,+ setups: setups.map((setup) => {+ const field = FileTypeDefaultModelFieldMap[setup?.fileFormat as FileType];+ const modelId = field ? defaultModelDictionary[field] : '';+ if (!modelId || setup?.vlm?.llm_id) {+ return setup;+ }+ return { ...setup, vlm: { ...setup?.vlm, llm_id: modelId } };+ }),+ };+}+export function getInitialParseMethod(fileType: FileType): string {const setup = initialParserValues.setups.find((x) => x.fileFormat === fileType,@@ -16,10 +39,9 @@ export function getInitialParseMethod(fileType: FileType): string {return setup?.parse_method ?? '';}-// Static parse-method values across all file types. With shouldUnregister the-// parse_method field is re-seeded from the node's saved form data when its-// widget remounts on a file-type switch, so it can hold a previous file type's-// static value. LLM model ids from the model tree are never in this set, so a+// Static parse-method values across all file types. Forms saved while the+// file type was still switchable can hold another file type's static value on+// parse_method. LLM model ids from the model tree are never in this set, so a// user-picked model is never treated as foreign.// Note: ParseDocumentType is a const enum — list members explicitly instead of// Object.values, which is not allowed on const enums (TS2475).diff --git a/web/src/pages/agent/hooks/use-add-node.ts b/web/src/pages/agent/hooks/use-add-node.tsindex d30aad25ff..96c80cebbd 100644--- a/web/src/pages/agent/hooks/use-add-node.ts+++ b/web/src/pages/agent/hooks/use-add-node.ts@@ -60,6 +60,7 @@ import {initialWikipediaValues,initialYahooFinanceValues,} from '../constant';+import { withDefaultParserModels } from '../form/parser-form/utils';import useGraphStore from '../store';import {generateNodeNamesWithIncreasingIndex,@@ -180,7 +181,10 @@ export const useInitializeOperatorParams = () => {[Operator.TavilyExtract]: initialTavilyExtractValues,[Operator.Placeholder]: {},[Operator.File]: {},- [Operator.Parser]: initialParserValues,+ [Operator.Parser]: withDefaultParserModels(+ initialParserValues,+ defaultModelDictionary,+ ),[Operator.Tokenizer]: initialTokenizerValues,[Operator.TokenChunker]: initialTokenChunkerValues,[Operator.TitleChunker]: initialTitleChunkerValues,@@ -210,7 +214,7 @@ export const useInitializeOperatorParams = () => {[Operator.Browser]: { ...initialBrowserValues, llm_id: llmId },[Operator.ExcelProcessor]: {},};- }, [llmId]);+ }, [defaultModelDictionary, llmId]);const initializeOperatorParams = useCallback((operatorName: Operator, position: Position) => {