{"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":"A generic argument guard at the top of the fixed-window chunker: fixed_window refuses to build chunks when the caller supplies a window size of zero or a negative number, because no positive-length slice of text could ever be produced. It fires before any slicing happens, so it always indicates a bad caller-supplied size (e.g. a config typo or an uninitialized variable), not a problem with the input text itself.","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":["Use a positive window size (the default is 400 characters)","Load window size from config with a bounds check before chunking","For token-based chunking, validate the converted token count is positive"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}