Retrieval-augmented agents cannot embed a whole book at once, so documents are cut into chunks, each embedded and indexed separately. Chunk size is a trade-off: small chunks are precise but lose context, large chunks keep context but dilute the embedding with unrelated text. Cutting at fixed positions has a side effect: a sentence that straddles the boundary is split between two chunks and may be found in neither. Overlap repeats the last overlap tokens of each chunk at the start of the next, so that anything near a boundary appears whole in at least one chunk.
Implement chunk_tokens.
tokens is a list. chunk_tokens(tokens, size, overlap) returns a list of chunks (lists), with 0 <= overlap < size.0, size - overlap, 2 * (size - overlap), .... Each chunk is tokens[start : start + size].[].The stride is size - overlap.
A chunk reaches the end when start + size >= len(tokens); make it the last one.
No results yet
Run your code to check it against the examples, or submit to run every test.