@dikolab/kbdb 0.4.3 → 0.6.0

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 -27
  5. package/README.md.bak +320 -0
  6. package/dist/README.md +320 -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/kbdb_fs_migration_bg.wasm +0 -0
  66. package/dist/wasm/fs-migration/package.json +1 -1
  67. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  68. package/dist/wasm/kb-worker/package.json +1 -1
  69. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  70. package/dist/wasm/query-parser/package.json +1 -1
  71. package/dist/worker.d.ts +0 -7
  72. package/dist/worker.mjs +37 -6
  73. package/dist/worker.mjs.map +3 -3
  74. package/package.json +13 -12
  75. package/dist/chunk-BJXEVALU.mjs.map +0 -7
  76. package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +0 -10
  77. package/docs/details/README.md +0 -30
  78. package/docs/details/agent-tooling.md +0 -132
  79. package/docs/details/cli.md +0 -777
  80. package/docs/details/knowledge-base.md +0 -180
  81. package/docs/details/library-api.md +0 -495
  82. package/docs/details/mcp-server.md +0 -482
  83. package/docs/details/search-and-ranking.md +0 -575
  84. package/docs/details/storage.md +0 -531
  85. package/docs/goals/agents.md +0 -751
  86. package/docs/goals/architecture.svg +0 -198
  87. package/docs/goals/auto-capture.md +0 -378
  88. package/docs/goals/benchmarking.md +0 -296
  89. package/docs/goals/cli.md +0 -2654
  90. package/docs/goals/concurrency.md +0 -259
  91. package/docs/goals/content-composer.md +0 -609
  92. package/docs/goals/content-parser.md +0 -279
  93. package/docs/goals/database.md +0 -1679
  94. package/docs/goals/document.md +0 -368
  95. package/docs/goals/hybrid-search.md +0 -465
  96. package/docs/goals/mcp.md +0 -1541
  97. package/docs/goals/overview.md +0 -124
  98. package/docs/goals/query-parser.md +0 -373
  99. package/docs/goals/query-result.md +0 -860
  100. package/docs/goals/semantic-dedup.md +0 -233
  101. package/docs/goals/skills.md +0 -810
  102. package/docs/goals/sync.md +0 -217
  103. package/docs/goals/worker-client.md +0 -1005
  104. package/docs/goals/worker-daemon.md +0 -1547
  105. package/docs/modules/overview.md +0 -319
  106. package/docs/modules/rust/embedding/module.md +0 -91
  107. package/docs/modules/rust/fs-database/functions/document.md +0 -48
  108. package/docs/modules/rust/fs-database/functions/integrity.md +0 -79
  109. package/docs/modules/rust/fs-database/functions/io.md +0 -87
  110. package/docs/modules/rust/fs-database/functions/module.md +0 -22
  111. package/docs/modules/rust/fs-database/functions/query-exec.md +0 -44
  112. package/docs/modules/rust/fs-database/functions/section.md +0 -76
  113. package/docs/modules/rust/fs-database/indexes/btree.md +0 -35
  114. package/docs/modules/rust/fs-database/indexes/corpus.md +0 -61
  115. package/docs/modules/rust/fs-database/indexes/inverted.md +0 -60
  116. package/docs/modules/rust/fs-database/indexes/module.md +0 -64
  117. package/docs/modules/rust/fs-database/indexes/positional.md +0 -39
  118. package/docs/modules/rust/fs-database/indexes/vectors.md +0 -110
  119. package/docs/modules/rust/fs-database/module.md +0 -150
  120. package/docs/modules/rust/fs-database/types/catalog.md +0 -53
  121. package/docs/modules/rust/fs-database/types/module.md +0 -12
  122. package/docs/modules/rust/fs-database/types/section.md +0 -127
  123. package/docs/modules/rust/kb-worker/functions/compose.md +0 -57
  124. package/docs/modules/rust/kb-worker/functions/module.md +0 -20
  125. package/docs/modules/rust/kb-worker/functions/retrieve.md +0 -194
  126. package/docs/modules/rust/kb-worker/functions/search.md +0 -173
  127. package/docs/modules/rust/kb-worker/functions/write.md +0 -172
  128. package/docs/modules/rust/kb-worker/module.md +0 -171
  129. package/docs/modules/rust/kb-worker/types/cache.md +0 -90
  130. package/docs/modules/rust/kb-worker/types/context.md +0 -26
  131. package/docs/modules/rust/kb-worker/types/module.md +0 -16
  132. package/docs/modules/rust/kb-worker/types/status.md +0 -29
  133. package/docs/modules/rust/kb-worker/types/token.md +0 -50
  134. package/docs/modules/rust/overview.md +0 -531
  135. package/docs/modules/rust/query-parser/functions/extract.md +0 -56
  136. package/docs/modules/rust/query-parser/functions/module.md +0 -18
  137. package/docs/modules/rust/query-parser/functions/parse.md +0 -33
  138. package/docs/modules/rust/query-parser/functions/pipeline.md +0 -9
  139. package/docs/modules/rust/query-parser/functions/rank.md +0 -85
  140. package/docs/modules/rust/query-parser/module.md +0 -131
  141. package/docs/modules/rust/query-parser/types/cache.md +0 -39
  142. package/docs/modules/rust/query-parser/types/keyphrase.md +0 -71
  143. package/docs/modules/rust/query-parser/types/module.md +0 -18
  144. package/docs/modules/rust/query-parser/types/token.md +0 -46
  145. package/docs/modules/rust/shared/content-composer/functions.md +0 -114
  146. package/docs/modules/rust/shared/content-composer/module.md +0 -147
  147. package/docs/modules/rust/shared/content-composer/types.md +0 -93
  148. package/docs/modules/rust/shared/content-parser/functions.md +0 -72
  149. package/docs/modules/rust/shared/content-parser/module.md +0 -99
  150. package/docs/modules/rust/shared/content-parser/types.md +0 -71
  151. package/docs/modules/rust/shared/corpus/module.md +0 -24
  152. package/docs/modules/rust/shared/corpus/types.md +0 -141
  153. package/docs/modules/rust/shared/document/module.md +0 -25
  154. package/docs/modules/rust/shared/document/types.md +0 -154
  155. package/docs/modules/rust/shared/encode/module.md +0 -22
  156. package/docs/modules/rust/shared/encode/traits.md +0 -304
  157. package/docs/modules/rust/shared/error/module.md +0 -28
  158. package/docs/modules/rust/shared/error/types.md +0 -302
  159. package/docs/modules/rust/shared/kbid/module.md +0 -24
  160. package/docs/modules/rust/shared/kbid/types.md +0 -147
  161. package/docs/modules/rust/shared/memory/functions.md +0 -209
  162. package/docs/modules/rust/shared/memory/module.md +0 -24
  163. package/docs/modules/rust/shared/module.md +0 -196
  164. package/docs/modules/rust/shared/pipeline/functions.md +0 -141
  165. package/docs/modules/rust/shared/pipeline/module.md +0 -62
  166. package/docs/modules/rust/shared/pipeline/types.md +0 -43
  167. package/docs/modules/rust/shared/query/module.md +0 -27
  168. package/docs/modules/rust/shared/query/types.md +0 -236
  169. package/docs/modules/rust/shared/section/module.md +0 -25
  170. package/docs/modules/rust/shared/section/types.md +0 -294
  171. package/docs/modules/rust/shared/term/module.md +0 -25
  172. package/docs/modules/rust/shared/term/types.md +0 -139
  173. package/docs/modules/typescript/cli.md +0 -131
  174. package/docs/modules/typescript/kbdb-worker.md +0 -150
  175. package/docs/modules/typescript/overview.md +0 -400
  176. package/docs/modules/typescript/shared/auto-capture/module.md +0 -73
  177. package/docs/modules/typescript/shared/cli/constants.md +0 -23
  178. package/docs/modules/typescript/shared/cli/functions.md +0 -809
  179. package/docs/modules/typescript/shared/cli/module.md +0 -138
  180. package/docs/modules/typescript/shared/cli/typings.md +0 -197
  181. package/docs/modules/typescript/shared/embedding/functions.md +0 -200
  182. package/docs/modules/typescript/shared/embedding/module.md +0 -77
  183. package/docs/modules/typescript/shared/embedding/typings.md +0 -124
  184. package/docs/modules/typescript/shared/hash/functions.md +0 -20
  185. package/docs/modules/typescript/shared/hash/module.md +0 -21
  186. package/docs/modules/typescript/shared/log/constants.md +0 -82
  187. package/docs/modules/typescript/shared/log/functions.md +0 -131
  188. package/docs/modules/typescript/shared/log/module.md +0 -153
  189. package/docs/modules/typescript/shared/log/typings.md +0 -82
  190. package/docs/modules/typescript/shared/mcp/classes.md +0 -179
  191. package/docs/modules/typescript/shared/mcp/functions.md +0 -386
  192. package/docs/modules/typescript/shared/mcp/module.md +0 -160
  193. package/docs/modules/typescript/shared/mcp/typings.md +0 -529
  194. package/docs/modules/typescript/shared/module.md +0 -110
  195. package/docs/modules/typescript/shared/platform/functions.md +0 -42
  196. package/docs/modules/typescript/shared/platform/module.md +0 -25
  197. package/docs/modules/typescript/shared/runtime/functions.md +0 -26
  198. package/docs/modules/typescript/shared/runtime/module.md +0 -27
  199. package/docs/modules/typescript/shared/runtime/typings.md +0 -13
  200. package/docs/modules/typescript/shared/version/module.md +0 -27
  201. package/docs/modules/typescript/shared/wasm-codec/functions.md +0 -391
  202. package/docs/modules/typescript/shared/wasm-codec/module.md +0 -98
  203. package/docs/modules/typescript/shared/worker-client/classes.md +0 -264
  204. package/docs/modules/typescript/shared/worker-client/functions.md +0 -175
  205. package/docs/modules/typescript/shared/worker-client/module.md +0 -92
  206. package/docs/modules/typescript/shared/worker-client/typings.md +0 -511
  207. package/docs/modules/typescript/shared/worker-daemon/classes.md +0 -239
  208. package/docs/modules/typescript/shared/worker-daemon/constants.md +0 -37
  209. package/docs/modules/typescript/shared/worker-daemon/functions.md +0 -234
  210. package/docs/modules/typescript/shared/worker-daemon/module.md +0 -118
  211. package/docs/modules/typescript/shared/worker-daemon/typings.md +0 -132
  212. package/docs/overview.md +0 -191
  213. package/docs/release-notes/0.1.0.md +0 -189
  214. package/docs/release-notes/0.1.1.md +0 -46
  215. package/docs/release-notes/0.1.2.md +0 -38
  216. package/docs/release-notes/0.1.3.md +0 -42
  217. package/docs/release-notes/0.2.0.md +0 -147
  218. package/docs/release-notes/0.3.0.md +0 -89
  219. package/docs/release-notes/0.3.1.md +0 -121
  220. package/docs/release-notes/0.3.2.md +0 -64
  221. package/docs/release-notes/0.4.0.md +0 -80
  222. package/docs/release-notes/0.4.1.md +0 -149
  223. package/docs/release-notes/0.4.3.md +0 -60
  224. package/docs/release-notes/README.md +0 -13
@@ -1,531 +0,0 @@
1
- # Rust Engine -- Overview
2
-
3
- *Architecture, crate structure, and module layout
4
- for the Rust/WASM engine.*
5
-
6
- ## Compilation Model
7
-
8
- Rust compiles by **crate** -- each crate is an
9
- independent compilation unit with its own
10
- `Cargo.toml`. Within a crate, code is organized into
11
- **modules** (namespaces) that compile together as one
12
- unit.
13
-
14
- ```
15
- crate = compilation unit (has Cargo.toml)
16
- module = namespace (has mod.rs)
17
- ```
18
-
19
- A crate can only use code from:
20
- 1. Its own modules (`crate::`)
21
- 2. Dependencies declared in its `Cargo.toml`
22
-
23
- There are no path-based imports across crates --
24
- unlike TypeScript/ESM where any file can import any
25
- other file. Code sharing requires a crate dependency.
26
-
27
- ## Workspace
28
-
29
- All Rust code lives in `engine/`. The workspace
30
- contains six crates under `engine/crates/`:
31
-
32
- ```
33
- engine/
34
- ├── Cargo.toml ← workspace root
35
- ├── Cargo.lock ← shared lock file
36
- ├── .cargo/
37
- │ └── config.toml ← default: wasm32
38
- └── crates/
39
- ├── shared/ ← rlib (library)
40
- ├── fs-database/ ← cdylib (→ .wasm)
41
- ├── fs-migration/ ← cdylib (→ .wasm)
42
- ├── default-embedding/ ← cdylib (→ .wasm)
43
- ├── query-parser/ ← cdylib (→ .wasm)
44
- └── kb-worker/ ← cdylib (→ .wasm)
45
- ```
46
-
47
- ## Crate Types
48
-
49
- ### `rlib` -- Rust Library
50
-
51
- Produces no output artifact. Compiled **into** each
52
- crate that depends on it. The compiler includes only
53
- the code each consumer actually uses (dead code
54
- elimination).
55
-
56
- - **`kbdb-shared`** is the only rlib crate.
57
-
58
- ### `cdylib` -- WebAssembly Module
59
-
60
- Produces a standalone `.wasm` file. Each cdylib crate
61
- is an entry point that compiles to a self-contained
62
- WASM binary.
63
-
64
- - **`kbdb-fs-database`** → `fs-database.wasm`
65
- - **`kbdb-query-parser`** → `query-parser.wasm`
66
- - **`kbdb-default-embedding`** → `default-embedding.wasm`
67
- - **`kbdb-worker`** → `kb-worker.wasm`
68
-
69
- ## Crate Dependency Graph
70
-
71
- ```
72
- kbdb-shared (rlib)
73
-
74
- ├──→ kbdb-fs-database (cdylib)
75
- │ produces: fs-database.wasm
76
-
77
- ├──→ kbdb-query-parser (cdylib)
78
- │ produces: query-parser.wasm
79
-
80
- ├──→ kbdb-default-embedding (cdylib)
81
- │ produces: default-embedding.wasm
82
-
83
- └──→ kbdb-worker (cdylib)
84
- produces: kb-worker.wasm
85
- also depends on:
86
- kbdb-fs-database (Cargo)
87
- kbdb-query-parser (Cargo)
88
- ```
89
-
90
- ### Cargo vs WASM Dependencies
91
-
92
- `kbdb-worker` depends on the other two crates at
93
- **two levels**:
94
-
95
- 1. **Cargo dependency** -- `kbdb-worker` lists
96
- `kbdb-fs-database` and `kbdb-query-parser` in its
97
- `Cargo.toml`. This gives it compile-time access to
98
- their type definitions and WASM import signatures.
99
-
100
- 2. **WASM runtime imports** -- at runtime,
101
- `kb-worker.wasm` imports functions from
102
- `fs-database.wasm` and `query-parser.wasm` through
103
- the shared `WebAssembly.Memory` interface.
104
-
105
- The standalone modules (`fs-database`, `query-parser`)
106
- have **no dependency** on each other or on `kb-worker`.
107
-
108
- ## Build Order
109
-
110
- ```
111
- 1. kbdb-shared (no deps, builds first)
112
- 2. kbdb-fs-database ┐ (all depend on shared,
113
- kbdb-query-parser │ built in parallel)
114
- kbdb-default-embedding┘
115
- 3. kbdb-worker (depends on all above)
116
- ```
117
-
118
- ## WASM Output
119
-
120
- ```
121
- dist/wasm/
122
- ├── fs-database/
123
- │ ├── fs-database.wasm
124
- │ └── fs-database.js ← JS glue
125
- ├── query-parser/
126
- │ ├── query-parser.wasm
127
- │ └── query-parser.js
128
- ├── embedding/
129
- │ ├── default-embedding.wasm
130
- │ └── default-embedding.js
131
- └── kb-worker/
132
- ├── kb-worker.wasm
133
- └── kb-worker.js
134
- ```
135
-
136
- All modules share one `WebAssembly.Memory`
137
- instance at runtime. Data crosses module boundaries
138
- via `(pointer, length)` pairs encoded with the
139
- `Encode` trait from `kbdb-shared`.
140
-
141
- ## WASM Size Optimization
142
-
143
- Each `.wasm` file is optimized for size:
144
-
145
- ```toml
146
- # engine/Cargo.toml [profile.release]
147
- opt-level = "z" # optimize for size
148
- lto = true # link-time optimization
149
- codegen-units = 1 # better optimization
150
- strip = true # remove debug symbols
151
- panic = "abort" # no unwinding (~10KB saved)
152
- ```
153
-
154
- The `shared` rlib is dead-code-eliminated per
155
- consumer -- each `.wasm` only includes the shared
156
- code it actually references.
157
-
158
- ---
159
-
160
- ## Crate Layouts
161
-
162
- ### kbdb-shared (rlib)
163
-
164
- Shared types, traits, memory helpers, and error
165
- types. Not compiled to WASM on its own -- compiled
166
- into each consumer.
167
-
168
- Namespaces are first-level directories inside `src/`.
169
- Each namespace owns one concern.
170
-
171
- ```
172
- engine/crates/shared/
173
- ├── Cargo.toml
174
- └── src/
175
- ├── lib.rs ← pub mod declarations
176
-
177
- ├── memory/ ← memory management
178
- │ ├── mod.rs
179
- │ └── alloc.rs
180
-
181
- ├── encode/ ← binary serialization
182
- │ ├── mod.rs
183
- │ └── encode.rs
184
-
185
- ├── kbid/ ← content-addressed ID
186
- │ ├── mod.rs
187
- │ └── kbid.rs
188
-
189
- ├── term/ ← search term newtype
190
- │ ├── mod.rs
191
- │ └── term.rs
192
-
193
- ├── section/ ← section types & records
194
- │ ├── mod.rs
195
- │ └── section.rs
196
-
197
- ├── document/ ← document manifests
198
- │ ├── mod.rs
199
- │ └── document.rs
200
-
201
- ├── query/ ← query plan & matches
202
- │ ├── mod.rs
203
- │ └── query.rs
204
-
205
- ├── corpus/ ← corpus statistics
206
- │ ├── mod.rs
207
- │ └── corpus.rs
208
-
209
- ├── content-parser/ ← content marker extraction
210
- │ ├── mod.rs
211
- │ ├── types.rs
212
- │ ├── extract.rs
213
- │ └── strip.rs
214
-
215
- ├── content-composer/ ← content composition
216
- │ ├── mod.rs
217
- │ ├── types.rs
218
- │ ├── compose.rs
219
- │ └── render.rs
220
-
221
- ├── pipeline/ ← 9-stage tokenizer
222
- │ ├── mod.rs
223
- │ ├── markers.rs
224
- │ ├── unicode.rs
225
- │ ├── segment.rs
226
- │ ├── identifiers.rs
227
- │ ├── case.rs
228
- │ ├── stopwords.rs
229
- │ ├── synonyms.rs
230
- │ ├── stem.rs
231
- │ ├── ngram.rs
232
- │ └── token_result.rs
233
-
234
- └── error/ ← error hierarchy
235
- ├── mod.rs
236
- └── error.rs
237
- ```
238
-
239
- Detailed docs: [shared/module.md](shared/module.md)
240
-
241
- ### kbdb-fs-database (cdylib → .wasm)
242
-
243
- Filesystem storage engine. Section CRUD, document
244
- manifests, B+ tree indexes, content-addressable
245
- storage.
246
-
247
- ```
248
- engine/crates/fs-database/
249
- ├── Cargo.toml
250
- └── src/
251
- ├── lib.rs ← WASM exports
252
- ├── io.rs ← host import wrappers
253
- ├── mem.rs ← shared-memory helpers
254
- ├── catalog.rs ← catalog.toml
255
-
256
- ├── section/ ← section CRUD
257
- │ ├── mod.rs
258
- │ ├── hash.rs
259
- │ ├── parse.rs
260
- │ └── shard.rs
261
-
262
- ├── document.rs ← document manifests
263
-
264
- ├── index/ ← index subsystem
265
- │ ├── mod.rs
266
- │ ├── btree.rs
267
- │ ├── inverted.rs
268
- │ ├── positional.rs
269
- │ └── corpus.rs
270
-
271
- ├── query_exec.rs ← query plan execution
272
- ├── integrity.rs ← checksum, GC
273
- └── atomic.rs ← temp-file + rename
274
- ```
275
-
276
- Detailed docs:
277
- [fs-database/module.md](fs-database/module.md)
278
-
279
- ### kbdb-query-parser (cdylib → .wasm)
280
-
281
- Query parsing, keyword extraction, and ranking.
282
- Tokenization is imported from `kbdb-shared`'s
283
- `pipeline` module.
284
-
285
- ```
286
- engine/crates/query-parser/
287
- ├── Cargo.toml
288
- └── src/
289
- ├── lib.rs ← WASM exports
290
- ├── mem.rs ← shared-memory helpers
291
-
292
- ├── parse.rs ← query → QueryPlan
293
-
294
- ├── extract/ ← keyword extraction
295
- │ ├── mod.rs
296
- │ ├── rake.rs
297
- │ └── tfidf.rs
298
-
299
- ├── rank/ ← scoring functions
300
- │ ├── mod.rs
301
- │ ├── bm25f.rs
302
- │ ├── proximity.rs
303
- │ ├── zone.rs
304
- │ └── freshness.rs
305
-
306
- └── cache.rs ← query-scoped cache
307
- ```
308
-
309
- Detailed docs:
310
- [query-parser/module.md](query-parser/module.md)
311
-
312
- ### kbdb-default-embedding (cdylib → .wasm)
313
-
314
- TF-IDF embedding computation. Reuses kbdb-shared's
315
- tokenization pipeline to produce feature-hashed
316
- sublinear TF vectors (256 dimensions, L2-normalized).
317
- Depends only on `kbdb-shared`. No host imports --
318
- pure computation with no file I/O.
319
-
320
- ```
321
- engine/crates/default-embedding/
322
- ├── Cargo.toml
323
- └── src/
324
- ├── lib.rs ← WASM exports
325
- ├── mem.rs ← shared-memory helpers
326
- ├── fnv1a.rs ← FNV-1a hash function
327
- └── feature_hash.rs ← feature hashing + L2 norm
328
- ```
329
-
330
- Detailed docs:
331
- [embedding/module.md](embedding/module.md)
332
-
333
- ### kbdb-worker (cdylib → .wasm)
334
-
335
- Orchestration layer. Imports the other two WASM
336
- modules, manages LRU cache and async result tokens.
337
-
338
- ```
339
- engine/crates/kb-worker/
340
- ├── Cargo.toml
341
- └── src/
342
- ├── lib.rs ← WASM exports
343
- ├── mem.rs ← shared-memory helpers
344
- ├── context.rs ← database context
345
-
346
- ├── orchestrate/ ← operation flows
347
- │ ├── mod.rs
348
- │ ├── search.rs
349
- │ ├── write.rs
350
- │ └── retrieve.rs
351
-
352
- ├── cache/ ← LRU cache
353
- │ ├── mod.rs
354
- │ ├── lru.rs
355
- │ ├── entry.rs
356
- │ └── config.rs
357
-
358
- ├── token.rs ← async result tokens
359
- └── status.rs ← status reporting
360
- ```
361
-
362
- Detailed docs:
363
- [kb-worker/module.md](kb-worker/module.md)
364
-
365
- ---
366
-
367
- ## Module Conventions
368
-
369
- ### File Roles
370
-
371
- | File | Purpose |
372
- |---------------|----------------------------|
373
- | `lib.rs` | Crate root. `pub mod` declarations, WASM exports |
374
- | `mod.rs` | Module entry. Declares sub-modules, re-exports public API |
375
- | `*.rs` | Implementation. Types, functions, or traits |
376
-
377
- ### Naming
378
-
379
- | Rust convention | File name |
380
- |------------------|----------------------|
381
- | Module | `snake_case/` |
382
- | Source file | `snake_case.rs` |
383
- | Struct / Enum | `PascalCase` |
384
- | Function | `snake_case` |
385
- | Trait | `PascalCase` |
386
- | Constant | `SCREAMING_SNAKE` |
387
-
388
- ### Visibility
389
-
390
- | Modifier | Scope |
391
- |----------------|---------------------------|
392
- | (none) | Private to current module |
393
- | `pub(super)` | Parent module only |
394
- | `pub(crate)` | Anywhere in the crate |
395
- | `pub` | External consumers |
396
-
397
- ### `mod.rs` Pattern
398
-
399
- Every directory module has a `mod.rs` that declares
400
- its children and re-exports the public API:
401
-
402
- ```rust
403
- // corpus/mod.rs
404
- mod types;
405
- mod functions;
406
-
407
- pub use types::CorpusStats;
408
- pub use functions::get_corpus_stats;
409
- ```
410
-
411
- This is analogous to TypeScript's `index.ts` with
412
- re-exports -- but in Rust, if a file is not declared
413
- with `mod`, the compiler does not see it even if it
414
- exists on disk.
415
-
416
- ### Shared Code Reuse
417
-
418
- Crates import shared namespaces via Cargo dependency:
419
-
420
- ```toml
421
- # fs-database/Cargo.toml
422
- [dependencies]
423
- kbdb-shared = { path = "../shared" }
424
- ```
425
-
426
- ```rust
427
- // fs-database/src/lib.rs
428
- use kbdb_shared::corpus::CorpusStats;
429
- use kbdb_shared::encode::Encode;
430
- use kbdb_shared::kbid::KbId;
431
- ```
432
-
433
- Only the imported code ends up in the final `.wasm`
434
- -- unused shared modules are stripped by dead code
435
- elimination.
436
-
437
- ---
438
-
439
- ## Testing Structure
440
-
441
- ### Unit Tests (TDD)
442
-
443
- Inline `#[cfg(test)] mod tests` block at the bottom
444
- of each `.rs` file. Written before the implementation
445
- (spec-first).
446
-
447
- ### BDD Module Tests
448
-
449
- `tests/` subdirectory inside a module for cross-unit
450
- scenarios:
451
-
452
- ```
453
- section/
454
- ├── mod.rs
455
- ├── hash.rs
456
- ├── parse.rs
457
- └── tests/
458
- ├── mod.rs
459
- └── hash_and_shard.rs
460
- ```
461
-
462
- ### Crate-Level Integration Tests
463
-
464
- `engine/tests/` directory for each crate's WASM API
465
- tests using `#[wasm_bindgen_test]`.
466
-
467
- ### Running Tests
468
-
469
- ```sh
470
- cd engine && cargo test # all
471
- cd engine && cargo test -p kbdb-shared # one crate
472
- cd engine && wasm-pack test --node # WASM tests
473
- ```
474
-
475
- ---
476
-
477
- ## Doc Directory Structure
478
-
479
- Documentation mirrors the source layout:
480
-
481
- ```
482
- docs/modules/rust/
483
- ├── overview.md ← this file
484
-
485
- ├── shared/ ← kbdb-shared crate
486
- │ ├── module.md ← crate overview
487
- │ ├── memory/
488
- │ │ ├── module.md ← namespace overview
489
- │ │ └── functions.md ← function docs
490
- │ ├── encode/
491
- │ │ ├── module.md
492
- │ │ └── traits.md
493
- │ ├── kbid/
494
- │ │ ├── module.md
495
- │ │ └── types.md
496
- │ └── ... ← one dir per namespace
497
-
498
- ├── fs-database/ ← kbdb-fs-database crate
499
- │ ├── module.md ← crate overview
500
- │ ├── types/
501
- │ │ ├── module.md
502
- │ │ ├── catalog.md
503
- │ │ └── section.md
504
- │ ├── functions/
505
- │ │ ├── module.md
506
- │ │ ├── io.md
507
- │ │ └── ...
508
- │ └── indexes/
509
- │ ├── module.md
510
- │ └── ...
511
-
512
- ├── query-parser/ ← kbdb-query-parser crate
513
- │ ├── module.md
514
- │ ├── types/
515
- │ ├── functions/
516
- │ └── ...
517
-
518
- ├── embedding/ ← kbdb-default-embedding crate
519
- │ └── module.md
520
-
521
- └── kb-worker/ ← kbdb-worker crate
522
- ├── module.md
523
- ├── types/
524
- ├── functions/
525
- └── ...
526
- ```
527
-
528
- `module.md` = `mod.rs` (namespace entry point).
529
- Category files (`types.md`, `functions.md`,
530
- `traits.md`) document the implementations within
531
- each namespace.
@@ -1,56 +0,0 @@
1
- # functions::extract -- Keyword Extraction
2
-
3
- *RAKE keyphrase extraction and TF-IDF term weighting.*
4
-
5
- ## Source
6
-
7
- `engine/crates/query-parser/src/extract/`
8
-
9
- ## RAKE (`rake.rs`)
10
-
11
- ```rust
12
- pub fn extract_keyphrases(
13
- tokens: &[Token],
14
- stop_words: &HashSet<String>,
15
- ) -> Vec<Keyphrase>;
16
- ```
17
-
18
- Rapid Automatic Keyword Extraction. Splits on stop
19
- words to identify candidate phrases. Scores each
20
- candidate by the ratio of word degree to word
21
- frequency. Unsupervised, no ML dependencies.
22
-
23
- ## TF-IDF (`tfidf.rs`)
24
-
25
- ```rust
26
- pub fn compute_tf(
27
- tokens: &[Token],
28
- ) -> Vec<(Term, f32)>;
29
-
30
- pub fn compute_field_tf(
31
- heading_tokens: &[Token],
32
- body_tokens: &[Token],
33
- code_tokens: &[Token],
34
- ) -> Vec<(Term, FieldTf)>;
35
-
36
- pub fn compute_tfidf(
37
- tf: &[(Term, f32)],
38
- idf: &dyn Fn(&Term) -> f32,
39
- ) -> Vec<WeightedTerm>;
40
- ```
41
-
42
- `compute_tf` calculates per-section term frequency
43
- for a single token stream.
44
-
45
- `compute_field_tf` computes per-field term
46
- frequencies from separately tokenized field streams.
47
- `kb-worker` calls this during indexing after running
48
- the tokenization pipeline separately for each field
49
- (title → heading, body + description → body,
50
- code → code). Returns `FieldTf` values with heading,
51
- body, and code frequencies per term.
52
-
53
- `compute_tfidf` combines TF with corpus-wide IDF
54
- (provided by `fs-database.wasm` via `kb-worker.wasm`)
55
- to produce final weights reflecting each term's
56
- discriminative value.
@@ -1,18 +0,0 @@
1
- # query-parser/functions -- Operations
2
-
3
- *Functions for query parsing, keyword extraction,
4
- and ranking.*
5
-
6
- ## Modules
7
-
8
- - **[parse](parse.md)** -- Query string parsing into
9
- structured `QueryPlan`.
10
- - **[extract](extract.md)** -- RAKE keyphrase
11
- extraction and TF-IDF term weighting.
12
- - **[rank](rank.md)** -- BM25F, proximity, zone, and
13
- freshness scoring functions.
14
-
15
- Tokenization is provided by
16
- [kbdb-shared pipeline](../../shared/pipeline/functions.md).
17
- This crate re-exports it via the `qp_tokenize`
18
- WASM export.
@@ -1,33 +0,0 @@
1
- # functions::parse -- Query Parsing
2
-
3
- *Parse a search query string into a structured
4
- `QueryPlan`.*
5
-
6
- ## Source
7
-
8
- `engine/crates/query-parser/src/parse.rs`
9
-
10
- ## Function
11
-
12
- ```rust
13
- pub fn parse_query(input: &str) -> QueryPlan;
14
- ```
15
-
16
- ## Parsing Stages
17
-
18
- 1. **Tokenize** -- Run the query through the
19
- tokenization pipeline.
20
- 2. **Parse syntax** -- Recognize operators: quoted
21
- phrases (`"..."`), boolean AND/OR, exclusions
22
- (`-term`).
23
- 3. **Build plan** -- Produce the `QueryPlan` with
24
- terms, phrase groups, exclusions, and match mode.
25
-
26
- ## Examples
27
-
28
- | Input | terms | phrases | exclusions | mode |
29
- |----------------------|--------------|------------------|------------|------|
30
- | `rust wasm` | [rust, wasm] | [] | [] | And |
31
- | `"file database"` | [] | [[file, databas]]| [] | And |
32
- | `rust -draft` | [rust] | [] | [draft] | And |
33
- | `rust OR wasm` | [rust, wasm] | [] | [] | Or |
@@ -1,9 +0,0 @@
1
- # functions::pipeline -- Moved to kbdb-shared
2
-
3
- The tokenization pipeline has moved to `kbdb-shared`.
4
-
5
- See [shared/pipeline/functions.md](../../shared/pipeline/functions.md)
6
- for the full documentation.
7
-
8
- This crate re-exports the pipeline via the
9
- `qp_tokenize` WASM FFI export.