@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,172 +0,0 @@
1
- # functions::write -- Write Orchestration
2
-
3
- *Add, update, and remove operations for text, code,
4
- and image sections.*
5
-
6
- ## Source
7
-
8
- `engine/crates/kb-worker/src/orchestrate/write.rs`
9
-
10
- ## Exported WASM Functions
11
-
12
- ### `worker_add_section`
13
-
14
- ```rust
15
- pub fn worker_add_section(
16
- params_ptr: *const u8,
17
- params_len: u32,
18
- ) -> u64;
19
- ```
20
-
21
- Params buffer contains Encode'd `AddSectionParams`.
22
- Returns `(ptr, len)` with the new `KbId`.
23
-
24
- ### `worker_update_section`
25
-
26
- ```rust
27
- pub fn worker_update_section(
28
- params_ptr: *const u8,
29
- params_len: u32,
30
- ) -> u64;
31
- ```
32
-
33
- ### `worker_remove_section`
34
-
35
- ```rust
36
- pub fn worker_remove_section(
37
- kbid_ptr: *const u8,
38
- kbid_len: u32,
39
- ) -> u64;
40
- ```
41
-
42
- ### `worker_group_sections`
43
-
44
- ```rust
45
- pub fn worker_group_sections(
46
- params_ptr: *const u8,
47
- params_len: u32,
48
- ) -> u64;
49
- ```
50
-
51
- Creates a document manifest grouping multiple
52
- sections.
53
-
54
- ### `worker_remove_grouping`
55
-
56
- ```rust
57
- pub fn worker_remove_grouping(
58
- doc_id_ptr: *const u8,
59
- doc_id_len: u32,
60
- ) -> u64;
61
- ```
62
-
63
- ## Add Flow (Text)
64
-
65
- ```
66
- 1. Receive content + metadata via shared memory
67
-
68
- 2. Per-field tokenization:
69
- - title → qp_tokenize → heading tokens
70
- - body + description → qp_tokenize → body tokens
71
-
72
- 3. qp_extract_keywords → Vec<Keyphrase>
73
-
74
- 4. qp_compute_field_tf → per-field TFs + token counts
75
-
76
- 5. db_add_section → KbId (content-addressed)
77
- (includes title, description, and 4 token counts
78
- in section header)
79
-
80
- 6. db_index_add → update inverted (per-field TFs)
81
- + positional index
82
-
83
- 7. Invalidate cache entries for affected terms
84
-
85
- Return AddSectionResult
86
- ```
87
-
88
- ## Add Flow (Code)
89
-
90
- ```
91
- 1. Receive source code + language tag
92
-
93
- 2. Per-field tokenization:
94
- - title → qp_tokenize → heading tokens
95
- - description → qp_tokenize → body tokens
96
- - code content → qp_split_identifiers
97
- + qp_tokenize → code tokens
98
-
99
- 3. Merge identifier tokens + content tokens
100
-
101
- 4. qp_extract_keywords → Vec<Keyphrase>
102
-
103
- 5. qp_compute_field_tf → per-field TFs + token counts
104
-
105
- 6-8. Same as text flow (store, index, cache)
106
- ```
107
-
108
- Code sections use `qp_split_identifiers` to split
109
- camelCase and snake_case identifiers into searchable
110
- terms before merging with tokens from comments and
111
- string literals. Code content feeds the code field;
112
- title feeds the heading field; description feeds the
113
- body field.
114
-
115
- ## Add Flow (Image)
116
-
117
- ```
118
- 1. Receive image binary + title (required)
119
- + description (optional)
120
-
121
- 2. Per-field tokenization:
122
- - title → qp_tokenize → heading tokens (2.0x)
123
- - description → qp_tokenize → body tokens (1.0x)
124
-
125
- 3. qp_compute_field_tf → per-field TFs + token counts
126
-
127
- 4. db_add_section → KbId (hash of binary)
128
- (includes title, description, and 4 token counts
129
- in section header)
130
-
131
- 5. db_index_add → index title/description terms
132
- with per-field TFs
133
-
134
- Return AddSectionResult
135
- ```
136
-
137
- Image binary is stored as-is and not indexed.
138
- Title (required) is tokenized into the heading
139
- field and description (optional) into the body
140
- field. Validation: image sections require a title.
141
-
142
- ## Update Flow
143
-
144
- ```
145
- 1. Receive KbId + new content
146
-
147
- 2. db_index_remove → remove old index entries
148
-
149
- 3. Re-run the appropriate add flow (text/code/image)
150
-
151
- 4. db_update_section → overwrite content
152
-
153
- 5. Invalidate cache for old + new terms
154
- ```
155
-
156
- Update is delete-old-indexes + re-add. The KbId may
157
- change if content changes (content-addressed), so the
158
- caller receives the new KbId.
159
-
160
- ## Remove Flow
161
-
162
- ```
163
- 1. Receive KbId
164
-
165
- 2. db_index_remove → remove all index entries
166
-
167
- 3. db_remove_section → delete content file
168
-
169
- 4. Invalidate cache for removed KbId
170
-
171
- Return success/failure
172
- ```
@@ -1,171 +0,0 @@
1
- # kb-worker -- Worker Orchestration and Cache
2
-
3
- *Rust crate that imports query-parser and fs-database,
4
- orchestrates all database operations, and manages the
5
- in-memory LRU cache. Compiles to `kb-worker.wasm`.*
6
-
7
- ## Crate
8
-
9
- | Field | Value |
10
- |-------------|------------------------------------|
11
- | Name | `kbdb-worker` |
12
- | Path | `engine/crates/kb-worker/` |
13
- | Crate type | `cdylib` (WASM) + `rlib` (tests) |
14
- | WASM output | `dist/wasm/kb-worker.wasm` |
15
- | Depends on | `kbdb-shared`, `kbdb-query-parser`, `kbdb-fs-database` |
16
-
17
- `kbdb-worker` is the **top-level** WASM module. It
18
- imports both `query-parser.wasm` and
19
- `fs-database.wasm` and sits between the TypeScript
20
- IPC layer and the two standalone modules.
21
-
22
- ```
23
- query-parser.wasm fs-database.wasm
24
- (standalone) (standalone)
25
- ↑ ↑
26
- └────────┬───────────┘
27
- |
28
- kb-worker.wasm
29
- (imports both, orchestrates)
30
-
31
- |
32
- src/worker.ts
33
- (TypeScript daemon, loads this module)
34
- ```
35
-
36
- See [Worker Daemon](../../../goals/worker-daemon.md)
37
- for the full behavioral specification.
38
-
39
- ## Workspace Position
40
-
41
- ```
42
- engine/
43
- ├── Cargo.toml # workspace root
44
- └── crates/
45
- ├── shared/ # kbdb-shared
46
- ├── fs-database/ # kbdb-fs-database
47
- ├── query-parser/ # kbdb-query-parser
48
- └── kb-worker/ # this crate
49
- ```
50
-
51
- ## Directory Layout
52
-
53
- ```
54
- engine/crates/kb-worker/
55
- ├── Cargo.toml
56
- └── src/
57
- ├── lib.rs # crate root, WASM exports
58
- ├── mem.rs # shared-memory helpers
59
- ├── context.rs # database context init
60
- ├── orchestrate/
61
- │ ├── mod.rs # dispatch facade
62
- │ ├── search.rs # search flow
63
- │ ├── write.rs # write flow
64
- │ └── retrieve.rs # read flow
65
- ├── cache/
66
- │ ├── mod.rs # cache facade
67
- │ ├── lru.rs # LRU data structure
68
- │ ├── entry.rs # cache entry with TTL
69
- │ └── config.rs # cache configuration
70
- ├── token.rs # result token management
71
- └── status.rs # status reporting
72
- ```
73
-
74
- ## Modules
75
-
76
- ### [types/](types/module.md) -- Structs
77
-
78
- - **[context](types/context.md)** -- `Context` struct.
79
- Database context initialization.
80
- - **[cache](types/cache.md)** -- `Cache`,
81
- `CacheConfig`, `CacheEntry`, `CacheStats`,
82
- `LruCache`.
83
- - **[token](types/token.md)** -- `TokenStore`,
84
- `TokenEntry`, `TokenStatus`. Async result token
85
- management.
86
- - **[status](types/status.md)** -- `StatusResult`.
87
-
88
- ### [functions/](functions/module.md) -- Orchestration
89
-
90
- - **[search](functions/search.md)** -- Search flow:
91
- parse → lookup → rank.
92
- - **[write](functions/write.md)** -- Write flow:
93
- tokenize → store → index (text/code/image).
94
- - **[retrieve](functions/retrieve.md)** -- Read flow:
95
- cache check → disk read. Status reporting.
96
- - **[compose](functions/compose.md)** -- Content
97
- composition flow: resolve → fetch → compose.
98
-
99
- ## WASM Exports
100
-
101
- | Export | Description |
102
- |---------------------------|--------------------------|
103
- | `worker_init` | Initialize context |
104
- | `worker_search` | Full search flow |
105
- | `worker_add_section` | Full add flow |
106
- | `worker_update_section` | Full update flow |
107
- | `worker_remove_section` | Full remove flow |
108
- | `worker_read_sections` | Read sections by kb-id |
109
- | `worker_retrieve_doc` | Read document + sections |
110
- | `worker_group_sections` | Create document grouping |
111
- | `worker_remove_grouping` | Remove document grouping |
112
- | `worker_status` | Database + cache status |
113
- | `worker_query` | Async query (returns token) |
114
- | `worker_result_status` | Poll token status |
115
- | `worker_get_result` | Fetch result by token |
116
- | `worker_invalidate` | Evict cache entries |
117
- | `worker_invalidate_all` | Evict entire cache |
118
- | `worker_compose` | Content composition flow |
119
- | `worker_check_integrity` | Run integrity checks |
120
- | `worker_garbage_collect` | Remove orphaned sections |
121
- | `worker_rebuild_indexes` | Full index rebuild |
122
- | `worker_recall` | Progressive context expansion (recall) |
123
- | `alloc` / `free` | Memory management (from `kbdb-shared`) |
124
-
125
- ## WASM Imports
126
-
127
- **From `query-parser.wasm`:** `qp_tokenize`,
128
- `qp_parse_query`, `qp_extract_keywords`,
129
- `qp_compute_tf`, `qp_compute_field_tf`,
130
- `qp_compute_tfidf`,
131
- `qp_score_bm25f`, `qp_score_proximity`,
132
- `qp_score_zone`, `qp_score_freshness`,
133
- `qp_split_identifiers`.
134
-
135
- **From `fs-database.wasm`:** `db_init`,
136
- `db_read_section`, `db_read_sections`,
137
- `db_add_section`, `db_update_section`,
138
- `db_remove_section`, `db_read_document`,
139
- `db_write_document`, `db_remove_document`,
140
- `db_update_section_ref`, `db_index_add`,
141
- `db_index_remove`, `db_index_rebuild`,
142
- `db_execute_plan`, `db_corpus_stats`, `db_status`,
143
- `db_check_integrity`, `db_garbage_collect`.
144
-
145
- ## Dependencies
146
-
147
- ```toml
148
- [dependencies]
149
- kbdb-shared = { path = "../shared" }
150
- kbdb-query-parser = { path = "../query-parser" }
151
- kbdb-fs-database = { path = "../fs-database" }
152
- ```
153
-
154
- ## Build
155
-
156
- ```sh
157
- cd engine
158
- wasm-pack build crates/kb-worker \
159
- --target no-modules \
160
- --out-dir ../../../dist/wasm/kb-worker
161
- ```
162
-
163
- Build order: `kbdb-shared` → `kbdb-query-parser` +
164
- `kbdb-fs-database` (parallel) → `kbdb-worker`.
165
-
166
- ## Testing
167
-
168
- ```sh
169
- cd engine && cargo test -p kbdb-worker
170
- cd engine && wasm-pack test --node crates/kb-worker
171
- ```
@@ -1,90 +0,0 @@
1
- # types::cache -- LRU Cache with TTL
2
-
3
- *In-memory cache between IPC request handling and
4
- disk I/O. Configuration from `worker.toml`.*
5
-
6
- ## Source
7
-
8
- `engine/crates/kb-worker/src/cache/`
9
-
10
- ## Type Definitions
11
-
12
- ### `CacheConfig`
13
-
14
- ```rust
15
- pub struct CacheConfig {
16
- pub item_limit: u32,
17
- pub index_limit: u32,
18
- pub item_ttl_ms: u64,
19
- }
20
- ```
21
-
22
- Defaults: `item_limit = 1000`,
23
- `index_limit = 100`, `item_ttl_ms = 60000`.
24
-
25
- ### `CacheEntry<V>`
26
-
27
- ```rust
28
- pub struct CacheEntry<V> {
29
- pub value: V,
30
- pub created_at: u64,
31
- pub last_accessed: u64,
32
- pub ttl_ms: u64,
33
- }
34
-
35
- impl<V> CacheEntry<V> {
36
- pub fn is_expired(&self, now: u64) -> bool;
37
- }
38
- ```
39
-
40
- ### `LruCache<K, V>`
41
-
42
- ```rust
43
- pub struct LruCache<K, V> { /* doubly-linked list + hashmap */ }
44
-
45
- impl<K: Hash + Eq, V> LruCache<K, V> {
46
- pub fn new(capacity: u32) -> Self;
47
- pub fn get(&mut self, key: &K) -> Option<&V>;
48
- pub fn put(&mut self, key: K, value: V);
49
- pub fn remove(&mut self, key: &K) -> bool;
50
- pub fn clear(&mut self);
51
- pub fn len(&self) -> u32;
52
- pub fn stats(&self) -> CacheStats;
53
- }
54
-
55
- pub struct CacheStats {
56
- pub items_cached: u32,
57
- pub hits: u64,
58
- pub misses: u64,
59
- pub hit_rate: f32,
60
- }
61
- ```
62
-
63
- O(1) access and O(1) eviction.
64
-
65
- ### `Cache`
66
-
67
- ```rust
68
- pub struct Cache {
69
- content: LruCache<KbId, SectionRecord>,
70
- indexes: LruCache<Term, PostingList>,
71
- manifests: LruCache<String, DocumentManifest>,
72
- config: CacheConfig,
73
- }
74
-
75
- impl Cache {
76
- pub fn new(config: CacheConfig) -> Self;
77
- pub fn get_section(&mut self, kbid: &KbId)
78
- -> Option<&SectionRecord>;
79
- pub fn put_section(
80
- &mut self, kbid: KbId, record: SectionRecord,
81
- );
82
- pub fn invalidate(&mut self, keys: &[KbId])
83
- -> u32;
84
- pub fn invalidate_all(&mut self) -> u32;
85
- pub fn stats(&self) -> CacheStats;
86
- }
87
- ```
88
-
89
- Separate LRU instances for content objects, index
90
- segments, and manifests, each with its own capacity.
@@ -1,26 +0,0 @@
1
- # types::context -- Database Context
2
-
3
- *The `Context` struct initialized at daemon startup.*
4
-
5
- ## Source
6
-
7
- `engine/crates/kb-worker/src/context.rs`
8
-
9
- ## Type Definition
10
-
11
- ```rust
12
- pub struct Context {
13
- pub ctx_id: String,
14
- pub target_dir: String,
15
- pub catalog: Catalog,
16
- }
17
-
18
- pub fn init_context(
19
- target_dir: &str,
20
- ) -> Result<Context, WorkerError>;
21
- ```
22
-
23
- `init_context` calls `db_init` from
24
- `kbdb-fs-database` to validate the database
25
- directory and load the catalog. The context is held
26
- for the daemon's lifetime.
@@ -1,16 +0,0 @@
1
- # kb-worker/types -- Type Definitions
2
-
3
- *Structs defined in the kb-worker crate for context,
4
- caching, result tokens, and status reporting.*
5
-
6
- ## Modules
7
-
8
- - **[context](context.md)** -- `Context` struct.
9
- Database context with catalog data.
10
- - **[cache](cache.md)** -- `Cache`, `CacheConfig`,
11
- `CacheEntry`, `CacheStats`, `LruCache`. In-memory
12
- LRU cache with TTL.
13
- - **[token](token.md)** -- `TokenStore`, `TokenEntry`,
14
- `TokenStatus`. Async result token management.
15
- - **[status](status.md)** -- `StatusResult`. Combined
16
- database and cache statistics.
@@ -1,29 +0,0 @@
1
- # types::status -- Status Reporting
2
-
3
- *Combined database and cache statistics returned by
4
- `worker_status`.*
5
-
6
- ## Source
7
-
8
- `engine/crates/kb-worker/src/status.rs`
9
-
10
- ## Type Definition
11
-
12
- ```rust
13
- pub struct StatusResult {
14
- pub target_dir: String,
15
- pub document_count: u32,
16
- pub section_count: u32,
17
- pub index_size_bytes: u64,
18
- pub last_modified: String,
19
- pub cache_stats: CacheStats,
20
- }
21
-
22
- pub fn get_status(
23
- ctx: &Context,
24
- cache: &Cache,
25
- ) -> Result<StatusResult, WorkerError>;
26
- ```
27
-
28
- Combines catalog data from `fs-database.wasm` with
29
- cache statistics from the local cache.
@@ -1,50 +0,0 @@
1
- # types::token -- Result Token Management
2
-
3
- *Async result tokens for the submit → poll → fetch
4
- query flow.*
5
-
6
- ## Source
7
-
8
- `engine/crates/kb-worker/src/token.rs`
9
-
10
- ## Type Definitions
11
-
12
- ```rust
13
- pub struct TokenStore {
14
- tokens: HashMap<String, TokenEntry>,
15
- }
16
-
17
- pub struct TokenEntry {
18
- pub status: TokenStatus,
19
- pub data: Option<Vec<u8>>,
20
- pub created_at: u64,
21
- }
22
-
23
- pub enum TokenStatus {
24
- Busy,
25
- Success,
26
- Fail(String),
27
- }
28
- ```
29
-
30
- ## Methods
31
-
32
- ```rust
33
- impl TokenStore {
34
- pub fn create(&mut self) -> String;
35
- pub fn complete(
36
- &mut self, token: &str, data: Vec<u8>,
37
- );
38
- pub fn fail(
39
- &mut self, token: &str, reason: String,
40
- );
41
- pub fn status(&self, token: &str)
42
- -> Option<&TokenStatus>;
43
- pub fn take_data(&mut self, token: &str)
44
- -> Option<Vec<u8>>;
45
- }
46
- ```
47
-
48
- Tokens are random 16-character hex strings. Tied to
49
- cached data -- when the cached entry is evicted, the
50
- token becomes invalid and returns `null` on fetch.