Dashboard
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
51 small wins to finish your pathNext question →

Q9EasyConcept

How do you choose top-k, and what is the "lost in the middle" problem?

30-second answerSay your answer out loud first, then reveal.

Choosing k

  • Retrieval k vs context k: retrieve 50–100 candidates for reranking, but pass only 3–10 chunks to the LLM.
  • Set it from data: plot recall@k on your eval set. If recall@5 = 0.82 and recall@10 = 0.90, decide whether 8 extra points of recall are worth double the context.
  • Question type: factoid questions need few chunks; summaries and comparisons need many.
  • Dynamic k: use a relevance-score threshold (only include chunks above a reranker score), with min/max bounds.

Mitigating lost-in-the-middle

  1. Rerank so the best chunks come first.
  2. Reorder: place the strongest chunks at the start and end of the context.
  3. Compress: remove irrelevant sentences from chunks (contextual compression).
  4. Fewer, better chunks instead of stuffing.

Modern long-context models have improved on this, but distraction from irrelevant context is still a real effect. Measure it on your own data rather than assuming.

Common mistakes

  • "Just send 50 chunks; the model has a 1M-token window." That costs more, adds latency, and often lowers answer precision.

This is what real progress feels like.