Graph-KV: Breaking Sequence via Injecting Structural Biases into Large Language Models

Haoyu Peter Wang, Peihao Wang, Mufei Li, Shikun Liu, Siqi Miao, Zhangyang Wang, Pan Li

Abstract

Large Language Models (LLMs) are traditionally constrained by linear processing, treating structured data as flat sequences. This serialization leads to positional bias, quadratic computational complexity, and rapid context window exhaustion. We present Graph-KV, a framework that injects structural inductive biases directly into the LLM's attention mechanism. By treating text segments as nodes in a graph and utilizing shared positional encodings, Graph-KV allows segments to attend to each other based on actual relationships rather than arbitrary sequence. Our results demonstrate that Graph-KV significantly reduces positional bias, improves accuracy in complex multi-hop reasoning tasks, and scales to much larger contexts than standard sequential encoding.

Introduction

The auto-regressive nature of modern LLMs forces them to process information as a fixed sequence. When dealing with inherently non-linear data—such as citation networks or retrieved document chunks in Retrieval-Augmented Generation (RAG)—this "forced serialization" introduces significant limitations. Specifically, models suffer from the "lost in the middle" phenomenon (positional bias), $O(n^2)$ complexity, and hard limits on context window size due to unique position indexing for every token.

Overview of the challenges in sequential LLM processing and the proposed Graph-KV solution.

Methods

Graph-KV re-imagines the LLM's input as a graph. It utilizes the Key-Value (KV) cache of text segments as node representations. The core innovation is a structure-aware attention mechanism implemented via a graph-structured block mask. This allows a "target" segment to attend only to its relevant "source" segments, effectively performing message-passing within the attention layers.

To mitigate positional bias and save context space, Graph-KV employs Shared Positional Encodings (PEs). All source segments share the same range of position indices $[0, L)$, while target segments follow at $[L, 2L)$. This makes the model invariant to the order of source documents and drastically reduces context window consumption. For RAG tasks, a bipartite graph is constructed where the most relevant chunks act as sources for the remaining content.

The two-step process of Graph-KV: injecting structural inductive biases during prefilling and attending to the query.

Evaluation and Results

The researchers evaluated Graph-KV across diverse challenges, including standard RAG benchmarks (NarrativeQA, HotpotQA) and a new ARXIV-QA benchmark consisting of 60 technical questions derived from 472 full-text scientific papers.

Key findings include:

  • Superior Accuracy: In multi-hop tasks like 2Wiki, Graph-KV-Top-3 outperformed the Block-RAG baseline by 6.93% in the "compose" category.
  • Robustness to Distractors: In the ARXIV-QA task, Graph-KV remained robust to distractor papers, maintaining high accuracy even as context grew to over 100k tokens, whereas standard sequential encoding accuracy plummeted.
  • Efficiency: Graph-KV can encode 3x more neighbor nodes than sequential encoding on the same hardware and achieves lower Time-To-First-Token (TTFT) by enabling parallel pre-filling of text chunks.

Conclusion

Graph-KV demonstrates that the linear constraint of LLMs is not an insurmountable barrier. By manipulating attention masks and positional encodings, we can leverage the inherent structural properties of data to improve both performance and efficiency. While current evaluations focus on one-hop dependencies, future work will explore deeper graph topologies and further fine-tuning to optimize LLM backbones for this non-linear architecture.

Summary updated

BibTeX
@inproceedings{wang2025graph,
  author = {Haoyu Peter Wang and Peihao Wang and Mufei Li and Shikun Liu and Siqi Miao and Zhangyang Wang and Pan Li},
  title = {{Graph-KV: Breaking Sequence via Injecting Structural Biases into Large Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=J4w4RtwLyB},
}
Figure