fix(index): 修复父子模式遗漏无父节点正文索引

This commit is contained in:
姚章浩
2026-10-28 08:56:14 +08:00
parent c64a48647c
commit 23387779c1
3 changed files with 71 additions and 23 deletions
@@ -0,0 +1,27 @@
package service
import "github.com/Tencent/WeKnora/internal/types"
// processTextChunks selects indexing inputs without linking parent-child context
// as if it were a flat document.
func processTextChunks(chunks []*types.Chunk, hasParentChild bool) []*types.Chunk {
textChunks := make([]*types.Chunk, 0, len(chunks))
for _, chunk := range chunks {
// Parent-less text can coexist with parent-child output (for example
// table chunks). Persisting it without indexing silently loses recall.
if chunk.ChunkType == types.ChunkTypeText {
textChunks = append(textChunks, chunk)
}
}
if !hasParentChild {
for i, chunk := range textChunks {
if i > 0 {
textChunks[i-1].NextChunkID = chunk.ID
}
if i < len(textChunks)-1 {
textChunks[i+1].PreChunkID = chunk.ID
}
}
}
return textChunks
}