@dikolab/kbdb 0.5.0 → 0.6.1

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 (224) hide show
  1. package/CLA.md +68 -0
  2. package/LICENSE +676 -12
  3. package/LICENSING.md +58 -0
  4. package/README.md +50 -25
  5. package/README.md.bak +322 -0
  6. package/dist/README.md +322 -0
  7. package/dist/{chunk-BJXEVALU.mjs → chunk-QLJ33C74.mjs} +44 -44
  8. package/dist/chunk-QLJ33C74.mjs.map +7 -0
  9. package/dist/cli.cjs +550 -232
  10. package/dist/cli.cjs.map +4 -4
  11. package/dist/cli.d.ts +0 -8
  12. package/dist/cli.mjs +483 -154
  13. package/dist/cli.mjs.map +4 -4
  14. package/dist/kbdb-worker.cjs +36 -5
  15. package/dist/kbdb-worker.cjs.map +3 -3
  16. package/dist/mod.cjs +89 -30
  17. package/dist/mod.cjs.map +4 -4
  18. package/dist/mod.mjs +88 -30
  19. package/dist/mod.mjs.map +4 -4
  20. package/dist/src/cli.d.ts +0 -8
  21. package/dist/src/shared/cli/constants/defaults.constant.d.ts +1 -1
  22. package/dist/src/shared/cli/constants/recfile-command-field-map.constant.d.ts +8 -0
  23. package/dist/src/shared/cli/constants/recfile-field-maps.constant.d.ts +21 -0
  24. package/dist/src/shared/cli/functions/compute-directory-level.function.d.ts +14 -0
  25. package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +2 -28
  26. package/dist/src/shared/cli/functions/format-command-output.function.d.ts +14 -0
  27. package/dist/src/shared/cli/functions/format-db-not-found.function.d.ts +20 -0
  28. package/dist/src/shared/cli/functions/format-output.function.d.ts +1 -0
  29. package/dist/src/shared/cli/functions/format-recfile-output.function.d.ts +11 -0
  30. package/dist/src/shared/cli/functions/render-recfile-value.function.d.ts +11 -0
  31. package/dist/src/shared/cli/functions/resolve-db-dir.function.d.ts +24 -0
  32. package/dist/src/shared/cli/functions/resolve-recfile-key.function.d.ts +9 -0
  33. package/dist/src/shared/cli/functions/run-db-path.function.d.ts +10 -0
  34. package/dist/src/shared/cli/functions/run-export.function.d.ts +8 -4
  35. package/dist/src/shared/cli/functions/run-import.function.d.ts +4 -0
  36. package/dist/src/shared/cli/functions/run-learn.function.d.ts +12 -0
  37. package/dist/src/shared/cli/index.d.ts +4 -1
  38. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +9 -2
  39. package/dist/src/shared/cli/typings/db-resolution.interface.d.ts +9 -0
  40. package/dist/src/shared/cli/typings/recfile-field-map.type.d.ts +10 -0
  41. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  42. package/dist/src/shared/wasm-codec/functions/decode-option-u8.function.d.ts +9 -0
  43. package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +4 -0
  44. package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +2 -45
  45. package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +10 -1
  46. package/dist/src/shared/wasm-codec/index.d.ts +1 -1
  47. package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +6 -0
  48. package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +5 -0
  49. package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +5 -0
  50. package/dist/src/shared/worker-client/functions/build-deno-permissions.function.d.ts +11 -0
  51. package/dist/src/shared/worker-client/functions/read-crash-reason.function.d.ts +9 -0
  52. package/dist/src/shared/worker-client/functions/resolve-spawn-script.function.d.ts +6 -0
  53. package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +1 -1
  54. package/dist/src/shared/worker-client/typings/section.model.d.ts +5 -0
  55. package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +0 -6
  56. package/dist/src/shared/worker-daemon/functions/count-files.function.d.ts +12 -0
  57. package/dist/src/shared/worker-daemon/functions/handle-import.function.d.ts +2 -0
  58. package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +8 -0
  59. package/dist/src/shared/worker-daemon/functions/validate-daemon-path.function.d.ts +15 -0
  60. package/dist/src/worker.d.ts +0 -7
  61. package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
  62. package/dist/wasm/default-embedding/package.json +1 -1
  63. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  64. package/dist/wasm/fs-database/package.json +1 -1
  65. package/dist/wasm/fs-migration/package.json +1 -1
  66. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  67. package/dist/wasm/kb-worker/package.json +1 -1
  68. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  69. package/dist/wasm/query-parser/package.json +1 -1
  70. package/dist/worker.d.ts +0 -7
  71. package/dist/worker.mjs +37 -6
  72. package/dist/worker.mjs.map +3 -3
  73. package/package.json +11 -10
  74. package/dist/chunk-BJXEVALU.mjs.map +0 -7
  75. package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +0 -10
  76. package/docs/details/README.md +0 -30
  77. package/docs/details/agent-tooling.md +0 -132
  78. package/docs/details/cli.md +0 -777
  79. package/docs/details/knowledge-base.md +0 -180
  80. package/docs/details/library-api.md +0 -495
  81. package/docs/details/mcp-server.md +0 -482
  82. package/docs/details/search-and-ranking.md +0 -575
  83. package/docs/details/storage.md +0 -531
  84. package/docs/goals/agents.md +0 -751
  85. package/docs/goals/architecture.svg +0 -198
  86. package/docs/goals/auto-capture.md +0 -378
  87. package/docs/goals/benchmarking.md +0 -296
  88. package/docs/goals/cli.md +0 -2654
  89. package/docs/goals/concurrency.md +0 -259
  90. package/docs/goals/content-composer.md +0 -609
  91. package/docs/goals/content-parser.md +0 -279
  92. package/docs/goals/database.md +0 -1679
  93. package/docs/goals/document.md +0 -368
  94. package/docs/goals/hybrid-search.md +0 -465
  95. package/docs/goals/mcp.md +0 -1541
  96. package/docs/goals/overview.md +0 -124
  97. package/docs/goals/query-parser.md +0 -373
  98. package/docs/goals/query-result.md +0 -860
  99. package/docs/goals/semantic-dedup.md +0 -233
  100. package/docs/goals/skills.md +0 -810
  101. package/docs/goals/sync.md +0 -217
  102. package/docs/goals/worker-client.md +0 -1005
  103. package/docs/goals/worker-daemon.md +0 -1547
  104. package/docs/modules/overview.md +0 -319
  105. package/docs/modules/rust/embedding/module.md +0 -91
  106. package/docs/modules/rust/fs-database/functions/document.md +0 -48
  107. package/docs/modules/rust/fs-database/functions/integrity.md +0 -79
  108. package/docs/modules/rust/fs-database/functions/io.md +0 -87
  109. package/docs/modules/rust/fs-database/functions/module.md +0 -22
  110. package/docs/modules/rust/fs-database/functions/query-exec.md +0 -44
  111. package/docs/modules/rust/fs-database/functions/section.md +0 -76
  112. package/docs/modules/rust/fs-database/indexes/btree.md +0 -35
  113. package/docs/modules/rust/fs-database/indexes/corpus.md +0 -61
  114. package/docs/modules/rust/fs-database/indexes/inverted.md +0 -60
  115. package/docs/modules/rust/fs-database/indexes/module.md +0 -64
  116. package/docs/modules/rust/fs-database/indexes/positional.md +0 -39
  117. package/docs/modules/rust/fs-database/indexes/vectors.md +0 -110
  118. package/docs/modules/rust/fs-database/module.md +0 -150
  119. package/docs/modules/rust/fs-database/types/catalog.md +0 -53
  120. package/docs/modules/rust/fs-database/types/module.md +0 -12
  121. package/docs/modules/rust/fs-database/types/section.md +0 -127
  122. package/docs/modules/rust/kb-worker/functions/compose.md +0 -57
  123. package/docs/modules/rust/kb-worker/functions/module.md +0 -20
  124. package/docs/modules/rust/kb-worker/functions/retrieve.md +0 -194
  125. package/docs/modules/rust/kb-worker/functions/search.md +0 -173
  126. package/docs/modules/rust/kb-worker/functions/write.md +0 -172
  127. package/docs/modules/rust/kb-worker/module.md +0 -171
  128. package/docs/modules/rust/kb-worker/types/cache.md +0 -90
  129. package/docs/modules/rust/kb-worker/types/context.md +0 -26
  130. package/docs/modules/rust/kb-worker/types/module.md +0 -16
  131. package/docs/modules/rust/kb-worker/types/status.md +0 -29
  132. package/docs/modules/rust/kb-worker/types/token.md +0 -50
  133. package/docs/modules/rust/overview.md +0 -531
  134. package/docs/modules/rust/query-parser/functions/extract.md +0 -56
  135. package/docs/modules/rust/query-parser/functions/module.md +0 -18
  136. package/docs/modules/rust/query-parser/functions/parse.md +0 -33
  137. package/docs/modules/rust/query-parser/functions/pipeline.md +0 -9
  138. package/docs/modules/rust/query-parser/functions/rank.md +0 -85
  139. package/docs/modules/rust/query-parser/module.md +0 -131
  140. package/docs/modules/rust/query-parser/types/cache.md +0 -39
  141. package/docs/modules/rust/query-parser/types/keyphrase.md +0 -71
  142. package/docs/modules/rust/query-parser/types/module.md +0 -18
  143. package/docs/modules/rust/query-parser/types/token.md +0 -46
  144. package/docs/modules/rust/shared/content-composer/functions.md +0 -114
  145. package/docs/modules/rust/shared/content-composer/module.md +0 -147
  146. package/docs/modules/rust/shared/content-composer/types.md +0 -93
  147. package/docs/modules/rust/shared/content-parser/functions.md +0 -72
  148. package/docs/modules/rust/shared/content-parser/module.md +0 -99
  149. package/docs/modules/rust/shared/content-parser/types.md +0 -71
  150. package/docs/modules/rust/shared/corpus/module.md +0 -24
  151. package/docs/modules/rust/shared/corpus/types.md +0 -141
  152. package/docs/modules/rust/shared/document/module.md +0 -25
  153. package/docs/modules/rust/shared/document/types.md +0 -154
  154. package/docs/modules/rust/shared/encode/module.md +0 -22
  155. package/docs/modules/rust/shared/encode/traits.md +0 -304
  156. package/docs/modules/rust/shared/error/module.md +0 -28
  157. package/docs/modules/rust/shared/error/types.md +0 -302
  158. package/docs/modules/rust/shared/kbid/module.md +0 -24
  159. package/docs/modules/rust/shared/kbid/types.md +0 -147
  160. package/docs/modules/rust/shared/memory/functions.md +0 -209
  161. package/docs/modules/rust/shared/memory/module.md +0 -24
  162. package/docs/modules/rust/shared/module.md +0 -196
  163. package/docs/modules/rust/shared/pipeline/functions.md +0 -141
  164. package/docs/modules/rust/shared/pipeline/module.md +0 -62
  165. package/docs/modules/rust/shared/pipeline/types.md +0 -43
  166. package/docs/modules/rust/shared/query/module.md +0 -27
  167. package/docs/modules/rust/shared/query/types.md +0 -236
  168. package/docs/modules/rust/shared/section/module.md +0 -25
  169. package/docs/modules/rust/shared/section/types.md +0 -294
  170. package/docs/modules/rust/shared/term/module.md +0 -25
  171. package/docs/modules/rust/shared/term/types.md +0 -139
  172. package/docs/modules/typescript/cli.md +0 -131
  173. package/docs/modules/typescript/kbdb-worker.md +0 -150
  174. package/docs/modules/typescript/overview.md +0 -400
  175. package/docs/modules/typescript/shared/auto-capture/module.md +0 -73
  176. package/docs/modules/typescript/shared/cli/constants.md +0 -23
  177. package/docs/modules/typescript/shared/cli/functions.md +0 -809
  178. package/docs/modules/typescript/shared/cli/module.md +0 -138
  179. package/docs/modules/typescript/shared/cli/typings.md +0 -197
  180. package/docs/modules/typescript/shared/embedding/functions.md +0 -200
  181. package/docs/modules/typescript/shared/embedding/module.md +0 -77
  182. package/docs/modules/typescript/shared/embedding/typings.md +0 -124
  183. package/docs/modules/typescript/shared/hash/functions.md +0 -20
  184. package/docs/modules/typescript/shared/hash/module.md +0 -21
  185. package/docs/modules/typescript/shared/log/constants.md +0 -82
  186. package/docs/modules/typescript/shared/log/functions.md +0 -131
  187. package/docs/modules/typescript/shared/log/module.md +0 -153
  188. package/docs/modules/typescript/shared/log/typings.md +0 -82
  189. package/docs/modules/typescript/shared/mcp/classes.md +0 -179
  190. package/docs/modules/typescript/shared/mcp/functions.md +0 -386
  191. package/docs/modules/typescript/shared/mcp/module.md +0 -160
  192. package/docs/modules/typescript/shared/mcp/typings.md +0 -529
  193. package/docs/modules/typescript/shared/module.md +0 -110
  194. package/docs/modules/typescript/shared/platform/functions.md +0 -42
  195. package/docs/modules/typescript/shared/platform/module.md +0 -25
  196. package/docs/modules/typescript/shared/runtime/functions.md +0 -26
  197. package/docs/modules/typescript/shared/runtime/module.md +0 -27
  198. package/docs/modules/typescript/shared/runtime/typings.md +0 -13
  199. package/docs/modules/typescript/shared/version/module.md +0 -27
  200. package/docs/modules/typescript/shared/wasm-codec/functions.md +0 -391
  201. package/docs/modules/typescript/shared/wasm-codec/module.md +0 -98
  202. package/docs/modules/typescript/shared/worker-client/classes.md +0 -264
  203. package/docs/modules/typescript/shared/worker-client/functions.md +0 -175
  204. package/docs/modules/typescript/shared/worker-client/module.md +0 -92
  205. package/docs/modules/typescript/shared/worker-client/typings.md +0 -511
  206. package/docs/modules/typescript/shared/worker-daemon/classes.md +0 -239
  207. package/docs/modules/typescript/shared/worker-daemon/constants.md +0 -37
  208. package/docs/modules/typescript/shared/worker-daemon/functions.md +0 -234
  209. package/docs/modules/typescript/shared/worker-daemon/module.md +0 -118
  210. package/docs/modules/typescript/shared/worker-daemon/typings.md +0 -132
  211. package/docs/overview.md +0 -191
  212. package/docs/release-notes/0.1.0.md +0 -189
  213. package/docs/release-notes/0.1.1.md +0 -46
  214. package/docs/release-notes/0.1.2.md +0 -38
  215. package/docs/release-notes/0.1.3.md +0 -42
  216. package/docs/release-notes/0.2.0.md +0 -147
  217. package/docs/release-notes/0.3.0.md +0 -89
  218. package/docs/release-notes/0.3.1.md +0 -121
  219. package/docs/release-notes/0.3.2.md +0 -64
  220. package/docs/release-notes/0.4.0.md +0 -80
  221. package/docs/release-notes/0.4.1.md +0 -149
  222. package/docs/release-notes/0.4.3.md +0 -60
  223. package/docs/release-notes/0.5.0.md +0 -41
  224. package/docs/release-notes/README.md +0 -16
@@ -1,180 +0,0 @@
1
- # Knowledge Base Guide
2
-
3
- How to build, search, and maintain a knowledge base
4
- with kbdb.
5
-
6
- ## Overview
7
-
8
- kbdb stores your documents in a plain `.kbdb` folder on
9
- disk and makes them searchable. No external server
10
- required -- just a directory you can back up, version
11
- with git, or move between machines.
12
-
13
- ## Getting Started
14
-
15
- **Create a knowledge base:**
16
-
17
- ```sh
18
- kbdb db init --db ./my-project
19
- ```
20
-
21
- **Feed it your docs:**
22
-
23
- ```sh
24
- kbdb learn ./docs --db ./my-project
25
- ```
26
-
27
- kbdb reads Markdown (`.md`) and plain text (`.txt`)
28
- files.
29
- It breaks them into sections, extracts keywords, and
30
- builds a search index.
31
-
32
- **Search:**
33
-
34
- ```sh
35
- kbdb search "how does auth work" --db ./my-project
36
- ```
37
-
38
- Results are ranked by relevance. Headings carry 2x
39
- weight, so well-titled sections surface first.
40
-
41
- ## Importing Content
42
-
43
- ### File import
44
-
45
- ```sh
46
- kbdb learn ./docs --db ./my-project
47
- ```
48
-
49
- Recursively imports all supported files. Each file is
50
- split into sections by heading.
51
-
52
- ### Stdin import
53
-
54
- ```sh
55
- echo "My note about auth." \
56
- | kbdb learn - --title "Auth notes" --db ./my-project
57
- ```
58
-
59
- ### Tags and source tracking
60
-
61
- ```sh
62
- kbdb learn ./docs --tags design,v2 --db ./my-project
63
- ```
64
-
65
- Tags scope content for filtering. Use `--replace` to
66
- update existing sections from the same source instead
67
- of creating duplicates.
68
-
69
- ## Search Modes
70
-
71
- | Flag | Mode | Description |
72
- |------|------|-------------|
73
- | _(default)_ | lexical | Keyword matching with stemming |
74
- | `--algo hybrid` | hybrid | Keyword + AI similarity |
75
- | `--algo vector` | vector | AI similarity only |
76
-
77
- Hybrid and vector modes work out of the box using a
78
- built-in TF-IDF embedding provider. For higher
79
- quality, configure an ONNX or API provider in
80
- `worker.toml`. See the [CLI Reference](cli.md) for
81
- provider configuration.
82
-
83
- When a query returns no exact matches, kbdb
84
- automatically loosens the search (OR instead of AND)
85
- and flags results with `relaxed: true`.
86
-
87
- ## Reading Data
88
-
89
- Three commands retrieve stored content at different
90
- granularities:
91
-
92
- | Command | Purpose |
93
- |---------|---------|
94
- | `search` | Find sections by query; ranked snippets |
95
- | `recall` | Expand context around known kbids |
96
- | `content` | Compose Markdown from kbid/docid lists |
97
-
98
- **Recall depths:**
99
-
100
- | Depth | Returns |
101
- |-------|---------|
102
- | 0 | Section content only |
103
- | 1 | + parent documents, back-references |
104
- | 2 | + siblings, forward references |
105
- | 3 | + full text of referenced sections |
106
-
107
- **kbid prefixes:** You don't need to paste full 26-char
108
- identifiers. Short prefixes work (like git short
109
- hashes) as long as they're unambiguous.
110
-
111
- ## Maintenance
112
-
113
- ```sh
114
- kbdb check --db ./my-project # integrity check
115
- kbdb gc --db ./my-project # remove stale data
116
- kbdb rebuild --db ./my-project # rebuild all indexes
117
- kbdb export --db ./my-project # portable snapshot
118
- ```
119
-
120
- ## Sync & Backup
121
-
122
- The `.kbdb` directory is self-contained and portable.
123
-
124
- **Git-based sync:**
125
-
126
- ```sh
127
- cd .kbdb
128
- git init && git add -A && git commit -m "snapshot"
129
- git remote add origin <url> && git push
130
- ```
131
-
132
- On another machine:
133
-
134
- ```sh
135
- git clone <url> .kbdb
136
- kbdb rebuild
137
- ```
138
-
139
- The `.gitignore` inside `.kbdb` already excludes
140
- binary indexes, so git only tracks raw section and
141
- document files. After cloning, `rebuild` reconstructs
142
- the indexes.
143
-
144
- **Export/import:**
145
-
146
- ```sh
147
- kbdb export --db ./project
148
- # copy the export directory to another machine
149
- kbdb db init --db ./project
150
- # re-import sections from the export
151
- ```
152
-
153
- ## Daemon Timeout and Retry
154
-
155
- All commands that talk to the worker daemon support
156
- two global flags:
157
-
158
- | Flag | Default | Description |
159
- |------|---------|-------------|
160
- | `--timeout-ms <ms>` | `30000` | Per-request daemon timeout |
161
- | `--retry <n>` | `1` | Retries with daemon respawn on timeout |
162
- | `--non-interactive` | off | Suppress prompts; use defaults |
163
-
164
- These can also be set via environment variables.
165
- The flags take priority over env vars.
166
-
167
- | Variable | Description |
168
- |----------|-------------|
169
- | `KBDB_DAEMON_TIMEOUT` | Per-request daemon timeout (ms) |
170
- | `KBDB_RETRY` | Max retry count |
171
- | `KBDB_LOG_LEVEL` | Log verbosity: `debug`, `info`, `warning`, `error` |
172
- | `KBDB_NON_INTERACTIVE` | Suppress prompts (`1` or `true`) |
173
-
174
- ## Deep Dives
175
-
176
- - [CLI Reference](cli.md) -- full command list
177
- - [Search and Ranking](search-and-ranking.md) --
178
- scoring, stemming, hybrid search internals
179
- - [Storage Architecture](storage.md) -- file formats,
180
- directory layout
@@ -1,495 +0,0 @@
1
- # Library API Reference
2
-
3
- ## Overview
4
-
5
- kbdb can be used as a library in Node.js and Deno
6
- projects. The main entry point is
7
- `createWorkerClient()`, which connects to a
8
- background worker daemon and returns a typed client
9
- for all knowledge base operations.
10
-
11
- ## Installation
12
-
13
- ```
14
- npm install @dikolab/kbdb # Node.js
15
- deno add @dikolab/kbdb # Deno
16
- ```
17
-
18
- ## Quick Start
19
-
20
- ```typescript
21
- import { createWorkerClient } from '@dikolab/kbdb';
22
-
23
- const client = await createWorkerClient({
24
- contextPath: '/path/to/.kbdb',
25
- });
26
-
27
- const results = await client.search({
28
- query: 'authentication',
29
- limit: 10,
30
- });
31
-
32
- console.log(results);
33
- client.disconnect();
34
- ```
35
-
36
- ## API Reference
37
-
38
- ### Factory
39
-
40
- #### `createWorkerClient(options?)`
41
-
42
- Creates and connects a `WorkerClient` to the worker
43
- daemon. Resolves the database path, discovers or
44
- spawns the daemon, and returns a connected client.
45
-
46
- ```typescript
47
- function createWorkerClient(
48
- options?: WorkerClientOptions,
49
- ): Promise<WorkerClient>;
50
- ```
51
-
52
- **Parameters:**
53
-
54
- | Name | Type | Description |
55
- |------|------|-------------|
56
- | `options.dbPath` | `string?` | Parent directory containing `.kbdb`. The client discovers `.kbdb` inside it. Defaults to `cwd()`. |
57
- | `options.contextPath` | `string?` | Direct absolute path to the `.kbdb` directory itself. Skips discovery. |
58
- | `options.autoSpawn` | `boolean?` | Auto-spawn daemon if not running. Default `true`. |
59
- | `options.connectTimeoutMs` | `number?` | Max ms to wait for daemon. Default `10000`. |
60
- | `options.requestTimeoutMs` | `number?` | Per-request timeout in milliseconds. Default `30000`. |
61
- | `options.workerScript` | `string?` | Path to worker daemon script. |
62
-
63
- #### `getOrCreateClient(options?)`
64
-
65
- Returns a cached `WorkerClient`, creating one on
66
- first call. Subsequent calls with the same
67
- `contextPath` return the existing connected client.
68
- Use this in long-lived processes to avoid spawning
69
- multiple daemon connections.
70
-
71
- ```typescript
72
- function getOrCreateClient(
73
- options?: WorkerClientOptions,
74
- ): Promise<WorkerClient>;
75
- ```
76
-
77
- #### `clearClientCache()`
78
-
79
- Disconnects and removes all cached clients created
80
- by `getOrCreateClient`. Call during shutdown to
81
- clean up connections.
82
-
83
- ```typescript
84
- function clearClientCache(): void;
85
- ```
86
-
87
- ---
88
-
89
- ### Search
90
-
91
- #### `search(params)`
92
-
93
- Queries the knowledge base and returns ranked
94
- results.
95
-
96
- ```typescript
97
- search(
98
- params: SearchParams,
99
- ): Promise<PagedSearchResult>
100
- ```
101
-
102
- | Param | Type | Description |
103
- |-------|------|-------------|
104
- | `params.query` | `string` | Search query string. |
105
- | `params.mode` | `'sections' \| 'documents' \| 'stats'?` | Entity type to return. Default `'sections'`. |
106
- | `params.limit` | `number?` | Maximum results to return. |
107
- | `params.offset` | `number?` | Zero-based result offset for pagination. |
108
- | `params.algo` | `'lexical' \| 'vector' \| 'hybrid'?` | Search algorithm. Default `'lexical'`. |
109
- | `params.relaxed` | `boolean?` | Use relaxed (OR) matching when strict returns no results. |
110
-
111
- ---
112
-
113
- ### Sections
114
-
115
- #### `readSections(kbids)`
116
-
117
- Fetches sections by their knowledge-base
118
- identifiers.
119
-
120
- ```typescript
121
- readSections(kbids: string[]): Promise<Section[]>
122
- ```
123
-
124
- #### `addSection(params)`
125
-
126
- Imports content as a new section into the knowledge
127
- base.
128
-
129
- ```typescript
130
- addSection(
131
- params: AddSectionParams,
132
- ): Promise<AddSectionResult>
133
- ```
134
-
135
- | Param | Type | Description |
136
- |-------|------|-------------|
137
- | `params.sectionType` | `string` | Semantic type label for the section. |
138
- | `params.content` | `string` | Raw text content. |
139
- | `params.docid` | `string?` | Parent document to attach to. |
140
-
141
- #### `updateSection(kbid, params)`
142
-
143
- Replaces an existing section's content and metadata.
144
-
145
- ```typescript
146
- updateSection(
147
- kbid: string,
148
- params: AddSectionParams,
149
- ): Promise<string>
150
- ```
151
-
152
- Returns the knowledge-base identifier of the
153
- updated section.
154
-
155
- #### `removeSection(kbid)`
156
-
157
- Deletes a section from the knowledge base.
158
-
159
- ```typescript
160
- removeSection(kbid: string): Promise<RemoveSectionResult>
161
- ```
162
-
163
- #### `listByType(sectionType)`
164
-
165
- Retrieves all sections matching the given type name.
166
-
167
- ```typescript
168
- listByType(sectionType: string): Promise<SectionRecord[]>
169
- ```
170
-
171
- ---
172
-
173
- ### Documents
174
-
175
- #### `groupSections(title, kbids, docType?)`
176
-
177
- Creates a document by grouping sections under a
178
- title.
179
-
180
- ```typescript
181
- groupSections(
182
- title: string,
183
- kbids: string[],
184
- docType?: string,
185
- ): Promise<string>
186
- ```
187
-
188
- Returns the assigned document identifier.
189
-
190
- #### `removeGrouping(docid)`
191
-
192
- Removes a document grouping. The sections themselves
193
- are not deleted.
194
-
195
- ```typescript
196
- removeGrouping(docid: string): Promise<void>
197
- ```
198
-
199
- #### `retrieveDocument(docid)`
200
-
201
- Fetches a full document record including its
202
- sections.
203
-
204
- ```typescript
205
- retrieveDocument(docid: string): Promise<unknown>
206
- ```
207
-
208
- #### `listDocumentsByType(docType)`
209
-
210
- Retrieves all documents matching the given type
211
- name.
212
-
213
- ```typescript
214
- listDocumentsByType(
215
- docType: string,
216
- ): Promise<DocumentManifest[]>
217
- ```
218
-
219
- ---
220
-
221
- ### Recall
222
-
223
- #### `recall(params)`
224
-
225
- Retrieves full content and progressive context for
226
- one or more sections. Use after `search()` to read
227
- relevant results.
228
-
229
- ```typescript
230
- recall(
231
- params: RecallParams,
232
- ): Promise<RecallResult | RecallResult[]>
233
- ```
234
-
235
- | Param | Type | Description |
236
- |-------|------|-------------|
237
- | `params.kbid` | `string?` | Single section identifier. |
238
- | `params.kbids` | `string[]?` | Batch section identifiers. |
239
- | `params.depth` | `number?` | Expansion depth (0--3). Default `0`. |
240
-
241
- At least one of `kbid` or `kbids` is required.
242
- Returns a single `RecallResult` for `kbid`, or an
243
- array for `kbids`. Depth controls progressive
244
- context expansion: 0 = section content, 1 = adds
245
- parent documents and back-references, 2 = adds
246
- siblings and forward references, 3 = adds full text
247
- of referenced sections.
248
-
249
- ---
250
-
251
- ### Content
252
-
253
- #### `content(ids)`
254
-
255
- Composes rendered Markdown from one or more kbid or
256
- docid identifiers (may be mixed).
257
-
258
- ```typescript
259
- content(ids: string[]): Promise<ContentResult>
260
- ```
261
-
262
- Returns a `ContentResult` with the composed Markdown
263
- string and character count.
264
-
265
- ---
266
-
267
- ### Maintenance
268
-
269
- #### `integrityCheck()`
270
-
271
- Verifies database integrity and reports all issues
272
- found.
273
-
274
- ```typescript
275
- integrityCheck(): Promise<IntegrityCheckResult>
276
- ```
277
-
278
- #### `gc()`
279
-
280
- Garbage collects unreferenced sections from the
281
- database.
282
-
283
- ```typescript
284
- gc(): Promise<GcResult>
285
- ```
286
-
287
- #### `rebuildIndexes()`
288
-
289
- Reconstructs all index files from section files and
290
- document manifests on disk.
291
-
292
- ```typescript
293
- rebuildIndexes(): Promise<RebuildResult>
294
- ```
295
-
296
- #### `initDirectory(targetPath)`
297
-
298
- Initialises a new `.kbdb` database directory at the
299
- given path.
300
-
301
- ```typescript
302
- initDirectory(targetPath: string): Promise<void>
303
- ```
304
-
305
- #### `migrateDatabase(targetPath)`
306
-
307
- Runs all pending database migrations for the
308
- `.kbdb` directory at the given path.
309
-
310
- ```typescript
311
- migrateDatabase(
312
- targetPath: string,
313
- ): Promise<MigrateResult>
314
- ```
315
-
316
- #### `checkVersion(targetPath)`
317
-
318
- Checks format version compatibility of the `.kbdb`
319
- database against the current WASM engine. Read-only.
320
-
321
- ```typescript
322
- checkVersion(
323
- targetPath: string,
324
- ): Promise<VersionStatus>
325
- ```
326
-
327
- ---
328
-
329
- ### Cache
330
-
331
- #### `invalidate(kbid)`
332
-
333
- Evicts a single section from the daemon's in-memory
334
- cache.
335
-
336
- ```typescript
337
- invalidate(kbid: string): Promise<void>
338
- ```
339
-
340
- #### `invalidateAll()`
341
-
342
- Clears all entries from the daemon's in-memory
343
- cache.
344
-
345
- ```typescript
346
- invalidateAll(): Promise<void>
347
- ```
348
-
349
- ---
350
-
351
- ### Lifecycle
352
-
353
- #### `status()`
354
-
355
- Returns diagnostic status including initialization
356
- state and cache statistics.
357
-
358
- ```typescript
359
- status(): Promise<StatusResult>
360
- ```
361
-
362
- #### `dbStatus()`
363
-
364
- Returns database metadata and status from the
365
- daemon's cached state.
366
-
367
- ```typescript
368
- dbStatus(): Promise<StatusResult>
369
- ```
370
-
371
- #### `disconnect()`
372
-
373
- Destroys the IPC socket and closes the connection.
374
-
375
- ```typescript
376
- disconnect(): void
377
- ```
378
-
379
- #### `isConnected`
380
-
381
- Read-only getter that returns `true` when the IPC
382
- socket is connected and healthy.
383
-
384
- ```typescript
385
- get isConnected(): boolean;
386
- ```
387
-
388
- ---
389
-
390
- ## Types
391
-
392
- ### `WorkerClientOptions`
393
-
394
- ```typescript
395
- interface WorkerClientOptions {
396
- readonly dbPath?: string;
397
- readonly contextPath?: string;
398
- readonly autoSpawn?: boolean;
399
- readonly connectTimeoutMs?: number;
400
- readonly requestTimeoutMs?: number;
401
- readonly workerScript?: string;
402
- }
403
- ```
404
-
405
- ### `SearchParams`
406
-
407
- ```typescript
408
- interface SearchParams {
409
- readonly query: string;
410
- readonly mode?: 'sections' | 'documents' | 'stats';
411
- readonly limit?: number;
412
- readonly offset?: number;
413
- readonly content?: boolean;
414
- }
415
- ```
416
-
417
- ### `PagedSearchResult`
418
-
419
- ```typescript
420
- interface PagedSearchResult {
421
- readonly items: readonly SearchResult[];
422
- readonly total: number;
423
- readonly offset: number;
424
- readonly limit: number;
425
- readonly has_more: boolean;
426
- readonly relaxed: boolean;
427
- }
428
- ```
429
-
430
- ### `SearchResult`
431
-
432
- ```typescript
433
- interface SearchResult {
434
- readonly kbid: string;
435
- readonly heading: string | null;
436
- readonly type: string;
437
- readonly docids: readonly string[];
438
- readonly score: number;
439
- readonly confidence: number;
440
- readonly snippet: string;
441
- readonly matched_terms: readonly string[];
442
- readonly matched_fields: readonly string[];
443
- readonly created_at: string;
444
- }
445
- ```
446
-
447
- ### `Section`
448
-
449
- ```typescript
450
- interface Section {
451
- readonly kbid: string;
452
- readonly docid?: string;
453
- readonly sectionType: string;
454
- readonly content: string;
455
- readonly size: number;
456
- readonly createdAt: number;
457
- readonly checksum: string;
458
- }
459
- ```
460
-
461
- ### `AddSectionParams`
462
-
463
- ```typescript
464
- interface AddSectionParams {
465
- readonly sectionType: string;
466
- readonly content: string;
467
- readonly docid?: string;
468
- }
469
- ```
470
-
471
- ### `StatusResult`
472
-
473
- ```typescript
474
- interface StatusResult {
475
- readonly initialized: boolean;
476
- readonly contextPath: string;
477
- readonly cacheStats: {
478
- readonly contentCount: number;
479
- readonly indexCount: number;
480
- };
481
- }
482
- ```
483
-
484
- ---
485
-
486
- ## How It Works
487
-
488
- The client spawns a background worker daemon that
489
- loads the Rust/WASM search engine. Communication
490
- between the client and daemon happens over a local
491
- IPC socket using JSON-RPC 2.0 with newline-delimited
492
- framing. The daemon auto-starts on first use and
493
- persists across invocations; if the connection drops,
494
- the client automatically rediscovers or respawns the
495
- daemon on the next method call.