refactor(chat_pipeline): enhance merging logic and add partial overlap removal

- Updated the merging process in the chat pipeline to include a new step for re-merging overlapping ranges introduced by context expansion.
- Implemented a new function, removePartialOverlaps, to eliminate chunks that are largely contained within higher-scored chunks, improving deduplication accuracy.
- Enhanced normalization and overlap checking utilities to support the new deduplication logic.
This commit is contained in:
wizardchen
2026-03-23 20:24:35 +08:00
committed by lyingbug
parent 15ebfe0b4c
commit 47397464ef
3 changed files with 148 additions and 2 deletions
@@ -39,7 +39,8 @@ func (p *PluginMerge) ActivationEvents() []types.EventType {
// 5. Group by knowledge source + chunk type, merge overlapping ranges
// 6. Populate FAQ answers
// 7. Expand short contexts with neighboring chunks
// 8. Final deduplication (catches duplicates introduced by steps 4-7)
// 7.5. Re-merge overlapping ranges introduced by expansion
// 8. Final deduplication (ID + signature + partial content overlap)
func (p *PluginMerge) OnEvent(ctx context.Context,
eventType types.EventType, chatManage *types.ChatManage, next func() *PluginError,
) *PluginError {
@@ -84,8 +85,12 @@ func (p *PluginMerge) OnEvent(ctx context.Context,
// Step 7: Expand short contexts
mergedChunks = p.expandShortContextWithNeighbors(ctx, chatManage, mergedChunks)
// Step 8: Final dedup (catches duplicates from parent resolution / expansion)
// Step 7.5: Re-merge overlapping ranges introduced by expansion
mergedChunks = p.groupAndMergeOverlapping(ctx, mergedChunks)
// Step 8: Final dedup — catches exact duplicates plus partial content overlaps
mergedChunks = p.dedup(ctx, "final_dedup", mergedChunks)
mergedChunks = removePartialOverlaps(ctx, mergedChunks)
chatManage.MergeResult = mergedChunks
return next()