EasyDeepLearn

How do you counter 'lost in the middle' in RAG?

medium

Answer

  • (1) Fewer, better chunks: retrieve top-5 with a reranker instead of stuffing top-20.
  • (2) Reorder retrieved docs so most relevant are at the start / end.
  • (3) Split into multiple LLM calls, each with a small context, then aggregate.
  • (4) 'Attention sink' prompts that summarize the middle.
  • (5) Use models with better long-context tuning (Claude 3, GPT-4.1, Gemini 1.5).
  • Measure with 'needle in a haystack' evaluations across your target context length.
Check yourself — multiple choice
  • Ignore the phenomenon
  • Fewer better chunks (rerank), reorder to edges, split into calls + aggregate, use long-context-tuned models; measure via NIAH
  • Only bigger models
  • Impossible to fix

Fix lost-in-middle: rerank / reorder / split / long-ctx tuned models + NIAH eval.

#rag#long-context

Practise LLMs & GenAI

214 interview questions in this topic.

Related questions