Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix(pipeline): deterministic merge output ordering

MidoriKurage3b476c07dff8
diff --git a/internal/application/service/chat_pipeline/merge.go b/internal/application/service/chat_pipeline/merge.go
index 82a6506d3..f1529deb9 100644
--- a/internal/application/service/chat_pipeline/merge.go
+++ b/internal/application/service/chat_pipeline/merge.go
@@ -201,6 +201,10 @@ func (p *PluginMerge) groupAndMergeOverlapping(ctx context.Context, results []*t
mergedChunks = append(mergedChunks, g...)
}
+ // Global sort restores relevance order after map-based grouping.
+ // n is typically < 100, O(n log n) is negligible here.
+ sortSearchResultsDeterministically(mergedChunks)
+
pipelineInfo(ctx, "Merge", "output", map[string]interface{}{
"merged_total": len(mergedChunks),
})