Skip to content

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

Fix: No need to validate data that is not in dataset format (#18871)

balibabu9b7cc2d1bc86
diff --git a/web/src/hooks/use-knowledge-request.ts b/web/src/hooks/use-knowledge-request.ts
index 3665d6a216..af15221dd0 100644
--- a/web/src/hooks/use-knowledge-request.ts
+++ b/web/src/hooks/use-knowledge-request.ts
@@ -17,6 +17,7 @@
import { useHandleFilterSubmit } from '@/components/list-filter-bar/use-handle-filter-submit';
import message from '@/components/ui/message';
import { useIsGoBackend } from '@/utils/backend-variant';
+import { isDatasetId } from '@/utils/dataset-util';
import { GenerateType, ParseType } from '@/constants/knowledge';
import { ResponsePostType, ResponseType } from '@/interfaces/database/base';
import {
@@ -1117,9 +1118,13 @@ export const useFetchKnowledgeList = (
* Fetch datasets by a set of IDs. Used to resolve already-selected datasets
* that are not present in the first page of the paginated list, e.g. to echo
* their names in a form field. For staleness checks see `useStaleDatasetIds`.
+ *
+ * Callers may pass values mixed with variable references (agent forms let
+ * users pick variables alongside datasets); those are not resolvable ids and
+ * are dropped before the request is built.
*/
export const useFetchDatasetsByIds = (ids: string[]) => {
- const sortedIds = useMemo(() => [...ids].sort(), [ids]);
+ const sortedIds = useMemo(() => ids.filter(isDatasetId).sort(), [ids]);
const { data, isFetching: loading } = useQuery<IDataset[]>({
queryKey: KnowledgeListKeys.byIds(sortedIds),
enabled: sortedIds.length > 0,
@@ -1144,7 +1149,13 @@ export const useFetchDatasetsByIds = (ids: string[]) => {
* until it settles; `settled` flips true once the lookup has finished.
*/
export const useStaleDatasetIds = (datasetIds?: string[]) => {
- const persistedIds = useMemo(() => datasetIds ?? [], [datasetIds]);
+ // Variable references (e.g. `sys.query`) never resolve to datasets, so
+ // exclude them up front instead of letting them fall out of the lookup
+ // below and get misreported as stale.
+ const persistedIds = useMemo(
+ () => (datasetIds ?? []).filter(isDatasetId),
+ [datasetIds],
+ );
const { data: datasets, loading } = useFetchDatasetsByIds(persistedIds);
const staleDatasetIds = useMemo(() => {
diff --git a/web/src/utils/dataset-util.ts b/web/src/utils/dataset-util.ts
index 881a0e7397..2ae2f42213 100644
--- a/web/src/utils/dataset-util.ts
+++ b/web/src/utils/dataset-util.ts
@@ -23,3 +23,13 @@ export function isKnowledgeGraphParser(parserId: DocumentParserType) {
export function isNaiveParser(parserId: DocumentParserType) {
return parserId === DocumentParserType.Naive;
}
+
+/**
+ * Dataset ids are 32-char hex strings (uuid with dashes stripped, on both
+ * the Python and Go backends). Anything else found in a `dataset_ids` list
+ * is a variable reference (e.g. `begin@x`, `sys.query`, `node@output`) that
+ * no dataset endpoint can resolve.
+ */
+export function isDatasetId(value: string) {
+ return /^[0-9a-f]{32}$/i.test(value);
+}
diff --git a/web/src/utils/tests/dataset-util.test.ts b/web/src/utils/tests/dataset-util.test.ts
new file mode 100644
index 0000000000..2932d74b29
--- /dev/null
+++ b/web/src/utils/tests/dataset-util.test.ts
@@ -0,0 +1,22 @@
+import { isDatasetId } from '../dataset-util';
+
+describe('isDatasetId', () => {
+ test('accepts 32-char hex ids from both backends', () => {
+ expect(isDatasetId('1b33f6e2922f11f182a6eb24e39177ff')).toBe(true);
+ expect(isDatasetId('1B33F6E2922F11F182A6EB24E39177FF')).toBe(true);
+ });
+
+ test('rejects variable references mixed into dataset_ids', () => {
+ expect(isDatasetId('sys.query')).toBe(false);
+ expect(isDatasetId('env.vvvv')).toBe(false);
+ expect(isDatasetId('begin@file')).toBe(false);
+ expect(isDatasetId('Retrieval:abc@content')).toBe(false);
+ });
+
+ test('rejects other non-id values', () => {
+ expect(isDatasetId('')).toBe(false);
+ expect(isDatasetId('timeline002')).toBe(false);
+ expect(isDatasetId('1b33f6e2-922f-11f1-82a6-eb24e39177ff')).toBe(false);
+ expect(isDatasetId('1b33f6e2922f11f182a6eb24e39177f')).toBe(false);
+ });
+});