WeKnora/internal/infrastructure/chunker
wizardchen 7b9a831db3 fix(chunker): trim surrounding whitespace before embedding
Heuristic and recursive splitters preserve original byte positions in
Chunk.Content (the End-Start == RuneCountInString invariant is required
by document-reconstruction code paths), which means a chunk sliced at a
boundary often carries leading/trailing newlines from the boundary
itself. Feeding that whitespace into the embedding model dilutes the
vector and wastes tokens for no benefit.

TrimSpace the body inside EmbeddingContent for both chunker.Chunk and
the two types.Chunk / types.ParsedChunk mirrors. Inner whitespace is
preserved; positions/Content are unchanged.

Also clean up appendChunk: the previous code computed a trimmed string
for the empty-check then stored a separate untrimmed copy, which read
as if it might be intentionally divergent. Replace with an explicit
'raw text, skip if pure whitespace' shape and document the invariant.
2026-05-06 21:16:48 +08:00
..
header_tracker.go feat(chunker): implement header tracking for Markdown tables during chunking 2026-04-01 13:38:40 +08:00
heading_hierarchy.go feat(chunker): heading hierarchy tracker 2026-05-06 17:17:07 +08:00
heading_hierarchy_test.go feat(chunker): heading hierarchy tracker 2026-05-06 17:17:07 +08:00
heading_splitter.go perf(chunker): thread DocProfile through splitter dispatch 2026-05-06 21:16:48 +08:00
heading_splitter_test.go perf(chunker): thread DocProfile through splitter dispatch 2026-05-06 21:16:48 +08:00
heuristic_splitter.go fix(chunker): trim surrounding whitespace before embedding 2026-05-06 21:16:48 +08:00
heuristic_splitter_test.go fix(chunker): heuristic splitter drops boundaries inside protected spans 2026-05-06 21:16:48 +08:00
patterns.go feat(chunker): foundation for adaptive 3-tier chunking 2026-05-06 17:17:07 +08:00
patterns_test.go feat(chunker): foundation for adaptive 3-tier chunking 2026-05-06 17:17:07 +08:00
profiler.go refactor(chunker): drop redundant TierRecursive 2026-05-06 20:23:05 +08:00
profiler_test.go refactor(chunker): drop redundant TierRecursive 2026-05-06 20:23:05 +08:00
splitter.go fix(chunker): trim surrounding whitespace before embedding 2026-05-06 21:16:48 +08:00
splitter_test.go fix(chunker): QA audit — position invariant, recursive split, perf 2026-05-06 17:17:07 +08:00
strategy.go perf(chunker): thread DocProfile through splitter dispatch 2026-05-06 21:16:48 +08:00
strategy_diagnostics_test.go fix(chunker): post-review fixes for preview endpoint robustness 2026-05-06 17:17:07 +08:00
strategy_test.go fix(chunker): QA audit — position invariant, recursive split, perf 2026-05-06 17:17:07 +08:00
strategy_token_test.go feat(chunker): recursive priority splitting + token-aware budget 2026-05-06 17:17:07 +08:00
tokens.go fix(chunker): post-review fixes for preview endpoint robustness 2026-05-06 17:17:07 +08:00
tokens_test.go feat(chunker): foundation for adaptive 3-tier chunking 2026-05-06 17:17:07 +08:00
validator.go feat(chunker): foundation for adaptive 3-tier chunking 2026-05-06 17:17:07 +08:00