Abstract
This paper addresses the challenge of comprehending very long contexts in Large Language Models (LLMs) by proposing a method that emulates Retrieval Augmented Generation (RAG) through specialized prompt engineering and chain-of-thought (CoT) reasoning. While recent LLMs support over 100,000 tokens in a single prompt, simply enlarging context windows has not guaranteed robust multi-hop reasoning when key details are scattered across massive input. Our approach treats the model as both the retriever and the reasoner: it first tags relevant segments within a long passage, then employs a stepwise CoT workflow to integrate these pieces of evidence. This single-pass method thereby reduces reliance on an external retriever, yet maintains focus on crucial segments. We evaluate our approach on selected tasks from BABILong, which interleaves standard bAbI QA problems with large amounts of distractor text. Compared to baseline (no retrieval) and naive RAG pipelines, our approach more accurately handles multi-fact questions such as object location tracking, counting, and indefinite knowledge. Furthermore, we analyze how prompt structure, including the order of question, relevant-text tags, and overall instructions, significantly affects performance. These findings underscore that optimized prompt engineering, combined with guided reasoning, can enhance LLMs' long-context comprehension and serve as a lightweight alternative to traditional retrieval pipelines.
Introduction
We are currently in the era of "Long Context" LLMs, with models like Gemini and GPT-4o supporting windows of 128k to 1M+ tokens. However, having a large "memory" does not necessarily equate to high "intelligence" over that memory. Two main issues persist in long-context processing: Context Dilution, where key facts are lost amidst "noise" (the "lost in the middle" phenomenon), and RAG Limitations, where external retrieval systems fail to capture all necessary facts for multi-hop reasoning.
Researchers at Kyoto University propose a "middle way" that utilizes the full context window but forces the model to focus like a retriever before it acts as a reasoner. This "Emulated RAG" strategy turns an LLM into its own retriever and reasoner within a single prompt pass.
Methodology
The core contribution is a four-step workflow executed in a single forward pass. This method, termed the RAGPromptingAgent, structures the interaction to ensure the model identifies and synthesizes relevant information before attempting a final answer.
The Single-Pass Workflow
- Tagging (Internal Retriever): The model is instructed to read the long text and wrap relevant sentences in
<relevant_section>tags, noting their approximate position (e.g., "position=12.3%"). - Localized Summaries: The model generates a bulleted list of entities and actions found exclusively within those tagged sections.
- Chain-of-Thought (CoT) Synthesis: The model performs multi-hop reasoning using only the summaries it just created.
- Final Answer: The model provides a concise response based on the synthesis.
A critical finding of the study is the importance of Prompt Order. The researchers found that a "Question First" approach—where the model knows exactly what it is looking for before it processes the massive input—is vital for effective attention filtering.
Experimental Evaluation
The method was evaluated using BABILong, a benchmark designed to test long-context reasoning by hiding facts inside massive amounts of distractor text from the PG19 book corpus. The study focused on several complex tasks:
- QA2 (Two Supporting Facts): Connecting two distant events.
- QA7 (Counting): Tracking multiple pick-up/drop-off events.
- QA10 (Indefinite Knowledge): Handling uncertainty (yes/no/maybe).
Tests were conducted at 16k, 32k, and 64k token lengths using models including gpt-4o-mini and llama-3.1-8b-instruct.
Results and Discussion
The proposed Emulated RAG method showed dominant performance over both vanilla long-context prompting (Baseline) and traditional external RAG pipelines.
As shown in the results for the QA2 multi-hop task, traditional RAG performed poorly (often near 0.04 accuracy) because external retrievers frequently failed to capture both necessary facts simultaneously. In contrast, the proposed method achieved an accuracy of 0.44 on gpt-4o-mini at 64k tokens, significantly outperforming the baseline's 0.28. Even the smaller llama-3.1-8b model showed significant improvements, hitting 0.52 accuracy on the QA7 counting task at 16k tokens compared to 0.32 for the RAG baseline.
These results demonstrate that modern LLMs are capable of acting as high-quality internal retrievers when provided with structural "scaffolding" like tags and position markers.
Conclusion
This research proves that optimized prompt engineering can effectively emulate RAG, providing a lightweight and robust alternative to external retrieval pipelines for long-context comprehension. While the method relies on model obedience to complex tagging instructions and may increase token costs due to longer outputs, it bypasses the narrowness of traditional RAG. Future work may involve hybrid tool integration, where the model attempts this single-pass method first and only calls an external retriever if it fails to identify relevant tags.
Summary updated