                                                             Eliciting In-context Retrieval and Reasoning for
                                                                  Long-context Large Language Models

                                                                  Yifu Qiu1 * , Varun Embar2 , Yizhe Zhang2 ,
                                                               Navdeep Jaitly2 , Shay B. Cohen1 , Benjamin Han2
                                                                       1
                                                                         University of Edinburgh, 2 Apple
                                                                      {yifu.qiu, scohen}@ed.ac.uk ,
                                                          {v_embar, yizhe_zhang, njaitly, ben.b.han}@apple.com


                                                               Abstract                              as agent trajectory modeling and planning (Zhao
                                                                                                     et al., 2024; Zhang et al., 2024b), video captioning
                                            Recent advancements in long-context lan-                 (Xue et al., 2024; Zhang et al., 2023), and text-to-
arXiv:2501.08248v3 [cs.CL] 9 Jun 2025




                                            guage models (LCLMs) promise to transform                video generation (Wang et al., 2024b; Lin et al.,
                                            Retrieval-Augmented Generation (RAG) by
                                                                                                     2023). Recent advancements in long-context lan-
                                            simplifying pipelines. With their expanded
                                            context windows, LCLMs can process entire                guage models (LCLMs) hold particular promise
                                            knowledge bases and perform retrieval and rea-           for reshaping the Retrieval-Augmented Generation
                                            soning directly – a capability we define as              (RAG) paradigm (Lee et al., 2024; Li et al., 2024).
                                            In-Context Retrieval and Reasoning (ICR2 ).              With their expanded context windows, LCLMs re-
                                            However, existing benchmarks like LOFT of-               duce reliance on complex pipelines required by
                                            ten overestimate LCLM performance by pro-                context-length limitations and simplify knowledge
                                            viding overly simplified contexts. To address
                                                                                                     updates by allowing context modifications. For
                                            this, we introduce ICR2 , a benchmark that
                                            evaluates LCLMs in more realistic scenarios              instance, LCLMs can accommodate entire knowl-
                                            by including confounding passages retrieved              edge bases within the context windows, effectively
                                            with strong retrievers. We then propose three            serving as working memory for new queries.
                                            methods to enhance LCLM performance: (1)                    Achieving this goal requires LCLMs to effec-
                                            retrieve-then-generate fine-tuning, (2) retrieval-       tively retrieve and reason within their “contextual
                                            attention-probing, which uses attention heads            knowledge base,” a capability we define as In-
                                            to filter and de-noise long contexts during de-          Context Retrieval and Reasoning (ICR2 ). How-
                                            coding, and (3) joint retrieval head training
                                                                                                     ever, existing benchmarks often fail to accurately
                                            alongside the generation head. Our evalua-
                                            tion of five well-known LCLMs on LOFT and                evaluate this capability. For example, Needle-in-a-
                                            ICR2 demonstrates significant gains with our             Haystack (NIAH; Kamradt 2023) is a popular test
                                            best approach applied to Mistral-7B: +17 and             to determine whether a model can retrieve a “nee-
                                            +15 points by Exact Match on LOFT, and +13               dle” (a specific fact or statement) randomly inserted
                                            and +2 points on ICR2 , compared to vanilla              into a “haystack” (a corpus). Yet, the semantic dis-
                                            RAG and supervised fine-tuning, respectively.            continuity between the needle and the haystack can
                                            It even outperforms GPT-4-Turbo on most tasks
                                                                                                     unintentionally reveal the needle’s location, mak-
                                            despite being a much smaller model. 1
                                                                                                     ing the task overly simple. LOFT (Lee et al., 2024),
                                        1       Introduction                                         the first large-scale benchmark for evaluating re-
                                                                                                     trieval and reasoning within contextual knowledge
                                        The ability of large language models to process              bases, uses human-annotated relevant documents
                                        long contexts has significantly expanded their ap-           as the needle, and fills the haystack with randomly
                                        plicability across various domains, including book-          sampled documents from an external knowledge
                                        level information retrieval (Ding et al., 2024; Jin          base. However, this random sampling results in a
                                        et al., 2024), summarization (Kim et al., 2024;              context with virtually no confounding information
                                        Saxena and Keller, 2024; Qiu et al., 2023), and              that is relevant but misleading, causing LOFT to
                                        question answering (Liu et al., 2024; Wang et al.,           significantly overestimate LCLM performance.
                                        2024a). They also enable more complex tasks, such               To bridge this evaluation gap, we introduce ICR2 ,
                                            *
                                                                                                     a novel and challenging benchmark designed to as-
                                             Work done while the author was an intern at Apple.
                                            1
                                            Our code and datasets are available at https://github.   sess LCLMs under more realistic conditions. ICR2
                                        com/apple/ml-icr2.                                           builds upon KILT (Petroni et al., 2021), a compre-
hensive knowledge base sourced from Wikipedia.               retrieval and reasoning capabilities of long-
Unlike LOFT, which relies on random sampling,                context language models (LCLMs), demon-
ICR2 uses strong retrievers to select challenging            strating that existing benchmarks overestimate
confounding documents, creating a more difficult             model performance.
“haystack.” Experimental results reveal that current
LCLMs struggle on ICR2 , with exact match rates            • We explore three novel methods to enhance
dropping by up to 51% compared to evaluations on             LCLMs ranging from supervised fine-tuning,
LOFT. These findings underscore the significant              inference-time approach, to model architec-
challenges LCLMs face in accurately performing               ture modification.
in-context retrieval in realistic scenarios.               • Our best approach, applied to a small LCLM,
   We next explore improving LCLMs’ in-context               tightens the performance gap with the Oracle
retrieval and reasoning capabilities. While RAG              RAG while beating the other baselines. It even
demonstrates strong results, it remains hindered             matches GPT-4 on both in-domain (ICR2 )
by complex multi-stage pipelines. Encouraged by              and out-of-domain benchmarks (LOFT), al-
recent studies such as LLM2Vec (BehnamGhader                 beit with a much smaller model size.
et al., 2024; Ma et al., 2024) showing that LCLMs
can be effectively adapted for accurate retrieval      2     Related Work
tasks, offering a more natural approach by enabling
                                                       Long-context large language models (LCLMs)
joint optimization of both retrieval and generation
                                                       have garnered significant attention for their ability
steps, we propose three approaches: (1) Retrieve-
                                                       to process extended sequences. Models like Long-
then-generate fine-tuning: Inspired by the distil-
                                                       former (Beltagy et al., 2020) and BigBird (Zaheer
lation of step-by-step reasoning abilities (Shridhar
                                                       et al., 2020) introduced sparse attention mecha-
et al., 2023; Hsieh et al., 2023), we train LCLMs
                                                       nisms to efficiently handle long context. Scaling ef-
to frame tasks as two-hop reasoning chains. In this
                                                       forts, exemplified by GPT-4 (Achiam et al., 2023),
formulation, LCLMs first retrieve relevant informa-
                                                       underscore the importance of expanding context
tion from the context and then generate the final
                                                       windows for the long-context tasks. Data engineer-
responses. (2) Retrieval-attention probing: At
                                                       ing methods (Fu et al., 2024; Xiong et al., 2024; Jin
inference time, we probe attention heads activated
                                                       et al., 2024), expanding positional encoding (Ding
for in-context retrieval (Wu et al., 2024) and use
                                                       et al., 2024), and the parameter-efficient fine-tuning
their top predictions to filter out confounders from
                                                       (Chen et al., 2024) have been effective.
lengthy contexts. (3) Joint retrieval head training:
                                                          LCLMs hold the promise in reshaping RAG
We introduce an architectural modification to equip
                                                       (Achiam et al. 2023; Jiang et al. 2023; Yang et al.
LCLMs with a dedicated retrieval head, enabling
                                                       2024; Abdin et al. 2024). By replacing static
joint optimization of retrieval and generation.
                                                       knowledge bases with the contextual one, this new
   We conduct extensive experiments using five         paradigm simplifies the deployment by discarding
LCLMs on both LOFT and our ICR2 benchmark.             intermediate components while enabling the direct
We compare our methods against baselines includ-       updates on LCLM’s knowledge (Lee et al., 2024).
ing Vanilla RAG, Closed-book, Oracle RAG, and             Unlike the existing works, we systematically
supervised fine-tuning (SFT). Notably, our best ap-    evaluate the use of LCLMs for scenarios where
proach, applied to Mistral-7B with a 32K token         knowledge bases are directly placed as the context
limit, has the best performance across the tasks. It   with a novel benchmark, ICR2 . ICR2 is different
outperforms Vanilla RAG and SFT baselines by an        with the popular long-context benchmark such as
average of +17 and +15 points measured by Ex-          (Bai et al., 2024) by emphasizing in the contex-
act Match on LOFT, and by +13 and +2 points on         tual confounders. We also show that with targeted
ICR2 , respectively. The approach achieves perfor-     enhancements, small-scale LCLMs can achieve per-
mance comparable to the state-of-the-art GPT-4,        formance comparable to state-of-the-art models.
despite using only 7B parameters. We also provide
in-depth analyses of our approaches.                   3     Are LCLMs Competent for RAG?
   Our key contributions are as follows:
                                                       3.1    LLMs Are Sensitive to the Confounders
   • We introduce ICR2 , a realistic and challeng-     LOFT (Lee et al., 2024) introduces a Corpus-in-
     ing benchmark for evaluating the in-context       Context (CiC) approach for retrieval-augmented
                                                     NaturalQuestions                                        HotpotQA                                                      FEVER                                                      WoW
                                                                                                                                                                                                          0.20
                                   0.9                                   Phi-7B          0.9                                   Phi-7B          0.9                                                                                                    Phi-7B
                                                                         Qwen-2-1.5B                                           Qwen-2-1.5B                                                                                                            Qwen-2-1.5B
                                                                         Qwen-2-7B                                             Qwen-2-7B                                                                  0.18                                        Qwen-2-7B
                                   0.8                                   Mistral-2-7B    0.8                                   Mistral-2-7B    0.8                                                                                                    Mistral-2-7B
                                                                         LLaMA-3-8B                                            LLaMA-3-8B                                                                                                             LLaMA-3-8B



           Task Specific Metrics
                                   0.7                                   GPT-4           0.7                                   GPT-4           0.7                                                        0.16                                        GPT-4

                                   0.6                                                   0.6                                                   0.6
                                                                                                                                                            Phi-7B                                        0.14
                                   0.5                                                   0.5                                                   0.5          Qwen-2-1.5B
                                                                                                                                                            Qwen-2-7B
                                                                                                                                                            Mistral-2-7B                                  0.12
                                   0.4                                                   0.4                                                   0.4          LLaMA-3-8B
                                                                                                                                                            GPT-4
                                   0.3                                                   0.3                                                   0.3                                                        0.10
                                         0.0   0.2     0.4       0.6     0.8       1.0         0.0   0.2     0.4       0.6     0.8       1.0          0.0     0.2       0.4       0.6       0.8   1.0            0.0      0.2      0.4       0.6       0.8      1.0
                                                     Confounding Ratio                                     Confounding Ratio                                          Confounding Ratio                                          Confounding Ratio



Figure 1: Task-specific performance of five LCLMs on 32K ICR2 test sets with varying confounding ratios. For all
tasks, a higher value of task-specific metric indicates a better performance.

generation, integrating a large-scale external knowl-                                                                                                Corpus: {
                                                                                                                                                        PSG001: {p_1},
                                                                                                                                                                                                   Indexing
                                                                                                                                                                                                                           Relevant
                                                                                                                                                        PSG002: {p_2},                                                     Context
                                                                                                                                                                                   KILT
edge base directly into the LLM’s context. How-                                                                                                         PSG002: {p_3},
                                                                                                                                                        …
                                                                                                                                                                                 Knowledge
                                                                                                                                                                                   Base
                                                                                                                                                                                                                                                                              -
                                                                                                                                                     }
ever, LOFT operates under the assumption that                                                                                                                                                                          Filtering
                                                                                                                                                                                                                                                     Merge & Shuf e
                                                                                                                                                                                                                                                                             +

                                                                                                                                                                                                                                                                              -

the context is free of confounders. In practice, a                                                                                                                                Contriever                                                                                  -

                                                                                                                                                                                                                                                                              -
corpus often contains confounders – documents                                                                                                          Query:
                                                                                                                                                       When is
                                                                                                                                                                                     DPR

                                                                                                                                                                                     DrQA
                                                                                                                                                                                                        Retrieving

                                                                                                                                                       Barry’s                                                                                               Confounding   ICR2
                                                                                                                                                                                                                                                               Context
related to the query but potentially leading to incor-                                                                                                 birthday?                     BM25
                                                                                                                                                                                                                                Retrieved
                                                                                                                                                                                                                                 Context
                                                                                                                                                                                                                                                                           Contextual
                                                                                                                                                                                                                                                                           Corpus
                                                                                                                                                                                    BLINK
rect answers. For example, given the query “Who
is the 44th U.S. President?”, the corpus might in-                                                                                               Figure 2: Construction pipeline for ICR2 . Based on
clude documents about the other presidents, such as                                                                                              KILT, we use five strong retrievers to retrieve con-
“The 45th U.S. President is Donald Trump”, which                                                                                                 founders to serve as the “haystack”, while the human-
could mislead the LLM. Consequently, LOFT’s de-                                                                                                  annotated contexts are used as the “needle”.
sign reduces the complexities of using real-world
corpora for RAG, potentially overestimating the                                                                                                  making them particularly difficult for LCLMs to
performance of LCLMs.                                                                                                                            handle. Consequently, benchmarks like LOFT that
                                                                                                                                                 overlook these “strong” confounders risk overes-
   We show that LCLMs are indeed sensitive to                                                                                                    timating
                                                                                                                                                      fl  model performance, as confounders are
the confounders missed in LOFT. We construct                                                                                                     prevalent in real-world scenarios.
multiple test sets with varying confounding ratios
– t0, 25%, 50%, 75%, 100%u – and evaluate the                                                                                                    3.2                ICR2 Benchmark
LCLMs under zero-shot settings. The confound-                                                                                                    To address this limitation, we propose an alternative
ing ratio p denotes the proportion of confounding                                                                                                benchmark, ICR2 , which leverages strong retriev-
context that are selected by retrievers while filter-                                                                                            ers to identify and incorporate these confounders
ing out the gold provenance, with the remaining,                                                                                                 into the contextual corpus used in CiC, providing
i.e., p100% ´ pq, randomly sampled from an ex-                                                                                                   a more realistic and challenging evaluation frame-
ternal knowledge base. At p “ 0, all confounding                                                                                                 work. We choose KILT (Petroni et al., 2021), a
passages in the contextual knowledge base are ran-                                                                                               comprehensive suite of benchmarks designed for
domly sampled, equivalent to the setup in LOFT                                                                                                   knowledge-intensive NLP tasks, to be our exter-
(Lee et al., 2024). Conversely, at p “ 1, all con-                                                                                               nal knowledge base (Figure 2). KILT covers tasks
founders are selected by the retrievers.                                                                                                         such as question answering (Kwiatkowski et al.,
   We evaluate five LCLMs with a context length of                                                                                               2019; Yang et al., 2018), fact verification (Thorne
at least 32K tokens: Phi-3-7B (Abdin et al., 2024),                                                                                              et al., 2018), and dialogue completion (Dinan et al.,
Qwen-2-1.5B/7B (Yang et al., 2024), Mistral-003-                                                                                                 2018), all paired with a single Wikipedia snap-
7B (Jiang et al., 2023), LLaMA-3-Instruct-8B                                                                                                     shot. Each KILT instance xq, a, P ` y consists of
(Dubey et al., 2024) and GPT-4-Turbo (Achiam                                                                                                     a query q, the reference answer a, and its prove-
et al., 2023). Our findings in Figure 1, demonstrates                                                                                            nances P ` “ tp1 , . . . , pm u, which is a set of rele-
that LCLM performance is highly sensitive to con-                                                                                                vant Wikipedia pages and specific locations within
founders, with performance generally degrading                                                                                                   them that support the answer.
as the confounding ratio increases. This indicates                                                                                                  Building on KILT, each ICR2 instance is rep-
that confounders in P ´ obtained via retrievers, as                                                                                              resented as xq, a, Cy, where q and a is a query-
in ICR2 , pose greater challenges for the models                                                                                                 answer pair from KILT, and C is the contextual
compared to those randomly sampled in LOFT.                                                                                                      knowledge base required to answer the query.
These retriever-selected passages are relevant to                                                                                                At test time, a standardized prompt template,
the queries but fail to lead to the correct answers,                                                                                             rag_promptrCs, is applied to the context, and the
Query:                                                            using the same process as above. For all retrievers,
Where are the giant redwoods located in California?               we exclude retrieved passages overlapping with
Reference Answer:                                                 P ` or containing exact substring matches with a,
Humboldt County
                                                                  and the remaining passages are collected to form
Contextual Knowledge Base:                                        the confounding provenance set, P ´ . The contex-
ID: PSG001
Title: 2010–11 California Golden Bears Men’s Basketball           tual corpus C is then constructed by concatenat-
Team                                                              ing P ` with P ´ up to the maximum length, i.e.,
Context: The 2010–11 California Golden Bears men’s bas-
ketball team represented the University of California, Berkeley
                                                                  C “ rP ` ; P ´ s. Finally, we shuffle all items in C
in the 2010–11 NCAA Division I men’s basketball season.           to remove position bias.
ID: PSG002                                                           Table 7 compares statistics between LOFT and
Title: Redwood National and State Parks                           our benchmark ICR2 . An example of an ICR2 in-
Context: Scenes set on the forest moon Endor in Star Wars
were filmed in the Tall Trees Redwood Grove in the northern       stance is provided in Table 1, and the rag_prompt
part of Humboldt County, though the majority of filming was       template used is detailed in Table 8 in Appendix B.
in private and public forests near the town of Smith River ...
... [90 context are omitted for the simplicity] ...               3.3    State of LCLMs Performance on ICR2
ID: PSG100                                                        We evaluate five LCLMs that support 32K or longer
Title: Malibu Grand Prix
Context: ... and San Antonio, Texas. Palace operates addi-        context length using LOFT (Lee et al., 2024) and
tional locations in Los Angeles, California and Dallas, Texas.    ICR2 benchmarks, with each one tested with in-
The Redwood City, CA location closed on August 18, 2013           put up to 32K tokens. We include three baselines
and the San Antonio location closed on September 7, 2015.
                                                                  for comparison: (1) Vanilla RAG, where the CiC
Table 1: An example ICR2 instance. We show the query              prompt from Lee et al. (2024) is used; (2) Closed-
with the reference answer, and the constructed contex-            book, where the entire context (C) is removed to
tual knowledge base. We highlight the true provenance             evaluate LCLM performance based solely on para-
in blue and the confounding passages in red.                      metric knowledge; and (3) Oracle RAG, which
                                                                  includes only the ground-truth relevant contexts
                                                                  Z ˚ in C to estimate an upper-bound performance.
result is sent to an LCLM to generate the final                      Table 2 presents our results. Overall, we observe
answer for evaluation. To construct C, we first                   that the Vanilla RAG significantly outperforms the
include all provenances P ` from KILT as the posi-                closed-book baseline for most models, except for
tive passages. For confounder P ´ , unlike LOFT’s                 Qwen-2-1.5B on the WoW dataset. This trend per-
random sampling approach, we run five strong re-                  sists even with the state-of-the-art GPT-4-Turbo,
trievers on queries formed by concatenating q with                suggesting that external knowledge remains cru-
a to select Top-K results as the confounding pas-                 cial for knowledge-intensive tasks despite the large
sages to be included in C.                                        parametric capacity of LCLMs. Furthermore, RAG
   We show the pipeline for ICR2 creation in Fig-                 performance on ICR2 lags notably behind that on
ure 2. To eliminate bias in the retrievers’ pref-                 LOFT, reflecting ICR2 ’s greater complexity due to
erences during the construction process, we pool                  its more realistic context construction. Lastly, the
the Top-K predictions from all retrievers and uni-                large performance gap between RAG and Oracle se-
formly sample passages from top to bottom until                   tups on both benchmarks underscores the impact of
reaching the maximum allowable size for the con-                  confounding information, which hampers accurate
textual knowledge base. The retrievers used in-                   retrieval and response generation in LCLMs.
clude Contriever (Izacard et al.), DPR (Karpukhin
et al., 2020), DrQA (Chen et al., 2017), BM25                     4     Eliciting ICR2 for LLMs
(Robertson and Jones, 1976; Robertson et al.,
2009), and BLINK (Wu et al., 2020). For passage-                  4.1    Retrieve-then-generate Fine-tuning
level retrievers such as Contriever, BM25, and                    Compared to the standard supervised fine-tuning
DPR, as input we chunk all documents in KILT’s                    where a model is asked to generate a Direct Answer
knowledge base and exclude passages overlapping                   (DA) to a given query, our first proposal, retrieve-
with any annotated provenance in P ` . We also                    then-generate, is a two-step process: the model
set K “ 200 for the 32K version of ICR2 . For                     first retrieves relevant passages from context and
document-level retrievers like DrQA and BLINK,                    then generates the final answer based on the context
we set K “ 20, and chunk retrieved documents                      and retrieved passages, all in one decoding pass.
                                                   LOFT                                        ICR2
                                                                                                                        All
                                   NQ     HotpotQA    MUSIQUE      Avg       NQ     HotpotQA   FEVER      WoW    Avg
           Closed-book
           Qwen-2-1.5B-32K         0.21     0.22          0.03     0.15      0.29     0.24       0.62     0.15   0.32   0.25
           Qwen-2-7B-32K           0.31     0.30          0.07     0.23      0.35     0.30       0.71     0.15   0.38   0.31
           Mistral-2-7B-32K        0.46     0.38          0.05     0.30      0.49     0.38       0.73     0.14   0.43   0.38
           Phi-3-7B-128K           0.39     0.35          0.09     0.28      0.46     0.32       0.73     0.13   0.41   0.35
           LLaMA-3-instruct-8B     0.41     0.19          0.01     0.20      0.44     0.19       0.53     0.14   0.32   0.27
           GPT-4-turbo             0.58     0.57          0.28     0.48      0.61     0.50       0.85     0.16   0.53   0.51
           Vanilla RAG
           Qwen-2-1.5B-32K         0.61     0.43          0.12     0.39      0.35     0.32       0.78     0.12   0.39   0.39
           Qwen-2-7B-32K           0.79     0.61          0.29     0.56      0.57     0.47       0.88     0.13   0.51   0.53
           Mistral-2-7B-32K        0.64     0.62          0.27     0.51      0.53     0.50       0.81     0.13   0.49   0.50
           Phi-3-7B-128K           0.76     0.68          0.41     0.62      0.60     0.50       0.90     0.14   0.53   0.57
           LLaMA-3-instruct-8B     0.45     0.56          0.16     0.39      0.53     0.45       0.83     0.15   0.49   0.45
           GPT-4-turbo             0.85     0.78          0.51     0.71      0.67     0.64       0.92     0.15   0.59   0.65
           Oracle RAG
           Qwen-2-1.5B-32K         0.80     0.76          0.44     0.67      0.77     0.65       0.86     0.15   0.61   0.63
           Qwen-2-7B-32K           0.88     0.81          0.56     0.75      0.83     0.80       0.91     0.17   0.68   0.71
           Mistral-2-7B-32K        0.89     0.81          0.41     0.70      0.83     0.81       0.94     0.18   0.69   0.70
           Phi-3-7B-128K           0.90     0.85          0.63     0.79      0.87     0.81       0.91     0.14   0.68   0.73
           LLaMA-3-instruct-8B     0.81     0.77          0.60     0.73      0.80     0.74       0.86     0.19   0.65   0.68
           GPT-4-turbo             0.88     0.87          0.72     0.82      0.79     0.82       0.94     0.18   0.68   0.74

Table 2: Performance evaluation of six LCLMs on LOFT and ICR2 benchmarks. All models benefit from the Vanilla
RAG approach, but a gap remains between vanilla and oracle RAG performance.

Formally, we train an LCLM to optimize,                                4.2     Retrieval Attention Probing
                     ÿ                                                 Our second proposal, Retrieval Attention Probing
   ppy | q, cq “            ppy | q, c, zi qppzi | q, cq, (1)          (RAP), is an inference-time approach compatible
                    zi PZ                                              with LCLMs without requiring re-training. Build-
                                                                       ing on Wu et al.’s findings that specific attention
where q, y is the query and target, respectively, c                    heads are highly active during retrieval tasks (e.g.,
is the contextual knowledge base, and Z is the                         NIAH), RAP utilizes these retrieval-focused atten-
collection of all relevant passages necessary for an-                  tion heads for context filtering before generating
swering q. This objective can be easily integrated                     responses. For each attention head h and query
into the next-token prediction task trained with the                   q, we track the Top-M attention scores AM     h pqq.
maximum likelihood estimation, just by sequen-                         ChM pqq, representing the M passages correspond-
tially executing the retrieval and generation in a                     ing to AMh pqq, are then selected, and the hit rate
single forward pass. The overall loss is given as                      for head h is calculated as follows:
                                                                                                      N
         N
                                                                                               1 ÿ |ChM pqq X Z ˚ pqq|
       1 ÿ                                                                     HitRateh “                              ,       (3)
L“             plog ppZi˚ |qi , ci q ` log ppyi˚ |Zi˚ , qi , ci qq ,                           N i“1    |Z ˚ pqq|
      N i“1
                                                           (2)         where N is the number of validation samples, and
where N is the number of training samples, and                         Z ˚ pqq is the set of all relevant contexts given query
Zi˚ “ tzi,1
          ˚ , z˚ , . . . , z˚
               i,2          i,|Zi˚ |
                                     u is the collection of all        q. Finally we select Q heads with the top hit rates
relevant passages for the query qi and contextual                      to be the retrieval heads as follows,
knowledge base ci .                                                                                       ÿ
                                                                            Hret “        arg max             HitRateh , (4)
   We use two variants of retrieve-then-generate                                      HĎt1,...,Hu,|Hret |“Q hPH
fine-tuning, both using the special tokens
<RETRIEVAL> and </RETRIEVAL> to delineate the                          where H is the number of attention heads, and Hret
retrieval step. In the first, Retrieve-Then-Answer                     is the set of Q attention heads with the top hit rates
(RTA), the model copies relevant passages. In the                      selected as the retrieval heads for context filtering.
second, Cite-Context-ID (CCI), the model gener-                           Note that our definition of retrieval heads dif-
ates only the IDs of the relevant passages. Figure 8                   fers from (Wu et al., 2024) in two key ways: (1)
shows the templates for all variations.                                Instead of focusing solely on the Top-1 passages,
we allow each head to retain the Top-M , which               S “ t. . . si . . . u, we can finally identify the indices
is particularly important for multi-hop reasoning            T of the selected passages as the ones that receive
tasks requiring multiple passages for reasoning. (2)         the top K scores,
We evaluate attention heads using the retrieval hit
rate, a more direct metric for our downstream tasks.                           T “ TopKpS, Kq.
   During inference, we union all passages selected
by all retrieval heads, Hret ,                               We then set the binary mask M for filtering the
                     ď                                       original context C down to C ˚ , which is then used
             C˚ “        Top-M αh pcq,           (5)         to prompt the LCLM to produce the final response.
                     hPHret   cPC
                                                             5   Experiment
where αh pcq is the attention score of head h on
                                                             Benchmarks. We use LOFT (Lee et al., 2024)
passage c, and C ˚ is the set of the Top-M selected
                                                             and our ICR2 benchmarks to evaluate LCLMs’ in-
passages from all heads Hret . We use C ˚ to form
                                                             context retrieval and reasoning capabilities. LOFT
a new CiC-style prompt and proceed to generat-
                                                             tests retrieval, single- and multi-hop question an-
ing the final response. Since |C ˚ | ! |C|, the final
                                                             swering, and reasoning using NaturalQuestions
decoding is actually performed on a filtered contex-
                                                             (Kwiatkowski et al., 2019), HotpotQA (Yang et al.,
tual knowledge base with a much smaller length.
                                                             2018), and MuSiQue (Trivedi et al., 2022). ICR2
4.3   Joint Retrieval Head Training                          uses NaturalQuestions and HotpotQA, and addi-
Our final proposal introduces a dedicated retrieval          tionally includes FEVER (Thorne et al., 2018) for
head to the LCLM model architecture. During in-              fact verification and WoW (Dinan et al., 2018) for
ference, the model first uses the head to identify           dialogue completion. Similar to LOFT, we report
relevant passages, after which the generation head           average scores across 100 test cases per task us-
decodes a response conditioned on the retrieved              ing the 32K context length versions, which is the
content. During training, the retrieval and genera-          maximum supported by all tested LCLMs.
tion heads are jointly optimized using the Gumbel-           Metrics. For the question answering and fact veri-
TopK trick (Kool et al., 2019), which mitigates the          fication tasks, we use the exact match in (Lee et al.,
non-differentiability of the retrieval process.              2024; Adlakha et al., 2024). We use ROUGE (Lin,
   Figure 9 illustrates the modified model architec-         2004) to assess on dialogue completion.
ture. The retrieval head generates a binary mask,            Training Details. We use ICR2 ’s training set to
M P t0, 1u|C| , indicating which passages to select          fine-tune all models. Specifically, we randomly
(1) or ignore (0). The selected passages are then            sample 7500, 7500, 5000, and 5000 instances for
passed to the generation head for response gener-            NaturalQuestions, HotpotQA, FEVER, and WoW,
ation. The retrieval head consists of: (1) encoders          respectively. To verify the effectiveness of our
for the query and passage, using the LCLM’s final            proposed methods, we focus our experiments on
hidden states, and (2) a scoring layer that computes         Mistral-Instruct-7B model (Jiang et al., 2023).
relevance scores by concatenating their encoded              Baselines. We compare our approaches with
vectors. The top K passages are then selected for            the baselines in Sec. 3.3: Vanilla RAG, Closed-
the generation head to produce a response.                   book, and Oracle RAG. We include the traditional
   More specifically, let q denote a query and C “           ranking pipeline where we use TinyBERT (Jiao
tc1 , c2 , . . . , cn u be the set of n passages. For each   et al., 2020) and MiniLM (Wang et al., 2020) fine-
pair pq, ci q, two single-layer encoders pool the final      tuned on MS Marco passage retrieval corpus (Bajaj
hidden states from an LCLM and generate a query              et al., 2016) to select the top-relevant passages for
vector, hQ , and a passage vector, hci :                     LCLMs. We report their retrieval performance in
                                                             Appendix D. We include the direct-answer SFT
          hq “ encq pqq;      hci “ encc pci q,              (SFT-DA) which follows Zhang et al. by con-
                                                             catenating the confounders with gold documents
Each pair phq , hci q is then concatenated to form           for SFT, and our methods in Sec. 4 include two
an input vector vi “ rhq ; hci s. A single scoring           retrieve-then-generate SFT variants — Retrieve-
layer then predicts a scalar relevance score si for          then-Answer (SFT-RTA), and Cite-Context-ID
each pair, essentially computing si “ f pvi q where          (SFT-CCI) — and the joint retrieval head training
f p¨q is our scoring function. With the set of scores        (RetHead) and retrieval attention probing (RAP).
                 Models & Methods                       LOFT                             ICR2
                                             NQ     HotpotQA   MUSIQUE   NQ     HotpotQA    FEVER      WoW
             GPT-4 w/
             Close-book                      0.58     0.57       0.28    0.61     0.50          0.85   0.16
             Vanilla RAG                     0.85     0.78       0.51    0.67     0.64          0.92   0.15
             Oracle                          0.88     0.87       0.72    0.79     0.82          0.94   0.18
             Mistral-7B w/
             Close-book                      0.46     0.38       0.05    0.49     0.38          0.73   0.14
             Vanilla RAG                     0.64     0.62       0.27    0.53     0.50          0.81   0.13
             RAG w/ RTA Prompting            0.60     0.70       0.27    0.54     0.51          0.83   0.15
             Re-ranking Strategy
             w/ TinyBERT pk “ 8q             0.88     0.78       0.29    0.52     0.47          0.88   0.12
             w/ MiniLM pk “ 8q               0.83     0.77       0.27    0.51     0.46          0.86   0.13
             w/ TinyBERT pk “ 32q            0.87     0.87       0.33    0.62     0.51          0.91   0.13
             w/ MiniLM pk “ 32q              0.84     0.84       0.39    0.61     0.47          0.92   0.12
             Oracle RAG                      0.89     0.81       0.41    0.83     0.81          0.94   0.18
             Supervised Fine-tuning
             SFT-Direct Answer               0.70     0.65       0.25    0.59     0.70          0.90   0.22
             SFT-Retrieve-then-Answer        0.74     0.69       0.33    0.60     0.67          0.91   0.22
             SFT-Cite-Context-ID             0.76     0.54       0.35    0.63     0.63          0.89   0.21
             Joint Retrieval Head Training
             RetHead w{Lgen ` Lret           0.15     0.13       0.07    0.48     0.54           0.9   0.21
             RetHead w{Lgen                    -        -          -     0.28     0.25          0.82   0.18
             RetHead w{Lret                    -        -          -     0.39     0.44          0.82   0.13
             Retrieval-Attention Probing
             SFT-DA w/ RAP                   0.78     0.76       0.47    0.64     0.67          0.89   0.21
             SFT-RTA w/ RAP                  0.85     0.79       0.39    0.63     0.71          0.92   0.23

Table 3: Main results on LOFT (Lee et al., 2024) and ICR2 for our methods applied on Mistral-2-7B-Instruct (Jiang
et al., 2023). We also report the GPT-4 performance in the top panel. We highlight the improved and worsen
performances compared with Vanilla RAG, and bold the best method based on Mistral-7B, except the Oracle.
5.1   Main Results                                             4%, 1%, and 1% on NaturalQuestions, HotpotQA,
                                                               FEVER, and WoW, respectively. It also achieves
As shown in Table 3, all SFT variants outperform
                                                               top performance on 5 out of the 7 tasks, demonstrat-
the Vanilla RAG on both benchmarks, indicating
                                                               ing its superiority.Remarkably, it achieves compa-
that LCLMs struggle to effectively leverage con-
                                                               rable performance with the state-of-the-art GPT-
text as a knowledge base for RAG tasks. Further-
                                                               4-Turbo on LOFT and ICR2 while using a much
more, the gap between SFT-DA and the Oracle
                                                               smaller model. Finally, RAP decoding is more
RAG highlights that supervised fine-tuning alone
                                                               effective for SFT models than with the original
is insufficient to achieve optimal results.
                                                               model, as SFT better activates retrieval-specific at-
   We first apply RTA-style generation as a prompt-            tention heads for the approach (see Sec. 6.3). To
only method (RTA Prompting). The resulting per-                verify the generalization of methods across various
formance gains, though modest, demonstrate the                 LLMs, we conduct experiments with LLaMA-3-
potential of decoupling the generation process into            Instruct (Dubey et al., 2024) in Appendix C: we
separate retrieval and generation stages. Among                observe the similar improvements for retrieve-then-
the SFT variants, SFT-RTA in general outperforms               generate training, and RAP decoding.
the others with an average improvement of 2%.
Specifically on LOFT benchmark, both SFT-RTA                      Compared to the traditional pipeline, LCLMs
and SFT-CCI outperform SFT-DA with 6% and 2%                   can effectively unify in-context retrieval and gen-
improvement on average, respectively, indicating               eration, particularly on challenging benchmarks
the retrieve-then-generate strategy helps. On ICR2 ,           such as ICR2 . This highlights the advantage of an
however, all SFT variants perform the same. This               end-to-end approach, wherein LCLMs contextually
demonstrates that ICR2 is a more discriminative                select retrieved items based on both the query and
benchmark than LOFT.                                           the evolving generation.
   We apply RAP to all SFT models. On aver-                      For the joint retrieval head training (RetHead),
age, RAP enhances the models significantly, with               we performed experiments on training only the
SFT-DA + RAP improving by 6% and SFT-RTA +                     generation head (w{Lgen ), only the retreieval head
RAP by 8%. The best-performing approach, SFT-                  (w{Lret ), and both (w{Lgen ` Lret ). The last vari-
RTA + RAP, achieves notable gains on the challeng-             ant achieves the best performance, outperforming
ing ICR2 benchmark, with improvements of 3%,                   the Vanilla RAG baseline on ICR2 . However, it is
                                                  NaturalQuestions                           HotpotQA                                 FEVER                           WoW                                       Avg.
                                   0.64                                      0.70                                                                                                            0.60



           Task Specific Metrics
                                                                                                                     0.8                                0.20
                                   0.62                                      0.68                                                                                                            0.55
                                   0.60                                                                                                                 0.15                                 0.50
                                                                             0.66                                    0.6
                                   0.58
                                                                                                                                                        0.10                                 0.45
                                   0.56                                      0.64                                    0.4
                                                                                                                                                                                             0.40
                                          10000    15000   20000     25000          10000   15000   20000    25000         10000    15000 20000 25000      10000   15000    20000    25000          10000   15000   20000    25000
                                                                                                                                   #Training Samples
                                                                                                                SFT-DA                SFT-RTA        SFT-CCI

                                                           Figure 3: Scaling the number of training samples in ICR2 ’s training set.

                                                            LOFT                                            ICR2                                          ICR2
                                                                                                                                                                           SFT-RTA                      Blocking Context
 Methods
                                                                                                                                                                     Metrics        Recall             Metrics      Recall
                                             NQ HPQA MUSI. NQ HPQA FEV. WoW
                                                                                                                                                          NQ                0.6       0.58       0.61 (Ò .01)        0.59 (Ò .01)
 SFT-RTA                                    0.81        0.83         0.37            0.58     0.78          0.64     0.43                                 HPQA             0.67       0.78       0.68 (Ò .01)       0.78 (“ .00)
 SFT-CCI                                    0.65        0.61         0.26            0.63     0.73          0.69     0.49                                 FEVER            0.91       0.64      0.91 (“ .00)         0.66 (Ò .02)
 RetHead                                                                                                                                                  WoW              0.22       0.43       0.21 (Ó .01)        0.46 (Ò .03)
 w{Lgen ` Lret 0.01                                     0.01         0.01            0.36     0.44          0.55     0.51                                 Avg               0.6       0.61          0.6 (“ .00)     0.62 (Ò .01)
 w{Lgen          -                                        -            -             0.00     0.00          0.00     0.02
 w{Lret          -                                        -            -             0.33     0.49          0.51     0.49                 Table 5: SFT-RTA’s performance before and after block-
 RAP Decoding                                                                                                                             ing the contextual knowledge base with attention mask.
 Vanilla RAG  0.19                                      0.25         0.10            0.36     0.13          0.00     0.00
 SFT-DA       0.95                                      0.70         0.27            0.75     0.67          0.60     0.69
 SFT-RTA      0.95                                      0.96         0.39            0.61     0.85          0.60     0.41                  an improved model performance. In particular, a
                                                                                                                                           smaller amount of training data fares worse with
Table 4: Retrieval performance measured by recall rate
for various methods using Mistral-2-7B.                                                                                                    the retrieve-then-generate approaches, as they are
                                                                                                                                           by nature more challenging to learn compared to
not comparable with the SFT variants.                                                                                                      the SFT-DA approach, where answer is directly
                                                                                                                                           generated without an explicit retrieval step.
5.2    In-Context Retrieval Performance
Table 4 reports the recall rates for all methods,                                                                                          6.2       Blocking Context Attention in
meaning how likely the models retrieve the relevant                                                                                                  Retrieve-then-generate Model
provenances. For the SFT variants, we evaluate
                                                                                                                                          To verify if models actually learn to generate the fi-
the retrieval predictions produced in the retrieval
                                                                                                                                          nal responses only from the retrieval predictions in
phase. For the joint retrieval head training approach
                                                                                                                                          our retrieve-then-generate methods (Sec. 4.1), addi-
(RetHead), we analyze the predictions from the
                                                                                                                                          tional experiments were performed where we block
retrieval head. For RAP decoding, we assess the
                                                                                                                                          attention to be paid onto the context beyond the
passages identified by the selected attention heads.
                                                                                                                                          retrieval predictions at the generation step. Table 5
   We find a strong correlation between a model’s
                                                                                                                                          reports the impact of the blocking on the SFT-RTA
recall rate and its downstream task performance,
                                                                                                                                          variant. We observe the performance essentially
highlighting the importance of in-context retrieval
                                                                                                                                          stays the same, indicating the model indeed learned
ability for LCLMs. Our best approach, SFT-RTA
                                                                                                                                          to generate largely on the retrieved passages, ignor-
+ RAP, achieves the highest recall. In contrast,
                                                                                                                                          ing the original context.
Vanilla RAG + RAP exhibits poor retrieval perfor-
mance, consistent with its limited improvement on                                                                                          6.3       Effect on Attention Heads of
the downstream tasks. The near-random retrieval                                                                                                      Retrieve-then-Generate Fine-tuning
performance of joint training of retrieval head in
LOFT explains its failure of generalization.                                                                                              To understand if fine-tuning sharpens attention
                                                                                                                                          heads’ focus on relevant passages, we compare the
6     Discussion                                                                                                                          hit rates (Sec. 4.2) achieved by the attention heads
                                                                                                                                          between Vanilla RAG and all of our SFT variants
6.1    Scaling the Supervised Fine-tuning                                                                                                 (Sec. 4.1), and the results are shown in Figure 4.
We are also interested in how the performance of                                                                                             Similar to (Wu et al., 2024), we find that a small
the proposed SFT variants scale with the training                                                                                         group of attention heads can obtain higher hit rates
set size. We train the three variants, SFT-DA, SFT-                                                                                       than the others. However, unlike Vanilla RAG,
RTA, and SFT-CCI, with the same 10K, 15K and                                                                                              SFT methods produce more retrieval-focused atten-
25K examples from ICR2 ’s training set, and re-                                                                                           tion heads, and achieve higher peak hit rates. This
port their performance on each task in the ICR2                                                                                           demonstrates the effectiveness of our SFT meth-
benchmark, as shown in Fig 3. We observe that                                                                                             ods and our curated ICR2 training set in enhancing
an increased training set size in general leads to                                                                                        LCLMs’ performance of in-context retrieval.
                                 Vanilla RAG                                SFT-DA                 SFT-RTA                                 SFT-CCI
                      0.75                                                          SFT-DA                          SFT-DA                              SFT-DA          Benchmark     SFT-DA     SFT-DA + RAP
                      0.50
 NQ

                      0.25                                                    Vanilla RAG                Vanilla RAG                              Vanilla RAG           NQ                4.23       4.99 (Ò .76)
                      0.00
                                                                                                                                                                        HotpotQA          4.19       4.81 (Ò .62)
                             0       200     400       0                       500            0           500                          0          200                   MUSIQUE           4.24       5.05 (Ò .81)
                      0.75                                                          SFT-DA                          SFT-DA                              SFT-DA
 HotpotQA




                      0.50                                                                                                                                       Table 6: Latency for SFT-DA with and without the RAP
                                                                              Vanilla RAG                Vanilla RAG                              Vanilla RAG
                      0.25
                                                                                                                                                                 decoding. Time is measured in seconds per query.
                      0.00
                             0         200             0                    250 500           0           500                          0            200
                                                                                                                                                                 section, we apply different value settings when de-
                      0.75
                      0.50                                                                                                                                       ploying the SFT-RTA + RAP combined approach
 FEVER




                                                                               Vanilla RAG               Vanilla RAG                              Vanilla RAG
                      0.25                                                           SFT-DA                          SFT-DA                             SFT-DA   to explore their effect on model performance.
                      0.00
                             0        200       400 0                           100           0            500                         0            200             Figure 5 shows the high-level results on both
                      0.75                                                          SFT-DA                            SFT-DA                            SFT-DA   LOFT and ICR2 (Appendix E has more details).
                      0.50
                                                                                                                                                                 As expected, we observe in the middle column that
 WoW




                      0.25
                                                                              Vanilla RAG                Vanilla RAG                              Vanilla RAG
                      0.00                                                                                                                                       an increasing M or Q will increase the recall rate as
                             0       200      400 0     200                                   0       200     400 0      200
                              Retrieval Head ID Retrieval Head ID                              Retrieval Head ID Retrieval Head ID                               the resulting larger pools of selected passages will
                                                                                                                                                                 more likely include the relevant ones. We also find
Figure 4: Attention heads with above-zero hit rates. SFT
produces more retrieval attention heads. Retrieve-then-                                                                                                          that increasing M as opposed to Q is more effective
generate training activates a higher peak of hit rate.                                                                                                           in improving the recall rate as certain task such as
                                                                                     ICR2
                                 ICR2-Metrics                                  ICR2-Recall-RAP                                     ICR2-Recall-RTA
                                                                                                                                                                 HotpotQA requires multi-hop retrieval. However,
                         0.60        0.58       0.59                         0.76      0.82       0.88                          0.61       0.59         0.60     the increased recall rate does not always translate to
    M=8 M=4 M=2 M=1




                                                          M=8 M=4 M=2 M=1




                                                                                                              M=8 M=4 M=2 M=1




                         0.61        0.59       0.59                         0.84      0.94       0.95                          0.60       0.63         0.61     a better performance (left column) or RTA’s recall
                         0.57        0.58       0.58                         0.92      0.97       0.99                          0.60       0.59         0.60     rate , as a higher M or Q may also introduce more
                         0.59        0.58       0.58                         0.96      0.99       1.00                          0.60       0.59         0.60     confounders. This suggests the further reduction in
                         Q=2         Q=4        Q=8                          Q=2       Q=4
                                                                                    LOFT
                                                                                                  Q=8                           Q=2        Q=4          Q=8      confounding effects is still an opening future work.
                               LOFT-Metrics                                    LOFT-Recall-RAP                                    LOFT-Recall-RTA
                        0.62        0.61      0.67                           0.84     0.88        0.93                          0.75       0.76      0.76        6.5    Decoding Speed
 M=8 M=4 M=2 M=1




                                                       M=8 M=4 M=2 M=1




                                                                                                           M=8 M=4 M=2 M=1




                        0.64        0.60      0.61                           0.91     0.96        0.98                          0.77       0.75      0.74        Our final analysis is on the efficiency of RAP.
                        0.61        0.62      0.63                           0.96     0.99        1.00                          0.74       0.71      0.71        Based on the SFT-DA variant, we report its latency
                        0.63        0.57      0.57                           0.99     1.00        1.00                          0.75       0.66      0.67        with and without the RAP enhancement in Table 6.
                        Q=2         Q=4       Q=8                            Q=2      Q=4         Q=8                           Q=2        Q=4          Q=8      We find that the RAP decoding does not increase
Figure 5: Effect of adjusting Q (number of attention                                                                                                             latency significantly, despite it adds one additional
heads for retrieval) and M (number of passages to se-                                                                                                            decoding step to the base method. This can be at-
lect) when applying SFT-RTA + RAP. Left column: av-                                                                                                              tributed to the much shorter context retrieved by
erage model performance measured by the tasks-specific                                                                                                           the attention heads, thus avoiding expensive long-
metrics. Middle column: attention heads’ retrieval mea-                                                                                                          context computation as in the baseline. This in-
sured by the recall rate. Right column: RTA’s retrieval
                                                                                                                                                                 crease can be further reduced with approaches such
measured by the exact match.
                                                                                                                                                                 as KV caching, which we leave for future work.
   Among the three SFT variants, we find that SFT-                                                                                                               7     Conclusion
RTA in general achieves higher peak hit rates and
activates more attention heads for retrieval. In par-                                                                                                            In this paper, we introduce ICR2 , a new bench-
ticular, SFT-CCI is not as effective in recruiting                                                                                                               mark designed as a more discriminative benchmark
as many attention heads, possibly because context                                                                                                                for evaluating LCLMs in in-context retrieval and
IDs themselves are not informative enough for the                                                                                                                reasoning. Our findings highlight the limitations
model to learn the retrieval task well. We also note                                                                                                             for the current models. We propose three methods
that SFT-DA fares a lot worse on FEVER, possibly                                                                                                                 —retrieve-then-generate fine-tuning, retrieval atten-
due to the lack of chain-of-thought style of assist.                                                                                                             tion probing, and joint retrieval head training — to
                                                                                                                                                                 enhance models, achieving the results comparable
6.4                      Retrieval Attention Probing                                                                                                             to GPT-4 with a smaller model footprint.
Our inference-time method RAP (Sec. 4.2) uses
                                                                                                                                                                 Ethical Considerations
two hyperparameters: Q is the number of the at-
tention heads we recruit for retrieval, and M is the                                                                                                             We do not expect any ethical concerns to be raised
number of passages each head retrieves. In this                                                                                                                  with respect to this work.
Limitations                                                  Andrew McNamara, Bhaskar Mitra, Tri Nguyen,
                                                             et al. 2016. Ms marco: A human generated ma-
We acknowledge several limitations in this work.             chine reading comprehension dataset. arXiv preprint
First, most experiments were conducted with a con-           arXiv:1611.09268.
text length of 32K tokens. Our findings indicate
                                                           Parishad BehnamGhader, Vaibhav Adlakha, Marius
that while many LCLMs claim to support longer                Mosbach, Dzmitry Bahdanau, Nicolas Chapados, and
contexts, their performance on tasks with 32K to-            Siva Reddy. 2024. Llm2vec: Large language models
kens remains suboptimal. Future work could focus             are secretly powerful text encoders. arXiv preprint
on extending ICR2 and the proposed approaches to             arXiv:2404.05961.
effectively support scenarios with longer context          Iz Beltagy, Matthew E. Peters, and Arman Cohan.
lengths.                                                      2020. Longformer: The long-document transformer.
   Second, while Joint Retrieval Head Training                arXiv:2004.05150.
demonstrates improved performance compared to              Danqi Chen, Adam Fisch, Jason Weston, and Antoine
Vanilla RAG, it still falls short of the performance         Bordes. 2017. Reading Wikipedia to answer open-
achieved by the SFT variant. Future research could           domain questions. In Association for Computational
explore improved architectural designs to better             Linguistics (ACL).
integrate the supervision signals from both the re-        Yukang Chen, Shengju Qian, Haotian Tang, Xin Lai,
trieval and generation tasks.                                Zhijian Liu, Song Han, and Jiaya Jia. 2024. Longlora:
   Finally, our evaluation primarily utilizes the            Efficient fine-tuning of long-context large language
Mistral-7B model due to computational constraints.           models. In The Twelfth International Conference on
                                                             Learning Representations.
Extending the proposed methods to other LCLMs
would provide a broader assessment of their gener-         Emily Dinan, Stephen Roller, Kurt Shuster, Angela
alization capabilities and effectiveness across dif-         Fan, Michael Auli, and Jason Weston. 2018. Wizard
ferent model architectures.                                  of wikipedia: Knowledge-powered conversational
                                                             agents. In International Conference on Learning
                                                             Representations.
References                                                 Yiran Ding, Li Lyna Zhang, Chengruidong Zhang,
Marah Abdin, Sam Ade Jacobs, Ammar Ahmad Awan,               Yuanyuan Xu, Ning Shang, Jiahang Xu, Fan Yang,
 Jyoti Aneja, Ahmed Awadallah, Hany Awadalla,                and Mao Yang. 2024. Longrope: Extending llm con-
 Nguyen Bach, Amit Bahree, Arash Bakhtiari, Harki-           text window beyond 2 million tokens. In Forty-first
 rat Behl, et al. 2024. Phi-3 technical report: A highly     International Conference on Machine Learning.
 capable language model locally on your phone. arXiv
                                                           Abhimanyu Dubey, Abhinav Jauhri, Abhinav Pandey,
 preprint arXiv:2404.14219.
                                                             Abhishek Kadian, Ahmad Al-Dahle, Aiesha Letman,
Josh Achiam, Steven Adler, Sandhini Agarwal, Lama            Akhil Mathur, Alan Schelten, Amy Yang, Angela
  Ahmad, Ilge Akkaya, Florencia Leoni Aleman,                Fan, et al. 2024. The llama 3 herd of models. arXiv
  Diogo Almeida, Janko Altenschmidt, Sam Altman,             preprint arXiv:2407.21783.
  Shyamal Anadkat, et al. 2023. Gpt-4 technical report.
  arXiv preprint arXiv:2303.08774.                         Yao Fu, Rameswar Panda, Xinyao Niu, Xiang Yue, Han-
                                                             naneh Hajishirzi, Yoon Kim, and Hao Peng. 2024.
Vaibhav Adlakha, Parishad BehnamGhader, Xing Han             Data engineering for scaling language models to 128k
  Lu, Nicholas Meade, and Siva Reddy. 2024. Eval-            context. In Forty-first International Conference on
  uating correctness and faithfulness of instruction-        Machine Learning.
  following models for question answering. Trans-
  actions of the Association for Computational Linguis-    Cheng-Yu Hsieh, Chun-Liang Li, Chih-kuan Yeh,
  tics, 12:775–793.                                          Hootan Nakhost, Yasuhisa Fujii, Alex Ratner, Ranjay
                                                             Krishna, Chen-Yu Lee, and Tomas Pfister. 2023. Dis-
Yushi Bai, Xin Lv, Jiajie Zhang, Hongchang Lyu,              tilling step-by-step! outperforming larger language
  Jiankai Tang, Zhidian Huang, Zhengxiao Du, Xiao            models with less training data and smaller model
  Liu, Aohan Zeng, Lei Hou, Yuxiao Dong, Jie Tang,           sizes. In Findings of the Association for Compu-
  and Juanzi Li. 2024. LongBench: A bilingual, multi-        tational Linguistics: ACL 2023, pages 8003–8017,
  task benchmark for long context understanding. In          Toronto, Canada. Association for Computational Lin-
  Proceedings of the 62nd Annual Meeting of the As-          guistics.
  sociation for Computational Linguistics (Volume 1:
  Long Papers), pages 3119–3137, Bangkok, Thailand.        Gautier Izacard, Mathilde Caron, Lucas Hosseini, Se-
  Association for Computational Linguistics.                 bastian Riedel, Piotr Bojanowski, Armand Joulin,
                                                             and Edouard Grave. Unsupervised dense informa-
Payal Bajaj, Daniel Campos, Nick Craswell, Li Deng,          tion retrieval with contrastive learning. Transactions
  Jianfeng Gao, Xiaodong Liu, Rangan Majumder,               on Machine Learning Research.
Albert Q Jiang, Alexandre Sablayrolles, Arthur Men-        Han Lin, Abhay Zala, Jaemin Cho, and Mohit Bansal.
  sch, Chris Bamford, Devendra Singh Chaplot, Diego          2023. Videodirectorgpt: Consistent multi-scene
  de las Casas, Florian Bressand, Gianna Lengyel, Guil-      video generation via llm-guided planning. arXiv
  laume Lample, Lucile Saulnier, et al. 2023. Mistral        preprint arXiv:2309.15091.
  7b. arXiv preprint arXiv:2310.06825.
                                                           Nelson F. Liu, Kevin Lin, John Hewitt, Ashwin Paran-
Xiaoqi Jiao, Yichun Yin, Lifeng Shang, Xin Jiang, Xiao       jape, Michele Bevilacqua, Fabio Petroni, and Percy
  Chen, Linlin Li, Fang Wang, and Qun Liu. 2020.             Liang. 2024. Lost in the middle: How language mod-
  Tinybert: Distilling bert for natural language under-      els use long contexts. Transactions of the Association
  standing. In Findings of the Association for Computa-      for Computational Linguistics, 12:157–173.
  tional Linguistics: EMNLP 2020, pages 4163–4174.
                                                           Xueguang Ma, Liang Wang, Nan Yang, Furu Wei, and
Hongye Jin, Xiaotian Han, Jingfeng Yang, Zhimeng             Jimmy Lin. 2024. Fine-tuning llama for multi-stage
  Jiang, Zirui Liu, Chia-Yuan Chang, Huiyuan Chen,           text retrieval. In Proceedings of the 47th Inter-
  and Xia Hu. 2024. Llm maybe longlm: Self-extend            national ACM SIGIR Conference on Research and
  llm context window without tuning. CoRR.                   Development in Information Retrieval, pages 2421–
Greg Kamradt. 2023. Needle in a haystack - pressure          2425.
  testing llms.  https://github.com/gkamradt/
  LLMTest_NeedleInAHaystack.                               Fabio Petroni, Aleksandra Piktus, Angela Fan, Patrick
                                                             Lewis, Majid Yazdani, Nicola De Cao, James Thorne,
Vladimir Karpukhin, Barlas Oguz, Sewon Min, Patrick          Yacine Jernite, Vladimir Karpukhin, Jean Maillard,
  Lewis, Ledell Wu, Sergey Edunov, Danqi Chen, and           Vassilis Plachouras, Tim Rocktäschel, and Sebastian
  Wen-tau Yih. 2020. Dense passage retrieval for open-       Riedel. 2021. KILT: a benchmark for knowledge
  domain question answering. In Proceedings of the           intensive language tasks. In Proceedings of the 2021
  2020 Conference on Empirical Methods in Natural            Conference of the North American Chapter of the
  Language Processing (EMNLP), pages 6769–6781.              Association for Computational Linguistics: Human
                                                             Language Technologies, pages 2523–2544, Online.
Yekyung Kim, Yapei Chang, Marzena Karpinska,                 Association for Computational Linguistics.
  Aparna Garimella, Varun Manjunatha, Kyle Lo,
  Tanya Goyal, and Mohit Iyyer. 2024. Fables: Evaluat-     Yifu Qiu, Yftah Ziser, Anna Korhonen, Edoardo Ponti,
  ing faithfulness and content selection in book-length      and Shay Cohen. 2023. Detecting and mitigating
  summarization. arXiv preprint arXiv:2404.01261.            hallucinations in multilingual summarisation. In Pro-
                                                             ceedings of the 2023 Conference on Empirical Meth-
Wouter Kool, Herke Van Hoof, and Max Welling. 2019.          ods in Natural Language Processing, pages 8914–
 Stochastic beams and where to find them: The                8932, Singapore. Association for Computational Lin-
 gumbel-top-k trick for sampling sequences without           guistics.
 replacement. In International Conference on Ma-
 chine Learning, pages 3499–3508. PMLR.                    Stephen Robertson, Hugo Zaragoza, et al. 2009. The
                                                              probabilistic relevance framework: Bm25 and be-
Tom Kwiatkowski, Jennimaria Palomaki, Olivia Red-            yond. Foundations and Trends® in Information Re-
  field, Michael Collins, Ankur Parikh, Chris Alberti,        trieval, 3(4):333–389.
  Danielle Epstein, Illia Polosukhin, Jacob Devlin, Ken-
  ton Lee, Kristina Toutanova, Llion Jones, Matthew        Stephen E Robertson and K Sparck Jones. 1976. Rel-
  Kelcey, Ming-Wei Chang, Andrew M. Dai, Jakob                evance weighting of search terms. Journal of the
  Uszkoreit, Quoc Le, and Slav Petrov. 2019. Natu-           American Society for Information science, 27(3):129–
  ral questions: A benchmark for question answering          146.
  research. Transactions of the Association for Compu-
  tational Linguistics, 7:452–466.                         Rohit Saxena and Frank Keller. 2024. MovieSum: An
Jinhyuk Lee, Anthony Chen, Zhuyun Dai, Dheeru Dua,           abstractive summarization dataset for movie screen-
   Devendra Singh Sachan, Michael Boratko, Yi Luan,          plays. In Findings of the Association for Compu-
   Sébastien MR Arnold, Vincent Perot, Siddharth             tational Linguistics: ACL 2024, pages 4043–4050,
   Dalmia, et al. 2024. Can long-context language mod-       Bangkok, Thailand. Association for Computational
   els subsume retrieval, rag, sql, and more? arXiv          Linguistics.
   preprint arXiv:2406.13121.
                                                           Kumar Shridhar, Alessandro Stolfo, and Mrinmaya
Huayang Li, Pat Verga, Priyanka Sen, Bowen Yang, Vi-         Sachan. 2023. Distilling reasoning capabilities into
  jay Viswanathan, Patrick Lewis, Taro Watanabe, and         smaller language models. In Findings of the Associa-
  Yixuan Su. 2024. Alr: A retrieve-then-reason frame-        tion for Computational Linguistics: ACL 2023, pages
  work for long-context question answering. arXiv            7059–7073.
  preprint arXiv:2410.03227.
                                                           Jianlin Su, Murtadha Ahmed, Yu Lu, Shengfeng Pan,
Chin-Yew Lin. 2004. Rouge: A package for automatic            Wen Bo, and Yunfeng Liu. 2024. Roformer: En-
  evaluation of summaries. In Text summarization              hanced transformer with rotary position embedding.
  branches out, pages 74–81.                                  Neurocomputing, 568:127063.
James Thorne,         Andreas Vlachos,        Christos     Zhilin Yang, Peng Qi, Saizheng Zhang, Yoshua Bengio,
  Christodoulopoulos, and Arpit Mittal. 2018.                William Cohen, Ruslan Salakhutdinov, and Christo-
  Fever: a large-scale dataset for fact extraction and       pher D Manning. 2018. Hotpotqa: A dataset for
  verification. In Proceedings of the 2018 Conference        diverse, explainable multi-hop question answering.
  of the North American Chapter of the Association           In Proceedings of the 2018 Conference on Empiri-
  for Computational Linguistics: Human Language              cal Methods in Natural Language Processing, pages
  Technologies, Volume 1 (Long Papers), pages                2369–2380.
  809–819.
                                                           Manzil Zaheer, Guru Guruganesh, Kumar Avinava
Harsh Trivedi, Niranjan Balasubramanian, Tushar Khot,       Dubey, Joshua Ainslie, Chris Alberti, Santiago On-
  and Ashish Sabharwal. 2022. Musique: Multi-               tanon, Philip Pham, Anirudh Ravula, Qifan Wang,
  hop questions via single-hop question composition.        Li Yang, et al. 2020. Big bird: Transformers for
  Transactions of the Association for Computational         longer sequences. Advances in neural information
  Linguistics, 10:539–554.                                  processing systems, 33:17283–17297.

Minzheng Wang, Longze Chen, Fu Cheng, Shengyi              Ce Zhang, Taixi Lu, Md Mohaiminul Islam, Ziyang
  Liao, Xinghua Zhang, Bingli Wu, Haiyang Yu, Nan            Wang, Shoubin Yu, Mohit Bansal, and Gedas Berta-
  Xu, Lei Zhang, Run Luo, Yunshui Li, Min Yang, Fei          sius. 2023. A simple llm framework for long-
  Huang, and Yongbin Li. 2024a. Leave no document            range video question-answering. arXiv preprint
  behind: Benchmarking long-context LLMs with ex-            arXiv:2312.17235.
  tended multi-doc QA. In Proceedings of the 2024
  Conference on Empirical Methods in Natural Lan-          Tianjun Zhang, Shishir G Patil, Naman Jain, Sheng
  guage Processing, pages 5627–5646, Miami, Florida,         Shen, Matei Zaharia, Ion Stoica, and Joseph E Gon-
  USA. Association for Computational Linguistics.            zalez. 2024a. Raft: Adapting language model to do-
                                                             main specific rag. arXiv preprint arXiv:2403.10131.
Wenhui Wang, Furu Wei, Li Dong, Hangbo Bao, Nan
 Yang, and Ming Zhou. 2020. Minilm: Deep self-             Yusen Zhang, Ruoxi Sun, Yanfei Chen, Tomas Pfister,
 attention distillation for task-agnostic compression        Rui Zhang, and Sercan Ö Arik. 2024b. Chain of
 of pre-trained transformers. Advances in neural in-         agents: Large language models collaborating on long-
 formation processing systems, 33:5776–5788.                 context tasks. arXiv preprint arXiv:2406.02818.

                                                           Jun Zhao, Can Zu, Hao Xu, Yi Lu, Wei He, Yiwen
Yuqing Wang, Tianwei Xiong, Daquan Zhou, Zhijie Lin,
                                                             Ding, Tao Gui, Qi Zhang, and Xuanjing Huang. 2024.
  Yang Zhao, Bingyi Kang, Jiashi Feng, and Xihui Liu.
                                                             Longagent: Scaling language models to 128k context
  2024b. Loong: Generating minute-level long videos
                                                             through multi-agent collaboration. arXiv preprint
  with autoregressive language models. arXiv preprint
                                                             arXiv:2402.11550.
  arXiv:2410.02757.

Ledell Wu, Fabio Petroni, Martin Josifoski, Sebastian
  Riedel, and Luke Zettlemoyer. 2020. Zero-shot entity
  linking with dense entity retrieval. In EMNLP.

Wenhao Wu, Yizhong Wang, Guangxuan Xiao, Hao
 Peng, and Yao Fu. 2024. Retrieval head mechanisti-
 cally explains long-context factuality. arXiv preprint
 arXiv:2404.15574.

Wenhan Xiong, Jingyu Liu, Igor Molybog, Hejia Zhang,
  Prajjwal Bhargava, Rui Hou, Louis Martin, Rashi
  Rungta, Karthik Abinav Sankararaman, Barlas Oguz,
  et al. 2024. Effective long-context scaling of founda-
  tion models. In Proceedings of the 2024 Conference
  of the North American Chapter of the Association for
 Computational Linguistics: Human Language Tech-
  nologies (Volume 1: Long Papers), pages 4643–4663.

Fuzhao Xue, Yukang Chen, Dacheng Li, Qinghao Hu,
  Ligeng Zhu, Xiuyu Li, Yunhao Fang, Haotian Tang,
  Shang Yang, Zhijian Liu, et al. 2024. Longvila: Scal-
  ing long-context visual language models for long
  videos. arXiv preprint arXiv:2408.10188.

An Yang, Baosong Yang, Binyuan Hui, Bo Zheng,
  Bowen Yu, Chang Zhou, Chengpeng Li, Chengyuan
  Li, Dayiheng Liu, Fei Huang, et al. 2024. Qwen2
  technical report. arXiv preprint arXiv:2407.10671.
A    Statistics for LOFT and ICR2                        D     Retrieval Performance for Re-ranking
                                                               Strategies
             Task       #CTX     #Tokens   #Prov         Table 10 presents a comprehensive evaluation of
             NQ         215      28,911    1             different re-ranking strategies applied to retrieval-
    LOFT     HPQA       276      28,924    1.98          augmented generation (RAG) across two bench-
             MUSIQ.     207      28,806    1.67
                                                         mark suites: LOFT (comprising NQ, HPQA, and
             NQ         202      20,441    1             MUSI.) and ICR2 (including NQ, HPQA, FEV, and
        2    HPQA       202      20,818    2.09
    ICR
             FEVER      202      21,136    1             WoW). We compare baseline RAG without re-
             WoW        202      21,068    1             ranking, re-ranking using lightweight models (Tiny-
                                                         BERT and MiniLM) at varying retrieval depths
Table 7: Statistics for LOFT and our dataset ICR2 :      k P t8, 32, 50u, and our best-performing variant
#CTX is to the average number of passages per query in   (SFT-RTA w/ RAP). Results show consistent im-
the contextual knowledge base, #Tokens is the average
                                                         provements with increased k, and MiniLM-based
length of the CiC prompt, and #Prov. is the average
number of provenance (positive passages) per query.      re-rankers often slightly outperform TinyBERT
                                                         counterparts. Notably, the SFT-RTA w/ RAP
  We present the comparison in dataset statistics        model yields the highest performance across most
between LOFT and ICR2 in Table 7.                        datasets, particularly excelling in more challenging
                                                         ICR2 domains. These findings suggest the strong re-
B   Prompt Template for the                              trieval capabilities of our SFT-RTA approach com-
    Retrieval-augmented Generation                       pared to the traditional re-ranking strategies.

We show the Corpus-in-Context (CiC; Lee et al.           E     Detailed Results for RAP Decoding
2024) prompt template used in our experiments in
                                                         We show the detailed results for each task of LOFT
Table 8.
                                                         and ICR2 in Figure 6 and 7.
C    Generalization to Other LCLMs                       F     Details of Experiment Setup
Table 9 presents the performance of the LLaMA-3-         F.1   Training Details
Instruct-8B model across two benchmarks—NQ-              For all models, we set the base value of the ro-
LOFT and HPQA-LOFT—evaluated under LOFT                  tary position embedding to 1e6 following Su et al.
and ICR2 . The results highlight several key trends.     (2024). Training is conducted with a batch size of
First, the baseline Closebook performs poorly, par-      1 per Nvidia A100-40G GPU, and gradients are ac-
ticularly on the HPQA dataset, underscoring the          cumulated every 4 steps. Each model is trained for
need for external information. Incorporating re-         up to 10,000 steps (approximately 2 epochs), with
trieval via RAG offers significant improvements,         the best-performing checkpoint on the validation
especially on HPQA, where performance increases          set selected as part of an early-stopping strategy.
from 0.19 to 0.56. The Oracle setting represents         The learning rate is set to 1e ´ 5, and the maxi-
the upper bound of retrieval quality, and shows the      mum sequence length during training is capped at
strongest performance overall.                           32,768 tokens, discarding any sequences exceeding
   We observe that adding a reranker such as Tiny-       this threshold.
BERT to RAG further improves results under
the LOFT setup, reaching 0.89 on both NQ and             F.2   Inference Parameters
HPQA—approaching Oracle-level performance.               During inference, we use greedy decoding for all
Among supervised fine-tuning methods, SFT-DA             models, allowing a maximum generated sequence
and SFT-RTA provide moderate improvements over           length of 1,024 tokens. For RAP decoding, 100 ran-
vanilla RAG. Notably, integrating our proposed           dom instances from the validation set are used to
RAP mechanism (e.g., in SFT-DA w/ RAP) leads             probe the attention heads responsible for retrieval.
to consistent gains, especially under ICR2 . For         For SFT-DA, retrieval is performed using the desig-
example, SFT-DA w/ RAP achieves the best NQ              nated retrieval attention heads based on the first and
score (0.61), validating the effectiveness of RAP        only decoded token. For SFT-RTA, retrieval is per-
in enhancing decision quality during retrieval and       formed using all tokens generated in the retrieval
answer generation.                                       step to ensure complete context coverage.
 Task                    Prompt Template
                         [INST] Please answer the following question given the following passages:
                         {Corpus}
   QA


                         Question: {Query}
                         Answer: [/INST]
     Fact Verification




                         [INST] According to the following passages, please verify the given claim
                         and predict your judgment on its factuality as TRUE or FALSE:
                         {Corpus}
                         Claim: {Query}
                         Judgement: [/INST]
                         [INST] According to the given passages, please provide a single response to
   Dialogue Completion




                         complete the following conversation by role-playing as either Person A or
                         Person B. Your response should be as knowledgeable and coherent with the
                         conversation history as possible:
                         {Corpus}
                         Conversation: {Query}
                         [/INST]

Table 8: Prompt template used for RAG tasks in our experiments. {Corpus} refers to the provided contextual
knowledge base, and {Query} refers to a query in ICR2 or LOFT. A {Query} can be a question in the question
answering tasks (Kwiatkowski et al., 2019; Yang et al., 2018), a claim to be verified in the fact verification task
(Thorne et al., 2018), or a conversation history in the dialogue completion task (Dinan et al., 2018).


                                      LOFT               ICR2          • HotpotQA: Q “ 4, M “ 4
 LLaMA-3-Instruct
                                   NQ      HPQA   NQ       HPQA
 Closebook                         0.41    0.19   0.44      0.19       • WoW: Q “ 8, M “ 2
 RAG                               0.45    0.56   0.53      0.45
 RAG w/ TinyBERT                   0.89    0.89   0.55      0.48       For SFT-RTA on ICR2 :
 Oracle                            0.81    0.77   0.80      0.74
 SFT-DA                            0.80    0.60   0.51      0.52
 SFT-RTA                           0.84    0.63   0.51      0.57       • NaturalQuestions: Q “ 2, M “ 1
 SFT-DA w/ RAP                     0.83    0.72   0.61      0.60
                                                                       • HotpotQA: Q “ 2, M “ 1
Table 9: LLaMA-3’s performances on NQ and Hot-
potQA for LOFT and ICR2 with our methods on NQ-                        • FEVER: Q “ 2, M “ 8
LOFT and HPQA-LOFT.

                                                                       • WoW: Q “ 4, M “ 8
F.2.1 RAP Hyperparameter Settings
In this section, we detail the hyperparameters used                    For SFT-RTA on LOFT:
in applying RAP decoding to SFT-DA and SFT-
RTA on ICR2 and LOFT.                                                  • NaturalQuestions: Q “ 8, M “ 4
   For SFT-DA on ICR2 :
                                                                       • HotpotQA: Q “ 4, M “ 2
    • NaturalQuestions: Q “ 4, M “ 1

    • HotpotQA: Q “ 8, M “ 1                                           • WoW: Q “ 8, M “ 2

    • FEVER: Q “ 4, M “ 4                                          G     Prompt Templates for Supervised
                                                                         Fine-tuning
    • WoW: Q “ 4, M “ 4

  For SFT-DA on LOFT:                                              We visualize three templates used for super-
                                                                   vised fine-tuning LCLMs to perform retrieve-then-
    • NaturalQuestions: Q “ 4, M “ 4                               generate generation in Figure 8.
                                                                                          LOFT                                              ICR2
                 Re-ranker Model                         K
                                                                     NQ                   HPQA     MUSI.          NQ                 HPQA            FEV      WoW
                 TinyBERT                                 8          0.99                 0.98          0.80      0.61                 0.65          0.68     0.35
                 MiniLM                                   8          1.00                 0.98          0.82      0.66                 0.65          0.70     0.27
                 TinyBERT                                32          0.99                 0.99          0.81      0.89                 0.82          0.87     0.55
                 MiniLM                                  32          1.00                 1.00          0.90      0.86                 0.81          0.89     0.43
                 TinyBERT                                50          0.99                 0.99          0.82      0.91                 0.84          0.92     0.60
                 MiniLM                                  50          1.00                 1.00          0.92      0.91                 0.88          0.91     0.50
                 SFT-RTA w/ RAP                          /           0.95                 0.99          1.00      0.90                 0.95          0.97     0.92

      Table 10: Retrieval performance comparison of re-ranker models across LOFT and ICR2 benchmarks.

                                                                                             LOFT-NQ
                                              LOFT-Metrics                                  LOFT-Recall-RAP                            LOFT-Recall-RTA
                                       0.85       0.83        0.82                        0.95   0.97      0.99                      0.92     0.93     0.90
                     M=8 M=4 M=2 M=1




                                                                        M=8 M=4 M=2 M=1




                                                                                                                   M=8 M=4 M=2 M=1
                                       0.80       0.80        0.82                        0.97   1.00      1.00                      0.95     0.93     0.92

                                       0.81       0.78        0.78                        0.99   1.00      1.00                      0.94     0.85     0.87

                                       0.84       0.73        0.75                        1.00   1.00      1.00                      0.93     0.81     0.80

                                       Q=2        Q=4         Q=8                         Q=2    Q=4       Q=8                       Q=2      Q=4      Q=8

                                                                                          LOFT-HotpotQA
                                              LOFT-Metrics                                  LOFT-Recall-RAP                            LOFT-Recall-RTA
                                       0.79       0.77        0.81                        0.94   0.98      0.99                      0.96     0.95     0.95
                     M=8 M=4 M=2 M=1




                                                                        M=8 M=4 M=2 M=1




                                                                                                                   M=8 M=4 M=2 M=1




                                       0.77       0.75        0.76                        0.98   0.99      1.00                      0.95     0.95     0.93

                                       0.73       0.76        0.71                        0.99   1.00      1.00                      0.91     0.96     0.88

                                       0.73       0.68        0.68                        1.00   1.00      1.00                      0.90     0.85     0.85

                                       Q=2        Q=4         Q=8                         Q=2    Q=4       Q=8                       Q=2      Q=4      Q=8

                                                                                          LOFT-MUSIQUE
                                              LOFT-Metrics                                  LOFT-Recall-RAP                            LOFT-Recall-RTA
                                       0.23       0.23        0.37                        0.62   0.69      0.81                      0.38     0.39     0.44
                     M=8 M=4 M=2 M=1




                                                                        M=8 M=4 M=2 M=1




                                                                                                                   M=8 M=4 M=2 M=1




                                       0.31       0.24        0.25                        0.79   0.89      0.94                      0.40     0.38     0.37

                                       0.29       0.32        0.39                        0.90   0.96      1.00                      0.36     0.33     0.39

                                       0.33       0.31        0.27                        0.96   1.00      1.00                      0.41     0.33     0.37

                                       Q=2        Q=4         Q=8                         Q=2    Q=4       Q=8                       Q=2      Q=4      Q=8



Figure 6: Effect of adjusting Q (number of attention heads for retrieval) and M (number of passages to select)
when applying SFT-RTA + RAP on all tasks in LOFT. Left column: average model performance measured by the
tasks-specific metrics. Middle column: retrieval performance measured by the recall rate. Right column: retrieval
performance measured by the exact match.


H    Visualization for Joint Retrieval Head                                                         I      Effect of Retrieval Delineation
     Training
                                                                                                    As outlined in Section 4.1, our retrieve-then-
We visualize the architecture for adding a retrieval                                                generate variants, SFT-RTA and SFT-CCI, utilize
head jointly trained with language generation in                                                    special symbols <RETRIEVAL> and </RETRIEVAL>
Figure 9 for easing the understanding of the ap-                                                    to explicitly mark the boundaries of the retrieval
proach.                                                                                             step. To examine the impact of these boundary to-
                                                                                               ICR2-NQ
                                                   ICR2-Metrics                               ICR2-Recall-RAP                         ICR2-Recall-RTA
                                            0.61       0.56       0.59                      0.80   0.85    0.89                     0.58   0.60    0.60




                          M=8 M=4 M=2 M=1




                                                                          M=8 M=4 M=2 M=1




                                                                                                                  M=8 M=4 M=2 M=1
                                            0.63       0.61       0.61                      0.90   0.96    0.97                     0.61   0.65    0.59

                                            0.54       0.58       0.56                      0.96   1.00    1.00                     0.60   0.59    0.57

                                            0.62       0.61       0.56                      0.97   1.00    1.00                     0.61   0.57    0.55

                                            Q=2        Q=4        Q=8                       Q=2    Q=4     Q=8                      Q=2    Q=4     Q=8

                                                                                            ICR2-HotpotQA
                                                   ICR2-Metrics                               ICR2-Recall-RAP                         ICR2-Recall-RTA
                                            0.71       0.65       0.67                      0.93   0.92    0.99                     0.85   0.75    0.81
                          M=8 M=4 M=2 M=1




                                                                          M=8 M=4 M=2 M=1




                                                                                                                  M=8 M=4 M=2 M=1
                                            0.71       0.65       0.64                      0.95   0.96    1.00                     0.80   0.81    0.78

                                            0.62       0.64       0.62                      0.99   1.00    1.00                     0.77   0.77    0.77

                                            0.59       0.59       0.64                      1.00   1.00    1.00                     0.78   0.77    0.79

                                            Q=2        Q=4        Q=8                       Q=2    Q=4     Q=8                      Q=2    Q=4     Q=8

                                                                                             ICR2-FEVER
                                                   ICR2-Metrics                               ICR2-Recall-RAP                         ICR2-Recall-RTA
                                            0.88       0.90       0.90                      0.82   0.87    0.93                     0.59   0.59    0.60
                          M=8 M=4 M=2 M=1




                                                                          M=8 M=4 M=2 M=1




                                                                                                                  M=8 M=4 M=2 M=1
                                            0.89       0.89       0.91                      0.87   0.96    0.96                     0.60   0.66    0.65

                                            0.89       0.90       0.91                      0.93   0.99    1.00                     0.60   0.61    0.64

                                            0.92       0.91       0.90                      0.97   1.00    1.00                     0.60   0.64    0.59

                                            Q=2        Q=4        Q=8                       Q=2    Q=4     Q=8                      Q=2    Q=4     Q=8

                                                                                              ICR2-WoW
                                                   ICR2-Metrics                               ICR2-Recall-RAP                         ICR2-Recall-RTA
                                            0.21       0.22       0.21                      0.50   0.66    0.71                     0.42   0.41    0.40
                          M=8 M=4 M=2 M=1




                                                                          M=8 M=4 M=2 M=1




                                                                                                                  M=8 M=4 M=2 M=1




                                            0.21       0.22       0.22                      0.66   0.86    0.88                     0.40   0.41    0.44

                                            0.21       0.22       0.22                      0.79   0.91    0.95                     0.42   0.41    0.43

                                            0.23       0.20       0.21                      0.92   0.98    0.99                     0.41   0.37    0.46

                                            Q=2        Q=4        Q=8                       Q=2    Q=4     Q=8                      Q=2    Q=4     Q=8



Figure 7: Effect of adjusting Q (number of attention heads for retrieval) and M (number of passages to select)
when applying SFT-RTA + RAP on all tasks in ICR2 . Left column: average model performance measured by the
tasks-specific metrics. Middle column: retrieval performance measured by the recall rate. Right column: retrieval
performance measured by the exact match.


 Benchmark      SFT-RTA                 w{o <RET>        SFT-CCI         w{o <RET>
                                                                                                      kens, we conducted an ablation study. As shown in
        NQ         0.74              0.7 (Ó .04)              0.76       0.63 (Ó .13)
                                                                                                      Table 11, removing these tokens in general leads to
 LOFT




        HPQA       0.69             0.66 (Ó .03)              0.54       0.58 (Ò .04)                 a decline in model performance. This suggests that
        MUSI.      0.33             0.24 (Ó .09)              0.35       0.24 (Ó .11)                 clearly delineating the retrieval step is crucial for
        NQ         0.60             0.56 (Ó .04)              0.63       0.61 (Ó .02)                 the model to learn effectively.
 ICR2




        HPQA       0.67              0.7 (Ó .03)              0.63       0.65 (Ò .02)
        FEVER      0.91             0.92 (Ò .01)              0.89       0.86 (Ó .03)
        WoW        0.22             0.20 (Ó .02)              0.21       0.22 (Ò .01)


Table 11: Effect of removing the special boundary to-
kens for the retrieve-then-generate variants.
                                                                                                          Direct Answer: The answer is
        Input: Answer the                                                                                 February 14, 2018.
        question based on the
        provided corpus.
                                                                                    LCLM
                                                                                                          Retrieve-then-Answer: The
                                                                                                          relevant passage for the
        Corpus: {                                                             Contextual Knowledge Base   question is, “Barry was born
           PSG001: {p_1}                                                                                  in February 14, 2018.” The
                                                                                                          correct answer is February
           PSG002: {p_2}
                                                                                                          14, 2018.
           …
        }
                                                                                                          Cite-Context-ID: The
                                                                                                          relevant passage ID for this
        Query: When is Barry’s                                                                            question is PSG004. The
        birthday?                                                                                         correct answer is February
                                                                                                          14, 2018.


    Figure 8: Templates for Direct Answer (DA), Retrieve-Then-Answer (RTA) and Cite-Context-ID (CCI).




                                      Gumbel           10010
            Retrieval Head             Top-K
                                                       01101




                LCLM                                   LCLM
          Contextual Knowledge Base              Contextual Knowledge Base




         Query: When is Barry’s                Direct Answer: The answer is
         birthday?                             February 14, 2018.




Figure 9: A retrieval head is added to predict the Top-
K context for generating final responses. The head is
jointly optimized with the generation head.
