Record Class NaruContextSegment
- Record Components:
id- stable logical identity, e.g.system-prompt,tool-defs,code-context:moduleX. Used for diagnostics and for pairing against persisted state; cache validity is decided by content, never by id.content- what the segment carriescacheable- whether this segment is a caching candidateminLifetime- hint for how long the caller expects this segment to stay stable. Advisory: it never causes NARU to cache a segment the caller marked volatile, and it never rescues one whose content actually changed.
Callers build the request as an ordered list of segments, most stable
first: system prompt, tool definitions, project/indexed context, older
conversation turns, and finally the volatile tail (latest user turn, latest
tool results). Marking a segment cacheable() is a claim that its
serialized bytes will not change on the next turn.
That claim is the whole basis of every provider's prefix cache, so NARU
verifies it rather than trusting it: the caching layer compares
canonical() values through a hash chain, precisely because NARU
permits mid-history edits and a segment that keeps its own hash can still sit
at a different position in the prefix.
-
Constructor Summary
ConstructorsConstructorDescriptionNaruContextSegment(String id, NaruSegmentContent content, boolean cacheable, Duration minLifetime) Creates an instance of aNaruContextSegmentrecord class. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the value of thecacheablerecord component.static NaruContextSegmentcacheable(String id, NaruSegmentContent content) A cacheable segment with no particular stability horizon.A deterministic textual rendering of exactly the content that will be serialized for this segment.content()Returns the value of thecontentrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.id()Returns the value of theidrecord component.Returns the value of theminLifetimerecord component.final StringtoString()Returns a string representation of this record class.static NaruContextSegmentvolatileSegment(String id, NaruSegmentContent content) A segment that must be re-sent as fresh content every turn.withCacheable(boolean newCacheable)
-
Constructor Details
-
NaruContextSegment
public NaruContextSegment(String id, NaruSegmentContent content, boolean cacheable, Duration minLifetime) Creates an instance of aNaruContextSegmentrecord class.- Parameters:
id- the value for theidrecord componentcontent- the value for thecontentrecord componentcacheable- the value for thecacheablerecord componentminLifetime- the value for theminLifetimerecord component
-
-
Method Details
-
cacheable
A cacheable segment with no particular stability horizon. -
volatileSegment
A segment that must be re-sent as fresh content every turn. -
withCacheable
-
canonical
A deterministic textual rendering of exactly the content that will be serialized for this segment.Determinism matters more than prettiness: the value feeds a hash chain whose only job is to answer "did this exact prefix change?". Map keys are sorted so two structurally identical segments cannot hash differently because of
HashMapiteration order. Fields the serializer would not emit (source,sourceName) are excluded, because they are bookkeeping and must not spuriously invalidate a cache.id()is excluded for the same reason. It is a label for diagnostics and for pairing against persisted state, and it is not part of what the provider receives. Hashing it would mean a caller who derives ids dynamically — a counter, a timestamp, a path that moves — misses on every single turn while the bytes on the wire are byte-identical. Excluding it cannot cause a false hit, because the content that follows is exactly what gets sent. -
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. -
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. -
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
content
Returns the value of thecontentrecord component.- Returns:
- the value of the
contentrecord component
-
cacheable
public boolean cacheable()Returns the value of thecacheablerecord component.- Returns:
- the value of the
cacheablerecord component
-
minLifetime
Returns the value of theminLifetimerecord component.- Returns:
- the value of the
minLifetimerecord component
-