{"record":{"id":"7b90fd7412a1428c","repo":"rohitg00/ai-engineering-from-scratch","slug":"overlap-words-must-be-between-zero-and-max-words","errorCode":null,"errorMessage":"overlap_words must be between zero and max_words - 1","messagePattern":"overlap_words must be between zero and max_words - 1","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"certifications/claude/lessons/24-rag-retrieval-and-data-pipelines/code/main.py","lineNumber":54,"sourceCode":"    text: str\n    updated_at: str\n    position: int\n\n\n@dataclass(frozen=True)\nclass RetrievalHit:\n    chunk_id: str\n    document_id: str\n    text: str\n    updated_at: str\n    score: float\n\n\ndef chunk_document(document: Document, max_words: int = 80, overlap_words: int = 12) -> list[Chunk]:\n    if max_words <= 0:\n        raise ValueError(\"max_words must be positive\")\n    if overlap_words < 0 or overlap_words >= max_words:\n        raise ValueError(\"overlap_words must be between zero and max_words - 1\")\n    words = document.text.split()\n    if not words:\n        return []\n    step = max_words - overlap_words\n    chunks = []\n    for position, start in enumerate(range(0, len(words), step)):\n        selected = words[start : start + max_words]\n        if not selected:\n            break\n        chunks.append(\n            Chunk(\n                chunk_id=f\"{document.document_id}:{position}\",\n                document_id=document.document_id,\n                text=\" \".join(selected),\n                updated_at=document.updated_at,\n                position=position,\n            )\n        )","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/certifications/claude/lessons/24-rag-retrieval-and-data-pipelines/code/main.py#L36-L72","documentation":"Raised in chunk_document when overlap_words is negative or >= max_words. The step size max_words - overlap_words must be at least 1 to make forward progress; outside that range the loop would stall or walk backwards and never terminate over the document.","triggerScenarios":"Thrown at certifications/claude/lessons/24-rag-retrieval-and-data-pipelines/code/main.py:54 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use an overlap strictly smaller than max_words (default 12 with max_words 80)","Set overlap_words to 0 to disable overlapping windows","Validate the overlap/window pair together in pipeline configuration"],"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"}