Abstract
Retrieval-Augmented Generation (RAG) enhances Large Language Model (LLM) accuracy by providing external context, yet identifying which specific segments influence model outputs remains a challenge. We present CAMAB (Context Attribution with Multi-Armed Bandit), a framework that treats attribution as a combinatorial optimization problem. By employing Combinatorial Thompson Sampling, CAMAB adaptively identifies influential context segments with high query efficiency. Our evaluations on SST-2 and HotpotQA benchmarks demonstrate that CAMAB achieves state-of-the-art attribution fidelity while significantly reducing the computational overhead compared to traditional methods like SHAP.
Introduction
While RAG systems are widely deployed to mitigate hallucinations and provide up-to-date information, LLMs remain "black boxes." Understanding which sentence or paragraph in a lengthy document led to a specific answer is crucial for interpretability and debugging. Current post-hoc attribution methods, such as SHAP or LIME, rely on systematic perturbations of the context. However, the astronomical number of possible context combinations makes these methods prohibitively slow and expensive for real-world, long-context applications.
Methodology
The CAMAB framework addresses the efficiency bottleneck by reframing context attribution as a multi-armed bandit problem.
The Bandit Framework
Each segment of the context (e.g., a sentence or paragraph) is treated as an individual "bandit arm." Selecting a subset of these segments to present to the model constitutes a "combinatorial action."
Combinatorial Thompson Sampling (CTS)
Unlike uniform sampling methods, CAMAB maintains a posterior distribution (a "belief") regarding the importance of each segment. In each iteration, the algorithm samples from this distribution to select the most promising segments for testing. This adaptive approach focuses the limited query budget on segments that significantly impact the model's output, avoiding wasted computation on irrelevant text.
Normalized Reward Function
To isolate the contribution of specific context segments, CAMAB utilizes a reward function based on normalized token likelihoods. By subtracting the model's "intrinsic" probability (the likelihood of the answer without any context), the system precisely measures the marginal utility of the selected segments.
Experimental Setup
The researchers evaluated CAMAB against two primary benchmarks:
- SST-2: A sentiment classification task used to assess attribution in high-precision, short-context scenarios.
- HotpotQA: A multi-hop question-answering benchmark that serves as a stress test for complex reasoning across multiple documents.
The framework was tested using two models of varying scales: the LLaMA3-8B and the lightweight SmolLM-1.7B.
Results
CAMAB consistently demonstrates superior efficiency and fidelity across both models and datasets.
As shown in Table 1, for the LLaMA3-8B model, CAMAB matches or exceeds the performance of state-of-the-art methods like ContextCite and SHAP. Notably, on the HotpotQA dataset, CAMAB achieves the lowest BERTScore (where lower is better), indicating it successfully identifies the most critical segments whose removal would most drastically alter the semantic meaning of the answer.
Table 2 illustrates performance on the smaller SmolLM-1.7B model. The significantly higher Log-Prob Drop values compared to the larger model confirm that smaller models are more sensitive to context perturbations. Despite this increased noise, CAMAB maintains high fidelity, outperforming competitors in identifying key context segments.
Conclusion
CAMAB offers a practical and efficient solution for context attribution in RAG systems. By leveraging bandit optimization, it overcomes the computational barriers of traditional post-hoc methods. Future work may explore incorporating internal model gradients to further accelerate the attribution process and developing more sophisticated reward signals to handle highly ambiguous or noisy contexts.
Summary updated