Skip to content

Commit 9bb776a

Browse files
committed
feat(chat): refine parent-child chunk replacement logic in merge process
- Enhanced the logic for replacing child content with parent content to only apply to text chunks whose parent is a parent_text chunk. - Added checks to skip non-text chunks and ensure that only appropriate parent chunks are used for replacement, improving content quality and integrity.
1 parent 4ea58bc commit 9bb776a

File tree

1 file changed

+17
-1
lines changed
  • internal/application/service/chat_pipeline

1 file changed

+17
-1
lines changed

internal/application/service/chat_pipeline/merge.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,31 @@ func (p *PluginMerge) resolveParentChunks(
265265
// within their own range, but the parent content spans all children.
266266
parentImageInfoMap := p.collectParentImageInfo(ctx, tenantID, ids)
267267

268-
// Replace child content with parent content
268+
// Replace child content with parent content.
269+
// Only replace for text chunks whose parent is a parent_text chunk
270+
// (i.e., the parent-child chunking strategy). Summary chunks also carry
271+
// a ParentChunkID that points to their source chunk, but that is a
272+
// different semantic — replacing summary content with its source would
273+
// degrade quality.
269274
for _, r := range results {
270275
if r.ParentChunkID == "" {
271276
continue
272277
}
278+
// Skip non-text chunks (e.g., summary, image_caption) — their
279+
// ParentChunkID has a different meaning than the parent-child
280+
// chunking strategy.
281+
if r.ChunkType != string(types.ChunkTypeText) {
282+
continue
283+
}
273284
parent, ok := parentMap[r.ParentChunkID]
274285
if !ok || parent.Content == "" {
275286
continue
276287
}
288+
// Only replace if the parent is actually a parent_text chunk from
289+
// the parent-child chunking strategy.
290+
if parent.ChunkType != types.ChunkTypeParentText {
291+
continue
292+
}
277293
pipelineInfo(ctx, "Merge", "parent_resolve", map[string]interface{}{
278294
"child_id": r.ID,
279295
"parent_id": r.ParentChunkID,

0 commit comments

Comments
 (0)