kg-gen routes every extraction through a provider-prefixed model string, and the two documented defaults disagree
[NeurIPS '25] Knowledge Graph Generation from Any Text
At a glance
- What is it?
- A knowledge graph extraction library that takes plain text or message arrays, hands the work to DSPy through LiteLLM, and ships chunking, clustering, aggregation, visualisation and an MCP server, where the interesting details are in the configuration defaults and the deduplication path.
- Who is it for?
- kg-gen fits a Python project that already has a model provider configured and wants a graph to sit beside its text, whether for retrieval, for synthetic training data, or for inspection of relationships in a source. It does not fit someone who needs the extraction to be reproducible without a model in the loop, since a temperature and a model choice sit between the input and the edges.
- Can I use it commercially?
- Not without permission. GitHub finds no licence file in the repository, and without a licence all rights are reserved by default: you may read the code but not reuse it. Check the README, or ask the authors, before using it.
- Is it still maintained?
- Activity is slowing. The repository last received commits 7 months ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.
Star history
- stair-lab/kg-gen1,294 ★ · +26
| Repository | 2026-09-10 | 2026-11-15 |
|---|---|---|
| stair-lab/kg-gen | 1.3k | 1.3k |
26 Stars in the last 66 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The constructor default temperature and the env file default are different numbers
Two different defaults are documented, and they are not the same value. The constructor example passes temperature 0.0, with a comment marking it as the default, alongside a model of openai/gpt-4o. The environment template sets LLM_TEMPERATURE=1.0 and LLM_MODEL=openai/gpt-5-nano, and adds a separate LLM_API_KEY line. So a project configured through the environment runs a different model at a different temperature than the snippet suggests, and the only way to know which path is in effect is to read your own configuration. The retrieval model is configured the same way, with RETRIEVAL_MODEL set to all-MiniLM-L6-v2, and the template also carries OpenAI, Anthropic, and Gemini keys marked as being for testing, which suggests the integration tests exercise more than one provider.
pip install kg-genModel names are provider-prefixed strings, and the key is optional for local models
Provider choice is a string rather than a configuration object, following the convention that LiteLLM expects, a provider name, a slash, and a model name. The named examples are openai/gpt-5, gemini/gemini-2.5-flash, and ollama_chat/deepseek-r1:14b, the last one showing the chat variant prefix used for a self-hosted runner. That form means a local model and a hosted one are configured identically, differing only in the prefix, which is why an API key is described as optional when it is already in the environment or when a local model is in use. A custom API base url is also accepted through a base_url argument, which is what makes a self-hosted gateway or a proxy possible without patching the library. Structured output is generated with DSPy rather than by hand-writing a schema, so the extraction prompt and parsing live in the same framework.
Chunking counts characters, and clustering takes a free-text context
Large inputs are handled by a chunk_size parameter, and the example sets it to 5000 to process the text in smaller pieces. There is no token count in the interface, which matters for anyone reasoning about cost, since a character budget and a token budget diverge on text with unusual punctuation or long identifiers. Clustering of similar entities and relations is available at two points in the lifecycle. Passing cluster=True during generation clusters as it goes, and calling the cluster method on an existing graph does it afterwards, which is the option to use when you want to compare pre-clustering and post-clustering output. Both take an optional context string intended to guide the clustering, the same way a context argument guides generation. The dependency list explains the mechanism: sentence-transformers, scikit-learn, semhash, and rank-bm25 are all present, so similarity is available through several routes rather than one.
graph = kg.generate(
input_data=large_text,
chunk_size=5000 # Process in chunks of 5000 characters
)Message arrays produce speaker-to-concept edges, not just concept pairs
Conversation input is treated as a distinct case rather than as flattened text. The role of each message is preserved, message order and boundaries are maintained, and the extraction covers three relationships: between concepts mentioned in the messages, between speakers and concepts, and across several messages at once. The worked example is a two-turn exchange about the capital of France, and the graph it produces contains user, assistant, France, and Paris as entities, with relations of the shape user asks about France, assistant states Paris, and Paris is capital of France. The middle relation is the interesting one, since it makes the role itself an entity in the graph rather than metadata attached to an edge. Two input shapes are supported overall, a single string and a list of message objects each carrying a role and content.
aggregate merges graphs and visualize writes a file, optionally opening it
Two utility operations round out the interface. The aggregate method takes a list of graphs and combines them, which is how several documents or several extraction runs become one graph, and the example builds two graphs from separate texts before combining them. Visualisation is a call on the class rather than a separate tool, taking the graph, an output path, and a flag that opens the result in a browser; the default in the documented call has the browser opening enabled. This is the path the basic test uses, since running the test script also writes a visualisation file next to it, which doubles as an installation check. The generated file is driven by a template shipped as package data, and the prompts themselves are shipped as text files in the package, so both travel with the install rather than being fetched at runtime.
One install gives you both the library and a kggen command
The packaging exposes a console script, kggen, wired to the command line entry point of the package, and the same install is what enables the MCP server. The documented sequence is to install the package and then run the server command, which is aimed at AI agents that need persistent memory capabilities and is described as usable with Claude Desktop, custom MCP clients, or other AI applications. The MCP pieces are an optional dependency group rather than part of the core, so a plain install does not pull in the server stack, and the test configuration covers both the main test directory and the tests inside the MCP directory, which is a small signal that the server is exercised rather than only documented. The repository keeps the server implementation, its documentation, and its tests together in one directory.
pip install kg-gen
kggen mcpDeduplication has its own container, script, and evaluation history
A separate branch of work has its own runtime. The container file in the root is explicitly for the deduplication script rather than for the library, built on a slim Python 3.11 image, installing build tools and a compiler, copying the packaging files plus an application requirements file, and then installing both that requirements file and the package itself. Two shell scripts sit beside it, one to run the deduplication job in Docker and one to run the server, and the environment template's retrieval model setting is what such a script would consume. The tag history shows this area was being measured rather than assumed: one tag expands the MINE evaluations, another is named for a deduplication comparison between scikit-learn and Faiss, and a third covers the WikiQA dataset. A large application directory, a cloud ignore file, and a lock file sit alongside the package source, which indicates experiment code lives next to the library rather than being separated from it.
The stated use cases are retrieval, synthetic data, and inspection
The reasons given for building a graph from text are four, and they imply different quality bars. Assisting retrieval-augmented generation means the graph has to be accurate enough that a wrong edge retrieves something wrong. Generating synthetic graph data for training and testing means the output is the input to somebody else's evaluation, so systematic bias in the extraction becomes bias in a benchmark. Structuring any text into a graph is the general case. Analysing relationships between concepts is the exploratory one, where an odd edge is a question rather than a defect. The project comes from a research group, with a paper on extracting knowledge graphs from plain text with language models and a NeurIPS 2025 designation, and it publishes a dataset generated with the tool alongside an MCP server and an experiment directory containing the MINE benchmark. The package itself is small, at version 0.4.0, and supports Python 3.10 through 3.13.
Editorial conclusion
kg-gen fits a Python project that already has a model provider configured and wants a graph to sit beside its text, whether for retrieval, for synthetic training data, or for inspection of relationships in a source. It does not fit someone who needs the extraction to be reproducible without a model in the loop, since a temperature and a model choice sit between the input and the edges. Before adopting it, check which temperature your path actually uses, because the documented constructor default and the environment file disagree, and confirm the Python version, since the package requires 3.10 or newer and caps at 4.0.
Frequently asked questions
Which model providers can kg-gen use?
Calls are routed through LiteLLM, with OpenAI, Ollama, Anthropic, Gemini, and Deepseek named among the supported providers. Model strings take a provider and name form, such as openai/gpt-5, gemini/gemini-2.5-flash, or ollama_chat/deepseek-r1:14b, and a custom base url is supported.
What input formats does kg-gen accept?
Either a single string or a list of message objects, each carrying a role and content. Message arrays keep role information, message order, and message boundaries, and the extraction covers concept pairs, speaker to concept relations, and relations across several messages.
How does kg-gen handle a large text file?
Pass a chunk_size to generate, with 5000 characters given as the example, and the text is processed in pieces. Similar entities and relations can be clustered during generation or afterwards with a context string, and separate graphs can be merged with the aggregate method.
Does kg-gen ship an MCP server?
Yes. Installing the package also provides a kggen command that starts the server, aimed at AI agents needing persistent memory and usable with Claude Desktop or custom MCP clients. The server stack sits in an optional dependency group with fastmcp and mcp.
How do I install and verify kg-gen from the repository?
Clone it and install the project in editable mode with the dev extra, then run python tests/test_basic.py from the root. That test doubles as an installation check and writes a graph visualisation to tests/test_basic.html. The package version is 0.4.0 and requires Python 3.10 or newer.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/stair-lab-kg-gen)Star history chart for your README
[](https://hysenlabs.com/projects/stair-lab-kg-gen)Was this useful?