{"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/scaling-retrieval-based-language-models-with","title":"Scaling Retrieval-Based Language Models with a Trillion-Token Datastore","arxiv_id":"2407.12854","date":"2024-07-09","proceeding":null,"authors":["Rulin Shao","Jacqueline He","Akari Asai","Weijia Shi","Tim Dettmers","Sewon Min","Luke Zettlemoyer","Pang Wei Koh"],"abstract":"Scaling laws with respect to the amount of training data and the number of parameters allow us to predict the cost-benefit trade-offs of pretraining language models (LMs) in different configurations. In this paper, we consider another dimension of scaling: the amount of data available at inference time. Specifically, we find that increasing the size of the datastore used by a retrieval-based LM monotonically improves language modeling and several downstream tasks without obvious saturation, such that a smaller model augmented with a large datastore outperforms a larger LM-only model on knowledge-intensive tasks. By plotting compute-optimal scaling curves with varied datastore, model, and pretraining data sizes, we show that using larger datastores can significantly improve model performance for the same training compute budget. We carry out our study by constructing a 1.4 trillion-token datastore named MassiveDS, which is the largest and the most diverse open-sourced datastore for retrieval-based LMs to date, and designing an efficient pipeline for studying datastore scaling in a computationally accessible manner. Finally, we analyze the effect of improving the retriever, datastore quality filtering, and other design choices on our observed scaling trends. Overall, our results show that datastore size should be considered as an integral part of LM efficiency and performance trade-offs. To facilitate future research, we open-source our datastore and code at https://github.com/RulinShao/retrieval-scaling.","url_abs":"https://arxiv.org/abs/2407.12854v1","url_pdf":"https://arxiv.org/pdf/2407.12854v1.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":"scaling-retrieval-based-language-models-with","repo_url":"https://github.com/rulinshao/retrieval-scaling","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"retrieval","task_name":"Retrieval"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2407.12854","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2407.12854"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+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/rulinshao/retrieval-scaling","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran_fixture":1,"ran":12,"unverified":1},"by_repo_kind":{"official":{"samples":14,"ran":13,"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":"bc7a7a194c238080","entry":"add_embeddings","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"contriever/passage_retrieval.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/contriever/passage_retrieval.py","link_basis":"plan_row","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"bc7a7a194c238080"}},{"code_sha256_prefix":"ce1279ff0f9d0ad4","entry":"check_below_lexical_overlap_threshold","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"src/decontamination.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/src/decontamination.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ce1279ff0f9d0ad4"}},{"code_sha256_prefix":"afaf6b8bca6e2795","entry":"check_endpoint","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"api/serve_main_node.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/api/serve_main_node.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"afaf6b8bca6e2795"}},{"code_sha256_prefix":"290c5134d15244b3","entry":"extract_answer","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"src/evaluate_perplexity.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/src/evaluate_perplexity.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"290c5134d15244b3"}},{"code_sha256_prefix":"24e1876e4b2645ed","entry":"extract_running_endpoints","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"api/serve_main_node.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/api/serve_main_node.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"24e1876e4b2645ed"}},{"code_sha256_prefix":"e199a8fd8e8c353f","entry":"generate_13word_grams","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"src/decontamination.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/src/decontamination.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e199a8fd8e8c353f"}},{"code_sha256_prefix":"71b717cfe94bf7d2","entry":"get_bm25_index_dir","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"src/index.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/src/index.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"71b717cfe94bf7d2"}},{"code_sha256_prefix":"ab7ba9276e2369aa","entry":"get_search_output_path","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"src/search.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/src/search.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ab7ba9276e2369aa"}},{"code_sha256_prefix":"00dd34a32eb05634","entry":"get_sharded_passages","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"src/embed.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/src/embed.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"00dd34a32eb05634"}},{"code_sha256_prefix":"5cbcb4692500af92","entry":"hydra_runner","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"src/hydra_runner.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/src/hydra_runner.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5cbcb4692500af92"}},{"code_sha256_prefix":"87bbb67c9c88bea4","entry":"max_contiguous_overlap","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"src/decontamination.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/src/decontamination.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"87bbb67c9c88bea4"}},{"code_sha256_prefix":"d2a9c470a304b933","entry":"rerank_elements","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"api/serve_main_node.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/api/serve_main_node.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d2a9c470a304b933"}},{"code_sha256_prefix":"7b2c46dc9de9bec4","entry":"split_data_into_chunks","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"src/data.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/src/data.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"7b2c46dc9de9bec4"}},{"code_sha256_prefix":"97e49e2086fde576","entry":"load_passages","repo":"rulinshao/retrieval-scaling","repo_kind":"official","path":"src/data.py","file_url":"https://github.com/rulinshao/retrieval-scaling/blob/HEAD/src/data.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"97e49e2086fde576"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}