okf-wiki-kit 0.2.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.
- okf_wiki_kit-0.2.0/LICENSE +21 -0
- okf_wiki_kit-0.2.0/PKG-INFO +150 -0
- okf_wiki_kit-0.2.0/README.md +113 -0
- okf_wiki_kit-0.2.0/okf_wiki_kit.egg-info/PKG-INFO +150 -0
- okf_wiki_kit-0.2.0/okf_wiki_kit.egg-info/SOURCES.txt +29 -0
- okf_wiki_kit-0.2.0/okf_wiki_kit.egg-info/dependency_links.txt +1 -0
- okf_wiki_kit-0.2.0/okf_wiki_kit.egg-info/entry_points.txt +2 -0
- okf_wiki_kit-0.2.0/okf_wiki_kit.egg-info/requires.txt +23 -0
- okf_wiki_kit-0.2.0/okf_wiki_kit.egg-info/top_level.txt +1 -0
- okf_wiki_kit-0.2.0/okfkit/__init__.py +6 -0
- okf_wiki_kit-0.2.0/okfkit/adapters/__init__.py +9 -0
- okf_wiki_kit-0.2.0/okfkit/adapters/base.py +66 -0
- okf_wiki_kit-0.2.0/okfkit/adapters/markdown_folder.py +48 -0
- okf_wiki_kit-0.2.0/okfkit/cli.py +298 -0
- okf_wiki_kit-0.2.0/okfkit/config.py +50 -0
- okf_wiki_kit-0.2.0/okfkit/engine.py +353 -0
- okf_wiki_kit-0.2.0/okfkit/enrich.py +286 -0
- okf_wiki_kit-0.2.0/okfkit/model.py +44 -0
- okf_wiki_kit-0.2.0/okfkit/render.py +108 -0
- okf_wiki_kit-0.2.0/okfkit/serve/__init__.py +29 -0
- okf_wiki_kit-0.2.0/okfkit/serve/embeddings.py +112 -0
- okf_wiki_kit-0.2.0/okfkit/serve/mcp.py +353 -0
- okf_wiki_kit-0.2.0/okfkit/serve/rag.py +313 -0
- okf_wiki_kit-0.2.0/okfkit/serve/vault.py +107 -0
- okf_wiki_kit-0.2.0/pyproject.toml +47 -0
- okf_wiki_kit-0.2.0/setup.cfg +4 -0
- okf_wiki_kit-0.2.0/tests/test_adapters.py +39 -0
- okf_wiki_kit-0.2.0/tests/test_engine.py +73 -0
- okf_wiki_kit-0.2.0/tests/test_render.py +36 -0
- okf_wiki_kit-0.2.0/tests/test_serve_mcp.py +305 -0
- okf_wiki_kit-0.2.0/tests/test_serve_rag.py +224 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 okf-wiki-kit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: okf-wiki-kit
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Build Open-Knowledge-Format (OKF) / Obsidian LLM wikis from any source material.
|
|
5
|
+
Author: okf-wiki-kit contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/olivermorgan2/okf-wiki-kit
|
|
8
|
+
Project-URL: Issues, https://github.com/olivermorgan2/okf-wiki-kit/issues
|
|
9
|
+
Project-URL: Repository, https://github.com/olivermorgan2/okf-wiki-kit
|
|
10
|
+
Keywords: okf,obsidian,knowledge-graph,llm,rag,wiki,markdown
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: PyYAML>=6.0
|
|
21
|
+
Provides-Extra: anthropic
|
|
22
|
+
Requires-Dist: anthropic>=0.40; extra == "anthropic"
|
|
23
|
+
Provides-Extra: openai
|
|
24
|
+
Requires-Dist: openai>=1.40; extra == "openai"
|
|
25
|
+
Provides-Extra: rag
|
|
26
|
+
Requires-Dist: numpy>=1.24; extra == "rag"
|
|
27
|
+
Provides-Extra: voyage
|
|
28
|
+
Requires-Dist: voyageai>=0.3; extra == "voyage"
|
|
29
|
+
Provides-Extra: local-embeddings
|
|
30
|
+
Requires-Dist: numpy>=1.24; extra == "local-embeddings"
|
|
31
|
+
Requires-Dist: model2vec>=0.3; extra == "local-embeddings"
|
|
32
|
+
Provides-Extra: mcp
|
|
33
|
+
Requires-Dist: mcp>=1.2; extra == "mcp"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# okf-wiki-kit
|
|
39
|
+
|
|
40
|
+
Build a cross-linked **[Open Knowledge Format](https://github.com/GoogleCloudPlatform/knowledge-catalog/tree/main/okf)
|
|
41
|
+
(OKF)** knowledge wiki — browsable in **Obsidian** and consumable by **LLMs/agents** — from *any*
|
|
42
|
+
source material.
|
|
43
|
+
|
|
44
|
+
OKF represents knowledge as a directory of markdown files: each file is a typed node with YAML
|
|
45
|
+
frontmatter (only `type` is required) and `[[wikilinks]]` that form a knowledge graph richer than
|
|
46
|
+
the folder hierarchy. `okf-wiki-kit` gives you a small, dependency-light engine that turns your
|
|
47
|
+
content into such a bundle, with optional LLM enrichment.
|
|
48
|
+
|
|
49
|
+
## How it works
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
your source ──► SourceAdapter.load() ──► [Node, Node, …] ──► engine ──► OKF/Obsidian vault
|
|
53
|
+
(you write ~40 lines, (normalized) (generic: frontmatter, wikilinks,
|
|
54
|
+
or use a built-in one) indexes, link-inference, validate)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
You implement **one method** — `load() -> Iterable[Node]` — that turns your source into a list of
|
|
58
|
+
`Node`s. The engine does everything else: unique filenames, frontmatter, wikilinks, per-type and
|
|
59
|
+
root `index.md` files, optional mention-based link inference, validation, and optional LLM
|
|
60
|
+
enrichment.
|
|
61
|
+
|
|
62
|
+
## Quickstart (zero code)
|
|
63
|
+
|
|
64
|
+
Point the built-in *markdown-folder* adapter at any folder of `.md` files:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install -e . # or: pip install okf-wiki-kit
|
|
68
|
+
cp okf.config.example.yaml okf.config.yaml
|
|
69
|
+
# edit okf.config.yaml -> adapter_options.path: ./my-notes
|
|
70
|
+
okf build # writes ./vault
|
|
71
|
+
okf validate # every node typed, every wikilink resolves
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Open the `./vault` folder in Obsidian and look at the Graph View.
|
|
75
|
+
|
|
76
|
+
## Optional: LLM enrichment
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install -e ".[openai]" # or ".[anthropic]"
|
|
80
|
+
export OPENROUTER_API_KEY=... # or ANTHROPIC_API_KEY
|
|
81
|
+
okf enrich # writes enrichment.json (canonical concepts + descriptions)
|
|
82
|
+
okf build # rebuild, applying the enrichment
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Enrichment is **provider-flexible**: Anthropic (`claude-sonnet-4-6`) or any OpenAI-compatible
|
|
86
|
+
endpoint such as **OpenRouter** (`qwen/qwen3.7-plus`). Provider is auto-detected from your env keys.
|
|
87
|
+
|
|
88
|
+
## Writing your own adapter
|
|
89
|
+
|
|
90
|
+
For structured sources (JSON, a database, a CMS), write a small adapter:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from okfkit.model import Node, Link
|
|
94
|
+
from okfkit.adapters.base import SourceAdapter
|
|
95
|
+
|
|
96
|
+
class MyAdapter(SourceAdapter):
|
|
97
|
+
def load(self):
|
|
98
|
+
for row in my_source():
|
|
99
|
+
yield Node(
|
|
100
|
+
id=row["slug"], type="Article", title=row["title"],
|
|
101
|
+
body=row["markdown"],
|
|
102
|
+
frontmatter={"author": row["author"]},
|
|
103
|
+
links=[Link(target=t, rel="related", section="See also")
|
|
104
|
+
for t in row["related_slugs"]],
|
|
105
|
+
tags=row["tags"],
|
|
106
|
+
)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Point `okf.config.yaml` at it: `adapter: path/to/my_adapter.py:MyAdapter`. See
|
|
110
|
+
[`docs/writing-an-adapter.md`](docs/writing-an-adapter.md) and the worked example in
|
|
111
|
+
[`examples/textbook/`](examples/textbook/).
|
|
112
|
+
|
|
113
|
+
## The `Node` model
|
|
114
|
+
|
|
115
|
+
| field | meaning |
|
|
116
|
+
|-------|---------|
|
|
117
|
+
| `id` | stable unique id → becomes the filename / wikilink target |
|
|
118
|
+
| `type` | OKF `type:` value (required) — `"Chapter"`, `"Concept"`, or anything you invent |
|
|
119
|
+
| `title` | human-readable name (wikilink display) |
|
|
120
|
+
| `body` | markdown body (no frontmatter) |
|
|
121
|
+
| `frontmatter` | any extra YAML fields (may contain `[[wikilinks]]`) |
|
|
122
|
+
| `links` | edges to other nodes; each `Link(target, rel, section)` renders under a `## section` heading |
|
|
123
|
+
| `tags`, `aliases` | Obsidian-native tags and aliases |
|
|
124
|
+
|
|
125
|
+
## Use with Claude Code / Claude Desktop
|
|
126
|
+
|
|
127
|
+
Serve a built vault as a read-only MCP server so agents can query it as tools:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pip install -e ".[mcp]"
|
|
131
|
+
claude mcp add okf-wiki -- okf serve -c /abs/path/okf.config.yaml
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The server exposes five read-only tools: `okf_vault_info` (orientation — call first),
|
|
135
|
+
`okf_search` (semantic; needs a prior `okf index`), `okf_list_notes` (browse/paginate by type or
|
|
136
|
+
tag), `okf_get_note` (full note with links and backlinks), and `okf_neighbors` (walk the link
|
|
137
|
+
graph). The graph tools need no API keys. Use `okf serve --vault /abs/path/vault` to serve any
|
|
138
|
+
OKF vault without a config, and `--no-rag` for graph tools only.
|
|
139
|
+
|
|
140
|
+
## Roadmap
|
|
141
|
+
|
|
142
|
+
- **Build** — engine, markdown-folder adapter, custom adapters, link inference, LLM enrichment, CLI.
|
|
143
|
+
- **Semantic RAG (Phase 7) ✓** — `okf index` / `okf search` / `okf ask`: embeddings index + retrieval-augmented Q&A.
|
|
144
|
+
- **MCP server (Phase 8) ✓** — `okf serve`: expose the vault as read-only tools for Claude Code / Desktop / any MCP client.
|
|
145
|
+
|
|
146
|
+
See [`docs/roadmap.md`](docs/roadmap.md) for details.
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# okf-wiki-kit
|
|
2
|
+
|
|
3
|
+
Build a cross-linked **[Open Knowledge Format](https://github.com/GoogleCloudPlatform/knowledge-catalog/tree/main/okf)
|
|
4
|
+
(OKF)** knowledge wiki — browsable in **Obsidian** and consumable by **LLMs/agents** — from *any*
|
|
5
|
+
source material.
|
|
6
|
+
|
|
7
|
+
OKF represents knowledge as a directory of markdown files: each file is a typed node with YAML
|
|
8
|
+
frontmatter (only `type` is required) and `[[wikilinks]]` that form a knowledge graph richer than
|
|
9
|
+
the folder hierarchy. `okf-wiki-kit` gives you a small, dependency-light engine that turns your
|
|
10
|
+
content into such a bundle, with optional LLM enrichment.
|
|
11
|
+
|
|
12
|
+
## How it works
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
your source ──► SourceAdapter.load() ──► [Node, Node, …] ──► engine ──► OKF/Obsidian vault
|
|
16
|
+
(you write ~40 lines, (normalized) (generic: frontmatter, wikilinks,
|
|
17
|
+
or use a built-in one) indexes, link-inference, validate)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
You implement **one method** — `load() -> Iterable[Node]` — that turns your source into a list of
|
|
21
|
+
`Node`s. The engine does everything else: unique filenames, frontmatter, wikilinks, per-type and
|
|
22
|
+
root `index.md` files, optional mention-based link inference, validation, and optional LLM
|
|
23
|
+
enrichment.
|
|
24
|
+
|
|
25
|
+
## Quickstart (zero code)
|
|
26
|
+
|
|
27
|
+
Point the built-in *markdown-folder* adapter at any folder of `.md` files:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install -e . # or: pip install okf-wiki-kit
|
|
31
|
+
cp okf.config.example.yaml okf.config.yaml
|
|
32
|
+
# edit okf.config.yaml -> adapter_options.path: ./my-notes
|
|
33
|
+
okf build # writes ./vault
|
|
34
|
+
okf validate # every node typed, every wikilink resolves
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Open the `./vault` folder in Obsidian and look at the Graph View.
|
|
38
|
+
|
|
39
|
+
## Optional: LLM enrichment
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install -e ".[openai]" # or ".[anthropic]"
|
|
43
|
+
export OPENROUTER_API_KEY=... # or ANTHROPIC_API_KEY
|
|
44
|
+
okf enrich # writes enrichment.json (canonical concepts + descriptions)
|
|
45
|
+
okf build # rebuild, applying the enrichment
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Enrichment is **provider-flexible**: Anthropic (`claude-sonnet-4-6`) or any OpenAI-compatible
|
|
49
|
+
endpoint such as **OpenRouter** (`qwen/qwen3.7-plus`). Provider is auto-detected from your env keys.
|
|
50
|
+
|
|
51
|
+
## Writing your own adapter
|
|
52
|
+
|
|
53
|
+
For structured sources (JSON, a database, a CMS), write a small adapter:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from okfkit.model import Node, Link
|
|
57
|
+
from okfkit.adapters.base import SourceAdapter
|
|
58
|
+
|
|
59
|
+
class MyAdapter(SourceAdapter):
|
|
60
|
+
def load(self):
|
|
61
|
+
for row in my_source():
|
|
62
|
+
yield Node(
|
|
63
|
+
id=row["slug"], type="Article", title=row["title"],
|
|
64
|
+
body=row["markdown"],
|
|
65
|
+
frontmatter={"author": row["author"]},
|
|
66
|
+
links=[Link(target=t, rel="related", section="See also")
|
|
67
|
+
for t in row["related_slugs"]],
|
|
68
|
+
tags=row["tags"],
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Point `okf.config.yaml` at it: `adapter: path/to/my_adapter.py:MyAdapter`. See
|
|
73
|
+
[`docs/writing-an-adapter.md`](docs/writing-an-adapter.md) and the worked example in
|
|
74
|
+
[`examples/textbook/`](examples/textbook/).
|
|
75
|
+
|
|
76
|
+
## The `Node` model
|
|
77
|
+
|
|
78
|
+
| field | meaning |
|
|
79
|
+
|-------|---------|
|
|
80
|
+
| `id` | stable unique id → becomes the filename / wikilink target |
|
|
81
|
+
| `type` | OKF `type:` value (required) — `"Chapter"`, `"Concept"`, or anything you invent |
|
|
82
|
+
| `title` | human-readable name (wikilink display) |
|
|
83
|
+
| `body` | markdown body (no frontmatter) |
|
|
84
|
+
| `frontmatter` | any extra YAML fields (may contain `[[wikilinks]]`) |
|
|
85
|
+
| `links` | edges to other nodes; each `Link(target, rel, section)` renders under a `## section` heading |
|
|
86
|
+
| `tags`, `aliases` | Obsidian-native tags and aliases |
|
|
87
|
+
|
|
88
|
+
## Use with Claude Code / Claude Desktop
|
|
89
|
+
|
|
90
|
+
Serve a built vault as a read-only MCP server so agents can query it as tools:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
pip install -e ".[mcp]"
|
|
94
|
+
claude mcp add okf-wiki -- okf serve -c /abs/path/okf.config.yaml
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The server exposes five read-only tools: `okf_vault_info` (orientation — call first),
|
|
98
|
+
`okf_search` (semantic; needs a prior `okf index`), `okf_list_notes` (browse/paginate by type or
|
|
99
|
+
tag), `okf_get_note` (full note with links and backlinks), and `okf_neighbors` (walk the link
|
|
100
|
+
graph). The graph tools need no API keys. Use `okf serve --vault /abs/path/vault` to serve any
|
|
101
|
+
OKF vault without a config, and `--no-rag` for graph tools only.
|
|
102
|
+
|
|
103
|
+
## Roadmap
|
|
104
|
+
|
|
105
|
+
- **Build** — engine, markdown-folder adapter, custom adapters, link inference, LLM enrichment, CLI.
|
|
106
|
+
- **Semantic RAG (Phase 7) ✓** — `okf index` / `okf search` / `okf ask`: embeddings index + retrieval-augmented Q&A.
|
|
107
|
+
- **MCP server (Phase 8) ✓** — `okf serve`: expose the vault as read-only tools for Claude Code / Desktop / any MCP client.
|
|
108
|
+
|
|
109
|
+
See [`docs/roadmap.md`](docs/roadmap.md) for details.
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: okf-wiki-kit
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Build Open-Knowledge-Format (OKF) / Obsidian LLM wikis from any source material.
|
|
5
|
+
Author: okf-wiki-kit contributors
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/olivermorgan2/okf-wiki-kit
|
|
8
|
+
Project-URL: Issues, https://github.com/olivermorgan2/okf-wiki-kit/issues
|
|
9
|
+
Project-URL: Repository, https://github.com/olivermorgan2/okf-wiki-kit
|
|
10
|
+
Keywords: okf,obsidian,knowledge-graph,llm,rag,wiki,markdown
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: PyYAML>=6.0
|
|
21
|
+
Provides-Extra: anthropic
|
|
22
|
+
Requires-Dist: anthropic>=0.40; extra == "anthropic"
|
|
23
|
+
Provides-Extra: openai
|
|
24
|
+
Requires-Dist: openai>=1.40; extra == "openai"
|
|
25
|
+
Provides-Extra: rag
|
|
26
|
+
Requires-Dist: numpy>=1.24; extra == "rag"
|
|
27
|
+
Provides-Extra: voyage
|
|
28
|
+
Requires-Dist: voyageai>=0.3; extra == "voyage"
|
|
29
|
+
Provides-Extra: local-embeddings
|
|
30
|
+
Requires-Dist: numpy>=1.24; extra == "local-embeddings"
|
|
31
|
+
Requires-Dist: model2vec>=0.3; extra == "local-embeddings"
|
|
32
|
+
Provides-Extra: mcp
|
|
33
|
+
Requires-Dist: mcp>=1.2; extra == "mcp"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# okf-wiki-kit
|
|
39
|
+
|
|
40
|
+
Build a cross-linked **[Open Knowledge Format](https://github.com/GoogleCloudPlatform/knowledge-catalog/tree/main/okf)
|
|
41
|
+
(OKF)** knowledge wiki — browsable in **Obsidian** and consumable by **LLMs/agents** — from *any*
|
|
42
|
+
source material.
|
|
43
|
+
|
|
44
|
+
OKF represents knowledge as a directory of markdown files: each file is a typed node with YAML
|
|
45
|
+
frontmatter (only `type` is required) and `[[wikilinks]]` that form a knowledge graph richer than
|
|
46
|
+
the folder hierarchy. `okf-wiki-kit` gives you a small, dependency-light engine that turns your
|
|
47
|
+
content into such a bundle, with optional LLM enrichment.
|
|
48
|
+
|
|
49
|
+
## How it works
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
your source ──► SourceAdapter.load() ──► [Node, Node, …] ──► engine ──► OKF/Obsidian vault
|
|
53
|
+
(you write ~40 lines, (normalized) (generic: frontmatter, wikilinks,
|
|
54
|
+
or use a built-in one) indexes, link-inference, validate)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
You implement **one method** — `load() -> Iterable[Node]` — that turns your source into a list of
|
|
58
|
+
`Node`s. The engine does everything else: unique filenames, frontmatter, wikilinks, per-type and
|
|
59
|
+
root `index.md` files, optional mention-based link inference, validation, and optional LLM
|
|
60
|
+
enrichment.
|
|
61
|
+
|
|
62
|
+
## Quickstart (zero code)
|
|
63
|
+
|
|
64
|
+
Point the built-in *markdown-folder* adapter at any folder of `.md` files:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install -e . # or: pip install okf-wiki-kit
|
|
68
|
+
cp okf.config.example.yaml okf.config.yaml
|
|
69
|
+
# edit okf.config.yaml -> adapter_options.path: ./my-notes
|
|
70
|
+
okf build # writes ./vault
|
|
71
|
+
okf validate # every node typed, every wikilink resolves
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Open the `./vault` folder in Obsidian and look at the Graph View.
|
|
75
|
+
|
|
76
|
+
## Optional: LLM enrichment
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install -e ".[openai]" # or ".[anthropic]"
|
|
80
|
+
export OPENROUTER_API_KEY=... # or ANTHROPIC_API_KEY
|
|
81
|
+
okf enrich # writes enrichment.json (canonical concepts + descriptions)
|
|
82
|
+
okf build # rebuild, applying the enrichment
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Enrichment is **provider-flexible**: Anthropic (`claude-sonnet-4-6`) or any OpenAI-compatible
|
|
86
|
+
endpoint such as **OpenRouter** (`qwen/qwen3.7-plus`). Provider is auto-detected from your env keys.
|
|
87
|
+
|
|
88
|
+
## Writing your own adapter
|
|
89
|
+
|
|
90
|
+
For structured sources (JSON, a database, a CMS), write a small adapter:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from okfkit.model import Node, Link
|
|
94
|
+
from okfkit.adapters.base import SourceAdapter
|
|
95
|
+
|
|
96
|
+
class MyAdapter(SourceAdapter):
|
|
97
|
+
def load(self):
|
|
98
|
+
for row in my_source():
|
|
99
|
+
yield Node(
|
|
100
|
+
id=row["slug"], type="Article", title=row["title"],
|
|
101
|
+
body=row["markdown"],
|
|
102
|
+
frontmatter={"author": row["author"]},
|
|
103
|
+
links=[Link(target=t, rel="related", section="See also")
|
|
104
|
+
for t in row["related_slugs"]],
|
|
105
|
+
tags=row["tags"],
|
|
106
|
+
)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Point `okf.config.yaml` at it: `adapter: path/to/my_adapter.py:MyAdapter`. See
|
|
110
|
+
[`docs/writing-an-adapter.md`](docs/writing-an-adapter.md) and the worked example in
|
|
111
|
+
[`examples/textbook/`](examples/textbook/).
|
|
112
|
+
|
|
113
|
+
## The `Node` model
|
|
114
|
+
|
|
115
|
+
| field | meaning |
|
|
116
|
+
|-------|---------|
|
|
117
|
+
| `id` | stable unique id → becomes the filename / wikilink target |
|
|
118
|
+
| `type` | OKF `type:` value (required) — `"Chapter"`, `"Concept"`, or anything you invent |
|
|
119
|
+
| `title` | human-readable name (wikilink display) |
|
|
120
|
+
| `body` | markdown body (no frontmatter) |
|
|
121
|
+
| `frontmatter` | any extra YAML fields (may contain `[[wikilinks]]`) |
|
|
122
|
+
| `links` | edges to other nodes; each `Link(target, rel, section)` renders under a `## section` heading |
|
|
123
|
+
| `tags`, `aliases` | Obsidian-native tags and aliases |
|
|
124
|
+
|
|
125
|
+
## Use with Claude Code / Claude Desktop
|
|
126
|
+
|
|
127
|
+
Serve a built vault as a read-only MCP server so agents can query it as tools:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
pip install -e ".[mcp]"
|
|
131
|
+
claude mcp add okf-wiki -- okf serve -c /abs/path/okf.config.yaml
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The server exposes five read-only tools: `okf_vault_info` (orientation — call first),
|
|
135
|
+
`okf_search` (semantic; needs a prior `okf index`), `okf_list_notes` (browse/paginate by type or
|
|
136
|
+
tag), `okf_get_note` (full note with links and backlinks), and `okf_neighbors` (walk the link
|
|
137
|
+
graph). The graph tools need no API keys. Use `okf serve --vault /abs/path/vault` to serve any
|
|
138
|
+
OKF vault without a config, and `--no-rag` for graph tools only.
|
|
139
|
+
|
|
140
|
+
## Roadmap
|
|
141
|
+
|
|
142
|
+
- **Build** — engine, markdown-folder adapter, custom adapters, link inference, LLM enrichment, CLI.
|
|
143
|
+
- **Semantic RAG (Phase 7) ✓** — `okf index` / `okf search` / `okf ask`: embeddings index + retrieval-augmented Q&A.
|
|
144
|
+
- **MCP server (Phase 8) ✓** — `okf serve`: expose the vault as read-only tools for Claude Code / Desktop / any MCP client.
|
|
145
|
+
|
|
146
|
+
See [`docs/roadmap.md`](docs/roadmap.md) for details.
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
okf_wiki_kit.egg-info/PKG-INFO
|
|
5
|
+
okf_wiki_kit.egg-info/SOURCES.txt
|
|
6
|
+
okf_wiki_kit.egg-info/dependency_links.txt
|
|
7
|
+
okf_wiki_kit.egg-info/entry_points.txt
|
|
8
|
+
okf_wiki_kit.egg-info/requires.txt
|
|
9
|
+
okf_wiki_kit.egg-info/top_level.txt
|
|
10
|
+
okfkit/__init__.py
|
|
11
|
+
okfkit/cli.py
|
|
12
|
+
okfkit/config.py
|
|
13
|
+
okfkit/engine.py
|
|
14
|
+
okfkit/enrich.py
|
|
15
|
+
okfkit/model.py
|
|
16
|
+
okfkit/render.py
|
|
17
|
+
okfkit/adapters/__init__.py
|
|
18
|
+
okfkit/adapters/base.py
|
|
19
|
+
okfkit/adapters/markdown_folder.py
|
|
20
|
+
okfkit/serve/__init__.py
|
|
21
|
+
okfkit/serve/embeddings.py
|
|
22
|
+
okfkit/serve/mcp.py
|
|
23
|
+
okfkit/serve/rag.py
|
|
24
|
+
okfkit/serve/vault.py
|
|
25
|
+
tests/test_adapters.py
|
|
26
|
+
tests/test_engine.py
|
|
27
|
+
tests/test_render.py
|
|
28
|
+
tests/test_serve_mcp.py
|
|
29
|
+
tests/test_serve_rag.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
PyYAML>=6.0
|
|
2
|
+
|
|
3
|
+
[anthropic]
|
|
4
|
+
anthropic>=0.40
|
|
5
|
+
|
|
6
|
+
[dev]
|
|
7
|
+
pytest>=7.0
|
|
8
|
+
|
|
9
|
+
[local-embeddings]
|
|
10
|
+
numpy>=1.24
|
|
11
|
+
model2vec>=0.3
|
|
12
|
+
|
|
13
|
+
[mcp]
|
|
14
|
+
mcp>=1.2
|
|
15
|
+
|
|
16
|
+
[openai]
|
|
17
|
+
openai>=1.40
|
|
18
|
+
|
|
19
|
+
[rag]
|
|
20
|
+
numpy>=1.24
|
|
21
|
+
|
|
22
|
+
[voyage]
|
|
23
|
+
voyageai>=0.3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
okfkit
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Source adapters — turn a specific source into `Node`s.
|
|
2
|
+
|
|
3
|
+
Built-in adapters are resolved by short name (e.g. "markdown_folder"). Custom
|
|
4
|
+
adapters are resolved by "path/to/file.py:ClassName".
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from okfkit.adapters.base import SourceAdapter, load_adapter
|
|
8
|
+
|
|
9
|
+
__all__ = ["SourceAdapter", "load_adapter"]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""The SourceAdapter contract and the resolver that loads one by name/path."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import importlib
|
|
6
|
+
import importlib.util
|
|
7
|
+
import os
|
|
8
|
+
from abc import ABC, abstractmethod
|
|
9
|
+
from collections.abc import Iterable
|
|
10
|
+
|
|
11
|
+
from okfkit.model import Node
|
|
12
|
+
|
|
13
|
+
# short name -> "module:Class" for built-in adapters
|
|
14
|
+
BUILTINS = {
|
|
15
|
+
"markdown_folder": "okfkit.adapters.markdown_folder:MarkdownFolderAdapter",
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SourceAdapter(ABC):
|
|
20
|
+
"""Subclass this and implement `load()`. That is the entire contract.
|
|
21
|
+
|
|
22
|
+
Options from `okf.config.yaml`'s `adapter_options:` are passed as keyword
|
|
23
|
+
arguments and stored on `self.options`.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, **options):
|
|
27
|
+
self.options = options
|
|
28
|
+
|
|
29
|
+
@abstractmethod
|
|
30
|
+
def load(self) -> Iterable[Node]:
|
|
31
|
+
"""Yield (or return a list of) `Node`s built from the source."""
|
|
32
|
+
raise NotImplementedError
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def load_adapter(spec: str, options: dict | None = None) -> SourceAdapter:
|
|
36
|
+
"""Instantiate an adapter from a built-in name or a "path.py:Class" / "module:Class" spec."""
|
|
37
|
+
options = options or {}
|
|
38
|
+
if spec in BUILTINS:
|
|
39
|
+
spec = BUILTINS[spec]
|
|
40
|
+
if ":" not in spec:
|
|
41
|
+
raise ValueError(
|
|
42
|
+
f"Adapter spec {spec!r} must be a built-in name ({', '.join(BUILTINS)}) "
|
|
43
|
+
f"or 'module_or_path:ClassName'."
|
|
44
|
+
)
|
|
45
|
+
target, class_name = spec.rsplit(":", 1)
|
|
46
|
+
|
|
47
|
+
if target.endswith(".py") or os.path.sep in target or os.path.exists(target):
|
|
48
|
+
module = _import_from_path(target)
|
|
49
|
+
else:
|
|
50
|
+
module = importlib.import_module(target)
|
|
51
|
+
|
|
52
|
+
cls = getattr(module, class_name, None)
|
|
53
|
+
if cls is None or not (isinstance(cls, type) and issubclass(cls, SourceAdapter)):
|
|
54
|
+
raise ValueError(f"{class_name!r} in {target!r} is not a SourceAdapter subclass.")
|
|
55
|
+
return cls(**options)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _import_from_path(path: str):
|
|
59
|
+
path = os.path.abspath(os.path.expanduser(path))
|
|
60
|
+
if not os.path.exists(path):
|
|
61
|
+
raise FileNotFoundError(f"Adapter file not found: {path}")
|
|
62
|
+
name = "okfkit_adapter_" + os.path.splitext(os.path.basename(path))[0]
|
|
63
|
+
spec = importlib.util.spec_from_file_location(name, path)
|
|
64
|
+
module = importlib.util.module_from_spec(spec)
|
|
65
|
+
spec.loader.exec_module(module)
|
|
66
|
+
return module
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Built-in zero-code adapter: turn a folder of markdown files into OKF nodes.
|
|
2
|
+
|
|
3
|
+
Each `.md` file becomes one node. `type`, `title`, `tags`, and `aliases` are read
|
|
4
|
+
from YAML frontmatter if present (falling back to sensible defaults). The file's
|
|
5
|
+
existing inline `[[wikilinks]]` are left in the body untouched — filenames are
|
|
6
|
+
preserved as node ids so those links keep resolving.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from okfkit import render
|
|
14
|
+
from okfkit.adapters.base import SourceAdapter
|
|
15
|
+
from okfkit.model import Node
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MarkdownFolderAdapter(SourceAdapter):
|
|
19
|
+
def load(self):
|
|
20
|
+
root = Path(self.options.get("path", ".")).expanduser()
|
|
21
|
+
if not root.is_dir():
|
|
22
|
+
raise NotADirectoryError(f"markdown_folder: path is not a directory: {root}")
|
|
23
|
+
default_type = self.options.get("default_type", "Note")
|
|
24
|
+
|
|
25
|
+
for f in sorted(root.glob("**/*.md")):
|
|
26
|
+
if f.name.lower() == "readme.md":
|
|
27
|
+
continue
|
|
28
|
+
fm, body = render.split_frontmatter(f.read_text(encoding="utf-8"))
|
|
29
|
+
node_id = str(fm.get("id") or f.stem) # preserve filename → inline links resolve
|
|
30
|
+
yield Node(
|
|
31
|
+
id=node_id,
|
|
32
|
+
type=str(fm.get("type") or default_type),
|
|
33
|
+
title=str(fm.get("title") or f.stem),
|
|
34
|
+
body=body.strip(),
|
|
35
|
+
frontmatter={k: v for k, v in fm.items()
|
|
36
|
+
if k not in ("id", "title", "type", "tags", "aliases")},
|
|
37
|
+
links=[], # inline [[wikilinks]] already live in the body
|
|
38
|
+
tags=_as_list(fm.get("tags")),
|
|
39
|
+
aliases=_as_list(fm.get("aliases")),
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _as_list(v):
|
|
44
|
+
if v is None:
|
|
45
|
+
return []
|
|
46
|
+
if isinstance(v, (list, tuple)):
|
|
47
|
+
return [str(x) for x in v]
|
|
48
|
+
return [str(v)]
|