Package sk.iway.iwcm.rag.indexing
Class SlidingWindowChunker
java.lang.Object
sk.iway.iwcm.rag.indexing.SlidingWindowChunker
Splits text into bounded, overlapping chunks, preferring sentence or paragraph boundaries.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordStores a passage and its start offset in the normalized, trimmed source text. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSplits text using the configured approximate chunk size and overlap.Chooses sentence or paragraph boundaries nearest the requested size and overlap.chunkWithOffsets(String text) Splits text using the configured size and overlap while retaining passage positions.chunkWithOffsets(String text, int chunkSize, int overlap) Retains source offsets for the same bounded, overlapping passages returned bychunk(String, int, int).
-
Constructor Details
-
SlidingWindowChunker
public SlidingWindowChunker()
-
-
Method Details
-
chunk
Splits text using the configured approximate chunk size and overlap.- Parameters:
text- the full text to split- Returns:
- list of text chunks
-
chunk
Chooses sentence or paragraph boundaries nearest the requested size and overlap. Each chunk adds new content, even when overlap is large. Chunks may exceed the target by up to 50%, with a minimum cap of two UTF-16 units to preserve surrogate pairs. Longer units split at whitespace, or inside an oversized token when necessary.- Parameters:
text- the full text to splitchunkSize- target number of characters per chunk; nonpositive values disable splittingoverlap- target overlap in characters, rounded to whole sentences or paragraphs- Returns:
- nonempty chunks with approximate sizes and no gaps in the source content
-
chunkWithOffsets
Splits text using the configured size and overlap while retaining passage positions.- Parameters:
text- full source text- Returns:
- chunks whose offsets refer to the source with normalized newlines and trimmed edges
-
chunkWithOffsets
Retains source offsets for the same bounded, overlapping passages returned bychunk(String, int, int).- Parameters:
text- full source textchunkSize- target number of characters per chunkoverlap- target overlap in characters- Returns:
- chunks whose offsets refer to the source with normalized newlines and trimmed edges
-