# Local Knowledge Graph

> A local AI reasoning tool that builds a load-bearing knowledge graph from step-by-step model reasoning, running entirely on your machine via Ollama.

Local Knowledge Graph is a Python tool by Morten Punnerud-Engelstad that runs a local language model through Ollama, captures its step-by-step reasoning, and materializes that reasoning as a knowledge graph that is actively used in subsequent inference — not merely visualized. It installs from PyPI as `mpe-lkg` and serves a web UI at `localhost:5100`. The project has 571 GitHub stars and is under active development, with CI badges for Linux, macOS, and Windows.

## What It Is

Local Knowledge Graph sits at the intersection of local inference and knowledge graph construction. Rather than treating a model's chain-of-thought as ephemeral text, it converts each reasoning step into graph nodes and edges that become the substrate for answering harder questions. The graph is described in the project's own documentation as "load-bearing" — meaning it participates in the answer, not just the display. The tool is designed to run entirely offline on the user's own hardware, with no cloud dependency.

## How the Reasoning Modes Work

The tool exposes three distinct query modes that control how thoroughly the model reasons before committing to an answer:

- **`mode=reason`** — a single reasoning pass, the default.
- **`mode=explore`** — each sub-question in a complex query gets its own independent reasoning run, broadening coverage.
- **`mode=settle`** — the model runs until two independent passes agree on an answer, trading speed for confidence.

Results from any mode can be exported as RDF via a REST endpoint (`/jobs/<id>/rdf`), making the graph portable and queryable with standard semantic-web tooling.

## Model Selection and Performance

The README documents measured performance differences between models on an arithmetic battery: `qwen3:4b-instruct-2507` answers 82.5% of test questions correctly versus `llama3.2:3b`'s 40%, making model choice the single most impactful configuration decision. The project also supports reading embeddings directly from internal model layers rather than a separate embedding endpoint, documented in `docs/internal-layers.md`. All model configuration is handled through environment variables.

## Architecture and Stack

Local Knowledge Graph is a Python application that communicates with a locally running Ollama instance. The web UI is served on port 5100. The REST API accepts JSON job submissions and returns RDF. CI pipelines run on all three major operating systems, and the package is published to PyPI under the name `mpe-lkg`. The project shares a license family with the author's other tools (`mpedb` and `MPEqs`).

## License and Open-Source Status

The project uses the **mpedb License 1.0**, which the README explicitly notes is **not an OSI-approved license**. It is free of charge for individuals and most organizations. The one exception is a one-time fee of seven US cents per device for any organization whose consolidated annual revenue or valuation exceeds USD 5 billion. This source-available but non-OSI model means the tool is freely usable for nearly all users while preserving a nominal commercial term for very large enterprises.

## Features
- Local-only inference via Ollama — no cloud dependency
- Step-by-step reasoning materialized as a knowledge graph
- Three query modes: reason, explore, settle
- RDF export of any reasoning job via REST API
- Web UI served at localhost:5100
- Strongest-path search over the knowledge graph
- Embeddings from internal model layers (no separate embedding endpoint)
- Configurable via environment variables
- Cross-platform: Linux, macOS, Windows CI
- PyPI installable as mpe-lkg

## Integrations
Ollama, PyPI, RDF / semantic-web tooling

## Platforms
WINDOWS, MACOS, LINUX, CLI, API

## Pricing
Open Source

## Version
mpe-lkg (latest on PyPI)

## Links
- Website: https://github.com/punnerud/Local_Knowledge_Graph
- Documentation: https://github.com/punnerud/Local_Knowledge_Graph/blob/main/docs/design.md
- Repository: https://github.com/punnerud/Local_Knowledge_Graph
- EveryDev.ai: https://www.everydev.ai/tools/local-knowledge-graph
