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,