AbstractAbstractKeyThe registration key for this segmenter. Must match the key passed to
@RegisterClass so metadata-driven resolution round-trips.
AbstractSupportedModalities this segmenter can produce. Used to validate configuration.
ProtectedresolveFill in defaults for any option the caller left unset.
Optionaloptions: SegmentationOptionsSegment content into embeddable units.
Never throws for content-shaped problems — inspect Success/ErrorMessage.
Protected AbstractSegmentProduce the raw, un-normalized segments for this content.
Implementations should focus purely on where the boundaries are; the base
class enforces the token ceiling afterwards, so returning a segment that is
too large is acceptable (it will be split, preserving Title and offsets).
ProtectedtokensStaticResolveResolve a registered segmenter by key via the MJ class factory. Returns null when no segmenter is registered under that key.
Uses TryCreateInstance rather than CreateInstance deliberately: the latter never returns
null for an unregistered key — it falls back to new BaseSegmenter(), a hollow object whose
abstract Key/SegmentCore are undefined. That failure stays invisible until something calls
it, so an unresolvable key must be reported as such here.
Base class for content segmentation strategies.
Why this exists
Chunking used to be a private helper inside whichever pipeline needed it, which meant every new strategy (structure-aware, LLM topic boundaries, audio chapters) would have been another bespoke branch.
BaseSegmenterturns "how do I split this content" into a registered, swappable strategy selected from metadata — the same patternBaseEmbeddingsandVectorDBBasealready use for their providers.Adding a new strategy
Implement SegmentCore and register the class. That is the whole contract — the base class handles validation, the token ceiling, small-segment merging, sequence numbering, parent/child remapping, and provenance stamping:
Subclasses emit RawSegments and never worry about numbering:
ParentIndexrefers to positions in the array they just returned, and the base class remaps it to realSequencevalues after any oversized segment has been split.