Chunk#

class scikitplot.corpus.Chunk(text, start_char, end_char, metadata=<factory>)[source]#

A single unit of text produced by a chunker.

Parameters:
textstr

The chunk’s text content (possibly including overlap context).

start_charint

Zero-based character offset of this chunk’s start in the source document. Set to 0 when offsets are disabled.

end_charint

Zero-based exclusive character offset of this chunk’s end. Set to 0 when offsets are disabled.

metadataMetadataDict

Arbitrary per-chunk key/value pairs (e.g. chunk_index, doc_id, backend, tokens). Always a dict — never None.

Parameters:

Notes

  • text must be a non-empty string. Validation is the chunker’s responsibility; Chunk itself does not re-validate to keep it a pure value object.

  • metadata is stored as-is. Callers must not mutate the dict after construction (frozen dataclass contract).

char_length()[source]#

Return the character span length of this chunk.

Returns:
int

end_char - start_char. Returns 0 when offsets are disabled (both fields are 0).

Return type:

int

content_hash()[source]#

Return a stable SHA-256 hex digest of text.

Useful as a deduplication key in storage backends.

Returns:
str

64-character lowercase hex string.

Return type:

str

end_char: int[source]#
metadata: dict[str, Any][source]#
start_char: int[source]#
text: str[source]#
with_metadata(**kwargs)[source]#

Return a new Chunk with additional metadata keys.

Parameters:
**kwargs

Key/value pairs to merge into a copy of metadata.

Returns:
Chunk

New frozen instance with merged metadata.

Parameters:

kwargs (Any)

Return type:

Chunk

Notes

Uses dataclasses.replace so any new fields added to Chunk are automatically preserved without editing this method (CRITICAL-04 / LOW-02 fix).