Commit 5d735bb
committed
Do not count whitespace runs as words in RecursiveDocumentSplitter fallback
The word-mode fixed-size fallback split words with re.findall(r"\S+|\s+", text),
which also yields multi-character whitespace tokens (" ", "\t", "\f"). The loop
counted every token that was not exactly a single space toward the chunk length,
so a multi-space or page-break token was counted as a word - producing chunks
shorter than split_length and, for a whitespace-only document, a whitespace-only
chunk. Count a token only when it contains a real word (word.strip()).1 parent 007c66b commit 5d735bb
3 files changed
Lines changed: 26 additions & 11 deletions
File tree
- haystack/components/preprocessors
- releasenotes/notes
- test/components/preprocessors
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
383 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
384 | 386 | | |
385 | 387 | | |
386 | 388 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 16 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
502 | 502 | | |
503 | 503 | | |
504 | 504 | | |
505 | | - | |
| 505 | + | |
506 | 506 | | |
507 | 507 | | |
508 | 508 | | |
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
| 536 | + | |
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | 541 | | |
547 | 542 | | |
548 | 543 | | |
| |||
899 | 894 | | |
900 | 895 | | |
901 | 896 | | |
902 | | - | |
903 | | - | |
904 | | - | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
905 | 901 | | |
906 | 902 | | |
907 | 903 | | |
| |||
1136 | 1132 | | |
1137 | 1133 | | |
1138 | 1134 | | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
0 commit comments