liveBook · Manning

Recency rule

As explained in LLM Customization and Fine-Tuning

A prompt-ordering heuristic that places the example most similar to the query last.

Place the example most similar to the query last. In long prompts, relevant information is harder to use when buried in the middle; deliberate ordering can outperform random ordering even with the same number of examples. section 4.3.4 section 4.8.1

Ordering a many-shot prompt

Compare two 100-shot prompts: one orders examples randomly, while the other puts the most query-similar examples at the end. The deliberately ordered prompt can perform better. More examples are not automatically better if relevant ones land in the middle or added context only increases cost. section 4.3.4 section 4.8.1

Figure 4.3 Lost-in-the-middle U-shape (illustrative): accuracy is high when the relevant content sits near the start or end of the context window and drops in the middle, so put your highest-signal examples at the boundaries, not the trough.

The U-shaped accuracy illustration shows why high-signal examples belong near the beginning or end, not in the middle. section 4.3.4

How LLM Customization and Fine-Tuning covers it

How deep it goes
Explains the long-context attention rationale and accuracy tradeoffs without detailing model internals.
Examples
Compares random and similarity-based ordering in 100-shot prompts and discusses when eight shots may suffice.
What you can do after
Apply the heuristic by placing the query’s most-similar demonstration last, especially in longer prompts.
How it connects
Connects demonstration ordering with few-shot prompting, many-shot in-context learning, and long-context attention.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLM Customization and Fine-Tuning. The section links point to the parts of the book it draws on.