ContextItem

A ContextItem is an immutable record representing a single piece of context in the pipeline. Every scorer, slicer, and placer operates on ContextItem instances.

Fields

FieldTypeRequiredDefaultDescription
contentstringYesThe textual content of the item. Non-null and non-empty.
tokensintegerYesThe token count for this context item, as provided by the caller. Items with negative token counts are excluded during classification.
kindContextKindNo"Message"The kind of context item. Used by KindScorer and QuotaSlice.
sourceContextSourceNo"Chat"The origin of this context item.
priorityinteger or nullNonullOptional priority override. Higher values indicate greater importance. Used by PriorityScorer.
tagslist of stringsNoempty listDescriptive tags for filtering and scoring. May be empty. Tag comparison is case-insensitive (ASCII fold). Used by TagScorer and FrequencyScorer.
metadatamap of string to anyNoempty mapArbitrary key-value metadata. Opaque to the pipeline — not read or modified by any pipeline stage. Preserved on output for caller use.
timestampdatetime (UTC) or nullNonullWhen this context item was created or observed. Used by RecencyScorer and ChronologicalPlacer.
futureRelevanceHintfloat64 or nullNonullHint for future relevance scoring, conventionally in the range [0.0, 1.0]. Used by ReflexiveScorer.
pinnedbooleanNofalseWhether this item is pinned. Pinned items bypass scoring and slicing — they are always included in the output regardless of score or budget.
originalTokensinteger or nullNonullThe original token count before any external summarization or truncation. Not used by the pipeline; preserved for caller diagnostics.

Constraints

  1. content MUST be a non-null, non-empty string. Implementations SHOULD reject construction of a ContextItem with null or empty content.

  2. tokens is caller-provided. The pipeline does not tokenize content; it trusts the caller’s token count. The pipeline excludes items with tokens < 0 during classification (see Stage 1: Classify).

  3. tags uses case-insensitive comparison. When comparing tags (e.g., in TagScorer or FrequencyScorer), implementations MUST use case-insensitive ASCII comparison. "Important" and "important" are considered equal.

  4. metadata is opaque. The pipeline MUST NOT read, interpret, or modify metadata values. Implementations MUST preserve metadata through the pipeline so that selected items retain their original metadata on output.

  5. timestamp represents a point in time with UTC semantics. Implementations may use any datetime representation that preserves UTC instant precision (e.g., ISO 8601 with timezone, Unix epoch milliseconds). Comparison is by temporal ordering.

  6. Immutability. Once constructed, a ContextItem MUST NOT be modified. Pipeline stages MUST NOT mutate any field of any ContextItem they receive.