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: Restrict the parser operator so that it can only be followed by a chunker, and a chunker cannot be followed by another chunker. (#19833)
balibabufaa0d8ca0de0
diff --git a/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsx b/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsxindex 813d5e3078..4660bbb4f4 100644--- a/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsx+++ b/web/src/pages/agent/canvas/node/dropdown/accordion-operators.tsx@@ -5,9 +5,12 @@ import {AccordionTrigger,} from '@/components/ui/accordion';import { Operator } from '@/constants/agent';-import useGraphStore from '@/pages/agent/store';+import { useIsGoBackend } from '@/utils/backend-variant';import { PropsWithChildren, useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';+import { ChunkerOperators } from '../../../constant/pipeline';+import useGraphStore from '../../../store';+import { isChunkerOperator } from '../../../utils/pipeline-connection';import { OperatorItemList } from './operator-item-list';function OperatorAccordionTrigger({ children }: PropsWithChildren) {@@ -171,34 +174,41 @@ export function PipelineAccordionOperators({}) {const restrictSingleOperatorOnCanvas = useRestrictSingleOperatorOnCanvas();const { getOperatorTypeFromId } = useGraphStore((state) => state);+ const isGoBackend = useIsGoBackend();+ const sourceOperator = getOperatorTypeFromId(nodeId);++ // Go pipelines require a Parser to feed a chunker, so from a Parser node+ // the menu offers only the chunker group.+ const parserMustFeedChunker =+ isGoBackend && sourceOperator === Operator.Parser;const operators = useMemo(() => {+ if (parserMustFeedChunker) {+ return [];+ }const list = [...restrictSingleOperatorOnCanvas([Operator.Parser, Operator.Tokenizer]),];list.push(Operator.Extractor);- if (getOperatorTypeFromId(nodeId) !== Operator.Compiler) {+ if (sourceOperator !== Operator.Compiler) {list.push(Operator.Compiler);}return list;- }, [getOperatorTypeFromId, nodeId, restrictSingleOperatorOnCanvas]);+ }, [parserMustFeedChunker, sourceOperator, restrictSingleOperatorOnCanvas]);const chunkerOperators = useMemo(() => {- return [- ...restrictSingleOperatorOnCanvas([- Operator.TokenChunker,- Operator.TitleChunker,- ]),- ];+ return [...restrictSingleOperatorOnCanvas(ChunkerOperators)];}, [restrictSingleOperatorOnCanvas]);const showChunker = useMemo(() => {- return (- getOperatorTypeFromId(nodeId) !== Operator.Extractor &&- getOperatorTypeFromId(nodeId) !== Operator.Compiler &&- chunkerOperators.length > 0- );- }, [chunkerOperators.length, getOperatorTypeFromId, nodeId]);+ // Go pipelines forbid chunker -> chunker, mirroring the existing rule+ // that Extractor/Compiler never offer the chunker group.+ const sourceExcluded =+ sourceOperator === Operator.Extractor ||+ sourceOperator === Operator.Compiler ||+ (isGoBackend && isChunkerOperator(sourceOperator as Operator));+ return !sourceExcluded && chunkerOperators.length > 0;+ }, [chunkerOperators.length, isGoBackend, sourceOperator]);return (<>diff --git a/web/src/pages/agent/constant/pipeline.tsx b/web/src/pages/agent/constant/pipeline.tsxindex 605b5b8440..815fcf033d 100644--- a/web/src/pages/agent/constant/pipeline.tsx+++ b/web/src/pages/agent/constant/pipeline.tsx@@ -434,6 +434,10 @@ export const initialCompilationValues = {export const NoDebugOperatorsList = [Operator.File];+// Chunker operators available on the Go pipeline canvas. GeneralChunker is a+// legacy Python operator and is deliberately excluded.+export const ChunkerOperators = [Operator.TokenChunker, Operator.TitleChunker];+export const SingleOperators = [Operator.Tokenizer,Operator.GeneralChunker,diff --git a/web/src/pages/agent/hooks.tsx b/web/src/pages/agent/hooks.tsxindex 86b491f402..a9fdcb2c4a 100644--- a/web/src/pages/agent/hooks.tsx+++ b/web/src/pages/agent/hooks.tsx@@ -3,12 +3,15 @@ import React, { useCallback, useEffect } from 'react';// import { shallow } from 'zustand/shallow';import { settledModelVariableMap } from '@/constants/knowledge';import { RAGFlowNodeType } from '@/interfaces/database/agent';+import { useIsGoBackend } from '@/utils/backend-variant';import { get, lowerFirst, omit } from 'lodash';import { UseFormReturn } from 'react-hook-form';import { useTranslation } from 'react-i18next';import { Operator, RestrictedUpstreamMap } from './constant';+import { useIsPipeline } from './hooks/use-is-pipeline';import useGraphStore, { RFState } from './store';import { buildCategorizeObjectFromList, replaceIdWithText } from './utils';+import { isValidGoPipelineConnection } from './utils/pipeline-connection';const selector = (state: RFState) => ({nodes: state.nodes,@@ -128,6 +131,9 @@ export const useHandleFormValuesChange = (export const useValidateConnection = () => {const { getOperatorTypeFromId, getParentIdById, edges, nodes } =useGraphStore((state) => state);+ const isGoBackend = useIsGoBackend();+ const isPipeline = useIsPipeline();+ const restrictPipelineTopology = isGoBackend && isPipeline;const isSameNodeChild = useCallback((connection: Connection | Edge) => {@@ -176,13 +182,25 @@ export const useValidateConnection = () => {const ret =!isSelfConnected &&RestrictedUpstreamMap[- getOperatorTypeFromId(connection.source) as Operator+ getOperatorTypeFromId(+ connection.source,+ ) as keyof typeof RestrictedUpstreamMap]?.every((x) => x !== getOperatorTypeFromId(connection.target)) &&isSameNodeChild(connection) &&- hasCanvasCycle(connection);+ hasCanvasCycle(connection) &&+ (!restrictPipelineTopology ||+ isValidGoPipelineConnection(+ getOperatorTypeFromId(connection.source) as Operator,+ getOperatorTypeFromId(connection.target) as Operator,+ ));return ret;},- [getOperatorTypeFromId, hasCanvasCycle, isSameNodeChild],+ [+ getOperatorTypeFromId,+ hasCanvasCycle,+ isSameNodeChild,+ restrictPipelineTopology,+ ],);return isValidConnection;diff --git a/web/src/pages/agent/utils/pipeline-connection.test.ts b/web/src/pages/agent/utils/pipeline-connection.test.tsnew file mode 100644index 0000000000..03c01f2434--- /dev/null+++ b/web/src/pages/agent/utils/pipeline-connection.test.ts@@ -0,0 +1,86 @@+import { Operator } from '@/constants/agent';+import {+ isChunkerOperator,+ isValidGoPipelineConnection,+} from './pipeline-connection';++describe('isChunkerOperator', () => {+ it('treats TokenChunker and TitleChunker as chunkers', () => {+ expect(isChunkerOperator(Operator.TokenChunker)).toBe(true);+ expect(isChunkerOperator(Operator.TitleChunker)).toBe(true);+ });++ it('excludes every other operator, including legacy GeneralChunker', () => {+ expect(isChunkerOperator(Operator.Parser)).toBe(false);+ expect(isChunkerOperator(Operator.GeneralChunker)).toBe(false);+ expect(isChunkerOperator(Operator.Tokenizer)).toBe(false);+ expect(isChunkerOperator(Operator.Extractor)).toBe(false);+ expect(isChunkerOperator(Operator.Compiler)).toBe(false);+ expect(isChunkerOperator(Operator.File)).toBe(false);+ });+});++describe('isValidGoPipelineConnection', () => {+ it('allows a Parser to feed a chunker', () => {+ expect(+ isValidGoPipelineConnection(Operator.Parser, Operator.TokenChunker),+ ).toBe(true);+ expect(+ isValidGoPipelineConnection(Operator.Parser, Operator.TitleChunker),+ ).toBe(true);+ });++ it('rejects a Parser feeding any non-chunker operator', () => {+ expect(+ isValidGoPipelineConnection(Operator.Parser, Operator.Tokenizer),+ ).toBe(false);+ expect(+ isValidGoPipelineConnection(Operator.Parser, Operator.Extractor),+ ).toBe(false);+ expect(+ isValidGoPipelineConnection(Operator.Parser, Operator.Compiler),+ ).toBe(false);+ expect(isValidGoPipelineConnection(Operator.Parser, Operator.Parser)).toBe(+ false,+ );+ expect(+ isValidGoPipelineConnection(Operator.Parser, Operator.GeneralChunker),+ ).toBe(false);+ });++ it('rejects a chunker feeding another chunker', () => {+ expect(+ isValidGoPipelineConnection(Operator.TokenChunker, Operator.TitleChunker),+ ).toBe(false);+ expect(+ isValidGoPipelineConnection(Operator.TitleChunker, Operator.TokenChunker),+ ).toBe(false);+ expect(+ isValidGoPipelineConnection(Operator.TokenChunker, Operator.TokenChunker),+ ).toBe(false);+ });++ it('allows a chunker to feed non-chunker operators', () => {+ expect(+ isValidGoPipelineConnection(Operator.TokenChunker, Operator.Tokenizer),+ ).toBe(true);+ expect(+ isValidGoPipelineConnection(Operator.TitleChunker, Operator.Extractor),+ ).toBe(true);+ expect(+ isValidGoPipelineConnection(Operator.TokenChunker, Operator.Compiler),+ ).toBe(true);+ });++ it('leaves unrelated pairs unrestricted', () => {+ expect(isValidGoPipelineConnection(Operator.File, Operator.Parser)).toBe(+ true,+ );+ expect(+ isValidGoPipelineConnection(Operator.Tokenizer, Operator.Extractor),+ ).toBe(true);+ expect(+ isValidGoPipelineConnection(Operator.Extractor, Operator.Compiler),+ ).toBe(true);+ });+});diff --git a/web/src/pages/agent/utils/pipeline-connection.ts b/web/src/pages/agent/utils/pipeline-connection.tsnew file mode 100644index 0000000000..0de4c838c5--- /dev/null+++ b/web/src/pages/agent/utils/pipeline-connection.ts@@ -0,0 +1,26 @@+import { Operator } from '@/constants/agent';+import { ChunkerOperators } from '../constant/pipeline';++export function isChunkerOperator(operator: Operator): boolean {+ return (ChunkerOperators as Operator[]).includes(operator);+}++/**+ * Go-backend pipeline topology rules, enforced when a connection is created:+ * a Parser may only feed a chunker, and a chunker may not feed another+ * chunker. All other source/target pairs are unrestricted. Pure function so+ * it can be unit-tested without mocking; callers gate on the backend through+ * `useIsGoBackend()`.+ */+export function isValidGoPipelineConnection(+ source: Operator,+ target: Operator,+): boolean {+ if (source === Operator.Parser) {+ return isChunkerOperator(target);+ }+ if (isChunkerOperator(source)) {+ return !isChunkerOperator(target);+ }+ return true;+}