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 than windowChars. Reserved for v0.2.0+; unused by the single-window assemble.
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 >= 0 and overlapChars < 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: return full verbatim.
  • 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"):

  1. Shipping a complex multi-window assembler before we know how callers consume it would lock us into the wrong shape.
  2. A single bounded prefix is honest — predictable, audit-able, no silent drops.
  3. Multi-window iteration lands when the surrounding API (Phase 3+ AssembledContext) can express it cleanly.
Since:
0.1.0
  • Constructor Details

    • SlidingWindow

      public SlidingWindow(int windowChars, int overlapChars)
      Creates an instance of a SlidingWindow record class.
      Parameters:
      windowChars - the value for the windowChars record component
      overlapChars - the value for the overlapChars record component
  • Method Details

    • assemble

      public String assemble(ParsedDocument doc)
      Render doc into a single bounded-prefix window. See class Javadoc for the full contract.
      Specified by:
      assemble in interface ContextStrategy
      Parameters:
      doc - the parsed document; must not be null.
      Returns:
      a single string suitable for use as the user prompt.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • windowChars

      public int windowChars()
      Returns the value of the windowChars record component.
      Returns:
      the value of the windowChars record component
    • overlapChars

      public int overlapChars()
      Returns the value of the overlapChars record component.
      Returns:
      the value of the overlapChars record component