Slicers

Slicers select a subset of scored items that fits within the token budget. They are invoked during Stage 5: Slice.

Slicer Interface

A slicer implements a single function:

Slice(scoredItems: list of ScoredItem, budget: ContextBudget) -> list of ContextItem

Contract

  1. Subset selection. The slicer MUST return a subset of the input items. It MUST NOT create, modify, or duplicate items.
  2. Budget compliance. The total tokens of selected items SHOULD NOT exceed budget.targetTokens. (Some strategies like KnapsackSlice may slightly under-fill due to discretization.)
  3. Zero-token items. Items with tokens = 0 are conventionally always included, as they consume no budget. Individual slicer implementations define this behavior.
  4. Empty input. If scoredItems is empty or budget.targetTokens <= 0, the slicer MUST return an empty list.

Slicer Summary

SlicerAlgorithmComplexityUse Case
GreedySliceValue-density greedy fillO(N log N)Fast, good-enough selection for most workloads
KnapsackSlice0/1 knapsack dynamic programmingO(N * C)Optimal selection when budget is tight
QuotaSlicePartitioned delegation by kindO(N + per-kind cost)Budget fairness across context kinds
CountQuotaSliceCount-based require/cap per kindO(N log N + inner cost)Absolute item-count guarantees per kind
CountConstrainedKnapsackSliceCount-require/cap + knapsack-optimal selectionO(N log N + N × C)Count guarantees with globally optimal token packing

Where N is the number of scored items and C is the discretized budget capacity.

StreamSlice (Implementation-Optional)

StreamSlice is an asynchronous/streaming slicer that processes items as they arrive rather than requiring the full sorted list upfront. It is documented here for completeness but is implementation-optional — the synchronous pipeline defined by this specification does not require streaming support.

Implementations that support asynchronous or streaming pipelines MAY provide a StreamSlice that conforms to the same behavioral contract (subset selection within budget) using a streaming evaluation model. The synchronous conformance test suite does not test StreamSlice.