Skip to content

Commit a84d4e7

Browse files
supachai-jclaude
andcommitted
Manual: add worked-example chapter + document okf-selftest (bilingual)
Audit found the manual covered every tool except the newly-added okf-selftest.sh, and lacked a hands-on walkthrough. Added (TH + EN): - part4/worked-example.md — full bookstore-KB walkthrough (init → ingest → validate → search → viz → MCP share) with a Mermaid graph; registered in SUMMARY + the TOC page. - appendix/tools.md — okf-selftest.sh entry. - appendix/faq.md — "how do I verify the toolchain works?" → okf-selftest. Verified: 26 chapters ↔ 26 TOC placeholders; links + fences balanced both languages. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a910f23 commit a84d4e7

10 files changed

Lines changed: 226 additions & 0 deletions

File tree

book-en/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- [Query and Search](./part4/query-search.md)
3030
- [Adding and editing concepts](./part4/authoring.md)
3131
- [Validate and Visualize](./part4/validate-viz.md)
32+
- [Worked example: a bookstore KB](./part4/worked-example.md)
3233

3334
# Part 5 — Authoring Well
3435

book-en/src/appendix/faq.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ Every concept must have a non-empty `type` in its frontmatter. Add `type: ...` (
3838

3939
### How do I migrate an existing wiki (Obsidian, etc.) into OKF?
4040
In most cases: add a `type` field to each frontmatter, add `index.md`/`log.md`, convert links to relative paths, then run validate.
41+
42+
### How do I verify the whole toolchain works?
43+
Run `bash tools/okf-selftest.sh` — 10 end-to-end checks (init/validate/index/search/viz/lease + embed/hybrid if Ollama is up); exits non-zero on any failure. See the [Worked Example](../part4/worked-example.md) for a hands-on full-loop walkthrough.

book-en/src/appendix/tools.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ python3 tools/okf-lease.py break <concept> # admin force-release
4949
```
5050
env: `OKF_LEASE_DIR` (lease storage location), `OKF_LEASE_TTL` (default 300)
5151

52+
## okf-selftest.sh — exercise the whole toolchain
53+
```bash
54+
bash tools/okf-selftest.sh
55+
```
56+
Runs 10 end-to-end checks (init → validate both a clean bundle and a deliberately-broken one →
57+
index → search → air-gap viz → lease → embed/hybrid if Ollama is up) · exits non-zero on any
58+
failure · suitable for CI.
59+
5260
## install.sh — Install Skill
5361
```bash
5462
./install.sh # global → ~/.claude/skills/okf
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Worked Example: a Bookstore KB
2+
3+
This chapter walks the whole path from zero to searchable — a small knowledge base for an
4+
online bookstore, with real commands. Use it as a template for your own domain.
5+
6+
## 1. Scaffold (init)
7+
8+
```bash
9+
python3 tools/okf-init.py ./bookstore-kb
10+
cd bookstore-kb
11+
```
12+
You get `AGENTS.md` + `wiki/{index.md, log.md, getting-started.md}` + `raw/`.
13+
14+
## 2. Add knowledge (simulated ingest)
15+
16+
Create concepts in the canonical layout — two tables, a metric, a join, a playbook. Example
17+
`wiki/tables/books.md`:
18+
19+
```markdown
20+
---
21+
type: BigQuery Table
22+
title: Books
23+
description: One row per book in the catalog.
24+
tags: [catalog, books]
25+
timestamp: 2026-06-16T00:00:00Z
26+
---
27+
28+
# Schema
29+
| Column | Type | Description |
30+
| :--- | :--- | :--- |
31+
| book_id | STRING | Book id (PK) |
32+
| author_id | STRING | FK to [authors](authors.md) |
33+
| price | NUMERIC | Price (USD) |
34+
| stock | INT64 | Units in stock |
35+
36+
# Joins
37+
Join [authors](authors.md) on `author_id` — see [Books → Authors](../references/joins/books__authors.md).
38+
Low stock → [restock runbook](../playbooks/low-stock-runbook.md)
39+
```
40+
41+
Do the same for `authors`, `references/metrics/monthly-revenue`, `references/joins/books__authors`,
42+
and `playbooks/low-stock-runbook`, then update `wiki/index.md` + `wiki/log.md`.
43+
44+
> In real use: drop a source into `raw/` and have the agent run the supervised INGEST flow
45+
> ([Ingest chapter](./ingest.md)) — it extracts claims, shows them for approval, then writes the
46+
> concepts and updates index/log for you.
47+
48+
The resulting KB is this graph:
49+
50+
<pre class="mermaid">
51+
flowchart LR
52+
D["datasets/bookstore"] --> B["tables/books"]
53+
D --> A["tables/authors"]
54+
B -->|author_id| A
55+
J["references/joins/books__authors"] --> B
56+
J --> A
57+
M["references/metrics/monthly-revenue"] --> D
58+
P["playbooks/low-stock-runbook"] --> B
59+
</pre>
60+
61+
## 3. Validate conformance
62+
63+
```bash
64+
python3 tools/okf-validate.py ./wiki
65+
# → ✓ CONFORMANT with OKF v0.1 (0 warning(s), 0 info)
66+
```
67+
68+
## 4. Search
69+
70+
```bash
71+
python3 tools/okf-index.py build ./wiki # build the BM25 index
72+
python3 tools/okf-search.py "how to join books to authors" --bundle ./wiki
73+
# → references/joins/books__authors [Reference] ranked #1
74+
```
75+
76+
Add semantic (optional, on-prem):
77+
```bash
78+
ollama pull nomic-embed-text
79+
python3 tools/okf-embed.py build ./wiki
80+
python3 tools/okf-search.py "who wrote the novels" --bundle ./wiki
81+
# → mode: hybrid (bm25+semantic, RRF) — finds authors even with no keyword overlap
82+
```
83+
84+
## 5. Visualize
85+
86+
```bash
87+
python3 tools/okf-viz.py ./wiki --name "Bookstore KB"
88+
open wiki/viz.html # one file, opens offline
89+
```
90+
91+
## 6. (Team) Share via MCP
92+
93+
To let the whole team/agents use it: commit `wiki/` to an internal git server and bring up the
94+
[MCP server](../part6/self-host.md) pointed at this bundle — agents can then `okf_search` (hybrid)
95+
and propose changes via PR/lease.
96+
97+
## Summary
98+
99+
```text
100+
okf-init → (ingest concepts) → okf-validate → okf-index/okf-search → okf-viz → [MCP share]
101+
```
102+
103+
That's the full loop! Next, see [Authoring Well](../part5/best-practices.md) to grow the KB with quality.

book-en/src/toc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [Query and Search](./part4/query-search.md)<span class="okf-leader"></span><span class="okf-pg"></span>
2929
- [Adding and editing concepts](./part4/authoring.md)<span class="okf-leader"></span><span class="okf-pg"></span>
3030
- [Validate and Visualize](./part4/validate-viz.md)<span class="okf-leader"></span><span class="okf-pg"></span>
31+
- [Worked example: a bookstore KB](./part4/worked-example.md)<span class="okf-leader"></span><span class="okf-pg"></span>
3132

3233
**Part 5 — Authoring Well**
3334

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- [Query และ Search](./part4/query-search.md)
3030
- [เพิ่มและแก้ไข concept](./part4/authoring.md)
3131
- [Validate และ Visualize](./part4/validate-viz.md)
32+
- [ตัวอย่างใช้งานจริง: KB ร้านหนังสือ](./part4/worked-example.md)
3233

3334
# ภาคที่ 5 — เขียนให้ดี
3435

book/src/appendix/faq.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ filing, bookkeeping
4444

4545
### จะ migrate wiki เดิม (Obsidian ฯลฯ) เข้า OKF ยังไง?
4646
ส่วนใหญ่แค่เพิ่มฟิลด์ `type` ใน frontmatter + เพิ่ม `index.md`/`log.md` + ปรับลิงก์ให้ relative แล้วรัน validate
47+
48+
### จะตรวจว่า toolchain ใช้ได้จริงทั้งชุดยังไง?
49+
รัน `bash tools/okf-selftest.sh` — เทสต์ end-to-end 10 ข้อ (init/validate/index/search/viz/lease + embed/hybrid ถ้ามี Ollama) exit ≠ 0 ถ้ามีข้อพลาด · ดู[ตัวอย่างใช้งานจริง](../part4/worked-example.md) สำหรับการเดินครบลูปด้วยมือ

book/src/appendix/tools.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ python3 tools/okf-lease.py break <concept> # admin บังคับป
4949
```
5050
env: `OKF_LEASE_DIR` (ที่เก็บ lease), `OKF_LEASE_TTL` (default 300)
5151

52+
## okf-selftest.sh — ทดสอบ toolchain ทั้งชุด
53+
```bash
54+
bash tools/okf-selftest.sh
55+
```
56+
รัน 10 ข้อ end-to-end (init → validate ทั้ง clean และจับ bundle เสีย → index → search → viz air-gap → lease → embed/hybrid ถ้ามี Ollama) · exit ≠ 0 ถ้ามีข้อพลาด · เหมาะใช้ใน CI
57+
5258
## install.sh — ติดตั้ง skill
5359
```bash
5460
./install.sh # global → ~/.claude/skills/okf

book/src/part4/worked-example.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# ตัวอย่างใช้งานจริง: KB ร้านหนังสือ
2+
3+
บทนี้เดินครบทุกขั้นตั้งแต่ศูนย์จนค้นได้ — สร้าง knowledge base เล็ก ๆ ของร้านหนังสือออนไลน์
4+
ด้วยคำสั่งจริง ใช้เป็นแม่แบบกับโดเมนของคุณได้เลย
5+
6+
## 1. สร้างโครง (init)
7+
8+
```bash
9+
python3 tools/okf-init.py ./bookstore-kb
10+
cd bookstore-kb
11+
```
12+
ได้ `AGENTS.md` + `wiki/{index.md, log.md, getting-started.md}` + `raw/`
13+
14+
## 2. ใส่ความรู้ (จำลอง ingest)
15+
16+
สร้าง concept ตามโครงสร้าง canonical — ตาราง 2 ตัว, metric, join, playbook ตัวอย่าง `wiki/tables/books.md`:
17+
18+
```markdown
19+
---
20+
type: BigQuery Table
21+
title: Books
22+
description: หนึ่งแถวต่อหนังสือหนึ่งเล่มในแคตตาล็อก
23+
tags: [catalog, books]
24+
timestamp: 2026-06-16T00:00:00Z
25+
---
26+
27+
# Schema
28+
| Column | Type | Description |
29+
| :--- | :--- | :--- |
30+
| book_id | STRING | รหัสหนังสือ (PK) |
31+
| author_id | STRING | FK ไปยัง [authors](authors.md) |
32+
| price | NUMERIC | ราคา (USD) |
33+
| stock | INT64 | จำนวนคงคลัง |
34+
35+
# Joins
36+
เชื่อม [authors](authors.md) ผ่าน `author_id` — ดู [Books → Authors](../references/joins/books__authors.md)
37+
stock ต่ำ → [restock runbook](../playbooks/low-stock-runbook.md)
38+
```
39+
40+
ทำแบบเดียวกันกับ `authors`, `references/metrics/monthly-revenue`, `references/joins/books__authors`,
41+
`playbooks/low-stock-runbook` แล้วอัปเดต `wiki/index.md` + `wiki/log.md`
42+
43+
> ในงานจริง: วาง source ลง `raw/` แล้วให้ agent ทำ INGEST แบบมีคนกำกับ ([บท Ingest](./ingest.md)) — agent จะดึงประเด็น แสดงให้อนุมัติ แล้วเขียน concept + อัปเดต index/log ให้
44+
45+
KB ที่ได้เป็นกราฟแบบนี้:
46+
47+
<pre class="mermaid">
48+
flowchart LR
49+
D["datasets/bookstore"] --> B["tables/books"]
50+
D --> A["tables/authors"]
51+
B -->|author_id| A
52+
J["references/joins/books__authors"] --> B
53+
J --> A
54+
M["references/metrics/monthly-revenue"] --> D
55+
P["playbooks/low-stock-runbook"] --> B
56+
</pre>
57+
58+
## 3. ตรวจ conformance
59+
60+
```bash
61+
python3 tools/okf-validate.py ./wiki
62+
# → ✓ CONFORMANT with OKF v0.1 (0 warning(s), 0 info)
63+
```
64+
65+
## 4. ค้นหา
66+
67+
```bash
68+
python3 tools/okf-index.py build ./wiki # สร้าง BM25 index
69+
python3 tools/okf-search.py "how to join books to authors" --bundle ./wiki
70+
# → references/joins/books__authors [Reference] อันดับ 1
71+
```
72+
73+
เพิ่ม semantic (ไม่บังคับ, on-prem):
74+
```bash
75+
ollama pull nomic-embed-text
76+
python3 tools/okf-embed.py build ./wiki
77+
python3 tools/okf-search.py "who wrote the novels" --bundle ./wiki
78+
# → mode: hybrid (bm25+semantic, RRF) — จับ authors ได้แม้ไม่มีคำตรงกัน
79+
```
80+
81+
## 5. ดูกราฟ
82+
83+
```bash
84+
python3 tools/okf-viz.py ./wiki --name "Bookstore KB"
85+
open wiki/viz.html # ไฟล์เดียว เปิด offline ได้
86+
```
87+
88+
## 6. (ทีม) แชร์ผ่าน MCP
89+
90+
ทำให้ทั้งทีม/agent ใช้ร่วมกัน: commit `wiki/` ขึ้น git ภายใน แล้วยก [MCP server](../part6/self-host.md)
91+
ชี้มาที่ bundle นี้ — agent จะ `okf_search` แบบ hybrid และเสนอแก้ผ่าน PR/lease ได้
92+
93+
## สรุปลำดับ
94+
95+
```text
96+
okf-init → (ingest concepts) → okf-validate → okf-index/okf-search → okf-viz → [MCP share]
97+
```
98+
99+
ครบลูปแล้ว! ต่อไปดู[แนวทางการเขียนที่ดี](../part5/best-practices.md) เพื่อให้ KB โตอย่างมีคุณภาพ

book/src/toc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [Query และ Search](./part4/query-search.md)<span class="okf-leader"></span><span class="okf-pg"></span>
2929
- [เพิ่มและแก้ไข concept](./part4/authoring.md)<span class="okf-leader"></span><span class="okf-pg"></span>
3030
- [Validate และ Visualize](./part4/validate-viz.md)<span class="okf-leader"></span><span class="okf-pg"></span>
31+
- [ตัวอย่างใช้งานจริง: KB ร้านหนังสือ](./part4/worked-example.md)<span class="okf-leader"></span><span class="okf-pg"></span>
3132

3233
**ภาคที่ 5 — เขียนให้ดี**
3334

0 commit comments

Comments
 (0)