From 00ac14aabbad0c35beb914a19b7575afdb5fccd3 Mon Sep 17 00:00:00 2001 From: lyingbug Date: Fri, 20 Mar 2026 22:55:26 +0000 Subject: [PATCH] fix: add LOAD_HISTORY to rag_stream pipeline for independent history MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, rag_stream relied entirely on the rewrite plugin's internal loadHistory() to load conversation history. This meant that when rewrite was disabled (enable_rewrite=false), RAG mode had NO conversation history at all — multi-turn conversations silently degraded to single-turn. Changes: 1. Add LOAD_HISTORY as the first step in rag_stream pipeline, ensuring history is always available regardless of rewrite config. 2. Make rewrite plugin reuse chatManage.History if already populated by the upstream LOAD_HISTORY step, avoiding duplicate DB queries. This brings rag_stream in line with chat_history_stream which already has LOAD_HISTORY as an independent step. --- .../application/service/chat_pipline/rewrite.go | 14 +++++++++++++- internal/types/chat_manage.go | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/application/service/chat_pipline/rewrite.go b/internal/application/service/chat_pipline/rewrite.go index 1f73c446..d8f4db8e 100644 --- a/internal/application/service/chat_pipline/rewrite.go +++ b/internal/application/service/chat_pipline/rewrite.go @@ -93,7 +93,19 @@ func (p *PluginRewrite) OnEvent(ctx context.Context, }) // --- Load and prepare conversation history --- - historyList := p.loadHistory(ctx, chatManage) + // If history was already loaded by a prior LOAD_HISTORY step, reuse it + // instead of fetching again. This allows rag_stream to work correctly + // even when rewrite is disabled. + var historyList []*types.History + if len(chatManage.History) > 0 { + historyList = chatManage.History + pipelineInfo(ctx, "Rewrite", "history_reused", map[string]interface{}{ + "session_id": chatManage.SessionID, + "rounds": len(historyList), + }) + } else { + historyList = p.loadHistory(ctx, chatManage) + } // Skip if there's nothing to do: no history to rewrite AND no images to analyse if len(historyList) == 0 && !hasImages { diff --git a/internal/types/chat_manage.go b/internal/types/chat_manage.go index 127e8fd7..e2a6a4b2 100644 --- a/internal/types/chat_manage.go +++ b/internal/types/chat_manage.go @@ -193,6 +193,7 @@ var Pipline = map[string][]EventType{ CHAT_COMPLETION, }, "rag_stream": { // Streaming Retrieval Augmented Generation + LOAD_HISTORY, // Load conversation history independently (works even when rewrite is disabled) REWRITE_QUERY, CHUNK_SEARCH_PARALLEL, // Parallel: CHUNK_SEARCH + ENTITY_SEARCH CHUNK_RERANK,