graphwalk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. graphwalk-0.1.0/LICENSE +177 -0
  2. graphwalk-0.1.0/PKG-INFO +151 -0
  3. graphwalk-0.1.0/README.md +109 -0
  4. graphwalk-0.1.0/pyproject.toml +113 -0
  5. graphwalk-0.1.0/src/graphwalk/__init__.py +46 -0
  6. graphwalk-0.1.0/src/graphwalk/agent_docs/SKILL.md +33 -0
  7. graphwalk-0.1.0/src/graphwalk/agent_docs/guide.md +188 -0
  8. graphwalk-0.1.0/src/graphwalk/cli.py +654 -0
  9. graphwalk-0.1.0/src/graphwalk/config.py +344 -0
  10. graphwalk-0.1.0/src/graphwalk/core/__init__.py +35 -0
  11. graphwalk-0.1.0/src/graphwalk/core/errors.py +55 -0
  12. graphwalk-0.1.0/src/graphwalk/core/hashing.py +27 -0
  13. graphwalk-0.1.0/src/graphwalk/core/merge.py +152 -0
  14. graphwalk-0.1.0/src/graphwalk/core/model.py +196 -0
  15. graphwalk-0.1.0/src/graphwalk/core/redact.py +20 -0
  16. graphwalk-0.1.0/src/graphwalk/decisions/__init__.py +30 -0
  17. graphwalk-0.1.0/src/graphwalk/decisions/base.py +182 -0
  18. graphwalk-0.1.0/src/graphwalk/decisions/fake.py +116 -0
  19. graphwalk-0.1.0/src/graphwalk/decisions/jev.py +245 -0
  20. graphwalk-0.1.0/src/graphwalk/decisions/llm_decider.py +173 -0
  21. graphwalk-0.1.0/src/graphwalk/embeddings/__init__.py +6 -0
  22. graphwalk-0.1.0/src/graphwalk/embeddings/base.py +28 -0
  23. graphwalk-0.1.0/src/graphwalk/embeddings/fake.py +41 -0
  24. graphwalk-0.1.0/src/graphwalk/embeddings/fastembed_embedder.py +54 -0
  25. graphwalk-0.1.0/src/graphwalk/embeddings/openai_compatible.py +69 -0
  26. graphwalk-0.1.0/src/graphwalk/eval/__init__.py +29 -0
  27. graphwalk-0.1.0/src/graphwalk/eval/agent.py +502 -0
  28. graphwalk-0.1.0/src/graphwalk/eval/calibration.py +73 -0
  29. graphwalk-0.1.0/src/graphwalk/eval/datasets/__init__.py +1 -0
  30. graphwalk-0.1.0/src/graphwalk/eval/datasets/cache.py +26 -0
  31. graphwalk-0.1.0/src/graphwalk/eval/datasets/fanoutqa.py +159 -0
  32. graphwalk-0.1.0/src/graphwalk/eval/datasets/hotpotqa.py +100 -0
  33. graphwalk-0.1.0/src/graphwalk/eval/datasets/metaqa.py +115 -0
  34. graphwalk-0.1.0/src/graphwalk/eval/datasets/rog.py +201 -0
  35. graphwalk-0.1.0/src/graphwalk/eval/datasets/twowiki.py +72 -0
  36. graphwalk-0.1.0/src/graphwalk/eval/evidence.py +359 -0
  37. graphwalk-0.1.0/src/graphwalk/eval/ingest_eval.py +330 -0
  38. graphwalk-0.1.0/src/graphwalk/eval/metrics.py +97 -0
  39. graphwalk-0.1.0/src/graphwalk/eval/per_question.py +48 -0
  40. graphwalk-0.1.0/src/graphwalk/eval/query_writer.py +274 -0
  41. graphwalk-0.1.0/src/graphwalk/eval/runner.py +348 -0
  42. graphwalk-0.1.0/src/graphwalk/eval/suite.py +295 -0
  43. graphwalk-0.1.0/src/graphwalk/eval/systems.py +900 -0
  44. graphwalk-0.1.0/src/graphwalk/eval/text_qa.py +347 -0
  45. graphwalk-0.1.0/src/graphwalk/eval/types.py +61 -0
  46. graphwalk-0.1.0/src/graphwalk/guide.py +17 -0
  47. graphwalk-0.1.0/src/graphwalk/index.py +349 -0
  48. graphwalk-0.1.0/src/graphwalk/ingest/__init__.py +46 -0
  49. graphwalk-0.1.0/src/graphwalk/ingest/cache.py +55 -0
  50. graphwalk-0.1.0/src/graphwalk/ingest/chunking.py +135 -0
  51. graphwalk-0.1.0/src/graphwalk/ingest/extraction.py +273 -0
  52. graphwalk-0.1.0/src/graphwalk/ingest/normalize.py +293 -0
  53. graphwalk-0.1.0/src/graphwalk/ingest/pipeline.py +565 -0
  54. graphwalk-0.1.0/src/graphwalk/ingest/resolution.py +175 -0
  55. graphwalk-0.1.0/src/graphwalk/ingest/routing.py +443 -0
  56. graphwalk-0.1.0/src/graphwalk/ingest/sources.py +176 -0
  57. graphwalk-0.1.0/src/graphwalk/ingest/spend.py +23 -0
  58. graphwalk-0.1.0/src/graphwalk/ingest/triples.py +369 -0
  59. graphwalk-0.1.0/src/graphwalk/llm/__init__.py +7 -0
  60. graphwalk-0.1.0/src/graphwalk/llm/base.py +39 -0
  61. graphwalk-0.1.0/src/graphwalk/llm/fake.py +36 -0
  62. graphwalk-0.1.0/src/graphwalk/llm/litellm_backend.py +121 -0
  63. graphwalk-0.1.0/src/graphwalk/llm/litellm_import.py +21 -0
  64. graphwalk-0.1.0/src/graphwalk/locate/__init__.py +26 -0
  65. graphwalk-0.1.0/src/graphwalk/locate/dense.py +122 -0
  66. graphwalk-0.1.0/src/graphwalk/locate/documents.py +109 -0
  67. graphwalk-0.1.0/src/graphwalk/locate/graph.py +243 -0
  68. graphwalk-0.1.0/src/graphwalk/locate/model.py +66 -0
  69. graphwalk-0.1.0/src/graphwalk/providers.py +145 -0
  70. graphwalk-0.1.0/src/graphwalk/py.typed +0 -0
  71. graphwalk-0.1.0/src/graphwalk/server/__init__.py +1 -0
  72. graphwalk-0.1.0/src/graphwalk/server/app.py +330 -0
  73. graphwalk-0.1.0/src/graphwalk/server/auth.py +230 -0
  74. graphwalk-0.1.0/src/graphwalk/server/service.py +547 -0
  75. graphwalk-0.1.0/src/graphwalk/server/settings.py +111 -0
  76. graphwalk-0.1.0/src/graphwalk/stores/__init__.py +7 -0
  77. graphwalk-0.1.0/src/graphwalk/stores/base.py +183 -0
  78. graphwalk-0.1.0/src/graphwalk/stores/migrate.py +64 -0
  79. graphwalk-0.1.0/src/graphwalk/stores/networkx_store.py +325 -0
  80. graphwalk-0.1.0/src/graphwalk/stores/sqlite_store.py +475 -0
  81. graphwalk-0.1.0/src/graphwalk/traversal/__init__.py +39 -0
  82. graphwalk-0.1.0/src/graphwalk/traversal/batching.py +58 -0
  83. graphwalk-0.1.0/src/graphwalk/traversal/config.py +135 -0
  84. graphwalk-0.1.0/src/graphwalk/traversal/engine.py +729 -0
  85. graphwalk-0.1.0/src/graphwalk/traversal/entry.py +309 -0
  86. graphwalk-0.1.0/src/graphwalk/traversal/escalation.py +59 -0
  87. graphwalk-0.1.0/src/graphwalk/traversal/prefilter.py +65 -0
  88. graphwalk-0.1.0/src/graphwalk/traversal/prompts.py +206 -0
  89. graphwalk-0.1.0/src/graphwalk/traversal/sampling.py +50 -0
  90. graphwalk-0.1.0/src/graphwalk/traversal/scoring.py +21 -0
  91. graphwalk-0.1.0/src/graphwalk/traversal/trace.py +187 -0
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.4
2
+ Name: graphwalk
3
+ Version: 0.1.0
4
+ Summary: Cheap, confidence-scored question answering over knowledge graphs: each hop is a calibrated classification decision. Library, CLI, and MCP server.
5
+ Keywords: knowledge graph,kgqa,graph traversal,mcp,llm agents,calibration,retrieval
6
+ Author: Manvir Chakal
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
17
+ Classifier: Typing :: Typed
18
+ Requires-Dist: networkx>=3.4
19
+ Requires-Dist: numpy>=2.1
20
+ Requires-Dist: pydantic>=2.12
21
+ Requires-Dist: pydantic-settings>=2.6
22
+ Requires-Dist: typer>=0.15
23
+ Requires-Dist: typesafe-sdk>=0.7.2,<0.8
24
+ Requires-Dist: fastembed>=0.7 ; extra == 'embeddings'
25
+ Requires-Dist: httpx>=0.28 ; extra == 'eval'
26
+ Requires-Dist: pyarrow>=17 ; extra == 'eval'
27
+ Requires-Dist: litellm>=1.60 ; extra == 'llm'
28
+ Requires-Dist: mcp>=1.20 ; extra == 'mcp'
29
+ Requires-Dist: pyjwt[crypto]>=2.10 ; extra == 'mcp'
30
+ Requires-Dist: uvicorn>=0.34 ; extra == 'mcp'
31
+ Requires-Python: >=3.12
32
+ Project-URL: Changelog, https://github.com/manvirchakal/graphwalk/blob/main/CHANGELOG.md
33
+ Project-URL: Documentation, https://manvirchakal.github.io/graphwalk/
34
+ Project-URL: Homepage, https://github.com/manvirchakal/graphwalk
35
+ Project-URL: Issues, https://github.com/manvirchakal/graphwalk/issues
36
+ Project-URL: Source, https://github.com/manvirchakal/graphwalk
37
+ Provides-Extra: embeddings
38
+ Provides-Extra: eval
39
+ Provides-Extra: llm
40
+ Provides-Extra: mcp
41
+ Description-Content-Type: text/markdown
42
+
43
+ # graphwalk
44
+
45
+ [![CI](https://github.com/manvirchakal/graphwalk/actions/workflows/ci.yml/badge.svg)](https://github.com/manvirchakal/graphwalk/actions/workflows/ci.yml)
46
+ [![PyPI](https://img.shields.io/pypi/v/graphwalk)](https://pypi.org/project/graphwalk/)
47
+ [![Docs](https://img.shields.io/badge/docs-github.io-blue)](https://manvirchakal.github.io/graphwalk/)
48
+ [![License](https://img.shields.io/badge/license-Apache--2.0-green)](https://github.com/manvirchakal/graphwalk/blob/main/LICENSE)
49
+
50
+ **Cheap, confidence-scored question answering over a knowledge graph you already
51
+ have.** Python library, CLI, and MCP server for agents.
52
+
53
+ graphwalk answers a question by walking the graph from the entities it names. Each hop
54
+ is a **constrained classification decision**: the current node's relations, plus
55
+ `STOP`, are the options, and a fast decision model returns a probability for each. So
56
+ every answer comes with a path and a **confidence**, and you can escalate the unsure
57
+ ones to a stronger model.
58
+
59
+ ```bash
60
+ pip install graphwalk
61
+ graphwalk import kg.nt --graph kg.db # triples: CSV, TSV, JSONL, N-Triples; no key needed
62
+ graphwalk query kg.db "Where was the director of Inception born?" --escalate-below 0.9
63
+ ```
64
+
65
+ ## When to use it (measured)
66
+
67
+ Every number below comes from an experiment in [`docs/`](https://github.com/manvirchakal/graphwalk/tree/main/docs/), on samples of 30–300
68
+ questions. Treat them as directions, not guarantees.
69
+
70
+ | Situation | What we found |
71
+ |---|---|
72
+ | **An agent exploring a KG** with graph tools (MCP) | Adding graphwalk's `walk` tool cut a strong agent's cost by **25%** (95% CI 7–45%) at equal accuracy (0.75 vs 0.71 F1, n=30, WebQSP). Text search over the same facts was as accurate and a little cheaper, but slower. |
73
+ | **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). |
74
+ | **Existing KG, best accuracy** | Have an LLM write the query instead: 0.66 vs 0.49 F1 on a 5,419-relation Freebase graph. |
75
+ | Questions with constraints or superlatives (CWQ) | Not graphwalk. Every system we tried scored about 0.3. |
76
+ | **Questions over documents** | Not graphwalk. Multi-step RAG wins by 10–19 F1. Text ingestion exists but is experimental. |
77
+
78
+ graphwalk does not claim to be more accurate than an LLM. What it offers is a cheap first
79
+ answer that **knows when it might be wrong**.
80
+
81
+ ## Quickstart
82
+
83
+ Decisions use the Jev model, through [OpenRouter](https://openrouter.ai)
84
+ (`OPENROUTER_API_KEY`) or TypeSafe (`TYPESAFE_API_KEY`). Without either,
85
+ `GRAPHWALK_DECISION_FALLBACK=llm` lets any chat model decide (slower, not calibrated).
86
+
87
+ ```python
88
+ import asyncio
89
+ from graphwalk import Index
90
+
91
+
92
+ async def main() -> None:
93
+ async with Index.open("kg.db", escalate_below=0.9) as index:
94
+ await index.import_triples("kg.nt") # idempotent
95
+ result = await index.walk("Where was the director of Inception born?")
96
+ print(result.best.names, result.confidence, result.escalated, result.cost_usd)
97
+
98
+
99
+ asyncio.run(main())
100
+ ```
101
+
102
+ A runnable example over a 15-triple movie graph is in
103
+ [`examples/kg/`](https://github.com/manvirchakal/graphwalk/blob/main/examples/kg/walk.py).
104
+
105
+ ## For agents (MCP)
106
+
107
+ ```bash
108
+ pip install 'graphwalk[mcp]'
109
+ claude mcp add --env OPENROUTER_API_KEY=sk-or-... graphwalk -- graphwalk mcp --db kg.db
110
+ ```
111
+
112
+ Tools: `walk` (answers, paths, confidence), `neighbors`, `get_node`, `status`, plus
113
+ `locate`/`read`/`ingest` for text. The usual loop: call `walk` first; at confidence 0.9
114
+ or above, take the answer; below it, check it with `neighbors` or escalate. The server
115
+ also runs over HTTP with bearer or OAuth 2.1 auth, and ships as a container. See
116
+ [MCP setup](https://manvirchakal.github.io/graphwalk/agents/).
117
+
118
+ The package carries its own guide for coding agents: `graphwalk guide` (or
119
+ `graphwalk guide --skill` for a `SKILL.md`), and [`llms.txt`](https://github.com/manvirchakal/graphwalk/blob/main/llms.txt).
120
+
121
+ ## Install options
122
+
123
+ | Extra | Enables |
124
+ |---|---|
125
+ | (none) | import, walk, query, the CLI |
126
+ | `mcp` | the MCP server (stdio and HTTP) |
127
+ | `llm` | LiteLLM: escalation, the LLM decider, text ingestion |
128
+ | `embeddings` | local fastembed embedder (prefilter, dense `locate`) |
129
+ | `eval` | dataset loaders for the benchmarks |
130
+
131
+ ## Documentation
132
+
133
+ - [Docs site](https://manvirchakal.github.io/graphwalk/): quickstart, agents and MCP,
134
+ configuration, text ingestion, evidence.
135
+ - [Results](https://github.com/manvirchakal/graphwalk/blob/main/docs/evidence.md): every experiment, with CIs, costs, and the runs behind it.
136
+ - [Design record](https://github.com/manvirchakal/graphwalk/blob/main/docs/design.md) and [roadmap](https://github.com/manvirchakal/graphwalk/blob/main/roadmap.md).
137
+
138
+ ## Status
139
+
140
+ Alpha (v0.1). The public API is what `graphwalk` exports; submodules may change between
141
+ minor versions. Results are from small samples, mostly one seed. The decision model
142
+ (Jev) is a hosted model from TypeSafe; this project has no affiliation with TypeSafe,
143
+ and the LLM-decider fallback keeps it usable without Jev.
144
+
145
+ ## Development
146
+
147
+ See [CONTRIBUTING.md](https://github.com/manvirchakal/graphwalk/blob/main/CONTRIBUTING.md).
148
+
149
+ ## License
150
+
151
+ Apache-2.0. See [LICENSE](https://github.com/manvirchakal/graphwalk/blob/main/LICENSE).
@@ -0,0 +1,109 @@
1
+ # graphwalk
2
+
3
+ [![CI](https://github.com/manvirchakal/graphwalk/actions/workflows/ci.yml/badge.svg)](https://github.com/manvirchakal/graphwalk/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/graphwalk)](https://pypi.org/project/graphwalk/)
5
+ [![Docs](https://img.shields.io/badge/docs-github.io-blue)](https://manvirchakal.github.io/graphwalk/)
6
+ [![License](https://img.shields.io/badge/license-Apache--2.0-green)](https://github.com/manvirchakal/graphwalk/blob/main/LICENSE)
7
+
8
+ **Cheap, confidence-scored question answering over a knowledge graph you already
9
+ have.** Python library, CLI, and MCP server for agents.
10
+
11
+ graphwalk answers a question by walking the graph from the entities it names. Each hop
12
+ is a **constrained classification decision**: the current node's relations, plus
13
+ `STOP`, are the options, and a fast decision model returns a probability for each. So
14
+ every answer comes with a path and a **confidence**, and you can escalate the unsure
15
+ ones to a stronger model.
16
+
17
+ ```bash
18
+ pip install graphwalk
19
+ graphwalk import kg.nt --graph kg.db # triples: CSV, TSV, JSONL, N-Triples; no key needed
20
+ graphwalk query kg.db "Where was the director of Inception born?" --escalate-below 0.9
21
+ ```
22
+
23
+ ## When to use it (measured)
24
+
25
+ Every number below comes from an experiment in [`docs/`](https://github.com/manvirchakal/graphwalk/tree/main/docs/), on samples of 30–300
26
+ questions. Treat them as directions, not guarantees.
27
+
28
+ | Situation | What we found |
29
+ |---|---|
30
+ | **An agent exploring a KG** with graph tools (MCP) | Adding graphwalk's `walk` tool cut a strong agent's cost by **25%** (95% CI 7–45%) at equal accuracy (0.75 vs 0.71 F1, n=30, WebQSP). Text search over the same facts was as accurate and a little cheaper, but slower. |
31
+ | **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). |
32
+ | **Existing KG, best accuracy** | Have an LLM write the query instead: 0.66 vs 0.49 F1 on a 5,419-relation Freebase graph. |
33
+ | Questions with constraints or superlatives (CWQ) | Not graphwalk. Every system we tried scored about 0.3. |
34
+ | **Questions over documents** | Not graphwalk. Multi-step RAG wins by 10–19 F1. Text ingestion exists but is experimental. |
35
+
36
+ graphwalk does not claim to be more accurate than an LLM. What it offers is a cheap first
37
+ answer that **knows when it might be wrong**.
38
+
39
+ ## Quickstart
40
+
41
+ Decisions use the Jev model, through [OpenRouter](https://openrouter.ai)
42
+ (`OPENROUTER_API_KEY`) or TypeSafe (`TYPESAFE_API_KEY`). Without either,
43
+ `GRAPHWALK_DECISION_FALLBACK=llm` lets any chat model decide (slower, not calibrated).
44
+
45
+ ```python
46
+ import asyncio
47
+ from graphwalk import Index
48
+
49
+
50
+ async def main() -> None:
51
+ async with Index.open("kg.db", escalate_below=0.9) as index:
52
+ await index.import_triples("kg.nt") # idempotent
53
+ result = await index.walk("Where was the director of Inception born?")
54
+ print(result.best.names, result.confidence, result.escalated, result.cost_usd)
55
+
56
+
57
+ asyncio.run(main())
58
+ ```
59
+
60
+ A runnable example over a 15-triple movie graph is in
61
+ [`examples/kg/`](https://github.com/manvirchakal/graphwalk/blob/main/examples/kg/walk.py).
62
+
63
+ ## For agents (MCP)
64
+
65
+ ```bash
66
+ pip install 'graphwalk[mcp]'
67
+ claude mcp add --env OPENROUTER_API_KEY=sk-or-... graphwalk -- graphwalk mcp --db kg.db
68
+ ```
69
+
70
+ Tools: `walk` (answers, paths, confidence), `neighbors`, `get_node`, `status`, plus
71
+ `locate`/`read`/`ingest` for text. The usual loop: call `walk` first; at confidence 0.9
72
+ or above, take the answer; below it, check it with `neighbors` or escalate. The server
73
+ also runs over HTTP with bearer or OAuth 2.1 auth, and ships as a container. See
74
+ [MCP setup](https://manvirchakal.github.io/graphwalk/agents/).
75
+
76
+ The package carries its own guide for coding agents: `graphwalk guide` (or
77
+ `graphwalk guide --skill` for a `SKILL.md`), and [`llms.txt`](https://github.com/manvirchakal/graphwalk/blob/main/llms.txt).
78
+
79
+ ## Install options
80
+
81
+ | Extra | Enables |
82
+ |---|---|
83
+ | (none) | import, walk, query, the CLI |
84
+ | `mcp` | the MCP server (stdio and HTTP) |
85
+ | `llm` | LiteLLM: escalation, the LLM decider, text ingestion |
86
+ | `embeddings` | local fastembed embedder (prefilter, dense `locate`) |
87
+ | `eval` | dataset loaders for the benchmarks |
88
+
89
+ ## Documentation
90
+
91
+ - [Docs site](https://manvirchakal.github.io/graphwalk/): quickstart, agents and MCP,
92
+ configuration, text ingestion, evidence.
93
+ - [Results](https://github.com/manvirchakal/graphwalk/blob/main/docs/evidence.md): every experiment, with CIs, costs, and the runs behind it.
94
+ - [Design record](https://github.com/manvirchakal/graphwalk/blob/main/docs/design.md) and [roadmap](https://github.com/manvirchakal/graphwalk/blob/main/roadmap.md).
95
+
96
+ ## Status
97
+
98
+ Alpha (v0.1). The public API is what `graphwalk` exports; submodules may change between
99
+ minor versions. Results are from small samples, mostly one seed. The decision model
100
+ (Jev) is a hosted model from TypeSafe; this project has no affiliation with TypeSafe,
101
+ and the LLM-decider fallback keeps it usable without Jev.
102
+
103
+ ## Development
104
+
105
+ See [CONTRIBUTING.md](https://github.com/manvirchakal/graphwalk/blob/main/CONTRIBUTING.md).
106
+
107
+ ## License
108
+
109
+ Apache-2.0. See [LICENSE](https://github.com/manvirchakal/graphwalk/blob/main/LICENSE).
@@ -0,0 +1,113 @@
1
+ [project]
2
+ name = "graphwalk"
3
+ version = "0.1.0"
4
+ description = "Cheap, confidence-scored question answering over knowledge graphs: each hop is a calibrated classification decision. Library, CLI, and MCP server."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "Manvir Chakal" }]
9
+ keywords = ["knowledge graph", "kgqa", "graph traversal", "mcp", "llm agents", "calibration", "retrieval"]
10
+ requires-python = ">=3.12"
11
+ classifiers = [
12
+ "Development Status :: 3 - Alpha",
13
+ "Intended Audience :: Developers",
14
+ "Intended Audience :: Science/Research",
15
+ "Operating System :: OS Independent",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.12",
18
+ "Programming Language :: Python :: 3.13",
19
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
20
+ "Typing :: Typed",
21
+ ]
22
+ dependencies = [
23
+ "networkx>=3.4",
24
+ "numpy>=2.1",
25
+ "pydantic>=2.12",
26
+ "pydantic-settings>=2.6",
27
+ "typer>=0.15",
28
+ "typesafe-sdk>=0.7.2,<0.8",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ embeddings = [
33
+ "fastembed>=0.7",
34
+ ]
35
+ llm = [
36
+ "litellm>=1.60",
37
+ ]
38
+ mcp = [
39
+ "mcp>=1.20",
40
+ "pyjwt[crypto]>=2.10",
41
+ "uvicorn>=0.34",
42
+ ]
43
+ eval = [
44
+ "httpx>=0.28",
45
+ "pyarrow>=17", # FanOutQA's Wikipedia corpus mirror is an Arrow file
46
+ ]
47
+
48
+ [project.urls]
49
+ Homepage = "https://github.com/manvirchakal/graphwalk"
50
+ Documentation = "https://manvirchakal.github.io/graphwalk/"
51
+ Source = "https://github.com/manvirchakal/graphwalk"
52
+ Changelog = "https://github.com/manvirchakal/graphwalk/blob/main/CHANGELOG.md"
53
+ Issues = "https://github.com/manvirchakal/graphwalk/issues"
54
+
55
+ [project.scripts]
56
+ graphwalk = "graphwalk.cli:app"
57
+
58
+ [build-system]
59
+ requires = ["uv_build>=0.8.17,<0.9.0"]
60
+ build-backend = "uv_build"
61
+
62
+ [dependency-groups]
63
+ dev = [
64
+ "pyright>=1.1.414",
65
+ "pytest>=9.1.1",
66
+ "pytest-asyncio>=1.4.0",
67
+ "pytest-socket>=0.8.1",
68
+ "ruff>=0.16.9",
69
+ "types-networkx>=3.6.1.20260911",
70
+ ]
71
+ docs = [
72
+ "mkdocs>=1.6,<2",
73
+ "mkdocs-material>=9.6",
74
+ ]
75
+
76
+ [tool.ruff]
77
+ line-length = 100
78
+ target-version = "py312"
79
+ src = ["src", "tests"]
80
+ extend-exclude = ["docs"]
81
+
82
+ [tool.ruff.lint]
83
+ select = [
84
+ "E", "W", "F", "I", "N", "UP", "B", "A", "C4", "SIM", "RUF",
85
+ "ASYNC", "PT", "PTH", "TC", "PL", "S", "BLE", "T20", "RET",
86
+ ]
87
+ ignore = [
88
+ "PLR0913", # protocols legitimately take many keyword args
89
+ ]
90
+
91
+ [tool.ruff.lint.per-file-ignores]
92
+ "examples/**" = ["T201", "ASYNC240"] # small scripts: print output, read files directly
93
+ "tests/**" = ["S101", "S311", "PLR2004", "PLC0415", "ASYNC240"] # seeded RNGs and blocking fs are fine in tests
94
+
95
+ [tool.pyright]
96
+ include = ["src", "tests"]
97
+ pythonVersion = "3.12"
98
+ venvPath = "."
99
+ venv = ".venv"
100
+ strict = ["src"]
101
+ extraPaths = ["tests"]
102
+ typeCheckingMode = "standard"
103
+
104
+ [tool.pytest.ini_options]
105
+ testpaths = ["tests"]
106
+ pythonpath = ["tests"]
107
+ asyncio_mode = "auto"
108
+ asyncio_default_fixture_loop_scope = "function"
109
+ addopts = ["-ra", "--strict-markers", "--disable-socket", "--allow-unix-socket"]
110
+ markers = [
111
+ "live: calls a real external API; skipped unless --run-live is given",
112
+ "neo4j: needs a running Neo4j; skipped unless --run-neo4j is given",
113
+ ]
@@ -0,0 +1,46 @@
1
+ """graphwalk: fast, probabilistic question answering over knowledge graphs.
2
+
3
+ When to use it and how: ``graphwalk.guide()`` (or ``graphwalk guide`` on the command
4
+ line). The public API is what this module exports. Everything else (``graphwalk.traversal``,
5
+ ``graphwalk.ingest``, ...) is internal and may change between minor versions.
6
+ """
7
+
8
+ from importlib.metadata import version
9
+
10
+ from graphwalk.core.errors import DocumentNotFoundError, GraphwalkError, StaleLocationError
11
+ from graphwalk.core.model import Edge, Neighbor, Node, Provenance
12
+ from graphwalk.guide import guide
13
+ from graphwalk.index import Index, WalkResult
14
+ from graphwalk.ingest.pipeline import IngestConfig, IngestReport
15
+ from graphwalk.ingest.sources import FileSource, SourceDocument, TextSource
16
+ from graphwalk.ingest.triples import ImportReport
17
+ from graphwalk.locate.documents import FileDocuments, StoredDocuments
18
+ from graphwalk.locate.model import Location, Passage
19
+ from graphwalk.traversal.config import TraversalConfig
20
+
21
+ __version__ = version("graphwalk")
22
+
23
+ __all__ = [
24
+ "DocumentNotFoundError",
25
+ "Edge",
26
+ "FileDocuments",
27
+ "FileSource",
28
+ "GraphwalkError",
29
+ "ImportReport",
30
+ "Index",
31
+ "IngestConfig",
32
+ "IngestReport",
33
+ "Location",
34
+ "Neighbor",
35
+ "Node",
36
+ "Passage",
37
+ "Provenance",
38
+ "SourceDocument",
39
+ "StaleLocationError",
40
+ "StoredDocuments",
41
+ "TextSource",
42
+ "TraversalConfig",
43
+ "WalkResult",
44
+ "__version__",
45
+ "guide",
46
+ ]
@@ -0,0 +1,33 @@
1
+ ---
2
+ name: graphwalk
3
+ description: Answer questions over an existing knowledge graph (triples, RDF, CSV/JSONL edge lists) by walking it hop by hop with a fast classifier, getting entity answers with a confidence and the path taken; escalate low-confidence queries to an LLM. Use when a user has a knowledge graph and wants cheap, fast multi-hop lookups with a per-answer confidence, and can accept lower accuracy than an LLM writing the query. Not for best-accuracy KG-QA (have an LLM write the query from the relations near the entity), QA over documents (use RAG), or constrained/superlative questions.
4
+ ---
5
+
6
+ # graphwalk
7
+
8
+ Run `graphwalk guide` (or `python -c "import graphwalk; print(graphwalk.guide())"`)
9
+ for the full guide: when to use it, the measured trade-offs, recipes, and API.
10
+
11
+ Short version:
12
+
13
+ 1. Check fit first. graphwalk answers from the graph's nodes. It is 6× cheaper and
14
+ ~4× faster than an LLM writing the query, and gives an informative confidence, but
15
+ is ~15 F1 points less accurate on curated graphs of any schema size. It loses to
16
+ multi-step RAG on documents. It does no filtering, ranking, or set intersection.
17
+ 2. Import: `graphwalk import kg.nt --graph kg.db` (also `.csv`, `.tsv`, `.jsonl`). No
18
+ key is needed. Give nodes readable names and types.
19
+ 3. Query from Python:
20
+
21
+ ```python
22
+ from graphwalk import Index
23
+
24
+ # walks with TraversalConfig.kgqa() by default
25
+ async with Index.open("kg.db", node_types=[...], escalate_below=0.9) as index:
26
+ result = await index.walk(question)
27
+ result.best.names, result.best.path, result.confidence, result.escalated
28
+ ```
29
+
30
+ 4. Treat `result.confidence` as a ranking signal. Validate the threshold on 50–100
31
+ labeled questions from the user's own graph before trusting it.
32
+ 5. Keys: `OPENROUTER_API_KEY` (Jev decisions; the LLM for escalation). Without Jev,
33
+ use `GRAPHWALK_DECISION_FALLBACK=llm`; its confidence is not calibrated.