Knowledge Graph Enhanced Memory-Augmented Retrieval for Long Context Modeling

Ghadir Alselwi, Basem Suleiman, Hao Xue, Shoaib Jameel, Hakim Hacid, Flora D. Salim, Imran RazzakarXiv 2026

TL;DR

KGERMAR advances long-context language modeling by dynamically constructing context-specific knowledge graphs from input text in real time during inference. By fusing structural entity relationships with traditional semantic and contextual memory, it achieves up to an 8.5% reduction in perplexity and 2–2.5× better memory efficiency than purely semantic retrieval baselines across context lengths up to 32K tokens.

What Problem Does This Paper Address?

As large language models (LLMs) scale to handle longer contexts, they face a fundamental challenge: maintaining a coherent understanding of entity states and causal relationships across thousands of tokens. Current solutions generally fall into two camps, both of which have critical blind spots:

  1. Extended-attention models suffer from "lost-in-the-middle" degradation, where the model systematically ignores information buried in the middle of a long prompt.
  2. Memory-augmented retrieval systems scale better by fetching relevant text chunks, but they rely exclusively on semantic similarity. They retrieve passages based on shared vocabulary rather than tracking how an entity's state changes over time.

For example, if a user troubleshooting a printer says, "It's showing that same error from the beginning," a semantic retriever might pull up any paragraph mentioning "error." It cannot inherently distinguish between the initial setup failure, a subsequent resolved issue, or an unrelated error code. Furthermore, existing structural approaches rely on static, general-purpose knowledge graphs (like ConceptNet), which completely miss session-specific details (like a specific printer model or a unique sequence of user actions).

Methods

The authors introduce KGERMAR (Knowledge Graph Enhanced Memory-Augmented Retrieval), a framework that extracts structural information directly from the input text on-the-fly to guide retrieval.

Figure 2: Architecture diagram illustrating the four main components: contextual knowledge graph construction, graph-enhanced embedding generation, multi-component memory architecture, and multi-modal retrieval mecha- nism.

The pipeline consists of four integrated components:

  1. Contextual Knowledge Graph Construction: During inference, the system uses a fine-tuned BERT-large model for Named Entity Recognition (NER) and a BERT-base model for Relation Extraction (RE) within a local sliding window. Variant mentions of the same entity are consolidated using string and embedding similarity.
  2. Graph-Enhanced Embedding Generation: A Relational Graph Convolutional Network (R-GCN) processes the extracted triples, allowing entities to aggregate neighborhood information across multiple hops. These structural graph embeddings are then fused with textual entity embeddings from the base LLM via cross-modal attention.
  3. Multi-Component Memory Architecture: KGERMAR maintains three distinct memory banks:
  4. Contextual memory: Token-level key-value (KV) pairs from intermediate layers.
  5. Semantic memory: Dense chunk-level text embeddings (using BGE-M3).
  6. Structural memory: The fused text-graph entity embeddings.
  7. Hybrid Retrieval Mechanism: For any given query, parallel top-$K$ retrieval is executed across all three banks. The retrieval signals are combined using learned fusion weights, and the most relevant historical contexts are injected back into the LLM's upper layers using retrieval causal attention.

Datasets

  • Fine-tuning: SlimPajama (84.7K training examples), a deduplicated web, book, and code corpus.
  • Long-Context Evaluation:
  • WikiText-103 (4,358 test examples): Rich in encyclopedic entity relationships.
  • PG-19 (100 test examples): Book-length narratives requiring long-range tracking.
  • Proof-pile (46.3K test examples): Mathematical and scientific text.
  • In-Context Learning (ICL) Benchmarks: Evaluated on five downstream NLU tasks: SST-2, MR, Subj, SST-5, and MPQA.

Key Insights and Ideas

  • The Text is Its Own Knowledge Base: Instead of relying on rigid, pre-built external knowledge bases, KGERMAR treats the input stream itself as a dynamic source of truth. This allows it to adapt to highly specialized, session-specific jargon in real time.
  • Structure Trumps Lexical Co-occurrence: In long documents, the most relevant context might share zero vocabulary with the current query but share an explicit causal or structural link. Fusing graph topology with text embeddings captures these hidden dependencies.
  • Deterministic Memory Access Stabilizes Scaling: By offloading long-term context to structured and semantic memory banks managed by an LRU (Least Recently Used) eviction policy, KGERMAR tames the quadratic memory growth typical of standard transformers.

Key Results

  • Perplexity Reductions: KGERMAR consistently achieved the lowest perplexity among all memory-augmented 3B models. Notably, it achieved up to an 8.5% lower perplexity on WikiText-103 compared to its direct predecessor, ERMAR.
  • Memory Efficiency: At a 32K token context length, KGERMAR demonstrated a 2–2.5× reduction in peak GPU memory usage compared to baselines, making long-context inference viable on commodity hardware.
  • In-Context Learning: In 4-shot NLU evaluations, KGERMAR outperformed ERMAR and MemLong across all tasks, showing the highest gains on Subj (+4.6%) and MPQA (+3.7%)—tasks that inherently demand fine-grained discrimination of entities and subjective expressions.
Figure 4: Scaling behavior of KGERMAR versus ER- MAR: (a) perplexity shows KGERMAR’s stronger mod- eling capability across all lengths; (b) memory demon- strates KGERMAR’s architectural efficiency advantage; (c) throughput reveals ERMAR’s speed advantage for short sequences; (d) latency illustrates KGERMAR’s more predictable near-linear scaling.

As shown in the scaling analysis, while KGERMAR introduces a slight latency overhead due to real-time graph construction, its latency scales predictably and near-linearly ($R^2 = 0.98$) compared to the higher-order scaling trends of purely attention-based alternatives.

Limitations and Future Work

  • Inference Latency: Performing NER and relation extraction on-the-fly introduces computational overhead, resulting in higher per-token latency. The authors note that for static document collections, this could be mitigated by pre-computing the knowledge graphs offline.
  • Windowed Relation Extraction: The relation extraction component operates within a fixed token window, meaning it struggles to directly capture relationships that span across distant paragraphs, relying instead on R-GCN graph propagation to bridge the gap.
  • Domain Sensitivity: The underlying NER and RE models were trained on general corpora (CoNLL-2003 and TACRED). Performance might degrade when processing highly specialized domains (e.g., legal or biomedical text) without domain-specific fine-tuning.

Summary updated

BibTeX
@misc{alselwi2026knowledge,
  author = {Ghadir Alselwi and Basem Suleiman and Hao Xue and Shoaib Jameel and Hakim Hacid and Flora D. Salim and Imran Razzak},
  title = {{Knowledge Graph Enhanced Memory-Augmented Retrieval for Long Context Modeling}},
  year = {2026},
  eprint = {2606.14047},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.14047},
}
Figure