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:
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
werrors "github.com/Tencent/WeKnora/internal/errors"
|
||||
"github.com/Tencent/WeKnora/internal/infrastructure/chunker"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -348,3 +349,32 @@ func TestMergeParserEngineOverrides(t *testing.T) {
|
||||
"k3": "v3",
|
||||
}, merged)
|
||||
}
|
||||
|
||||
func TestBuildParentChildConfigs_PropagatesStrategy(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
base := chunker.SplitterConfig{
|
||||
ChunkSize: 1000,
|
||||
ChunkOverlap: 100,
|
||||
Separators: []string{"\n\n", "\n"},
|
||||
Strategy: chunker.StrategyAuto,
|
||||
}
|
||||
cc := types.ChunkingConfig{
|
||||
EnableParentChild: true,
|
||||
ParentChunkSize: 4096,
|
||||
ChildChunkSize: 512,
|
||||
}
|
||||
|
||||
parent, child := buildParentChildConfigs(cc, base)
|
||||
|
||||
require.Equal(t, chunker.StrategyAuto, parent.Strategy,
|
||||
"parent splitting must honour the configured strategy; empty resolves to the legacy tier")
|
||||
require.Equal(t, chunker.StrategyAuto, child.Strategy,
|
||||
"child splitting must honour the configured strategy; empty resolves to the legacy tier")
|
||||
require.Equal(t, 4096, parent.ChunkSize)
|
||||
require.Equal(t, 512, child.ChunkSize)
|
||||
require.Equal(t, base.ChunkOverlap, parent.ChunkOverlap)
|
||||
require.Equal(t, 512/5, child.ChunkOverlap)
|
||||
require.Equal(t, base.Separators, parent.Separators)
|
||||
require.Equal(t, base.Separators, child.Separators)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user