@@ -44,9 +44,15 @@ export interface ChunkingOptions {
4444 strategy ?: 'markdown' | 'fixed' | 'auto' ;
4545}
4646
47+ /** A document with a guaranteed ID — used by chunkers.
48+ * Context.load() always assigns id via pathToId before chunking. */
49+ export interface ChunkableDocument extends Document {
50+ id : string ;
51+ }
52+
4753/** Chunker interface — custom chunkers can implement this. */
4854export interface Chunker {
49- chunk ( doc : Document ) : Chunk [ ] ;
55+ chunk ( doc : ChunkableDocument ) : Chunk [ ] ;
5056}
5157
5258// ---------------------------------------------------------------------------
@@ -77,7 +83,7 @@ export class MarkdownChunker implements Chunker {
7783 this . chunkOverlap = opts . chunkOverlap ;
7884 }
7985
80- chunk ( doc : Document ) : Chunk [ ] {
86+ chunk ( doc : ChunkableDocument ) : Chunk [ ] {
8187 return chunkMarkdown ( doc , this . maxChunkSize , this . chunkOverlap ) ;
8288 }
8389}
@@ -87,7 +93,7 @@ export class MarkdownChunker implements Chunker {
8793 * sections that exceed maxChunkSize with a fixed-size sliding window.
8894 */
8995function chunkMarkdown (
90- doc : Document ,
96+ doc : ChunkableDocument ,
9197 maxChunkSize : number ,
9298 overlap : number ,
9399) : Chunk [ ] {
@@ -205,7 +211,7 @@ export class FixedSizeChunker implements Chunker {
205211 this . chunkOverlap = opts . chunkOverlap ;
206212 }
207213
208- chunk ( doc : Document ) : Chunk [ ] {
214+ chunk ( doc : ChunkableDocument ) : Chunk [ ] {
209215 const parts = fixedSizeSplit ( doc . content , this . maxChunkSize , this . chunkOverlap ) ;
210216 return parts . map ( ( content , i ) => ( {
211217 content,
@@ -505,7 +511,7 @@ class AutoChunker implements Chunker {
505511 this . fixed = new FixedSizeChunker ( options ) ;
506512 }
507513
508- chunk ( doc : Document ) : Chunk [ ] {
514+ chunk ( doc : ChunkableDocument ) : Chunk [ ] {
509515 // If the document content contains markdown headings (## or ###), use
510516 // heading-aware chunking; otherwise fall back to fixed-size splits.
511517 if ( / ^ # { 1 , 3 } \s + \S / m. test ( doc . content ) ) {
0 commit comments