Skip to main content

graphwalk

CI PyPI Docs License

Cheap, confidence-scored question answering over a knowledge graph you already have. Python library, CLI, and MCP server for agents.

graphwalk answers a question by walking the graph from the entities it names. Each hop is a constrained classification decision: the current node's relations, plus STOP, are the options, and a decider returns a probability for each. So every answer comes with a path and a confidence, and you can escalate the unsure ones to a stronger model.

Bring your own decider. graphwalk is the machinery (options, walks, confidence, escalation, the MCP tools); the decider plugs in:

  • Jev (default), TypeSafe's classification model: the fastest we measured.
  • Any model that returns token probabilities, at any OpenAI-compatible endpoint (OpenRouter, vLLM, llama.cpp, OpenAI). With Qwen3.8-27B (open weights) it matched Jev's accuracy and confidence quality, at about 10× the latency through OpenRouter; other models vary, so check yours.
  • Your own: anything implementing DecisionBackend (a fine-tuned classifier, a cross-encoder). See deciders.
pip install graphwalk
graphwalk import kg.nt --graph kg.db          # triples: CSV, TSV, JSONL, N-Triples; no key needed
graphwalk query kg.db "Where was the director of Inception born?" --escalate-below 0.9

When to use it (measured)

Every number below comes from an experiment in docs/, on samples of 30–300 questions. Treat them as directions, not guarantees.

Situation What we found
An agent exploring a KG with graph tools (MCP) Adding graphwalk's walk tool cut a strong agent's cost by 17% (95% CI 8–27%) at equal accuracy (0.76 vs 0.75 F1, n=100, WebQSP). Text search over the same facts was as accurate and a little cheaper, but slower; with entity names replaced by meaningless aliases (no help from the model's memory), graph tools beat it by 0.25 F1.
Existing KG, cost or latency first, or you need a per-answer confidence walk is ~6× cheaper and ~4× faster than an LLM writing the query, and its confidence ranks answers well (AUROC 0.92 on WebQSP, up to 0.97 on MetaQA).
Existing KG, best accuracy Have an LLM write the query instead: 0.66 vs 0.49 F1 on a 5,419-relation Freebase graph.
Questions with constraints or superlatives (CWQ) Not graphwalk. Every system we tried scored about 0.3.
Questions over documents Not graphwalk. Multi-step RAG wins by 10–19 F1. Text ingestion exists but is experimental.

graphwalk does not claim to be more accurate than an LLM. What it offers is a cheap first answer that knows when it might be wrong.

Quickstart

The default decider is Jev, through OpenRouter (OPENROUTER_API_KEY) or TypeSafe (TYPESAFE_API_KEY). GRAPHWALK_DECIDER=logprob decides with an open-weights model's token probabilities instead (on OpenRouter by default, or your own server via GRAPHWALK_DECIDER_BASE_URL).

import asyncio
from graphwalk import Index


async def main() -> None:
    async with Index.open("kg.db", escalate_below=0.9) as index:
        await index.import_triples("kg.nt")  # idempotent
        result = await index.walk("Where was the director of Inception born?")
        print(result.best.names, result.confidence, result.escalated, result.cost_usd)


asyncio.run(main())

A runnable example over a 15-triple movie graph is in examples/kg/.

For agents (MCP)

pip install 'graphwalk[mcp]'
claude mcp add --env OPENROUTER_API_KEY=sk-or-... graphwalk -- graphwalk mcp --db kg.db

Tools: walk (answers, paths, confidence), neighbors, get_node, status, plus locate/read/ingest for text. The usual loop: call walk first; at confidence 0.9 or above, take the answer; below it, check it with neighbors or escalate. The server also runs over HTTP with bearer or OAuth 2.1 auth, and ships as a container. See MCP setup.

The package carries its own guide for coding agents: graphwalk guide (or graphwalk guide --skill for a SKILL.md), and llms.txt.

Install options

Extra Enables
(none) import, walk, query, the CLI
mcp the MCP server (stdio and HTTP)
llm LiteLLM: escalation, the LLM decider, text ingestion
embeddings local fastembed embedder (prefilter, dense locate)
eval dataset loaders for the benchmarks

Documentation

Status

Alpha (v0.2). The public API is what graphwalk exports; submodules may change between minor versions. Results are from small samples, mostly one seed. Jev is a hosted model from TypeSafe; this project has no affiliation with TypeSafe, and does not depend on it: any model with token probabilities can decide.

Development

See CONTRIBUTING.md.

License

Apache-2.0. See LICENSE.

Metadata

Release files for graphwalk 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for graphwalk 0.2.0
File Size Uploaded Provenance Actions
graphwalk-0.2.0.tar.gz 183.6 kB With provenance Details for graphwalk-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for graphwalk 0.2.0
File Interpreter ABI Platform Actions
graphwalk-0.2.0-py3-none-any.whl Python 3 none any Details for graphwalk-0.2.0-py3-none-any.whl

Total release size: 416.1 kB

Release files / graphwalk-0.2.0.tar.gz

Download URL graphwalk-0.2.0.tar.gz
Size 183.6 kB
Tags Source
SHA-256 checksum
How to use checksums
751f4c84dbe66ad374b0dd56fd62f5c4ffa89892fffd8313b2e34b3653250417
BLAKE2b-256 checksum
How to use checksums
ee637de71d74b530e6732f5e5561483507be9e77b87d8c5cbca0e1c53f113f92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 25, 2026.

Transparency log

Release files / graphwalk-0.2.0-py3-none-any.whl

Download URL graphwalk-0.2.0-py3-none-any.whl
Size 232.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01ca84f93df364777f4505a5561750fd0b673e3368f23f885a9c9b41e8e70c56
BLAKE2b-256 checksum
How to use checksums
2d9e53597c57035ace9be02e1cd9b3ab2408bc858ab8ee422be6ecde31f0bc70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 25, 2026.

Transparency log

Security for graphwalk 0.2.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for graphwalk-0.2.0.tar.gz

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 Oct 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page