rohitg00/ai-engineering-from-scratch · error · ValueError
size must be positive
Error message
size must be positive
What it means
Error "size must be positive" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at phases/19-capstone-projects/64-chunking-strategies-advanced/code/main.py:40
@dataclass
class Chunk:
doc_id: str
strategy: str
start: int
end: int
text: str
def overlaps(self, gold_start: int, gold_end: int) -> bool:
return not (self.end <= gold_start or self.start >= gold_end)
# ---------------------------------------------------------------------------
# strategy 1 -- fixed window
# ---------------------------------------------------------------------------
def fixed_window(doc_id: str, text: str, size: int = 400, overlap: int = 80) -> list[Chunk]:
if size <= 0:
raise ValueError("size must be positive")
if overlap < 0 or overlap >= size:
raise ValueError("overlap must be non-negative and smaller than size")
out: list[Chunk] = []
step = size - overlap
i = 0
n = len(text)
while i < n:
end = min(i + size, n)
out.append(Chunk(doc_id, "fixed", i, end, text[i:end]))
if end == n:
break
i += step
return out
# ---------------------------------------------------------------------------
# strategy 2 -- sentence packer
# ---------------------------------------------------------------------------View on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at phases/19-capstone-projects/64-chunking-strategies-advanced/code/main.py:40 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/68f4461ed739431c.
Report an issue: GitHub.