|
| 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. |
0 commit comments