
Which Documents Did RAG Use? Shapley Source Attribution
How to trace the documents behind a RAG answer with Shapley values, and where it falls short
Tracing which retrieved documents a RAG answer relied on with Shapley values: cheaper approximations, which to choose, and why overlap breaks attribution. RAG source attribution means pointing, with numbers, to which retrieved documents an AI answer actually relied on.
In RAG (retrieval-augmented generation), "source attribution" means pointing, with numbers, to which retrieved documents an AI answer actually relied on. The 2025 paper Source Attribution in Retrieval-Augmented Generation by Nematov et al. carries machine learning's Shapley values over to the document level in RAG, laying out a systematic way to answer this question along with its limits [1]. If GEO, which makes content get cited in AI answers, is a problem on the "sending side," source attribution is about tracing back, on the "receiving side," what was actually used.
RAG first retrieves documents relevant to a question, feeds them into an LLM, and generates an answer grounded in that context. Answer quality improves, but the process is still a black box. If you put in ten documents, it's hard to know which ones actually produced the answer, or whether the documents the retriever fetched helped or got in the way. If you can pinpoint the source documents, user trust goes up, and you can filter out irrelevant documents to improve the retrieval step.
Inside RAG's black box: what produced the answer?
The problem is cost. Traditional attribution techniques need you to run the model many times while tweaking the input bit by bit, and with an LLM, each run is an API call that costs money and time. With n documents, an exact calculation over every subset requires calls, which becomes practically impossible once you go beyond a handful of documents [1].
So the study has three goals: (1) carry established attribution principles over to the document level in RAG, (2) measure how well cheap approximations reproduce exact attribution, and (3) check whether they actually hold up in hard situations where documents are tangled together through redundancy, complementarity, or synergy [1].
How Shapley values split contribution
The core idea is to treat each document as a "player in a cooperative game." The Shapley value of document in document set is the weighted average of the utility gained by adding to every possible subset [3][4].
The key is how you define the payoff, that is, the utility. The paper defines the utility of document subset as the log-likelihood that the LLM, given only query and , generates the original full-context answer . It's the sum of each token's log probability under teacher forcing [1][2].
The more plausible the original answer becomes when a given bundle of documents is present, the higher that bundle's utility. This definition is what lets existing attribution techniques like SHAP and ContextCite plug straight into RAG [1][2].
Alongside exact Shapley, the methods compared are TMC-Shapley, Beta-Shapley, Kernel SHAP, ContextCite, and the simplest one, LOO (leave-one-out). The models are LLaMA-3.2-8B, Mistral-7B, and Qwen-3B, and the datasets are BioASQ, Natural Questions, and synthetic scenarios the paper built itself [1].
Experiment 1. Can cheap methods stand in for expensive Shapley?
The first experiment measures how faithfully cheap approximations reproduce the exact Shapley ranking, using Pearson correlation, Kendall's Tau, and Precision@k.

Figure 1. How accurately each approximation reproduces Shapley values by sample size (32, 64, 100).
The results are clear. Kernel SHAP was the most accurate on most metrics, with ContextCite close behind. Both methods train a simple surrogate linear model, so as the sample grows from 32 to 64 to 100, performance rises monotonically and Pearson correlation goes above 0.95. By contrast, TMC-Shapley, Beta-Shapley, and LOO fell noticeably behind [1]. Precision@1, which picks out the single most important document, mostly stayed above 0.8, showing that even cheap methods identify the key evidence well [1].
Experiment 2. Picking out the most influential documents
The second experiment looks at how well each method finds the top k documents whose removal "breaks the answer the most." Measured with Precision@k, exact Shapley was, as expected, the highest or close to it, and Kernel SHAP and ContextCite found them about as well. That's because the linear model respects the additivity axiom [1]. Still, every method had some flaws left, and their cause is the topic of the next experiment: dependencies between documents.
Experiment 3. When documents get tangled, it breaks down
The really interesting part is when documents relate to each other. The paper designed three situations with synthetic data. The scenarios use nonexistent places and people so the answers can't leak in from prior knowledge [1].
Figure 2. Three ways documents get tangled: redundancy, complementarity, and synergy.
The first is redundancy. This is when two documents carry essentially the same information, so either one can answer the question.

Figure 3. Redundancy scenario. Even when the order is swapped, the document in front gets higher attribution.
This is where position bias shows up. The redundant document placed first consistently gets a higher score, and if you swap the two documents, the bias flips with them. The content is the same, yet position alone splits the score [1].
The second, complementarity, is when each document provides a different piece and the two must be combined for a complete answer. In this situation, every method found both documents well. But one issue remains: utility values alone make it hard to tell redundancy and complementarity apart, because in both cases one document comes out high and the other slightly lower [1].
The third, synergy (multi-step reasoning), is when you have to draw a fact from one document and then complete the answer with another.

Figure 4. Synergy scenario. Only the document containing the direct answer is rated highly, and the document needed for synthesis is undervalued.
Here, every method piled the score onto the document containing the direct answer and undervalued the other document that was essential for synthesizing the answer. Swapping the order didn't change it, since the same document kept getting the high score, so it wasn't a position effect either. When you normalize and average the scores of documents A and B across all questions, "B," which contains the answer, comes out systematically far higher than "A," which is needed for synthesis [1].

Figure 5. Average normalized attribution scores for synergy documents A and B across three models. The document needed for synthesis is consistently suppressed.
Limitations of this method
To sum up, with a tailored utility function on top, RAG source attribution works quite well even cheaply, but its boundaries are also clear [1].
- Non-additivity: Utility (log-likelihood) isn't additive, so Shapley's theoretical guarantees don't fully hold.
- Position bias: Even with the same content, documents placed first are overvalued.
- Relationship confusion: Utility alone makes it hard to tell redundancy from complementarity.
- Undervalued synthesis: In multi-step reasoning, documents needed for synthesis are systematically suppressed.
The TRAIL view: measurement and design go together
The question this study raises touches the problems we deal with every day. In AEO and GEO, too, you ultimately need to know "which sources did the AI rely on to produce this answer," and TRAIL Search tracks exactly those citation and source signals. The paper's lesson is clear. If you look only at a single attribution score, position bias or undervaluation can fool you, so you need to read the relationships between documents as well.
If GEO and FeatGEO, which design content to be cited, are about "what to include," source attribution is a lens pointing the other way, tracing back "what was actually used." To really know what an AI based its answer on, you need one more step: interpreting the interactions among the documents that scored highly.
You can continue with Why RAG misses the evidence an answer needs, Is agent memory better than RAG over the raw conversation?, and The world model that teaches a robot from video.
Frequently asked questions
Why does RAG source attribution matter?
Because you need to know which retrieved documents an AI answer actually relied on before you can trust it, debug it, or improve retrieval quality. Even if an answer sounds plausible, a pipeline that pulled it from the wrong document can go wrong at any time. This paper covers how to point to those source documents with numbers.
What is a Shapley value?
It's a fair-allocation concept from cooperative game theory. It splits the total contribution (the answer) by how much each participant (document) produced, as its average contribution across every possible combination. In effect, it gives each document a single score for how much it helped produce the answer.
What's the most accurate method that's also cheap?
In the paper's experiments, Kernel SHAP was the most accurate, with ContextCite close behind. Both train a surrogate linear model that reproduces the exact Shapley values almost exactly while sharply cutting the number of LLM calls.
Can I trust every source this method points to?
No. When documents are tangled together through redundancy, complementarity, or synergy, the scores get distorted. In particular, there's a position bias where earlier documents get higher scores, and when an answer requires combining several documents, one of them gets undervalued. Don't look only at the scores; interpret the relationships between documents too.
References
- [1]Nematov et al., "Source Attribution in Retrieval-Augmented Generation", arXiv:2507.04480 (2025)
- [2]Cohen-Wang et al., "ContextCite: Attributing Model Generation to Context", NeurIPS 2024
- [3]Lundberg & Lee, "A Unified Approach to Interpreting Model Predictions (SHAP)", NeurIPS 2017
- [4]Ghorbani & Zou, "Data Shapley", ICML 2019
- [5]Experiment and implementation code (iNema9590/LLMX)
Summary
- RAG source attribution means pointing, with numbers, to which retrieved documents an AI answer actually relied on.
- Each document's contribution is split with Shapley values, and utility is defined as the log-likelihood of the original answer.
- Expensive Shapley values can be reproduced almost exactly, and far more cheaply, with surrogate models like Kernel SHAP and ContextCite, which were also precise at picking out the most important document.
- But when documents are tangled through redundancy, complementarity, or synergy, position bias and undervaluation appear, so scores alone aren't enough; you need to interpret the relationships.
Check this topic against your own brand
TRAIL Search measures how ChatGPT and Perplexity answer your customers' questions and finds and fixes where the brand is missing, turning this post into a diagnosis. Start with 10 questions, no card required.
More posts

Cutting LLM agent costs: delegate decisions to a 4B model
Cutting LLM agent costs: delegating choices to a small decision model saved 81 to 89 percent, but only with thresholds fitted on the agent's own runs.

How to build a small LLM: Sheared-LLaMA's 3% compute path
How to build a small LLM, what LLM pruning is, whether small models are enough for AI agents, and the cost of building one, read through Sheared-LLaMA.

The world model that teaches a robot from video: V-JEPA 2
Whether you can teach a robot from video alone, what an AI world model is, and how it differs from a video generator, read through Meta's V-JEPA 2 paper.
Keep reading on this topic
- Does AI search use your exact question? 70,000 queries showHow AI search turns a question into queries, why uncited pages are not irrelevant, and what retrievers miss, from Perplexity's Q2D-Web benchmark paper.
- Is agent memory better than RAG over the raw conversation?A 2026 UIUC study of why agent memory systems trail RAG over raw history, what LLM summaries lose, and how a path back to the source cuts the loss.
- Why RAG misses the evidence an answer needsA 2026 MBZUAI study of why RAG retrieves only part of the evidence multi-fact questions need and how chunking erases document identity.
This post is part of the Papers category, which collects all 36 posts on the topic. See all posts in Papers