Skip to content

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

The retrieval component needs to support returning JSON data(#10170) (#10171)

Wilmerc8b79dfed46c
diff --git a/agent/tools/retrieval.py b/agent/tools/retrieval.py
index a6e1e4fcd1..156469811e 100644
--- a/agent/tools/retrieval.py
+++ b/agent/tools/retrieval.py
@@ -163,9 +163,16 @@ class Retrieval(ToolBase, ABC):
self.set_output("formalized_content", self._param.empty_response)
return
+ # Format the chunks for JSON output (similar to how other tools do it)
+ json_output = kbinfos["chunks"].copy()
+
self._canvas.add_reference(kbinfos["chunks"], kbinfos["doc_aggs"])
form_cnt = "\n".join(kb_prompt(kbinfos, 200000, True))
+
+ # Set both formalized content and JSON output
self.set_output("formalized_content", form_cnt)
+ self.set_output("json", json_output)
+
return form_cnt
def thoughts(self) -> str:
diff --git a/web/src/pages/agent/constant.tsx b/web/src/pages/agent/constant.tsx
index ef7aed18ae..5abad0a03a 100644
--- a/web/src/pages/agent/constant.tsx
+++ b/web/src/pages/agent/constant.tsx
@@ -263,6 +263,10 @@ export const initialRetrievalValues = {
type: 'string',
value: '',
},
+ json: {
+ type: 'Array<Object>',
+ value: [],
+ },
},
};
diff --git a/web/src/pages/agent/form/retrieval-form/next.tsx b/web/src/pages/agent/form/retrieval-form/next.tsx
index 425d08e4b3..69204d4da5 100644
--- a/web/src/pages/agent/form/retrieval-form/next.tsx
+++ b/web/src/pages/agent/form/retrieval-form/next.tsx
@@ -83,6 +83,10 @@ function RetrievalForm({ node }: INextOperatorForm) {
title: 'formalized_content',
type: initialRetrievalValues.outputs.formalized_content.type,
},
+ {
+ title: 'json',
+ type: initialRetrievalValues.outputs.json.type,
+ },
];
}, []);
diff --git a/web/src/pages/data-flow/constant.tsx b/web/src/pages/data-flow/constant.tsx
index d1d124f488..85967bb67d 100644
--- a/web/src/pages/data-flow/constant.tsx
+++ b/web/src/pages/data-flow/constant.tsx
@@ -133,6 +133,10 @@ export const initialRetrievalValues = {
type: 'string',
value: '',
},
+ json: {
+ type: 'Array<Object>',
+ value: [],
+ },
},
};
diff --git a/web/src/pages/data-flow/form/retrieval-form/next.tsx b/web/src/pages/data-flow/form/retrieval-form/next.tsx
index 425d08e4b3..69204d4da5 100644
--- a/web/src/pages/data-flow/form/retrieval-form/next.tsx
+++ b/web/src/pages/data-flow/form/retrieval-form/next.tsx
@@ -83,6 +83,10 @@ function RetrievalForm({ node }: INextOperatorForm) {
title: 'formalized_content',
type: initialRetrievalValues.outputs.formalized_content.type,
},
+ {
+ title: 'json',
+ type: initialRetrievalValues.outputs.json.type,
+ },
];
}, []);