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
Fix: Update the prompt text for file types not supported by the current pipeline. (#20911)
balibabu98fa2413e229
diff --git a/web/src/locales/en.ts b/web/src/locales/en.tsindex 8f18431a02..f237fd16c2 100644--- a/web/src/locales/en.ts+++ b/web/src/locales/en.ts@@ -410,8 +410,16 @@ Example: A 1 KB message with 1024-dim embedding uses ~9 KB. The 5 MB default limuploadUnsupportedTypesTitle: 'Some file types cannot be parsed',fileTypeUnsupported:'{{name}} ({{fileType}}): not supported by the current parser configuration',+ fileTypeUnsupportedAutoSwitch:+ '{{name}} ({{fileType}}): not supported by the current parser configuration; it will automatically switch to the built-in {{parser}} configuration',+ fileTypeUnsupportedManualSwitch:+ '{{name}} ({{fileType}}): not supported by the current parser configuration; switch its parsing method manually after upload',reselectParserAfterUploadHint:'Continue uploading, then system will automatically switch these files to a supported built-in parsing configuration.',+ manualSwitchAfterUploadHint:+ 'Continue uploading, then switch the parsing method for these files manually.',+ mixedSwitchAfterUploadHint:+ 'Continue uploading. Some files will switch to a supported built-in parsing configuration automatically; switch the rest manually after upload.',reselectParserToParseHint:'Reselect a parse method for the affected files, then parse again.',addModelAfterUploadHint:diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.tsindex 8ce5747d33..2518a8c1bb 100644--- a/web/src/locales/zh.ts+++ b/web/src/locales/zh.ts@@ -368,8 +368,16 @@ export default {uploadUnsupportedTypesTitle: '部分文件类型不支持解析',fileTypeUnsupported:'{{name}}({{fileType}}):当前解析配置不支持该文件类型',+ fileTypeUnsupportedAutoSwitch:+ '{{name}}({{fileType}}):当前解析配置不支持该文件类型,将自动切换为内置 {{parser}} 配置',+ fileTypeUnsupportedManualSwitch:+ '{{name}}({{fileType}}):当前解析配置不支持该文件类型,上传后可手动切换解析配置',reselectParserAfterUploadHint:'可继续上传,系统将自动切换至支持这些文件类型的内置解析配置。',+ manualSwitchAfterUploadHint:+ '可继续上传,上传后可手动切换这些文件的解析配置。',+ mixedSwitchAfterUploadHint:+ '可继续上传,部分文件将自动切换至内置解析配置,其余文件上传后可手动切换解析配置。',reselectParserToParseHint: '请重新选择对应文件的解析方法后再解析。',addModelAfterUploadHint: '可继续上传,上传后前往添加模型即可解析。',addModelToParseHint: '请前往添加模型后再解析。',diff --git a/web/src/pages/dataset/dataset/parser-gap-content.tsx b/web/src/pages/dataset/dataset/parser-gap-content.tsxindex 8d0c94b2db..745500687c 100644--- a/web/src/pages/dataset/dataset/parser-gap-content.tsx+++ b/web/src/pages/dataset/dataset/parser-gap-content.tsx@@ -1,44 +1,108 @@import type { TFunction } from 'i18next';import type { ReactNode } from 'react';import { ParserGapReason, ParserModelKind } from './constant';-import { pickByGapKind, type FileParserGap } from './utils';+import {+ BuiltinSwitchTargetLabels,+ pickByGapKind,+ pickBySwitchFate,+ type FileParserGap,+ type UploadFileParserGap,+} from './utils';/*** Builds the body of the parser-gap modals (upload warning, parse-click* error). Strings are resolved with the caller's `t` because the static Modal* API renders content in a separate React root without the app providers.- * The hint follows the gap kind: missing models point to adding the model,- * unsupported types to reselecting the parse method.+ *+ * Two entry points share one layout: `buildParserGapModalContent` renders+ * already-uploaded documents (parse-click validation), while+ * `buildUploadGapModalContent` renders pre-upload files and annotates each+ * unsupported file with its switch fate — the built-in pipeline the backend+ * will switch it to, or the need to reselect a parse method manually.*/-export function buildParserGapModalContent(++type GapHintKeys = { missingModel: string; unsupportedType: string };++type UploadGapHintKeys = {+ missingModel: string;+ autoSwitch: string;+ manualSwitch: string;+ mixedSwitch: string;+};++function renderGapLine(t: TFunction, gap: FileParserGap): ReactNode {+ if (gap.reason === ParserGapReason.MissingModel) {+ return t('knowledgeDetails.fileModelMissing', {+ name: gap.name,+ fileType: t(`flow.fileFormatOptions.${gap.fileType}`),+ model: t(+ gap.modelKind === ParserModelKind.Asr+ ? 'knowledgeDetails.missingModelAsr'+ : 'knowledgeDetails.missingModelVision',+ ),+ });+ }+ return t('knowledgeDetails.fileTypeUnsupported', {+ name: gap.name,+ fileType: t(`flow.fileFormatOptions.${gap.fileType}`),+ });+}++function renderUploadGapLine(t: TFunction,- gaps: FileParserGap[],- hintKeys: { missingModel: string; unsupportedType: string },+ gap: UploadFileParserGap,+): ReactNode {+ if (gap.reason === ParserGapReason.MissingModel) {+ return renderGapLine(t, gap);+ }+ const fileType = t(`flow.fileFormatOptions.${gap.fileType}`);+ return gap.autoSwitchTarget+ ? t('knowledgeDetails.fileTypeUnsupportedAutoSwitch', {+ name: gap.name,+ fileType,+ parser: BuiltinSwitchTargetLabels[gap.autoSwitchTarget],+ })+ : t('knowledgeDetails.fileTypeUnsupportedManualSwitch', {+ name: gap.name,+ fileType,+ });+}++function buildContent<G extends FileParserGap>(+ t: TFunction,+ gaps: G[],+ hintKey: string,+ renderLine: (t: TFunction, gap: G) => ReactNode,): ReactNode {- const hintKey = pickByGapKind(gaps, hintKeys);return (<div className="space-y-2"><ul className="list-disc pl-4 space-y-1">{gaps.map((gap, index) => (- <li key={`${gap.name}-${index}`}>- {gap.reason === ParserGapReason.MissingModel- ? t('knowledgeDetails.fileModelMissing', {- name: gap.name,- fileType: t(`flow.fileFormatOptions.${gap.fileType}`),- model: t(- gap.modelKind === ParserModelKind.Asr- ? 'knowledgeDetails.missingModelAsr'- : 'knowledgeDetails.missingModelVision',- ),- })- : t('knowledgeDetails.fileTypeUnsupported', {- name: gap.name,- fileType: t(`flow.fileFormatOptions.${gap.fileType}`),- })}- </li>+ <li key={`${gap.name}-${index}`}>{renderLine(t, gap)}</li>))}</ul><p className="text-text-secondary">{t(hintKey)}</p></div>);}++export function buildParserGapModalContent(+ t: TFunction,+ gaps: FileParserGap[],+ hintKeys: GapHintKeys,+): ReactNode {+ return buildContent(t, gaps, pickByGapKind(gaps, hintKeys), renderGapLine);+}++export function buildUploadGapModalContent(+ t: TFunction,+ gaps: UploadFileParserGap[],+ hintKeys: UploadGapHintKeys,+): ReactNode {+ return buildContent(+ t,+ gaps,+ pickBySwitchFate(gaps, hintKeys),+ renderUploadGapLine,+ );+}diff --git a/web/src/pages/dataset/dataset/use-parser-gap-validation.ts b/web/src/pages/dataset/dataset/use-parser-gap-validation.tsindex ed27c98e4b..c7bb118b24 100644--- a/web/src/pages/dataset/dataset/use-parser-gap-validation.ts+++ b/web/src/pages/dataset/dataset/use-parser-gap-validation.ts@@ -2,10 +2,12 @@ import type { IDocumentInfo } from '@/interfaces/database/document';import { useCallback } from 'react';import { useKnowledgeBaseContext } from '../contexts/knowledge-base-context';import {+ attachAutoSwitchTargets,FileParserGap,findDocumentsParserGaps,findFilesParserGaps,getSavedParserConfig,+ type UploadFileParserGap,} from './utils';/**@@ -20,8 +22,12 @@ export function useParserGapValidation() {// yet and every file would look unsupported. A missing Parser entry means// the config predates operator-scoped settings, so type support cannot be// determined either.+ //+ // Upload runs before the backend parser switch, so each gap is annotated+ // with the fate the backend will give the file (see+ // attachAutoSwitchTargets).const findParseGaps = useCallback(- (names: string[]): FileParserGap[] => {+ (names: string[]): UploadFileParserGap[] => {if (loading) {return [];}@@ -29,7 +35,10 @@ export function useParserGapValidation() {if (!config) {return [];}- return findFilesParserGaps(names, config);+ return attachAutoSwitchTargets(+ findFilesParserGaps(names, config),+ knowledgeBase?.pipeline_id,+ );},[loading, knowledgeBase],);diff --git a/web/src/pages/dataset/dataset/use-upload-document.ts b/web/src/pages/dataset/dataset/use-upload-document.tsindex bb9e93ba2a..004baf9a8b 100644--- a/web/src/pages/dataset/dataset/use-upload-document.ts+++ b/web/src/pages/dataset/dataset/use-upload-document.ts@@ -10,7 +10,7 @@ import { IDocumentInfo } from '@/interfaces/database/document';import { getExtension, getUnSupportedFilesCount } from '@/utils/document-util';import { useCallback } from 'react';import { useTranslation } from 'react-i18next';-import { buildParserGapModalContent } from './parser-gap-content';+import { buildUploadGapModalContent } from './parser-gap-content';import { useParserGapValidation } from './use-parser-gap-validation';import { getFileTypeByExtension, hasUnsupportedTypeGap } from './utils';@@ -116,9 +116,11 @@ export const useHandleUploadDocument = () => {? 'knowledgeDetails.uploadUnsupportedTypesTitle': 'knowledgeDetails.uploadMissingModelsTitle',),- content: buildParserGapModalContent(t, gaps, {+ content: buildUploadGapModalContent(t, gaps, {missingModel: 'knowledgeDetails.addModelAfterUploadHint',- unsupportedType: 'knowledgeDetails.reselectParserAfterUploadHint',+ autoSwitch: 'knowledgeDetails.reselectParserAfterUploadHint',+ manualSwitch: 'knowledgeDetails.manualSwitchAfterUploadHint',+ mixedSwitch: 'knowledgeDetails.mixedSwitchAfterUploadHint',}),okText: t('knowledgeDetails.continueUpload'),cancelText: t('common.cancel'),diff --git a/web/src/pages/dataset/dataset/utils.test.ts b/web/src/pages/dataset/dataset/utils.test.tsindex 6ec3d7270b..c08d05a15f 100644--- a/web/src/pages/dataset/dataset/utils.test.ts+++ b/web/src/pages/dataset/dataset/utils.test.ts@@ -6,6 +6,8 @@ import {RunningStatus,} from './constant';import {+ attachAutoSwitchTargets,+ builtinParserSwitchTarget,findDocumentsParserGaps,findFilesParserGaps,findParserGap,@@ -17,7 +19,9 @@ import {ingestionStatusToRunningStatus,isDocumentProcessing,isDocumentStopping,+ pickBySwitchFate,type SavedParserConfig,+ type UploadFileParserGap,} from './utils';describe('isDocumentStopping', () => {@@ -265,6 +269,139 @@ describe('hasUnsupportedTypeGap', () => {});});+describe('builtinParserSwitchTarget', () => {+ it('never switches for a dataset on a custom pipeline', () => {+ expect(builtinParserSwitchTarget('photo.jpg', 'canvas-1')).toBeNull();+ expect(builtinParserSwitchTarget('song.mp3', 'canvas-1')).toBeNull();+ expect(builtinParserSwitchTarget('mail.msg', 'canvas-1')).toBeNull();+ });++ it('maps owned file types to their built-in pipelines', () => {+ // The visual bucket includes the video extensions, mirroring the backend.+ expect(builtinParserSwitchTarget('photo.JPG')).toBe('picture');+ expect(builtinParserSwitchTarget('movie.mp4')).toBe('picture');+ expect(builtinParserSwitchTarget('clip.mov')).toBe('picture');+ expect(builtinParserSwitchTarget('song.mp3')).toBe('audio');+ expect(builtinParserSwitchTarget('song.opus')).toBe('audio');+ expect(builtinParserSwitchTarget('deck.ppt')).toBe('presentation');+ expect(builtinParserSwitchTarget('deck.pptx')).toBe('presentation');+ expect(builtinParserSwitchTarget('deck.pages')).toBe('presentation');+ expect(builtinParserSwitchTarget('mail.msg')).toBe('email');+ expect(builtinParserSwitchTarget('mail.eml')).toBe('email');+ });++ it('keeps the dataset parser for every other type', () => {+ expect(builtinParserSwitchTarget('laws.txt')).toBeNull();+ expect(builtinParserSwitchTarget('laws.pdf')).toBeNull();+ expect(builtinParserSwitchTarget('book.docx')).toBeNull();+ expect(builtinParserSwitchTarget('sheet.xlsx')).toBeNull();+ // Frontend-known audio suffixes the backend rejects at upload keep the+ // dataset parser too — the switch map mirrors the backend exactly.+ expect(builtinParserSwitchTarget('song.wma')).toBeNull();+ });+});++describe('attachAutoSwitchTargets', () => {+ it('annotates unsupported gaps with the target and other gaps with null', () => {+ const gaps = attachAutoSwitchTargets(+ [+ {+ name: 'photo.jpg',+ reason: ParserGapReason.UnsupportedType,+ fileType: FileType.Image,+ },+ {+ name: 'song.mp3',+ reason: ParserGapReason.MissingModel,+ fileType: FileType.Audio,+ modelKind: ParserModelKind.Asr,+ },+ {+ name: 'notes.txt',+ reason: ParserGapReason.UnsupportedType,+ fileType: FileType.Code,+ },+ ],+ null,+ );+ expect(gaps.map((x) => x.autoSwitchTarget)).toEqual([+ 'picture',+ null,+ null,+ ]);+ });++ it('annotates nothing switchable on a custom pipeline', () => {+ const gaps = attachAutoSwitchTargets(+ [+ {+ name: 'photo.jpg',+ reason: ParserGapReason.UnsupportedType,+ fileType: FileType.Image,+ },+ ],+ 'canvas-1',+ );+ expect(gaps[0].autoSwitchTarget).toBeNull();+ });+});++describe('pickBySwitchFate', () => {+ const Options = {+ missingModel: 'missing',+ autoSwitch: 'auto',+ manualSwitch: 'manual',+ mixedSwitch: 'mixed',+ } as const;++ const unsupportedGap = (+ autoSwitchTarget: UploadFileParserGap['autoSwitchTarget'],+ ): UploadFileParserGap => ({+ name: 'f',+ reason: ParserGapReason.UnsupportedType,+ fileType: FileType.PDF,+ autoSwitchTarget,+ });++ const missingModelGap: UploadFileParserGap = {+ name: 'song.mp3',+ reason: ParserGapReason.MissingModel,+ fileType: FileType.Audio,+ modelKind: ParserModelKind.Asr,+ autoSwitchTarget: null,+ };++ it('picks the missing-model hint when nothing is unsupported', () => {+ expect(pickBySwitchFate([missingModelGap], Options)).toBe('missing');+ });++ it('picks the auto-switch hint only when every unsupported file switches', () => {+ expect(+ pickBySwitchFate(+ [unsupportedGap('picture'), unsupportedGap('email')],+ Options,+ ),+ ).toBe('auto');+ });++ it('picks the manual hint when no unsupported file switches', () => {+ expect(pickBySwitchFate([unsupportedGap(null)], Options)).toBe('manual');+ });++ it('picks the mixed hint when only some unsupported files switch', () => {+ expect(+ pickBySwitchFate(+ [unsupportedGap('picture'), unsupportedGap(null)],+ Options,+ ),+ ).toBe('mixed');+ // Missing-model gaps join the list without diluting the composition.+ expect(+ pickBySwitchFate([unsupportedGap(null), missingModelGap], Options),+ ).toBe('manual');+ });+});+describe('getSavedParserConfig', () => {it('returns null without a saved parser config', () => {expect(getSavedParserConfig(null)).toBeNull();diff --git a/web/src/pages/dataset/dataset/utils.ts b/web/src/pages/dataset/dataset/utils.tsindex bbb6c68604..25b6d84bd6 100644--- a/web/src/pages/dataset/dataset/utils.ts+++ b/web/src/pages/dataset/dataset/utils.ts@@ -167,6 +167,159 @@ export function pickByGapKind<T>(: options.missingModel;}+// --- Upload-time built-in parser switch ------------------------------------+// Mirrors the backend's document parser selection+// (internal/service/document/document_parser_selection.go): for a dataset+// without a custom pipeline, upload reseeds a document with the built-in+// pipeline owning its file type — visual (images and video) -> picture,+// aural -> audio, .ppt/.pptx/.pages -> presentation, .msg/.eml -> email —+// and keeps the dataset parser for everything else. A dataset on a custom+// pipeline never switches. The upload modal annotates each unsupported file+// with this fate so it never promises a switch that will not happen.++export type BuiltinSwitchTarget =+ | 'picture'+ | 'audio'+ | 'presentation'+ | 'email';++// Display labels match the dataset table's parse column, which renders the+// parser id capitalized.+export const BuiltinSwitchTargetLabels: Record<BuiltinSwitchTarget, string> = {+ picture: 'Picture',+ audio: 'Audio',+ presentation: 'Presentation',+ email: 'Email',+};++// Extension sets mirror utility.FilenameType (internal/utility/file.go); the+// visual bucket intentionally includes the video extensions.+const VisualSwitchSuffixes = new Set([+ 'jpg',+ 'jpeg',+ 'png',+ 'tif',+ 'gif',+ 'bmp',+ 'pcx',+ 'tga',+ 'exif',+ 'fpx',+ 'svg',+ 'psd',+ 'cdr',+ 'pcd',+ 'dxf',+ 'ufo',+ 'eps',+ 'ai',+ 'raw',+ 'wmf',+ 'webp',+ 'avif',+ 'apng',+ 'icon',+ 'ico',+ 'mpg',+ 'mpeg',+ 'avi',+ 'rm',+ 'rmvb',+ 'mov',+ 'wmv',+ 'asf',+ 'dat',+ 'asx',+ 'wvx',+ 'mpe',+ 'mpa',+ 'mp4',+ 'mkv',+]);++const AuralSwitchSuffixes = new Set([+ 'wav',+ 'flac',+ 'ape',+ 'alac',+ 'wv',+ 'mp3',+ 'aac',+ 'ogg',+ 'vorbis',+ 'opus',+]);++/**+ * The built-in pipeline the backend switches an uploaded file to, or null+ * when the file keeps the dataset parser. `pipelineId` is the dataset's+ * custom pipeline id: once set, the backend never switches.+ */+export function builtinParserSwitchTarget(+ name: string,+ pipelineId?: string | null,+): BuiltinSwitchTarget | null {+ if (pipelineId) {+ return null;+ }+ const suffix = getExtension(name);+ if (VisualSwitchSuffixes.has(suffix)) {+ return 'picture';+ }+ if (AuralSwitchSuffixes.has(suffix)) {+ return 'audio';+ }+ if (suffix === 'ppt' || suffix === 'pptx' || suffix === 'pages') {+ return 'presentation';+ }+ if (suffix === 'msg' || suffix === 'eml') {+ return 'email';+ }+ return null;+}++/** An upload-time gap annotated with the file's parser-switch fate. */+export type UploadFileParserGap = FileParserGap & {+ /** Built-in pipeline the file switches to, or null when it keeps the dataset parser. */+ autoSwitchTarget: BuiltinSwitchTarget | null;+};++export function attachAutoSwitchTargets(+ gaps: FileParserGap[],+ pipelineId?: string | null,+): UploadFileParserGap[] {+ return gaps.map((gap) => ({+ ...gap,+ autoSwitchTarget:+ gap.reason === ParserGapReason.UnsupportedType+ ? builtinParserSwitchTarget(gap.name, pipelineId)+ : null,+ }));+}++// Upload modal copy keyed by switch fate: only when every unsupported file+// will switch can the modal promise an automatic switch; when none will,+// the files keep a parser that cannot parse them and the user must reselect+// one after upload.+export function pickBySwitchFate<T>(+ gaps: UploadFileParserGap[],+ options: { missingModel: T; autoSwitch: T; manualSwitch: T; mixedSwitch: T },+): T {+ const unsupported = gaps.filter(+ (gap) => gap.reason === ParserGapReason.UnsupportedType,+ );+ if (unsupported.length === 0) {+ return options.missingModel;+ }+ const switchable = unsupported.filter((gap) => gap.autoSwitchTarget !== null);+ if (switchable.length === 0) {+ return options.manualSwitch;+ }+ return switchable.length === unsupported.length+ ? options.autoSwitch+ : options.mixedSwitch;+}+type ParserSetup = Record<string, any> & { fileFormat?: string };/**