Class NormalizedDocumentChunker
Small documents retain their original identity and content. Larger
normalized documents prefer extractor-provided DocumentBlocks so
format-native structural paths and line provenance survive indexing. Raw
source files use language boundaries where available and otherwise fall
back to bounded line and character groups.
Fixed-size windows overlap by OVERLAP_LINES so a sentence
that straddles an arbitrary cut is still present in one chunk.
Semantic boundaries — markdown headings, source-code symbols — do not
overlap: those split points are already meaningful.
@Knowledge.unit = LINE and HEADING emit
position-addressed slices rather than overlapping windows, so overlap
is suppressed there. DOCUMENT is a single unit. AUTO
and CHUNK apply overlap only on the fixed-size fallback.
- Since:
- 0.13.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne stable retrieval unit. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum characters retained in one generic chunk.static final intMaximum retrieval units admitted from one source document.static final intMaximum characters admitted from one source document.static final intMaximum physical lines retained in one generic chunk.static final intMaximum physical lines admitted from one source document.static final intLines repeated from the previous fixed-size window. 15% ofMAX_LINES_PER_CHUNK; not applied across semantic boundaries orLINE/HEADINGunits. -
Method Summary
Modifier and TypeMethodDescriptionstatic List<NormalizedDocumentChunker.Chunk> chunk(ExtractedDocument document) Chunks one extractor-normalized document.static List<NormalizedDocumentChunker.Chunk> chunk(ExtractedDocument document, KnowledgeUnit unit) Applies an explicit ingest unit to one extractor-normalized document.static List<NormalizedDocumentChunker.Chunk> Chunks a raw source file using the shared server/declarative fallback.static StringdetectLanguage(String fileName) Derives the normalized language key from a file extension.static voidvalidateUnit(KnowledgeUnit unit, DocumentFormat format) Validates one explicit ingest unit against a concrete or AUTO format.
-
Field Details
-
MAX_LINES_PER_CHUNK
public static final int MAX_LINES_PER_CHUNKMaximum physical lines retained in one generic chunk.- See Also:
-
OVERLAP_LINES
public static final int OVERLAP_LINESLines repeated from the previous fixed-size window. 15% ofMAX_LINES_PER_CHUNK; not applied across semantic boundaries orLINE/HEADINGunits.- Since:
- 0.15.0
- See Also:
-
MAX_CHARS_PER_CHUNK
public static final int MAX_CHARS_PER_CHUNKMaximum characters retained in one generic chunk.- See Also:
-
MAX_LINES_PER_DOCUMENT
public static final int MAX_LINES_PER_DOCUMENTMaximum physical lines admitted from one source document.This is the document-size contract, and it is deliberately unchanged by overlapping windows. Overlap repeats
OVERLAP_LINESlines per window, so covering the same document costs proportionally more windows; that cost is paid by a dedicated overlap expansion budget rather than by shrinking what a caller may ingest.- Since:
- 0.15.0
- See Also:
-
MAX_CHUNKS_PER_DOCUMENT
public static final int MAX_CHUNKS_PER_DOCUMENTMaximum retrieval units admitted from one source document.This remains the pre-overlap admission ceiling. Overlapping windows consume a separate internal expansion budget, so callers that suppress overlap do not inherit a fourfold global resource allowance.
- See Also:
-
MAX_DOCUMENT_CHARS
public static final int MAX_DOCUMENT_CHARSMaximum characters admitted from one source document.- See Also:
-
-
Method Details
-
chunk
Chunks one extractor-normalized document.- Parameters:
document- normalized document- Returns:
- immutable chunks, or an empty list for blank content
-
chunk
public static List<NormalizedDocumentChunker.Chunk> chunk(ExtractedDocument document, KnowledgeUnit unit) Applies an explicit ingest unit to one extractor-normalized document.- Parameters:
document- normalized documentunit- requested ingest unit- Returns:
- immutable retrieval units, or an empty list for blank content
- Throws:
IllegalArgumentException- when the unit is incompatible with the document format or would exceed a retrieval-unit limit- Since:
- 0.15.0
-
validateUnit
Validates one explicit ingest unit against a concrete or AUTO format. AUTO defers compatibility until content detection resolves the format.- Parameters:
unit- requested ingest unitformat- declared or detected document format- Throws:
IllegalArgumentException- when the pair has no defined slicing semantics- Since:
- 0.15.0
-
chunk
public static List<NormalizedDocumentChunker.Chunk> chunk(Path filePath, String content, String language) Chunks a raw source file using the shared server/declarative fallback.- Parameters:
filePath- stable source-relative file pathcontent- UTF-8 textlanguage- normalized language key- Returns:
- immutable chunks
-
detectLanguage
Derives the normalized language key from a file extension.
-