|
16 | 16 | * character, the next level only for a piece the level above left too long. |
17 | 17 | * A Markdown table or list item is one unit while it fits. Adjacent pieces |
18 | 18 | * are merged while the merged piece is shorter than `minChars`. |
19 | | - * - `markdown` — one section per ATX heading (outside code fences); each |
20 | | - * section is cut as `recursive` cuts, and every passage begins with its |
21 | | - * heading path, which counts toward its length and is embedded with it. A |
22 | | - * heading with no text of its own is named by the path of the section after |
23 | | - * it when it is that section's ancestor, and is a passage of its own |
24 | | - * otherwise — never a line of another heading's section. |
| 19 | + * - `markdown` — one section per ATX heading (outside code fences); every |
| 20 | + * passage begins with its heading path, which counts toward its length and |
| 21 | + * is embedded with it. A section that fits — its text together with the |
| 22 | + * heading path it is given, within `maxChars` and the token budget — is one |
| 23 | + * passage, whatever `minChars` is; only a section that does not fit is cut |
| 24 | + * as `recursive` cuts, its pieces merged up to `minChars`. A parent heading's |
| 25 | + * text before its first child, and the text before the first heading, are |
| 26 | + * sections of their own. A heading with no text of its own is named by the |
| 27 | + * path of the section after it when it is that section's ancestor, and is a |
| 28 | + * passage of its own otherwise — never a line of another heading's section. |
25 | 29 | * |
26 | 30 | * ## The sentence end (the Chinese-aware part) |
27 | 31 | * |
@@ -97,7 +101,7 @@ export interface ResolvedSplit { |
97 | 101 | strategy: KnowledgeSplitStrategy; |
98 | 102 | /** Longest passage, in characters. Not read by `whole`. */ |
99 | 103 | maxChars: number; |
100 | | - /** Adjacent pieces shorter than this are merged. Never above `maxChars`. */ |
| 104 | + /** Adjacent pieces shorter than this are merged; under `markdown`, only in a section that does not fit. Never above `maxChars`. */ |
101 | 105 | minChars: number; |
102 | 106 | /** Largest `estimateTokens` of a passage; absent when no limit is known. */ |
103 | 107 | maxTokens?: number; |
@@ -566,9 +570,10 @@ export function matchHeading(line: string): { level: number; text: string } | nu |
566 | 570 | * section's ancestor; otherwise it is a passage of its own, under its own path |
567 | 571 | * (its ancestors and itself). It never joins a section that is not its |
568 | 572 | * descendant, so no heading is filed under one that is not its ancestor, and |
569 | | - * every heading is in some passage's path. Each section is cut by |
570 | | - * {@link splitRecursive} within the bounds left after its heading path, and |
571 | | - * every passage begins with that path. |
| 573 | + * every heading is in some passage's path. A section whose text, with its |
| 574 | + * heading path, fits the bounds is one passage; any other is cut by |
| 575 | + * {@link splitRecursive} within the bounds left after its heading path. Every |
| 576 | + * passage begins with that path. |
572 | 577 | */ |
573 | 578 | export function splitMarkdown( |
574 | 579 | text: string, |
|
0 commit comments