Skip to main content

order_by_value

Function order_by_value 

Source
pub fn order_by_value(
    frames: Vec<(String, ContextFrame)>,
) -> Vec<(String, ContextFrame)>
Expand description

Order frames for placement in the prompt, highest value at the attention-favored edges — the Lost-in-the-Middle placement (Liu et al., TACL 2024, arXiv:2307.03172; docs/protocol-advantages.md §12), which shows an LLM attends most to the top and bottom of a long context and least to its middle.

Frames are first ranked by score descending, ties broken by canonical FrameId — so the ranking, and therefore the placement, is a pure function of the input set. The ranked frames are then dealt to alternating ends of the output: rank 0 to the top, rank 1 to the bottom, rank 2 just below the top, rank 3 just above the bottom, and so on, leaving the lowest-value frames in the low-attention middle. For a fixed set of frames and scores this yields identical bytes every time; it does not promise the stricter score-independence of compose_context, because placing by value is exactly a choice to let score matter.

§Ranking across providers is this host’s policy, not a protocol guarantee

score is provider-local and ordinal (SPEC.md §6.6, F10): the protocol defines no shared scale, so one provider’s 0.8 and another’s are not the same claim. Ranking a mixed set by raw score therefore favors whichever provider scores most generously.

This function does it anyway, deliberately, as a documented default for a host that has no better ranking policy — some total order is required to place frames at all, and an arbitrary one would be worse. A host that has a ranking policy has two ways to say so: pass a ranking::RankingStrategy to order_by or compose_for_prompt_withranking::RoundRobinByRank and ranking::PerProviderQuota ship here and need no configuration — or rank the frames itself and call fold_to_edges, which is the placement without any ranking at all.

What F10 forbids is not this ordering but laundering it: a host must never apply a cross-provider score threshold, nor present a raw score to a user as a cross-provider measure of relevance.