rohitg00/ai-engineering-from-scratch · error · ValueError

max_words must be positive

Error message

max_words must be positive

What it means

Error "max_words must be positive" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at certifications/claude/lessons/24-rag-retrieval-and-data-pipelines/code/main.py:52

    chunk_id: str
    document_id: str
    text: str
    updated_at: str
    position: int


@dataclass(frozen=True)
class RetrievalHit:
    chunk_id: str
    document_id: str
    text: str
    updated_at: str
    score: float


def chunk_document(document: Document, max_words: int = 80, overlap_words: int = 12) -> list[Chunk]:
    if max_words <= 0:
        raise ValueError("max_words must be positive")
    if overlap_words < 0 or overlap_words >= max_words:
        raise ValueError("overlap_words must be between zero and max_words - 1")
    words = document.text.split()
    if not words:
        return []
    step = max_words - overlap_words
    chunks = []
    for position, start in enumerate(range(0, len(words), step)):
        selected = words[start : start + max_words]
        if not selected:
            break
        chunks.append(
            Chunk(
                chunk_id=f"{document.document_id}:{position}",
                document_id=document.document_id,
                text=" ".join(selected),
                updated_at=document.updated_at,
                position=position,

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at certifications/claude/lessons/24-rag-retrieval-and-data-pipelines/code/main.py:52 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/5e9ea8889914543c. Report an issue: GitHub.