{"record":{"id":"0ec9373e6667475e","repo":"rohitg00/ai-engineering-from-scratch","slug":"overlap-must-be-non-negative-and-smaller-than-size","errorCode":null,"errorMessage":"overlap must be non-negative and smaller than size","messagePattern":"overlap must be non-negative and smaller than size","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/64-chunking-strategies-advanced/code/main.py","lineNumber":42,"sourceCode":"    doc_id: str\n    strategy: str\n    start: int\n    end: int\n    text: str\n\n    def overlaps(self, gold_start: int, gold_end: int) -> bool:\n        return not (self.end <= gold_start or self.start >= gold_end)\n\n\n# ---------------------------------------------------------------------------\n# strategy 1  --  fixed window\n# ---------------------------------------------------------------------------\n\ndef fixed_window(doc_id: str, text: str, size: int = 400, overlap: int = 80) -> list[Chunk]:\n    if size <= 0:\n        raise ValueError(\"size must be positive\")\n    if overlap < 0 or overlap >= size:\n        raise ValueError(\"overlap must be non-negative and smaller than size\")\n    out: list[Chunk] = []\n    step = size - overlap\n    i = 0\n    n = len(text)\n    while i < n:\n        end = min(i + size, n)\n        out.append(Chunk(doc_id, \"fixed\", i, end, text[i:end]))\n        if end == n:\n            break\n        i += step\n    return out\n\n\n# ---------------------------------------------------------------------------\n# strategy 2  --  sentence packer\n# ---------------------------------------------------------------------------\n\n_SENTENCE_BOUNDARY = re.compile(r\"(?<=[.!?])\\s+(?=[A-Z0-9])\")","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/64-chunking-strategies-advanced/code/main.py#L24-L60","documentation":"Error \"overlap must be non-negative and smaller than size\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/19-capstone-projects/64-chunking-strategies-advanced/code/main.py:42 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}