fix(pipeline): deterministic merge output ordering

Sort mergedChunks after groupAndMergeOverlapping concatenates results
from different merge units. The unit order depends on Go map iteration
in the grouping phase, which is non-deterministic.

Uses the same tie-breakers as filter_top_k.go to restore consistent
ordering at the merge source.
main
MidoriKurage 2026-07-26 14:41:21 +08:00 committed by lyingbug
parent dfb371154c
commit 3b476c07df
1 changed files with 4 additions and 0 deletions

View File

@ -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),
})