Skip to content

chunking

triplum.steps.chunking

Chunker

Bases: Protocol

Split one source into chunks whose start and text are exact slices of its text.

__call__ abstractmethod

__call__(source: Source, /) -> list[Chunk]
Source code in src/triplum/steps/chunking.py
13
14
@abstractmethod
def __call__(self, source: Source, /) -> list[Chunk]: ...

FixedSize

FixedSize(size: int)

Bases: Chunker, FingerprintedComputationMixin

Slice the text every size characters; the last chunk keeps the remainder.

Chunks do not overlap and concatenate back to the source text. Empty text yields no chunks.

Source code in src/triplum/steps/chunking.py
23
24
25
26
def __init__(self, size: int) -> None:
    if isinstance(size, bool) or size < 1:
        raise ValueError("size must be a positive integer")
    self.size = size

size instance-attribute

size = size

fingerprint_config

fingerprint_config() -> dict[str, object]
Source code in src/triplum/steps/chunking.py
28
29
def fingerprint_config(self) -> dict[str, object]:
    return {"size": self.size}

__call__

__call__(source: Source, /) -> list[Chunk]
Source code in src/triplum/steps/chunking.py
31
32
33
34
35
36
37
38
39
40
41
42
def __call__(self, source: Source, /) -> list[Chunk]:
    return [
        Chunk(
            collection_id=source.collection_id,
            source_id=source.id,
            origin=source.origin,
            ordinal=ordinal,
            start=start,
            text=source.text[start : start + self.size],
        )
        for ordinal, start in enumerate(range(0, len(source.text), self.size))
    ]

WholeText

Bases: Chunker, FingerprintedComputationMixin

One chunk holding the whole source text; empty text yields no chunks.

Keeps a benchmark's native passages as retrieval units, as passage-level recall assumes.

fingerprint_config

fingerprint_config() -> dict[str, object]
Source code in src/triplum/steps/chunking.py
51
52
def fingerprint_config(self) -> dict[str, object]:
    return {}

__call__

__call__(source: Source, /) -> list[Chunk]
Source code in src/triplum/steps/chunking.py
54
55
56
57
58
59
60
61
62
63
64
65
66
def __call__(self, source: Source, /) -> list[Chunk]:
    if not source.text:
        return []
    return [
        Chunk(
            collection_id=source.collection_id,
            source_id=source.id,
            origin=source.origin,
            ordinal=0,
            start=0,
            text=source.text,
        )
    ]