Skip to content

Repository files navigation

GraphRAG — AI Copyright & Governance Knowledge Graph

A GraphRAG pipeline built around GitHub Copilot instead of a hosted LLM API: you supply Markdown articles, Copilot extracts entities and relationships from them straight in your editor, and a small deterministic Python script merges everything into a queryable, visualized knowledge graph. No OpenAI/Anthropic key, no LangChain, no LlamaIndex — the only "intelligence" in this repo is Copilot itself, guided by .github/copilot-instructions.md.

How it works

  1. You collect the data. Drop one Markdown file per article/source into data/, with YAML front-matter for title/source/date — or just hand Copilot a URL (e.g. "extract this: https://example.com/article") and it fetches the page and writes the Markdown file itself, per .github/copilot-instructions.md.
  2. Copilot extracts. Ask Copilot (chat or agent mode) to process a file per .github/copilot-instructions.md — it reads ontology.json, extracts entities/relationships from the article, and writes a matching data/<name>.entities.json sidecar.
  3. build_graph.py merges, deterministically. No LLM calls — it parses the Markdown + sidecar JSON, validates every entity/relation type against ontology.json, builds the graph with NetworkX, runs Louvain community detection (also NetworkX), and writes graph_data.json + ai_copyright_graph.html.
  4. You ask Copilot questions. There's no query engine — just ask Copilot about graph_data.json directly in chat; it groups by the community field on each node to reason about clusters, or answers cross-cutting questions from the whole graph.

Tech Stack

Layer Tools
Extraction / Q&A GitHub Copilot, interactively — no API calls in code
Graph build NetworkX (graph structure + Louvain community detection)
Validation Pydantic (validates extraction sidecars against ontology.json)
Visualization D3.js v7, vis-network 9.1.2

Project Structure

graphrag/
├── data/
│   ├── example-lawsuit.md          # example article (front-matter + body)
│   └── example-lawsuit.entities.json  # matching Copilot-extracted sidecar
├── ontology.json                   # allowed entity/relationship types — single source of truth
├── build_graph.py                  # deterministic merge → graph_data.json + html, no LLM
├── graph_data.json                 # extracted knowledge graph (generated)
├── ai_copyright_graph.html         # interactive visualization (generated)
├── graph_template.html             # D3.js template for visualization
├── .github/copilot-instructions.md # tells Copilot how to extract + how to answer questions
└── lib/
    ├── bindings/utils.js           # graph interaction utilities
    ├── vis-9.1.2/                  # vis-network library
    └── tom-select/                 # dropdown UI component

Prerequisites

  • Python 3.10+
  • GitHub Copilot in your editor (chat or agent mode)
  • No API keys — nothing in this repo calls an LLM over the network

Setup

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Usage

Step 1 — Add your articles

Create a Markdown file per article in data/:

---
title: "Article title"
source: "where it's from"
date: "2026-01-15"
---

The article body goes here.

Or skip the manual step and ask Copilot directly:

Extract this: https://example.com/some-article

It fetches the page and writes the Markdown file for you (see "Your job: ingest a website" in .github/copilot-instructions.md).

Step 2 — Extract with Copilot

Ask Copilot to process the file, e.g. in chat:

Extract entities and relationships from data/my-article.md per .github/copilot-instructions.md.

Copilot writes data/my-article.entities.json. See data/example-lawsuit.md + data/example-lawsuit.entities.json for a worked example (fictional content, just to show the format).

Step 3 — Build the graph

python build_graph.py

Merges every data/*.md + sidecar pair, runs community detection, and (re)writes graph_data.json and ai_copyright_graph.html. Deterministic and cheap — re-run any time you add or re-extract an article.

Step 4 — Explore

Open ai_copyright_graph.html in a browser:

  • Force-directed graph layout (D3.js)
  • Filter nodes by entity type via the sidebar legend
  • Search nodes by name
  • Click a node to highlight its direct connections
  • Hover for entity details in a tooltip
  • Adjust link distance with the slider

Or just ask Copilot questions about graph_data.json directly in chat.

About

based on the work of https://github.com/thu-vu92/graphRAG and claude

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages