{"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/block-attention-for-efficient-rag","title":"Block-Attention for Efficient RAG","arxiv_id":"2409.15355","date":"2024-09-14","proceeding":null,"authors":["East Sun","Yan Wang","Lan Tian"],"abstract":"We introduce Block-Attention, an attention mechanism designed to address the increased inference latency and cost in Retrieval-Augmented Generation (RAG) scenarios. Traditional approaches often encode the entire context. Instead, Block-Attention divides retrieved documents into discrete blocks, with each block independently calculating key-value (KV) states except for the final block. In RAG scenarios, by defining each passage as a block, Block-Attention enables us to reuse the KV states of passages that have been seen before, thereby significantly reducing the latency and the computation overhead during inference. The implementation of Block-Attention involves block segmentation, position re-encoding, and fine-tuning the LLM to adapt to the Block-Attention mechanism. Experiments on four RAG benchmarks demonstrate that after block fine-tuning, the Block-Attention model achieves performance comparable to self-attention models (68.4\\% vs 67.9\\% on Llama3) or even superior performance (62.8\\% vs 59.6\\% on Mistral). Notably, Block-Attention significantly reduces the time to first token (TTFT) and floating point operations (FLOPs) to a very low level. It only takes 45 ms to output the first token for an input sequence with a total length of 32K. Compared to the self-attention models, the time consumption and corresponding FLOPs are reduced by 98.7\\% and 99.8\\%, respectively.","url_abs":"https://arxiv.org/abs/2409.15355v4","url_pdf":"https://arxiv.org/pdf/2409.15355v4.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":"block-attention-for-efficient-rag","repo_url":"https://github.com/temporarylora/block-attention","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"rag","task_name":"RAG"},{"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.15355","atlas_url":"https://app.syntology.ai/?focus=2409.15355","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2409.15355"}},"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/temporarylora/block-attention","reach":null}],"summary":{"ran_draft_wrong":1,"unverified":6},"by_repo_kind":{"official":{"samples":7,"ran":1,"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":7,"samples":[{"code_sha256_prefix":"be9b02c5fb845efa","entry":"rotate_half","repo":"temporarylora/block-attention","repo_kind":"official","path":"server/block_generate_server.py","file_url":"https://github.com/temporarylora/block-attention/blob/HEAD/server/block_generate_server.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"be9b02c5fb845efa"}},{"code_sha256_prefix":"1853a543d08b4755","entry":"apply_pkv_rerotary_position_embeddings","repo":"temporarylora/block-attention","repo_kind":"official","path":"server/block_generate_server.py","file_url":"https://github.com/temporarylora/block-attention/blob/HEAD/server/block_generate_server.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1853a543d08b4755"}},{"code_sha256_prefix":"1accbb1e8317f01e","entry":"apply_pkv_rotary_position_embeddings","repo":"temporarylora/block-attention","repo_kind":"official","path":"server/block_generate_server.py","file_url":"https://github.com/temporarylora/block-attention/blob/HEAD/server/block_generate_server.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"1accbb1e8317f01e"}},{"code_sha256_prefix":"a3b19d6770296556","entry":"apply_rotary_pos_emb","repo":"temporarylora/block-attention","repo_kind":"official","path":"server/block_generate_server.py","file_url":"https://github.com/temporarylora/block-attention/blob/HEAD/server/block_generate_server.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a3b19d6770296556"}},{"code_sha256_prefix":"7787b520e2578066","entry":"block_generate","repo":"temporarylora/block-attention","repo_kind":"official","path":"server/block_generate_server.py","file_url":"https://github.com/temporarylora/block-attention/blob/HEAD/server/block_generate_server.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7787b520e2578066"}},{"code_sha256_prefix":"c269b57f84d7e5a5","entry":"build_block_past_key_values","repo":"temporarylora/block-attention","repo_kind":"official","path":"server/block_generate_server.py","file_url":"https://github.com/temporarylora/block-attention/blob/HEAD/server/block_generate_server.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c269b57f84d7e5a5"}},{"code_sha256_prefix":"4f72af19df6fbcfa","entry":"merge_and_rotary_past_key_values","repo":"temporarylora/block-attention","repo_kind":"official","path":"server/block_generate_server.py","file_url":"https://github.com/temporarylora/block-attention/blob/HEAD/server/block_generate_server.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"4f72af19df6fbcfa"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}