Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
[NeurIPS '25] Knowledge Graph Generation from Any Text
| Date | Stars |
|---|---|
| 2026-07-31 | 1239 |
| 2026-08-01 | 1241 |
| 2026-08-06 | 1241 |
Today
— stars today
This week
— stars this week
This month
— stars this month
Momentum
0.0
growth rate 0.00%/day
# kg-gen: Knowledge Graph Generation from Any Text
📄 [**Paper**](https://arxiv.org/abs/2502.09956) | 🐍 [**Package**](https://pypi.org/project/kg-gen/) | 🤖 [**MCP**](https://github.com/stair-lab/kg-gen/tree/main/mcp/) | 🔬 [**Experiments**](https://github.com/stair-lab/kg-gen/tree/main/experiments/) | 👩🏻💻 [**Dataset**](https://huggingface.co/datasets/belindamo/wiki_qa_kggen) | 🐦 [**X Updates**](https://x.com/belindmo)
Welcome! `kg-gen` helps you extract knowledge graphs from any plain text using AI. It can process both small and large text inputs, and it can also handle messages in a conversation format.
Why generate knowledge graphs? `kg-gen` is great if you want to:
- Create a graph to assist with RAG (Retrieval-Augmented Generation)
- Create graph synthetic data for model training and testing
- Structure any text into a graph
- Analyze the relationships between concepts in your source text
We support API-based and local model providers via [LiteLLM](https://docs.litellm.ai/docs/providers), including OpenAI, Ollama, Anthropic, Gemini, Deepseek, and others. We also use [DSPy](https://dspy.ai/) for structured output generation.
- Try it out by running the scripts in [`tests/`](https://github.com/stair-lab/kg-gen/tree/main/tests).
- Instructions to run our KG benchmark MINE are in [`MINE/`](https://github.com/stair-lab/kg-gen/tree/main/experiments/MINE).
- Read the paper: [KGGen: Extracting Knowledge Graphs from Plain Text with Language Models](https://arxiv.org/abs/2502.09956)
## Powered by a model of your choice
Pass in a `model` string to use a model of your choice. Model calls are routed via LiteLLM, and usually LiteLLM goes by the format of `{model_provider}/{model_name}`. See specifically how to format it at [https://docs.litellm.ai/docs/providers](https://docs.litellm.ai/docs/providers).
Examples of models you can pass in:
- `openai/gpt-5`
- `gemini/gemini-2.5-flash`
- `ollama_chat/deepseek-r1:14b`
You may specify a custom API base url with `base_url` ([example here](https://github.com/stair-lab/kg-gen/tree/main/tests/test_custom_api_base.py)).
## Quick start
Install the module:
```bash
pip install kg-gen
```
Then import and use `kg-gen`. You can provide your text input in one of two formats:
1. A single string
2. A list of Message objects (each with a role and content)
Below are some example snippets:
```python
from kg_gen import KGGen
# Initialize KGGen with optional configuration
kg = KGGen(
model="openai/gpt-4o", # Default model
temperature=0.0, # Default temperature
api_key="YOUR_API_KEY" # Optional if set in environment or using a local model
)
# EXAMPLE 1: Single string with context
text_input = "Linda is Josh's mother. Ben is Josh's brother. Andrew is Josh's father."
graph_1 = kg.generate(
input_data=text_input,
context="Family relationships"
)
# Output:
# entities={'Linda', 'Ben', 'Andrew', 'Josh'}
# edges={'is brother of', 'is father of', 'is mother of'}
# relations={('Ben', 'is brother of', 'Josh'),
# ('Andrew', 'is father of', 'Josh'),
# ('Linda', 'is mother of', 'Josh')}
```
### Visualizing KGs
```python
KGGen.visualize(graph, output_path, open_in_browser=True)
```

### More Examples - chunking, clustering, passing in a messages array
```python
# EXAMPLE 2: Large text with chunking and clustering
with open('large_text.txt', 'r') as f:
large_text = f.read()
# Example input text:
# """
# Neural networks are a type of machine learning model. Deep learning is a subset of machine learning
# that uses multiple layers of neural networks. Supervised learning requires training data to learn
# patterns. Machine learning is a type of AI technology that enables computers to learn from data.
# AI, also known as artificial intelligence, is related to the broader field of artificial intelligence.
# Neural nets (NN) are commonly used in ML applications. Machine learning (ML) has revolutionized
# many fields of studExcerpt of 9,236 characters
Read on GitHubJoan Cabezas · United States
84
58
29
16
7
6
Steven Dillmann · Stanford University
2
1
1
1
Serge Panev · @NVIDIA · United States
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:3b0188050551d317, topic:knowledge-graph, desc:knowledge graph
matched fp:3b0188050551d317, topic:llm
matched fp:3b0188050551d317, topic:benchmark