Retrieval augmented generation has a quiet failure mode. Two queries arrive with the same instructions and three of the same four retrieved chunks, yet the provider computes the whole prefix again because the fourth chunk, or the order of the four, differs. The model had already done that work; the prompt just did not repeat it exactly.
Prefix caching matches from the first token forward. The serving engine finds the longest cached token sequence that matches the new request from the beginning, loads those KV states, and runs prefill only for the remaining tokens. Whitespace and formatting count: a single character difference breaks the match (Modular's inference handbook). That is the mechanical reason chunk order matters. Retrieval ranks chunks by similarity score, and scores shift with every query and every embedding refresh. If you concatenate chunks in rank order, the prefix changes constantly and the cache can only ever match the system prompt.
Retrieval pipelines produce a hard case for prefix caching. A given chunk is repeatedly retrieved across user questions, but it can appear at arbitrary locations with arbitrary neighboring context, so naive reuse of its cached KV states degrades output quality (Cache-Craft, arXiv). You cannot reorder chunks freely for cache reasons without regard to what the model needs to read, so the ordering policy has to serve both goals at once.
The payoff is worth the discipline. Providers discount cached input heavily: Anthropic's pricing page lists cache hits and refreshes at a fraction of the base input rate and cache writes at a premium over it (Claude platform docs). One engineering team reported cache hit rate rising from 7% to 84% after restructuring how it marked and ordered stable prefixes, with overall cost falling 59% on the same token volume (ProjectDiscovery).



