{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/can-t-remember-details-in-long-documents-you","title":"Can't Remember Details in Long Documents? You Need Some R&R","arxiv_id":"2403.05004","date":"2024-03-08","proceeding":null,"authors":["Devanshu Agrawal","Shang Gao","Martin Gajek"],"abstract":"Long-context large language models (LLMs) hold promise for tasks such as question-answering (QA) over long documents, but they tend to miss important information in the middle of context documents (arXiv:2307.03172v3). Here, we introduce $\\textit{R&R}$ -- a combination of two novel prompt-based methods called $\\textit{reprompting}$ and $\\textit{in-context retrieval}$ (ICR) -- to alleviate this effect in document-based QA. In reprompting, we repeat the prompt instructions periodically throughout the context document to remind the LLM of its original task. In ICR, rather than instructing the LLM to answer the question directly, we instruct it to retrieve the top $k$ passage numbers most relevant to the given question, which are then used as an abbreviated context in a second QA prompt. We test R&R with GPT-4 Turbo and Claude-2.1 on documents up to 80k tokens in length and observe a 16-point boost in QA accuracy on average. Our further analysis suggests that R&R improves performance on long document-based QA because it reduces the distance between relevant context and the instructions. Finally, we show that compared to short-context chunkwise methods, R&R enables the use of larger chunks that cost fewer LLM calls and output tokens, while minimizing the drop in accuracy.","url_abs":"https://arxiv.org/abs/2403.05004v1","url_pdf":"https://arxiv.org/pdf/2403.05004v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"can-t-remember-details-in-long-documents-you","repo_url":"https://github.com/casetext/r-and-r","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok"}}],"tasks":[{"task_slug":"question-answering","task_name":"Question Answering"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"gpt-4","method_name":"GPT-4"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2403.05004","atlas_url":"https://app.syntology.ai/?focus=2403.05004","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2403.05004"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/casetext/r-and-r","reach":{"status":"ok"}}],"summary":{"ran":9},"by_repo_kind":{"official":{"samples":9,"ran":9,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":9,"samples":[{"code_sha256_prefix":"841e9916ae689986","entry":"fuzzy_match","repo":"casetext/r-and-r","repo_kind":"official","path":"src/metrics.py","file_url":"https://github.com/casetext/r-and-r/blob/HEAD/src/metrics.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"841e9916ae689986"}},{"code_sha256_prefix":"1aa6ab3d47a5bf82","entry":"get_answer","repo":"casetext/r-and-r","repo_kind":"official","path":"src/prompts.py","file_url":"https://github.com/casetext/r-and-r/blob/HEAD/src/prompts.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1aa6ab3d47a5bf82"}},{"code_sha256_prefix":"2be958fb9ab8b142","entry":"get_files","repo":"casetext/r-and-r","repo_kind":"official","path":"tables.py","file_url":"https://github.com/casetext/r-and-r/blob/HEAD/tables.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2be958fb9ab8b142"}},{"code_sha256_prefix":"33f4638415122885","entry":"get_single_page","repo":"casetext/r-and-r","repo_kind":"official","path":"src/prompts.py","file_url":"https://github.com/casetext/r-and-r/blob/HEAD/src/prompts.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"33f4638415122885"}},{"code_sha256_prefix":"3d1e818d7f65a61c","entry":"paginate","repo":"casetext/r-and-r","repo_kind":"official","path":"src/datasets.py","file_url":"https://github.com/casetext/r-and-r/blob/HEAD/src/datasets.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"3d1e818d7f65a61c"}},{"code_sha256_prefix":"71a5af9ea11d13f8","entry":"parse_json","repo":"casetext/r-and-r","repo_kind":"official","path":"src/parsers.py","file_url":"https://github.com/casetext/r-and-r/blob/HEAD/src/parsers.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"71a5af9ea11d13f8"}},{"code_sha256_prefix":"e7306a01494995f2","entry":"parse_page","repo":"casetext/r-and-r","repo_kind":"official","path":"src/parsers.py","file_url":"https://github.com/casetext/r-and-r/blob/HEAD/src/parsers.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e7306a01494995f2"}},{"code_sha256_prefix":"14bb61c15d11669b","entry":"parse_single_json","repo":"casetext/r-and-r","repo_kind":"official","path":"src/parsers.py","file_url":"https://github.com/casetext/r-and-r/blob/HEAD/src/parsers.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"14bb61c15d11669b"}},{"code_sha256_prefix":"2e07faa19f9232b0","entry":"query_expansion","repo":"casetext/r-and-r","repo_kind":"official","path":"src/prompts.py","file_url":"https://github.com/casetext/r-and-r/blob/HEAD/src/prompts.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2e07faa19f9232b0"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}