Record Class SlidingWindow
java.lang.Object
java.lang.Record
ai.doctruth.SlidingWindow
- Record Components:
windowChars- size of the assembled window in characters; strict upper bound.overlapChars- characters of overlap between consecutive windows; must be strictly less thanwindowChars. Reserved for v0.2.0+; unused by the single-windowassemble.
- All Implemented Interfaces:
ContextStrategy
public record SlidingWindow(int windowChars, int overlapChars)
extends Record
implements ContextStrategy
Fixed-size character windows with optional overlap. Useful when the document is long-form
prose and priority-section heuristics don't apply (e.g., legal contracts read end-to-end).
Invariants (compact constructor):
windowChars >= 1.overlapChars >= 0andoverlapChars < windowChars. Equal-or-greater overlap would either spin in place or run backwards.
Phase-1 single-window assemble. The strategy renders every section via
SectionRenderer, joins them with "\n\n" into a single string full,
and returns ONE bounded prefix:
- If
full.length() <= windowChars: returnfullverbatim. - Otherwise: return
full.substring(0, windowChars)— strict cap, never exceeds. - Empty document (zero sections): return
"".
The overlapChars field is reserved for v0.2.0+ multi-window iteration and
is intentionally NOT consulted by this single-window assemble. Multi-window
orchestration (where the strategy emits successive overlapping windows for sequential
downstream LLM calls) arrives in v0.2.0+ when ContextStrategy is widened to return a
richer AssembledContext record.
Why so minimal? Three reasons (per CONTRIBUTING.md "Engineering principles"):
- Shipping a complex multi-window assembler before we know how callers consume it would lock us into the wrong shape.
- A single bounded prefix is honest — predictable, audit-able, no silent drops.
- Multi-window iteration lands when the surrounding API (Phase 3+
AssembledContext) can express it cleanly.
- Since:
- 0.1.0
-
Constructor Summary
ConstructorsConstructorDescriptionSlidingWindow(int windowChars, int overlapChars) Creates an instance of aSlidingWindowrecord class. -
Method Summary
Modifier and TypeMethodDescriptionassemble(ParsedDocument doc) Renderdocinto a single bounded-prefix window.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intReturns the value of theoverlapCharsrecord component.final StringtoString()Returns a string representation of this record class.intReturns the value of thewindowCharsrecord component.
-
Constructor Details
-
SlidingWindow
public SlidingWindow(int windowChars, int overlapChars) Creates an instance of aSlidingWindowrecord class.- Parameters:
windowChars- the value for thewindowCharsrecord componentoverlapChars- the value for theoverlapCharsrecord component
-
-
Method Details
-
assemble
Renderdocinto a single bounded-prefix window. See class Javadoc for the full contract.- Specified by:
assemblein interfaceContextStrategy- Parameters:
doc- the parsed document; must not be null.- Returns:
- a single string suitable for use as the user prompt.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with thecomparemethod from their corresponding wrapper classes. -
windowChars
public int windowChars()Returns the value of thewindowCharsrecord component.- Returns:
- the value of the
windowCharsrecord component
-
overlapChars
public int overlapChars()Returns the value of theoverlapCharsrecord component.- Returns:
- the value of the
overlapCharsrecord component
-