diff --git a/internal/application/service/chat_pipeline/merge.go b/internal/application/service/chat_pipeline/merge.go index 82a6506d..f1529deb 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), })