Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Move the most relevant content to the start or end of the retrieved block, rerank and trim to keep context dense, and restate the question near the answer position.
Imagine reading a thirty-page printout to answer a single question. You always look at the first and last pages most carefully; you skim the middle. Even if someone hands you sixty pages instead of thirty, your eyes still favor the edges. The trick is not to give you more paper, it is to put the load-bearing facts on page one and the last page, and to repeat the question right before the answer goes. A sticky note saying "pay attention" on page fifteen does very little. The same is true for a language model reading a long context: structural placement beats verbal nudges every time.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
6 minutes: the U-curve, three structural mitigations that work, three reflexes that fail, and how to measure curve shape on a new model.
def head_and_tail_layout(chunks_sorted_desc: list) -> list:
"""
Interleave so highest-rerank chunks land at position 0 and -1,
next-highest at position 1 and -2, and so on. Lowest scores in middle.
"""
head, tail = [], []
for i, chunk in enumerate(chunks_sorted_desc):
(head if i % 2 == 0 else tail).append(chunk)
return head + list(reversed(tail))
def build_prompt(user_q: str, chunks_sorted_desc: list, system: str) -> str:
laid_out = head_and_tail_layout(chunks_sorted_desc)
retrieval_block = '\n\n'.join(f'[{i+1}] {c.text}' for i, c in enumerate(laid_out))
return (
f'{system}\n\n'
f'User question (for context): {user_q}\n\n'
f'Retrieved evidence:\n{retrieval_block}\n\n'
f'User question (answer this now): {user_q}\n'
)Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Reaching for a bigger model context window or stuffing more chunks instead of restructuring retrieval. Both make the U-curve worse, not better.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.