{"record":{"id":"68f4461ed739431c","repo":"rohitg00/ai-engineering-from-scratch","slug":"size-must-be-positive","errorCode":null,"errorMessage":"size must be positive","messagePattern":"size must be positive","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/64-chunking-strategies-advanced/code/main.py","lineNumber":40,"sourceCode":"@dataclass\nclass Chunk:\n    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# ---------------------------------------------------------------------------","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/64-chunking-strategies-advanced/code/main.py#L22-L58","documentation":"Error \"size must be positive\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/19-capstone-projects/64-chunking-strategies-advanced/code/main.py:40 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"}