Skip to main content

Local Knowledge Graph

Linux macOS Windows PyPI Python

Example

Ask a local model a question, watch it reason step by step, and see the steps drawn as a graph where the edges are how similar the steps are to each other.

The run starts by breaking the question into angles worth checking, then works through them — about eight steps, each with a named job rather than a quota to fill. Any arithmetic a step relies on is handed over as an expression and evaluated exactly, in fractions, by mpeqs. Those sums are shown above the graph: they are the one part of a run the model did not decide, and you can check 20-13.5 = 6.5 at a glance in a way you cannot check a paragraph of reasoning.

The graph draws in two colours, because it holds two kinds of claim. Blue links steps by how similar their embeddings are — an association, with no truth value, and the thing that makes indirect knowledge visible. Green is what an exact evaluator settled: a sum, or a conversion between two units, derived from exact ratios. A reader should never have to guess which is which.

Everything runs on your machine. Nothing is uploaded anywhere.

Headless, and as RDF

A run can be started without a browser, polled, and taken as RDF — the graph as text, for anything that would rather query it than look at it.

ID=$(curl -sX POST localhost:5100/jobs -H 'content-type: application/json' \
       -d '{"query":"How many seconds are there in 23 weeks?"}' | jq -r .id)

curl -s localhost:5100/jobs/$ID              # {"state":"running","steps":3,...}
curl -s localhost:5100/jobs/$ID/stream       # N-Triples, live, one triple per line
curl -s localhost:5100/jobs/$ID/rdf          # Turtle, once it has finished
curl -sX DELETE localhost:5100/jobs/$ID      # stop it

Two formats for two purposes. N-Triples streams: each line is a complete document, so a consumer can parse what has arrived without waiting for the end. Turtle is prefixed and readable, and needs the whole document, so it is what a finished run serialises to.

The lkg:basis predicate carries the same distinction as the colours, so a consumer can take only the part it can rely on:

<run/a1b2/link/Step1-Step2>  lkg:similarity "0.8371"^^xsd:decimal ;
                             lkg:basis      lkg:Embedding .     # measured association

<run/a1b2/conversion/1>      lkg:statement  "23 week = 13910400 second" ;
                             lkg:from       <unit/week> ;
                             lkg:to         <unit/second> ;
                             lkg:basis      lkg:Exact .         # derived, reproducible

Run it

pip install mpe-lkg
mpe-lkg

Then open http://localhost:5100.

It needs a local model, which it reaches through Ollama. You do not need to work that out from here — start it and it will tell you what it found, what is missing, and the one command that fixes it. mpe-lkg doctor reports the same thing without starting the server, and exits non-zero, so it works in a script.

Python 3.10 or newer. The wheel is py3-none-any, so nothing is compiled and the same artefact serves Linux, macOS and Windows — all three tested on every push.

From a clone, or from Python
git clone https://github.com/punnerud/Local_Knowledge_Graph
cd Local_Knowledge_Graph
python3 -m venv .venv && .venv/bin/pip install -e .
.venv/bin/mpe-lkg

python app.py still works from a clone as it always has.

from mpe_lkg import create_app, health

print(health())
create_app().run(port=5100)

More

Models and configuration Choosing models, every environment variable, troubleshooting
Embeddings from inside a model Reading a chosen layer instead of an embedding endpoint
How it works The modules, the strongest-path search, why there is no ANN index
Development Tests, and the gate that checks this documentation against measured data

Licence

The mpedb License 1.0 — the same licence as mpedb and MPEqs, byte for byte.

Free of charge for every person and every organization, with one exception: a group whose revenue or valuation exceeds five billion dollars owes a one-time fee of seven US cents per device. Not an OSI-approved licence.


Published to PyPI as mpe-lkgMorten Punnerud-Engelstad Local Knowledge Graph.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpe_lkg-0.6.0.tar.gz (720.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mpe_lkg-0.6.0-py3-none-any.whl (247.7 kB view details)

Uploaded Python 3

File details

Details for the file mpe_lkg-0.6.0.tar.gz.

File metadata

  • Download URL: mpe_lkg-0.6.0.tar.gz
  • Upload date:
  • Size: 720.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.12

File hashes

Hashes for mpe_lkg-0.6.0.tar.gz
Algorithm Hash digest
SHA256 0c5ca0ed421d054ec0b988e2c6a7c2988bef22845048c3f9e81cfb48686d1ec9
MD5 30424be208b74a959fa8b6b9e7f05046
BLAKE2b-256 fae39a29ed29c7f86604a6d79b7cd8caa20fa5889501c9eca824256c0003d2f5

See more details on using hashes here.

File details

Details for the file mpe_lkg-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: mpe_lkg-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 247.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.12

File hashes

Hashes for mpe_lkg-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 148aba7e42a4f2b5afae6c0c6b7a3d0433ac383dc943effff75d0573cfce8e2d
MD5 34bdc77ba7388d26cadbdccb2155dbb3
BLAKE2b-256 dba46fe0fea0409bfea33bbc8ecba4604fd2f549fb006f2920dc9df051193de3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page