fix(knowledge): propagate chunking strategy to parent-child splitter configs
buildParentChildConfigs only copied ChunkSize/ChunkOverlap/Separators into the parent and child SplitterConfigs, dropping base.Strategy. Since an empty Strategy resolves to the legacy tier (resolveChainWithProfile treats "" as legacy for backwards compatibility), parent-child chunking always ran the legacy recursive splitter regardless of the configured strategy: no heading alignment and no ContextHeader breadcrumbs in child embeddings, silently. The flat path (buildSplitterConfigFromChunking) already propagates Strategy; parent-child predates the strategy system (b3334990, 2026-03) and was not updated when the 3-tier strategy landed (ae6fde23, 2026-05). SplitParentChild's docstring ("Child splitting honours childCfg.Strategy") and mergeBreadcrumbs both assume the strategy reaches the parent-child path. Copy base.Strategy into both configs and add a regression test.
This commit is contained in:
@@ -226,7 +226,11 @@ func buildSplitterConfigFromChunking(cc types.ChunkingConfig) chunker.SplitterCo
|
||||
}
|
||||
|
||||
// buildParentChildConfigs derives parent and child SplitterConfig from ChunkingConfig.
|
||||
// The base config (already validated with defaults) is used for separators.
|
||||
// The base config (already validated with defaults) is used for separators and
|
||||
// the splitting strategy. Strategy must be propagated: an empty Strategy resolves
|
||||
// to the legacy tier (see resolveChainWithProfile), which never runs the heading
|
||||
// splitter, so parent-child chunks would silently lose heading alignment and
|
||||
// ContextHeader breadcrumbs regardless of the configured strategy.
|
||||
func buildParentChildConfigs(cc types.ChunkingConfig, base chunker.SplitterConfig) (parent, child chunker.SplitterConfig) {
|
||||
parentSize := cc.ParentChunkSize
|
||||
if parentSize <= 0 {
|
||||
@@ -240,11 +244,13 @@ func buildParentChildConfigs(cc types.ChunkingConfig, base chunker.SplitterConfi
|
||||
ChunkSize: parentSize,
|
||||
ChunkOverlap: base.ChunkOverlap, // reuse configured overlap for parents
|
||||
Separators: base.Separators,
|
||||
Strategy: base.Strategy,
|
||||
}
|
||||
child = chunker.SplitterConfig{
|
||||
ChunkSize: childSize,
|
||||
ChunkOverlap: childSize / 5, // ~20% overlap for child chunks
|
||||
Separators: base.Separators,
|
||||
Strategy: base.Strategy,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user