kgmd
A CLI that builds a knowledge graph from a directory of markdown files and exposes it via MCP.
- Extracts entities and relations using any LLM (via litellm)
- Resolves duplicate entities using local embeddings + LLM verification
- Induces a typed schema from the extracted data
- Stores everything in a single SQLite file (powered by sqlite-vec)
- Exposes the graph via CLI queries and an MCP server
Install
pip install kgmd
Or with uv:
uv tool install kgmd
Requirements
- Python 3.10+
- An API key for any LLM provider supported by litellm (OpenRouter, OpenAI, Anthropic, etc.)
- Embeddings run locally by default via fastembed (no API key needed)
- Your Python must be built with SQLite extension loading enabled — see
docs/install.md if
kgmd buildfails on extension loading
Quickstart
cd my-notes/
kgmd init # create .kgmd/ (config, prompts, graph.db)
export OPENROUTER_API_KEY="sk-..."
kgmd build # extract -> resolve -> induce
kgmd stats # what got built
kgmd find "machine learning" # semantic search
kgmd entity "Brian Anderson" # one entity, with mentions and relations
kgmd neighbors "Brian Anderson" --depth 2
Full walkthrough: docs/quickstart.md.
How it works
kgmd build runs three stages:
- Extract — each markdown file is chunked and sent to an LLM, which returns structured JSON with entities (people, organizations, projects, etc.) and relations between them.
- Resolve — entity mentions are embedded locally, clustered by cosine similarity, and duplicate clusters are verified by the LLM before merging.
- Induce — aggregate statistics about entity types and relation predicates are sent to the LLM, which produces a typed YAML schema with hierarchies.
All state lives in .kgmd/graph.db, a single SQLite file. Re-running kgmd build is incremental —
unchanged files are skipped. See docs/concepts.md.
A .kgmdignore file at the corpus root keeps material out of the graph, and therefore out of the
paid extraction path; kgmd build --dry-run shows what would be indexed before you spend anything.
Syntax and precedence: docs/reference/configuration.md.
MCP server
kgmd mcp launches an MCP server over stdio exposing seven read-only tools over the graph. Setup,
the exact registered tool names, and client configuration are in
docs/guides/mcp.md.
Documentation
| Topic | Page |
|---|---|
| Install, prerequisites, credentials | docs/install.md |
| Zero to a queryable graph | docs/quickstart.md |
| Pipeline stages and vocabulary | docs/concepts.md |
| Every command and option | docs/reference/cli.md |
| Every configuration setting | docs/reference/configuration.md |
| Export formats | docs/reference/export.md |
| MCP integration | docs/guides/mcp.md |
| Re-runs, cost, reset, backup | docs/guides/maintenance.md |
| Troubleshooting | docs/guides/troubleshooting.md |
| Worked examples | docs/examples/personal-notes.md |
| Contributing | docs/contributing/development.md |
| Release history | CHANGELOG.md |
Index: docs/README.md.
Development
git clone https://github.com/johncarpenter/kgmd.git
cd kgmd
make install # pip install -e ".[dev]"
make test # pytest
make lint # ruff check
make format # ruff format
See docs/contributing/development.md and docs/contributing/architecture.md.
License
Release files for kgmd 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kgmd-0.2.0.tar.gz | 267.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kgmd-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 310.0 kB
Release files / kgmd-0.2.0.tar.gz
| Download URL | kgmd-0.2.0.tar.gz |
|---|---|
| Size | 267.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
958ed421e42b1251b4f302f49db80e27e7e5da693ebf9fe3f99dfdbbd47ac7bd
|
|
BLAKE2b-256 checksum How to use checksums |
dd10ecbd1f2d2dd7a92e74232f1783aa453edb12ee93e3ba927c0e6847d971a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.
Transparency logRelease files / kgmd-0.2.0-py3-none-any.whl
| Download URL | kgmd-0.2.0-py3-none-any.whl |
|---|---|
| Size | 42.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
20d54ced1d40d33f8c8644b641bb3f598b771dc3408aa4253d8c0ec880908098
|
|
BLAKE2b-256 checksum How to use checksums |
edf793690328cd4cc736121cf0de42bf8633645d5953a971d4a3eecd5d7bb5b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 28, 2026.
Transparency log