Skip to content

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

fix: Update answer concatenation logic to handle overlapping values (#12676)

Hwwwww-devb27dc26be3e9
diff --git a/web/src/hooks/logic-hooks.ts b/web/src/hooks/logic-hooks.ts
index 1f7909016b..25b2589ff6 100644
--- a/web/src/hooks/logic-hooks.ts
+++ b/web/src/hooks/logic-hooks.ts
@@ -274,8 +274,17 @@ export const useSendMessageWithSse = (
const val = JSON.parse(value?.data || '');
const d = val?.data;
if (typeof d !== 'boolean') {
+
setAnswer((prev) => {
- let newAnswer = (prev.answer || '') + (d.answer || '');
+ const prevAnswer = prev.answer || '';
+ const currentAnswer = d.answer || '';
+
+ let newAnswer: string;
+ if (prevAnswer && currentAnswer.startsWith(prevAnswer)) {
+ newAnswer = currentAnswer;
+ } else {
+ newAnswer = prevAnswer + currentAnswer;
+ }
if (d.start_to_think === true) {
newAnswer = newAnswer + '<think>';