feat(chunker): recursive priority splitting + token-aware budget
The Go splitter previously combined all separators into one regex, losing the priority-based recursive behavior of the Python reference. This pass walks the separator list in order: the first separator that yields >1 piece wins, mirroring docreader/splitter/splitter.py. Larger semantic boundaries (\n\n) now win over smaller ones (\n). Additional cross-cutting changes: - ChunkingConfig gains Strategy / TokenLimit / Languages fields so the per-KB config can pick a tier and pin embedding token budgets. - buildSplitterConfig in the knowledge service uses the new chunker.DefaultChunkSize / DefaultChunkOverlap constants (overlap consolidated to 80 ≈ 15%) instead of the previous hardcoded 50. - ensureDefaults clamps ChunkSize to a per-language character budget derived from TokenLimit so chunks stay safe under embedding model token caps. Chinese (~1.7 chars/tok) gets a tighter clamp than English (~4 chars/tok). https://claude.ai/code/session_01XADhx6mtu2ZYW3DE9Lun6k
This commit is contained in:
@@ -151,6 +151,17 @@ type ChunkingConfig struct {
|
||||
// ChildChunkSize is the size of child chunks used for embedding (default: 384).
|
||||
// Only used when EnableParentChild is true.
|
||||
ChildChunkSize int `yaml:"child_chunk_size,omitempty" json:"child_chunk_size,omitempty"`
|
||||
// Strategy selects the adaptive chunking tier. Empty / "legacy" preserves
|
||||
// the historical recursive splitter; "auto" lets a profiler pick between
|
||||
// heading-aware, heuristic and recursive tiers; "heading" / "heuristic" /
|
||||
// "recursive" pin the tier explicitly.
|
||||
Strategy string `yaml:"strategy,omitempty" json:"strategy,omitempty"`
|
||||
// TokenLimit caps chunk size in approximate tokens. 0 = use ChunkSize
|
||||
// as a character count.
|
||||
TokenLimit int `yaml:"token_limit,omitempty" json:"token_limit,omitempty"`
|
||||
// Languages hints the heuristic patterns. Empty = auto-detect from content.
|
||||
// Examples: ["de"], ["en", "zh"].
|
||||
Languages []string `yaml:"languages,omitempty" json:"languages,omitempty"`
|
||||
}
|
||||
|
||||
// ResolveParserEngine returns the engine name for the given file type
|
||||
|
||||
Reference in New Issue
Block a user