Skip to content

Implement universal knowledge graph builder with LLM extraction and visual interface#1

Draft
Copilot wants to merge 7 commits into
mainfrom
copilot/add-visual-knowledge-graph-tool
Draft

Implement universal knowledge graph builder with LLM extraction and visual interface#1
Copilot wants to merge 7 commits into
mainfrom
copilot/add-visual-knowledge-graph-tool

Conversation

Copy link
Copy Markdown

Copilot AI commented Dec 4, 2025

Implements a domain-agnostic knowledge graph construction tool that extracts entities and relationships from unstructured text using LLMs, with interactive visualization and a GUI interface.

Core Components

  • Knowledge Graph (src/kg_builder/graph.py): NetworkX-based directed graph with entity/relationship management, JSON serialization, and graph statistics
  • Extractor (src/kg_builder/extractor.py): LLM-powered extraction (OpenAI/Anthropic) with regex-based fallback for offline operation
  • Visualizer (src/kg_builder/visualizer.py): PyVis interactive HTML graphs with color-coded entity types and draggable layouts
  • Config (src/kg_builder/config.py): Environment-based LLM client initialization and settings management

Interfaces

  • GUI (gui.py): Tkinter application with text input, domain selection, extraction controls, and visualization triggers
  • CLI (cli.py): Command-line tool supporting batch processing, statistics display, and visualization generation
  • Demo (demo.py): Interactive walkthrough demonstrating extraction → graph building → visualization pipeline

Usage

from kg_builder import KnowledgeGraph, KnowledgeGraphExtractor, KnowledgeGraphVisualizer

kg = KnowledgeGraph()
extractor = KnowledgeGraphExtractor(llm_client=openai_client)

extraction = extractor.extract_from_text(text, domain='technology')
kg.merge_from_extraction(extraction)

visualizer = KnowledgeGraphVisualizer(kg)
visualizer.visualize_interactive('output.html')

Or via GUI:

python gui.py  # Load text → Select domain → Extract → Visualize

Features

  • Supports 7 domain contexts (medical, finance, technology, science, legal, education, general)
  • Dual extraction modes: LLM-based (high accuracy) and pattern-based (no API required)
  • Interactive visualizations with physics-based layouts and entity type coloring
  • JSON import/export for graph persistence and incremental building
  • UV project management with pip fallback

Testing

  • test_complete.py: End-to-end validation of extraction → graph → visualization pipeline
  • test_basic.py: Core data structure operations
  • test_visualization.py: HTML output generation
  • test_gui.py: Component initialization and workflow simulation

All tests passing with 0 CodeQL vulnerabilities detected.

Examples

Included examples demonstrate extraction from:

  • examples/python_ecosystem.txt: Technology domain (programming languages, frameworks)
  • examples/cardiovascular_system.txt: Medical domain (anatomy, diseases)
Original prompt

是一个现代化的、可视化的知识图谱构建工具。它不再局限于化学领域,而是提供了一套通用的流水线,帮助用户利用大语言模型 (LLM) 从非结构化或半结构化数据中提取信息,构建任意领域的知识图谱。我们以Python UV作为项目管理并主要通过运行gui.py运行,直接调用图形化界面进行操作。


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 6 commits December 4, 2025 10:53
Co-authored-by: SiderLock <156282495+SiderLock@users.noreply.github.com>
Co-authored-by: SiderLock <156282495+SiderLock@users.noreply.github.com>
Co-authored-by: SiderLock <156282495+SiderLock@users.noreply.github.com>
Co-authored-by: SiderLock <156282495+SiderLock@users.noreply.github.com>
Co-authored-by: SiderLock <156282495+SiderLock@users.noreply.github.com>
Copilot AI changed the title [WIP] Add modern visual knowledge graph building tool Implement universal knowledge graph builder with LLM extraction and visual interface Dec 4, 2025
Copilot AI requested a review from SiderLock December 4, 2025 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants