Section 1

Prerequisites

Before you begin, make sure you have the following installed and working:

Verify Docker is running:

Terminal
$ docker info --format '{{.ServerVersion}}'
Tip

Python 3.10+ is required, but make setup in the next section will create a virtual environment for you automatically.

Section 2

Setup

Clone and install

Terminal
$ git clone https://github.com/agtm1199/build-kg.git && cd build-kg

Run the full setup. This creates a virtual environment, installs dependencies, starts the PostgreSQL + Apache AGE container, and initializes the graph schema:

Terminal
$ make setup

Configure environment variables

The setup creates a .env file from the example template. Open it and set your API key:

.env
# .env # Anthropic (default provider): ANTHROPIC_API_KEY=sk-ant-your-actual-key-here # Or if using OpenAI instead: # OPENAI_API_KEY=sk-your-actual-key-here # LLM_PROVIDER=openai # Database password (matches Docker container defaults): DB_PASSWORD=build_kg_pass
Note

The database credentials in .env.example already match the Docker container defaults. You only need to add your API key.

Verify everything works

Terminal
$ make verify

Activate the skill

The /build-kg skill is included in the repository and activates automatically:

AgentSkill fileActivation
Claude Code.claude/skills/build-kg/SKILL.mdAuto-detected. Type /build-kg <topic>
Amazon Kiro.claude/skills/build-kg/SKILL.mdAuto-detected (Agent Skills standard). Type /build-kg <topic>
Qoder.claude/skills/build-kg/SKILL.mdAuto-detected (Agent Skills standard). Type /build-kg <topic>
Antigravity.claude/skills/build-kg/SKILL.mdAuto-detected (Agent Skills standard). Type /build-kg <topic>
OpenAI CodexAGENTS.mdAuto-detected. Ask “build a knowledge graph about <topic>”
GitHub Copilot.github/copilot-instructions.mdAuto-detected. Ask “build a knowledge graph about <topic>”
Cursor.cursor/rules/build-kg.mdcAuto-detected. Ask “build a knowledge graph about <topic>”
Windsurf.windsurf/rules/build-kg.mdAuto-detected. Ask “build a knowledge graph about <topic>”
Tip

No extra installation is needed. The skill files ship with the repo — cloning is all it takes.

Expected output
Output
====================================================================== Setup Verification ====================================================================== 1. Verifying database connection... Connected to PostgreSQL Version: PostgreSQL 16.x 2. Verifying Apache AGE extension... AGE extension installed (version 1.5.0) Graph 'knowledge_graph' exists 3. Verifying source data... Found 0 fragments with excerpts Found 0 source documents 4. Verifying LLM API access... Anthropic API connection successful Model: claude-haiku-4-5-20251001 ====================================================================== All checks passed! System is ready. ======================================================================
Section 3

Your First Knowledge Graph

The fastest way to build a graph is the /build-kg skill command in your coding agent. It runs the entire pipeline automatically: generates an ontology, discovers sources, crawls, chunks, loads, and parses.

In your coding agent, run:

Terminal
$ /build-kg kubernetes networking

Your coding agent will execute six phases in sequence. Here is what each phase does:

PhaseWhat happensCost
OntologyGenerates node types, edge types, and properties for your topic. Saves to ontology.yaml.~$0.01
DiscoverSearches for authoritative sources across multiple rounds, producing a crawl manifest.~$0.02
CrawlDownloads pages from discovered sources as markdown files into crawl_output/.Free
ChunkSplits documents into semantically meaningful fragments saved to chunk_output/.Free
LoadInserts documents and fragments into PostgreSQL with metadata from the manifest.Free
ParseLLM extracts structured entities and relationships from each fragment into the Apache AGE graph.~$0.25
Sample output
Output
Ontology 3 node types · 3 edge types · saved ontology.yaml Discover 14 sources found across 5 rounds Crawl 247 pages → crawl_output/ Chunk 1,832 fragments → chunk_output/ Load 14 docs · 1,832 fragments → PostgreSQL Parse 892 Components · 341 Concepts · 127 Configs ————————————————— 1,360 nodes · 1,247 edges Graph: kg_k8s_net (Apache AGE) Cost: $0.27
Tip

You can use any topic: /build-kg React architecture patterns, /build-kg machine learning algorithms, /build-kg python async programming. Your coding agent will generate a suitable ontology for each.

Section 4

Exploring the Graph

Your knowledge graph is stored in Apache AGE, a PostgreSQL extension that adds Cypher graph queries. Connect with psql or any PostgreSQL client.

Connect to the database

Terminal
$ psql -h localhost -U build_kg_user -d build_kg

Load the AGE extension and set the search path:

LOAD 'age';
SET search_path = ag_catalog, '$user', public;

Count nodes by type

SELECT * FROM cypher('kg_k8s_net', $$
    MATCH (n)
    RETURN label(n), count(n)
    ORDER BY count(n) DESC
$$) AS (node_type agtype, count agtype);
Sample result
Output
node_type | count --------------+------- "Component" | 892 "Concept" | 341 "Config" | 127

List all node types

SELECT * FROM cypher('kg_k8s_net', $$
    MATCH (n)
    RETURN DISTINCT label(n)
$$) AS (node_type agtype);

Traverse relationships

SELECT * FROM cypher('kg_k8s_net', $$
    MATCH (a)-[r]->(b)
    RETURN label(a), type(r), label(b), count(*)
    ORDER BY count(*) DESC
    LIMIT 10
$$) AS (from_type agtype, rel_type agtype, to_type agtype, count agtype);

Find specific entities

SELECT * FROM cypher('kg_k8s_net', $$
    MATCH (n)
    WHERE n.name CONTAINS 'Service'
    RETURN n.name, label(n), n.description
    LIMIT 5
$$) AS (name agtype, type agtype, description agtype);

Walk a path

SELECT * FROM cypher('kg_k8s_net', $$
    MATCH path = (a)-[*1..2]->(b)
    WHERE a.name = 'kube-proxy'
    RETURN a.name, b.name, length(path)
    LIMIT 10
$$) AS (from_name agtype, to_name agtype, path_len agtype);
Note

Replace kg_k8s_net with the graph name shown in your build output.

Section 5

Visualize Your Graph

build-kg-viewer is the visual companion to build-kg. Point it at the same database and explore your graph interactively.

git clone https://github.com/agtm1199/build-kg-viewer.git && cd build-kg-viewer
npm run setup && npm start

Connect using the same database credentials from your .env file. Features include 24+ visualization components, AI-powered chat (natural language to Cypher), dark mode, path finder, graph algorithms, and more.

Next Steps

Need help?

Check the troubleshooting guide or open an issue on GitHub.