Skip to content

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

Fix: It is not possible to select dataset metadata values ​​for the condition in the retrieval operator. (#20280)

balibabu7a750fa86364
diff --git a/web/src/components/metadata-filter/agent-metadata-filter-conditions.tsx b/web/src/components/metadata-filter/agent-metadata-filter-conditions.tsx
new file mode 100644
index 0000000000..b97d1254c3
--- /dev/null
+++ b/web/src/components/metadata-filter/agent-metadata-filter-conditions.tsx
@@ -0,0 +1,46 @@
+/*
+ * 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 { useBuildQueryVariableOptions } from '@/pages/agent/hooks/use-get-begin-query';
+import { useMemo } from 'react';
+import { MetadataFilterConditions } from './metadata-filter-conditions';
+import { flattenVariableOptions } from './utils';
+
+// Agent-only variant of the manual metadata conditions: besides the candidate
+// values from the knowledge base summary, the value field also offers the
+// upstream canvas variables as options. Kept out of the shared component so
+// non-agent pages never mount the agent query hooks.
+export function AgentMetadataFilterConditions({
+ kbIds,
+ prefix = '',
+}: {
+ kbIds: string[];
+ prefix?: string;
+}) {
+ const variableOptionGroups = useBuildQueryVariableOptions();
+ const variableOptions = useMemo(
+ () => flattenVariableOptions(variableOptionGroups),
+ [variableOptionGroups],
+ );
+
+ return (
+ <MetadataFilterConditions
+ kbIds={kbIds}
+ prefix={prefix}
+ variableOptions={variableOptions}
+ />
+ );
+}
diff --git a/web/src/components/metadata-filter/index.tsx b/web/src/components/metadata-filter/index.tsx
index bdc15f1f46..b081a296c1 100644
--- a/web/src/components/metadata-filter/index.tsx
+++ b/web/src/components/metadata-filter/index.tsx
@@ -20,6 +20,7 @@ import { useFormContext, useWatch } from 'react-hook-form';
import { z } from 'zod';
import { SelectWithSearch } from '../originui/select-with-search';
import { RAGFlowFormItem } from '../ragflow-form';
+import { AgentMetadataFilterConditions } from './agent-metadata-filter-conditions';
import { MetadataFilterConditions } from './metadata-filter-conditions';
import { MetadataSemiAutoFields } from './metadata-semi-auto-fields';
@@ -91,6 +92,10 @@ export function MetadataFilter({
};
});
+ const Conditions = canReference
+ ? AgentMetadataFilterConditions
+ : MetadataFilterConditions;
+
return (
<>
{hasKnowledge && (
@@ -106,11 +111,7 @@ export function MetadataFilter({
</RAGFlowFormItem>
)}
{hasKnowledge && metadata === DatasetMetadata.Manual && (
- <MetadataFilterConditions
- kbIds={kbIds}
- prefix={prefix}
- canReference={canReference}
- ></MetadataFilterConditions>
+ <Conditions kbIds={kbIds} prefix={prefix}></Conditions>
)}
{hasKnowledge && metadata === DatasetMetadata.SemiAutomatic && (
<MetadataSemiAutoFields
diff --git a/web/src/components/metadata-filter/metadata-filter-conditions.test.tsx b/web/src/components/metadata-filter/metadata-filter-conditions.test.tsx
index e127f1147f..e44ca10b07 100644
--- a/web/src/components/metadata-filter/metadata-filter-conditions.test.tsx
+++ b/web/src/components/metadata-filter/metadata-filter-conditions.test.tsx
@@ -13,10 +13,6 @@ jest.mock('@/hooks/use-knowledge-request', () => ({
useFetchKnowledgeMetadata: jest.fn(),
}));
-jest.mock('@/pages/agent/form/components/prompt-editor', () => ({
- PromptEditor: () => null,
-}));
-
jest.mock('react-i18next', () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));
diff --git a/web/src/components/metadata-filter/metadata-filter-conditions.tsx b/web/src/components/metadata-filter/metadata-filter-conditions.tsx
index 1233b26933..edd598152c 100644
--- a/web/src/components/metadata-filter/metadata-filter-conditions.tsx
+++ b/web/src/components/metadata-filter/metadata-filter-conditions.tsx
@@ -34,7 +34,6 @@ import { SwitchLogicOperator, SwitchOperatorOptions } from '@/constants/agent';
import { useBuildSwitchOperatorOptions } from '@/hooks/logic-hooks/use-build-operator-options';
import { useFetchKnowledgeMetadata } from '@/hooks/use-knowledge-request';
import { cn } from '@/lib/utils';
-import { PromptEditor } from '@/pages/agent/form/components/prompt-editor';
import { Plus, X } from 'lucide-react';
import { useCallback, useMemo } from 'react';
import { useFieldArray, useFormContext, useWatch } from 'react-hook-form';
@@ -42,7 +41,7 @@ import { useTranslation } from 'react-i18next';
import { LogicalOperator } from '../logical-operator';
import { SelectWithSearch } from '../originui/select-with-search';
import { Card, CardContent } from '../ui/card';
-import { InputSelect } from '../ui/input-select';
+import { InputSelect, InputSelectOption } from '../ui/input-select';
type ConditionCardsProps = {
fieldName: string;
@@ -51,7 +50,7 @@ type ConditionCardsProps = {
remove: (index: number) => void;
switchOperatorOptions: ReturnType<typeof useBuildSwitchOperatorOptions>;
metadata: ReturnType<typeof useFetchKnowledgeMetadata>;
- canReference?: boolean;
+ variableOptions: InputSelectOption[];
};
function ConditionCards({
@@ -61,22 +60,25 @@ function ConditionCards({
remove,
switchOperatorOptions,
metadata,
- canReference,
+ variableOptions,
}: ConditionCardsProps) {
const { t } = useTranslation();
const form = useFormContext();
const op = useWatch({ name: `${name}.${index}.op` });
const key = useWatch({ name: fieldName });
const valueOptions = useMemo(() => {
- if (!key || !metadata?.data || !metadata?.data[key]) return [];
- if (typeof metadata?.data[key] === 'object') {
- return Object.keys(metadata?.data[key]).map((item: string) => ({
- value: item,
- label: item,
- }));
- }
- return [];
- }, [key, metadata?.data]);
+ const candidateOptions =
+ !key ||
+ !metadata?.data ||
+ !metadata.data[key] ||
+ typeof metadata.data[key] !== 'object'
+ ? []
+ : Object.keys(metadata.data[key]).map((item: string) => ({
+ value: item,
+ label: item,
+ }));
+ return [...candidateOptions, ...variableOptions];
+ }, [key, metadata?.data, variableOptions]);
const handleChangeOp = useCallback(
(value: string) => {
@@ -148,21 +150,13 @@ function ConditionCards({
return (
<FormItem>
<FormControl>
- {canReference ? (
- <PromptEditor
- {...valueField}
- multiLine={false}
- showToolbar={false}
- ></PromptEditor>
- ) : (
- <InputSelect
- placeholder={t('common.pleaseInput')}
- {...valueField}
- options={valueOptions}
- className="w-full"
- multi={op === 'in' || op === 'not in'}
- />
- )}
+ <InputSelect
+ placeholder={t('common.pleaseInput')}
+ {...valueField}
+ options={valueOptions}
+ className="w-full"
+ multi={op === 'in' || op === 'not in'}
+ />
</FormControl>
<FormMessage />
</FormItem>
@@ -181,11 +175,11 @@ function ConditionCards({
export function MetadataFilterConditions({
kbIds,
prefix = '',
- canReference,
+ variableOptions = [],
}: {
kbIds: string[];
prefix?: string;
- canReference?: boolean;
+ variableOptions?: InputSelectOption[];
}) {
const { t } = useTranslation();
const form = useFormContext();
@@ -249,7 +243,7 @@ export function MetadataFilterConditions({
remove={remove}
switchOperatorOptions={switchOperatorOptions}
metadata={metadata}
- canReference={canReference}
+ variableOptions={variableOptions}
/>
);
})}
diff --git a/web/src/components/metadata-filter/utils.test.ts b/web/src/components/metadata-filter/utils.test.ts
new file mode 100644
index 0000000000..65753e1f66
--- /dev/null
+++ b/web/src/components/metadata-filter/utils.test.ts
@@ -0,0 +1,54 @@
+import { flattenVariableOptions } from './utils';
+
+describe('flattenVariableOptions', () => {
+ it('flattens groups and wraps leaf values as `{...}` reference text', () => {
+ expect(
+ flattenVariableOptions([
+ {
+ title: 'Retrieval',
+ options: [
+ { label: 'content', value: 'retrieval_0@content' },
+ { label: 'json', value: 'retrieval_0@json' },
+ ],
+ },
+ ]),
+ ).toEqual([
+ { value: '{retrieval_0@content}', label: 'Retrieval / content' },
+ { value: '{retrieval_0@json}', label: 'Retrieval / json' },
+ ]);
+ });
+
+ it('falls back to the bare leaf label when the group title is not a string', () => {
+ expect(
+ flattenVariableOptions([
+ {
+ title: { toString: () => 'ignored' } as never,
+ options: [{ label: 'userid', value: 'begin@userid' }],
+ },
+ ]),
+ ).toEqual([{ value: '{begin@userid}', label: 'userid' }]);
+ });
+
+ it('falls back to the raw value when the leaf label is not a string', () => {
+ expect(
+ flattenVariableOptions([
+ {
+ title: 'Begin input',
+ options: [{ label: { nested: true } as never, value: 'sys.files' }],
+ },
+ ]),
+ ).toEqual([{ value: '{sys.files}', label: 'Begin input / sys.files' }]);
+ });
+
+ it('skips groups without options and leaves without a value', () => {
+ expect(
+ flattenVariableOptions([
+ { title: 'Empty' },
+ {
+ title: 'Retrieval',
+ options: [{ label: 'ghost' }, { label: 'json', value: 'a@json' }],
+ },
+ ]),
+ ).toEqual([{ value: '{a@json}', label: 'Retrieval / json' }]);
+ });
+});
diff --git a/web/src/components/metadata-filter/utils.ts b/web/src/components/metadata-filter/utils.ts
new file mode 100644
index 0000000000..293e4a1503
--- /dev/null
+++ b/web/src/components/metadata-filter/utils.ts
@@ -0,0 +1,44 @@
+/*
+ * 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 type { ReactNode } from 'react';
+import type { InputSelectOption } from '../ui/input-select';
+
+export type VariableOptionGroup = {
+ title?: ReactNode;
+ options?: { label?: ReactNode; value?: string }[];
+};
+
+// Query variable options arrive grouped by upstream node; flatten them into
+// InputSelect options whose value is the `{...}` reference text the agent
+// runtime resolves when the retrieval tool runs.
+export function flattenVariableOptions(
+ groups: VariableOptionGroup[],
+): InputSelectOption[] {
+ return groups.flatMap((group) => {
+ const groupTitle = typeof group.title === 'string' ? group.title : '';
+ return (group.options ?? [])
+ .filter((leaf) => !!leaf.value)
+ .map((leaf) => {
+ const value = leaf.value as string;
+ const leafLabel = typeof leaf.label === 'string' ? leaf.label : value;
+ return {
+ value: `{${value}}`,
+ label: groupTitle ? `${groupTitle} / ${leafLabel}` : leafLabel,
+ };
+ });
+ });
+}