Your LLM's new side gig: professional knowledge graph extractor
kg-gen uses your existing LLM to turn any text—articles, transcripts, even chat logs—into structured knowledge graphs without building a custom pipeline.

What it does
kg-gen is a Python library that feeds text to a language model and returns a structured knowledge graph complete with entities, edges, and relations. It handles both short strings and long documents via configurable chunking, plus it can process conversation-style message arrays. The output includes optional clustering maps that group synonymous entities and relations—so “ML” and “machine learning” end up in the same bucket.
The interesting bit
Instead of locking you into a specific model, it routes calls through LiteLLM and uses DSPy for structured outputs, meaning you can point it at OpenAI, local Ollama instances, or Gemini with a single string change. It also treats conversations as first-class citizens, extracting not just factual claims but speaker-to-concept relationships.
Key highlights
- Works with any LiteLLM-supported provider (
openai/gpt-4o,ollama_chat/deepseek-r1:14b, etc.) - Chunks large texts automatically and aggregates multiple graphs into one
- Clusters synonymous entities and relations during or after generation
- Includes an MCP server for AI agent memory integration
- Ships with a built-in visualization tool that exports to HTML
Caveats
- The README shows example outputs but does not include accuracy metrics or benchmark results for its MINE benchmark
- Extraction quality is entirely dependent on the external LLM you configure via LiteLLM
Verdict
Worth exploring if you need knowledge graph extraction for RAG, synthetic data, or conversation analysis and want provider flexibility through LiteLLM. Look elsewhere if you need deterministic parsing independent of LLM inference.
Frequently asked
- What is stair-lab/kg-gen?
- kg-gen uses your existing LLM to turn any text—articles, transcripts, even chat logs—into structured knowledge graphs without building a custom pipeline.
- Is kg-gen open source?
- Yes — stair-lab/kg-gen is an open-source project tracked on heatdrop.
- What language is kg-gen written in?
- stair-lab/kg-gen is primarily written in Python.
- How popular is kg-gen?
- stair-lab/kg-gen has 1.2k stars on GitHub.
- Where can I find kg-gen?
- stair-lab/kg-gen is on GitHub at https://github.com/stair-lab/kg-gen.