perf(chunker): thread DocProfile through splitter dispatch
Strategy.Split / SplitWithDiagnostics already run ProfileDocument once when the auto strategy resolves the chain. splitByHeadingsImpl was rerunning the same O(N) pass on entry, so every auto-mode call paid 2x scan cost; SplitParentChild paid 2x per parent. Pass the profile down through runTier and let splitters compute their own only when called outside the auto path (where profile == nil).
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
func TestSplitByHeuristics_FormFeedBoundary(t *testing.T) {
|
||||
doc := strings.Repeat("page one body text. ", 30) + "\f" + strings.Repeat("page two body. ", 30)
|
||||
cfg := SplitterConfig{ChunkSize: 400, ChunkOverlap: 20, Separators: []string{". "}}
|
||||
chunks := splitByHeuristicsImpl(doc, cfg)
|
||||
chunks := splitByHeuristicsImpl(doc, cfg, nil)
|
||||
if len(chunks) < 2 {
|
||||
t.Fatalf("form feed should produce ≥2 chunks, got %d", len(chunks))
|
||||
}
|
||||
@@ -18,7 +18,7 @@ func TestSplitByHeuristics_NumberedSections(t *testing.T) {
|
||||
body := strings.Repeat("body sentence. ", 8)
|
||||
doc := "1. Introduction\n" + body + "\n\n2. Methods\n" + body + "\n\n3. Results\n" + body
|
||||
cfg := SplitterConfig{ChunkSize: 200, ChunkOverlap: 20, Separators: []string{". "}}
|
||||
chunks := splitByHeuristicsImpl(doc, cfg)
|
||||
chunks := splitByHeuristicsImpl(doc, cfg, nil)
|
||||
if len(chunks) < 2 {
|
||||
t.Fatalf("numbered sections should split: got %d chunks", len(chunks))
|
||||
}
|
||||
@@ -28,7 +28,7 @@ func TestSplitByHeuristics_GermanChapterMarkers(t *testing.T) {
|
||||
body := strings.Repeat("Beispieltext. ", 10)
|
||||
doc := "Kapitel 1: Einführung\n" + body + "\n\nKapitel 2: Hauptteil\n" + body
|
||||
cfg := SplitterConfig{ChunkSize: 200, ChunkOverlap: 20, Separators: []string{". "}}
|
||||
chunks := splitByHeuristicsImpl(doc, cfg)
|
||||
chunks := splitByHeuristicsImpl(doc, cfg, nil)
|
||||
if len(chunks) < 2 {
|
||||
t.Fatalf("German chapter markers should split: got %d", len(chunks))
|
||||
}
|
||||
@@ -38,7 +38,7 @@ func TestSplitByHeuristics_ChineseChapterMarkers(t *testing.T) {
|
||||
body := strings.Repeat("内容内容内容。", 60)
|
||||
doc := "第一章 引言\n" + body + "\n\n第二章 方法\n" + body
|
||||
cfg := SplitterConfig{ChunkSize: 200, ChunkOverlap: 20, Separators: []string{"。"}, Languages: []string{LangChinese}}
|
||||
chunks := splitByHeuristicsImpl(doc, cfg)
|
||||
chunks := splitByHeuristicsImpl(doc, cfg, nil)
|
||||
if len(chunks) < 2 {
|
||||
t.Fatalf("Chinese chapter markers should split: got %d", len(chunks))
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func TestSplitByHeuristics_ChineseChapterMarkers(t *testing.T) {
|
||||
func TestSplitByHeuristics_FallsThroughForUnstructuredDoc(t *testing.T) {
|
||||
doc := strings.Repeat("plain prose without structure. ", 5)
|
||||
cfg := SplitterConfig{ChunkSize: 1000, ChunkOverlap: 20}
|
||||
chunks := splitByHeuristicsImpl(doc, cfg)
|
||||
chunks := splitByHeuristicsImpl(doc, cfg, nil)
|
||||
if len(chunks) != 1 {
|
||||
t.Errorf("unstructured short doc should be one chunk, got %d", len(chunks))
|
||||
}
|
||||
@@ -57,7 +57,7 @@ func TestSplitByHeuristics_OversizeBlockRecursesIntoLegacy(t *testing.T) {
|
||||
huge := strings.Repeat("This is a long sentence. ", 200) // ~5000 chars
|
||||
doc := "1. Intro\n" + huge
|
||||
cfg := SplitterConfig{ChunkSize: 500, ChunkOverlap: 50, Separators: []string{". "}}
|
||||
chunks := splitByHeuristicsImpl(doc, cfg)
|
||||
chunks := splitByHeuristicsImpl(doc, cfg, nil)
|
||||
if len(chunks) < 5 {
|
||||
t.Errorf("oversize block should produce many sub-chunks, got %d", len(chunks))
|
||||
}
|
||||
@@ -83,7 +83,7 @@ func TestSplitByHeuristics_BoundariesAreOrdered(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSplitByHeuristics_EmptyText(t *testing.T) {
|
||||
if got := splitByHeuristicsImpl("", DefaultConfig()); got != nil {
|
||||
if got := splitByHeuristicsImpl("", DefaultConfig(), nil); got != nil {
|
||||
t.Errorf("empty doc should be nil, got %v", got)
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func TestSplitByHeuristics_OverlapActuallyOverlaps(t *testing.T) {
|
||||
doc := sb.String()
|
||||
|
||||
cfg := SplitterConfig{ChunkSize: 200, ChunkOverlap: 80, Separators: []string{". "}}
|
||||
chunks := splitByHeuristicsImpl(doc, cfg)
|
||||
chunks := splitByHeuristicsImpl(doc, cfg, nil)
|
||||
if len(chunks) < 2 {
|
||||
t.Fatalf("need >=2 chunks to test overlap, got %d", len(chunks))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user