fix: add LOAD_HISTORY to rag_stream pipeline for independent history

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.
This commit is contained in:
lyingbug
2026-03-20 22:55:26 +00:00
committed by lyingbug
parent 03fda55261
commit 00ac14aabb
2 changed files with 14 additions and 1 deletions
@@ -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 {
+1
View File
@@ -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,