Fixed-size chunking
# grade this stage (from your course directory)
npx theinference test --stage fixed-size-chunking --watchThe simplest splitter: fixed-size token windows with overlap. Slide a window of size tokens across the paragraph, stepping by size - overlap each time. The last window may be short.
What to build
Implement chunkFixed
Given a paragraph's tokens: string[], a size, and an overlap, emit chunks of size tokens stepping by stride = size - overlap. The final chunk may be short; emit no empty chunks. Build each chunk's id and text from its offsets.
export function chunkFixed(
paragraphId: string, tokens: string[], size: number, overlap: number,
): Chunk[] {
// stride = size - overlap; for start = 0; start < tokens.length; start += stride
// end = min(start + size, tokens.length)
// id = `${paragraphId}::${start}-${end}`, text = detokenize(tokens.slice(start, end))
}
./your_program.sh chunk fixed "eiffel-tower#p1" 12 4
# -> JSON array of {id, paragraphId, startTok, endTok, text}, compared exactly
process mode, stdout_json_match. The chunk fixed <paragraphId> <size> <overlap> command prints the chunk records; your token offsets, ids, and text must match the reference exactly.
With size=12, overlap=4 you advance 8 tokens each step — adjacent chunks share their last/first 4 tokens. Guard against overlap >= size: that makes stride <= 0 and loops forever.