Context-KG: Context-Aware Knowledge Graph Visualization with User Preferences and Ontological Guidance

Rumali Perera, Xiaoqi Wang, Han-wei ShenarXiv 2026 · arXiv

TL;DR

Traditional Knowledge Graph (KG) visualizations often produce uninterpretable "hairball" layouts because they treat graphs as purely topological networks. Context-KG solves this by using Large Language Models (LLMs) to extract user intent from natural language queries, driving an ontology-guided layout that clusters data by semantics and user preferences. The result is a structured, context-rich visualization that transforms complex graph exploration into an intuitive, insight-driven experience.

What Problem Does This Paper Address?

Knowledge Graphs are incredibly powerful for organizing interconnected data, but exploring them is notoriously difficult. Standard tools like Neo4j typically rely on force-directed layouts that treat nodes like physical particles under pairwise forces. This approach completely ignores the underlying ontology (the schema and rules governing the data) and the user's specific query context.

Consequently, unrelated entities often end up clumped together, while semantically related ones are scattered across the screen—a phenomenon known as the "hairball" effect. Furthermore, users face a persistent paradox: they must understand the graph's structure to write a precise query, but they need to query the graph to understand its structure. Existing tools fail to provide the broader context surrounding a user's question, leaving them with flat, unhelpful direct answers.

Methods

Context-KG introduces a three-stage pipeline that bridges natural language processing and semantic graph drawing:

  1. User Preference Understanding: The system uses an LLM (GPT-4 Turbo) to translate a user's natural language question into four structured elements: the primary node type of interest, a key attribute, the attribute value, and connected node types.
  2. Ontology-Guided Global Arrangement: To prevent semantic distortion, the global layout space is partitioned into distinct regions based on "ontological distance"—the shortest-path distance between node types within the KG's schema.
  3. Semantic-Aware Node Organization: Within these regions, nodes of interest are grouped into clusters using DBSCAN (for numeric attributes like publication year) or K-means (for textual embeddings). To maintain cluster cohesion without sacrificing global readability, the authors developed a novel refinement of the Fruchterman–Reingold algorithm using pseudo-edges to anchor nodes to their cluster centroids and pseudo-interest nodes to attract connected neighbor nodes.

Additionally, the framework supports iterative context refinement (allowing users to dynamically emphasize neighbors, edges, or paths) and automatically generates natural language insights from the graph's structural features.

The Context-KG framework pipeline, showing how user queries are translated into ontology-guided layouts and automated insights.

Datasets

The authors evaluated Context-KG using three real-world knowledge graphs:

  • TVCG KG: Contains publication data and metadata from the IEEE Transactions on Visualization and Computer Graphics.
  • DBLP KG: A large-scale bibliography dataset covering computer science publications.
  • PPOD KG: A dataset modeling connections among people, projects, organizations, and datasets within regional food systems and smart foodsheds.
  • Ground Truth Dataset: A human-annotated benchmark of 135 diverse natural language questions used specifically to evaluate the LLM's preference extraction accuracy.

Key Insights and Ideas

  • Ontology as a Spatial Guide: By mapping Euclidean distance directly to ontological distance, the layout guarantees that spatial proximity actually means semantic relevance.
  • The Power of Pseudo-Anchors: Using invisible "pseudo-edges" and "pseudo-nodes" allows the system to preserve local cluster structures while naturally forming sub-clusters for connected entities (e.g., grouping authors neatly around the specific years they published papers).
  • LLMs as Visual Translators: Instead of just generating text, the LLM acts as an intermediary that maps vague, multi-stage user intents into concrete visual modifications (like adjusting node sizes for prolific authors or bundling edges).
A comparison showing how traditional layouts scatter nodes randomly (left) versus Context-KG's ontology-aware layout that separates node types into distinct, interpretable regions (right).

Key Results

  • High Extraction Accuracy: The LLM extracted primary node types with 96.92% accuracy and connected nodes with 97.70% accuracy from natural language queries.
  • Perfect Cluster Preservation: Quantitative clustering metrics (Adjusted Rand Index and Normalized Mutual Information) achieved a perfect score of 1.0, proving that the layout perfectly preserves semantic sub-clusters.
  • Smooth Scalability: Performance benchmarks showed that clustering and layout times scale gradually as graph sizes increase from 100 to 1,000 nodes, while memory usage remains stable.
  • Superior User Performance: In a user study with 15 visualization and KG experts, Context-KG consistently achieved full task-completion scores (3/3) across 12 complex exploration tasks, significantly outperforming Neo4j and KinGVisher, which frequently left users stuck due to visual clutter.

Limitations and Future Work

While Context-KG marks a significant step forward, the authors note a few limitations. Currently, the system relies on a single LLM model, and the generated textual insights are not yet interactively embedded back into the visual graph. The framework is also optimized around a single primary node type per query, limiting its utility for highly complex, multi-type compound questions.

Future work will focus on explicitly incorporating edge types, edge attributes, and multi-relational structures directly into the layout and clustering calculations to support even richer visual encodings.

Summary updated

Abstract

Knowledge Graphs (KGs) are increasingly used to represent and explore complex, interconnected data across diverse domains. However, existing KG visualization systems remain limited because they fail to provide the context of user questions. They typically return only the direct query results and arrange them with force-directed layouts by treating the graph as purely topological. Such approaches overlook user preferences, ignore ontological distances and semantics, and provide no explanation for node placement. To address these challenges, we propose Context-KG, a context-aware KG visualization framework. Context-KG reframes KG visualization around ontology, context, and user intent. Using Large Language Models (LLMs), it iteratively extracts user preferences from natural language questions and context descriptions, identifying relevant node types, attributes, and contextual relations. These preferences drive a semantically interpretable, ontology-guided layout that is tailored to each query, producing type-aware regions. Context-KG also generates high-level insights unavailable in traditional methods, opening new avenues for effective KG exploration. Evaluations on real world KGs and a comprehensive user study demonstrate improved interpretability, relevance, and task performance, establishing Context-KG as a new paradigm for KG visualization.
BibTeX
@misc{perera2026context,
  author = {Rumali Perera and Xiaoqi Wang and Han-wei Shen},
  title = {{Context-KG: Context-Aware Knowledge Graph Visualization with User Preferences and Ontological Guidance}},
  year = {2026},
  eprint = {2604.10384},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2604.10384},
}

Loading related content...

Figure