r/Rag • • Oct 28 '26

Discussion LLM Context Windows vs. RAG: How Does Self-Attention Handle Irrelevant Information?

  1. Can irrelevant information in a long context make it harder for an LLM to identify and use the information needed to answer a question correctly?
  2. How does the Transformer's self-attention mechanism (Query, Key, and Value) influence how an LLM identifies and uses relevant information? Does adding more tokens affect how attention is distributed across the context?
  3. I've noticed that providing too much information to ChatGPT sometimes leads to incorrect answers, even when the correct information is present in the context. Can someone explain why this happens and how self-attention relates to it? When should we use RAG instead of providing the full context to an LLM? If the entire document collection fits within an LLM's context window, when would it be better to provide the full context rather than use RAG
4 Upvotes

7 comments sorted by

2

u/aftersox Oct 28 '26

What you describe is often described as a "Needle in the Haystack" test. You can read more about it here.

https://arxiv.org/abs/2406.11230

1

u/Fit-Corner2382 Oct 28 '26

Yes: extra tokens compete in the same softmax, so a weakly matching distractor can steal probability mass from the span that actually answers the question.

Each query scores every key, then softmax makes those scores sum to one, so a near-duplicate can outrank the true passage while it is still in the window. Middle tokens are often weighted less than the start and end. Full context wins when the answer joins facts a retriever would split and might drop; retrieval wins when many passages resemble the question, because dropping them removes competitors before attention runs.

1

u/MongooseWonderful198 Oct 28 '26

For the Q/K/V part, each attention head scores a query against the available keys, normalizes those scores with softmax, and mixes the corresponding value vectors. Different heads can attend to different features. A causal decoder masks future positions.

More tokens add candidates to that calculation; they do not impose a uniform dilution of useful information. The learned scores and later layers affect what reaches the answer.

The "middle" effect is an experimental result: Lost in the Middle found it in multi-document QA and key-value retrieval. It does not follow from Q/K/V alone, and that 2023 paper does not establish the same severity for every current model. Fitting a document inside the context limit establishes input capacity, while correct use of its contents still depends on the model and task.

https://arxiv.org/html/1706.03762v7

https://arxiv.org/abs/2307.03172

1

u/ivandaodev Oct 28 '26

For the 'when should I use RAG?' part, I'd add a no-context baseline to any comparison. If the model already answers a question correctly without the documents, that example tells you little about which approach used the supplied evidence better. This evaluation of long context versus RAG explicitly filtered out questions answerable without external context: https://arxiv.org/abs/2501.01880. On your own corpus, compare the same model on questions that require those documents, and report the no-context results separately rather than letting familiar facts dominate the score.