{"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/memorag-moving-towards-next-gen-rag-via","title":"MemoRAG: Moving towards Next-Gen RAG Via Memory-Inspired Knowledge Discovery","arxiv_id":"2409.05591","date":"2024-09-09","proceeding":null,"authors":["Hongjin Qian","Peitian Zhang","Zheng Liu","Kelong Mao","Zhicheng Dou"],"abstract":"Retrieval-Augmented Generation (RAG) leverages retrieval tools to access external databases, thereby enhancing the generation quality of large language models (LLMs) through optimized context. However, the existing retrieval methods are constrained inherently, as they can only perform relevance matching between explicitly stated queries and well-formed knowledge, but unable to handle tasks involving ambiguous information needs or unstructured knowledge. Consequently, existing RAG systems are primarily effective for straightforward question-answering tasks. In this work, we propose MemoRAG, a novel retrieval-augmented generation paradigm empowered by long-term memory. MemoRAG adopts a dual-system architecture. On the one hand, it employs a light but long-range LLM to form the global memory of database. Once a task is presented, it generates draft answers, cluing the retrieval tools to locate useful information within the database. On the other hand, it leverages an expensive but expressive LLM, which generates the ultimate answer based on the retrieved information. Building on this general framework, we further optimize MemoRAG's performance by enhancing its cluing mechanism and memorization capacity. In our experiment, MemoRAG achieves superior performance across a variety of evaluation tasks, including both complex ones where conventional RAG fails and straightforward ones where RAG is commonly applied.","url_abs":"https://arxiv.org/abs/2409.05591v2","url_pdf":"https://arxiv.org/pdf/2409.05591v2.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":"memorag-moving-towards-next-gen-rag-via","repo_url":"https://github.com/qhjqhj00/memorag","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"memorization","task_name":"Memorization"},{"task_slug":"question-answering","task_name":"Question Answering"},{"task_slug":"rag","task_name":"RAG"},{"task_slug":"retrieval","task_name":"Retrieval"},{"task_slug":"retrieval-augmented-generation","task_name":"Retrieval-augmented Generation"}],"methods":[{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"bart","method_name":"BART"},{"method_slug":"bert","method_name":"BERT"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"linear-warmup-with-linear-decay","method_name":"Linear Warmup With Linear Decay"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"rag","method_name":"RAG"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"weight-decay","method_name":"Weight Decay"},{"method_slug":"wordpiece","method_name":"WordPiece"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2409.05591","atlas_url":"https://app.syntology.ai/?focus=2409.05591","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2409.05591"}},"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/qhjqhj00/memorag","reach":{"status":"ok","spdx":"Apache-2.0"}}],"summary":{"ran":9,"unverified":2},"by_repo_kind":{"official":{"samples":11,"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":0,"samples":[{"code_sha256_prefix":"019064fb2dc127e6","entry":"cat_tensor","repo":"qhjqhj00/memorag","repo_kind":"official","path":"train/src/modeling_beacon.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/train/src/modeling_beacon.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"019064fb2dc127e6"}},{"code_sha256_prefix":"8f2480ff6950770e","entry":"except_retry_dec","repo":"qhjqhj00/memorag","repo_kind":"official","path":"memorag/agent.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/memorag/agent.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"8f2480ff6950770e"}},{"code_sha256_prefix":"5e960b1ca7bef007","entry":"get_shifted_labels","repo":"qhjqhj00/memorag","repo_kind":"official","path":"train/src/modeling_utils.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/train/src/modeling_utils.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"5e960b1ca7bef007"}},{"code_sha256_prefix":"141f4c8b387bca52","entry":"mask_nested_lists","repo":"qhjqhj00/memorag","repo_kind":"official","path":"train/src/chat.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/train/src/chat.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"141f4c8b387bca52"}},{"code_sha256_prefix":"f29d09a2b245b362","entry":"merge_inputs","repo":"qhjqhj00/memorag","repo_kind":"official","path":"memorag/memorag.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/memorag/memorag.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"f29d09a2b245b362"}},{"code_sha256_prefix":"b8a81a4b39c05cff","entry":"move_to_device","repo":"qhjqhj00/memorag","repo_kind":"official","path":"train/src/modeling_utils.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/train/src/modeling_utils.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"b8a81a4b39c05cff"}},{"code_sha256_prefix":"7598dbd722b803a3","entry":"optional_grad_ctx","repo":"qhjqhj00/memorag","repo_kind":"official","path":"train/src/modeling_utils.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/train/src/modeling_utils.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"7598dbd722b803a3"}},{"code_sha256_prefix":"defaf52f8cef4a26","entry":"slice_activations","repo":"qhjqhj00/memorag","repo_kind":"official","path":"train/src/modeling_beacon.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/train/src/modeling_beacon.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"defaf52f8cef4a26"}},{"code_sha256_prefix":"6b7f09c9bef8e516","entry":"slice_tensor","repo":"qhjqhj00/memorag","repo_kind":"official","path":"train/src/modeling_beacon.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/train/src/modeling_beacon.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"6b7f09c9bef8e516"}},{"code_sha256_prefix":"561fab9ba99c10a9","entry":"apply_chat_template","repo":"qhjqhj00/memorag","repo_kind":"official","path":"train/src/chat.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/train/src/chat.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"561fab9ba99c10a9"}},{"code_sha256_prefix":"63d36f1757a0760e","entry":"get_conv_template","repo":"qhjqhj00/memorag","repo_kind":"official","path":"train/src/chat.py","file_url":"https://github.com/qhjqhj00/memorag/blob/HEAD/train/src/chat.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"63d36f1757a0760e"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}