Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
refactor(chunk): improve parent-child chunk relationship handling in SplitTextParentChild
wizardchen92b6b7507d74
diff --git a/internal/infrastructure/chunker/splitter.go b/internal/infrastructure/chunker/splitter.goindex a634f2c9b..d110e22d9 100644--- a/internal/infrastructure/chunker/splitter.go+++ b/internal/infrastructure/chunker/splitter.go@@ -519,10 +519,18 @@ func SplitTextParentChild(text string, parentCfg, childCfg SplitterConfig) Parenreturn ParentChildResult{}}+ var newParents []Chunkvar children []ChildChunkchildSeq := 0- for pi, parent := range parents {+ for _, parent := range parents {subs := SplitText(parent.Content, childCfg)++ parentIndex := -1+ if len(subs) > 1 || (len(subs) == 1 && subs[0].Content != parent.Content) {+ parentIndex = len(newParents)+ newParents = append(newParents, parent)+ }+for _, sub := range subs {// Adjust offsets: sub positions are relative to parent content,// shift to document-level offsets.@@ -533,12 +541,12 @@ func SplitTextParentChild(text string, parentCfg, childCfg SplitterConfig) Parensub.End += parent.Startchildren = append(children, ChildChunk{Chunk: sub,- ParentIndex: pi,+ ParentIndex: parentIndex,})childSeq++}}- return ParentChildResult{Parents: parents, Children: children}+ return ParentChildResult{Parents: newParents, Children: children}}// ExtractImageRefs extracts markdown image references from text.