@dikolab/kbdb 0.4.0 → 0.4.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 (99) hide show
  1. package/README.md +13 -5
  2. package/dist/{chunk-BJPSPNGX.mjs → chunk-BJXEVALU.mjs} +115 -1
  3. package/dist/chunk-BJXEVALU.mjs.map +7 -0
  4. package/dist/cli.cjs +462 -79
  5. package/dist/cli.cjs.map +4 -4
  6. package/dist/cli.mjs +356 -79
  7. package/dist/cli.mjs.map +4 -4
  8. package/dist/kbdb-worker.cjs +413 -53
  9. package/dist/kbdb-worker.cjs.map +4 -4
  10. package/dist/mod.cjs +230 -54
  11. package/dist/mod.cjs.map +4 -4
  12. package/dist/mod.mjs +229 -53
  13. package/dist/mod.mjs.map +4 -4
  14. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +5 -0
  15. package/dist/src/shared/embedding/classes/tfidf-embedding-provider.class.d.ts +28 -0
  16. package/dist/src/shared/embedding/constants/tfidf-defaults.constant.d.ts +4 -0
  17. package/dist/src/shared/embedding/functions/create-embedding-provider.function.d.ts +5 -2
  18. package/dist/src/shared/embedding/index.d.ts +2 -0
  19. package/dist/src/shared/log/constants/log-colors.constant.d.ts +5 -0
  20. package/dist/src/shared/log/constants/log-defaults.constant.d.ts +3 -0
  21. package/dist/src/shared/log/constants/log-icons.constant.d.ts +3 -0
  22. package/dist/src/shared/log/functions/configure-log.function.d.ts +12 -0
  23. package/dist/src/shared/log/functions/log.function.d.ts +28 -0
  24. package/dist/src/shared/log/functions/parse-log-level.function.d.ts +10 -0
  25. package/dist/src/shared/log/functions/resolve-log-level.function.d.ts +12 -0
  26. package/dist/src/shared/log/functions/write-stderr.function.d.ts +10 -0
  27. package/dist/src/shared/log/index.d.ts +10 -0
  28. package/dist/src/shared/log/typings/log-config.interface.d.ts +7 -0
  29. package/dist/src/shared/log/typings/log-level.type.d.ts +7 -0
  30. package/dist/src/shared/log/typings/log-output.interface.d.ts +4 -0
  31. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  32. package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +7 -0
  33. package/dist/src/shared/worker-client/functions/retry-on-timeout.function.d.ts +1 -0
  34. package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
  35. package/dist/src/shared/worker-daemon/functions/run-worker.function.d.ts +6 -1
  36. package/dist/src/shared/worker-daemon/typings/wasm-modules.interface.d.ts +5 -0
  37. package/dist/wasm/default-embedding/kbdb_default_embedding.d.ts +55 -0
  38. package/dist/wasm/default-embedding/kbdb_default_embedding.js +156 -0
  39. package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
  40. package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm.d.ts +12 -0
  41. package/dist/wasm/default-embedding/package.json +13 -0
  42. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  43. package/dist/wasm/fs-migration/kbdb_fs_migration.d.ts +38 -0
  44. package/dist/wasm/fs-migration/kbdb_fs_migration.js +130 -0
  45. package/dist/wasm/fs-migration/kbdb_fs_migration_bg.wasm +0 -0
  46. package/dist/wasm/fs-migration/kbdb_fs_migration_bg.wasm.d.ts +9 -0
  47. package/dist/wasm/fs-migration/package.json +13 -0
  48. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  49. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  50. package/dist/worker.mjs +306 -54
  51. package/dist/worker.mjs.map +4 -4
  52. package/docs/details/agent-tooling.md +10 -0
  53. package/docs/details/cli.md +29 -13
  54. package/docs/details/knowledge-base.md +15 -8
  55. package/docs/details/mcp-server.md +16 -1
  56. package/docs/details/search-and-ranking.md +6 -2
  57. package/docs/goals/cli.md +33 -4
  58. package/docs/goals/content-parser.md +1 -1
  59. package/docs/goals/hybrid-search.md +71 -42
  60. package/docs/goals/mcp.md +3 -1
  61. package/docs/goals/overview.md +1 -1
  62. package/docs/goals/query-parser.md +1 -1
  63. package/docs/goals/semantic-dedup.md +7 -3
  64. package/docs/goals/worker-daemon.md +31 -20
  65. package/docs/modules/overview.md +43 -22
  66. package/docs/modules/rust/embedding/module.md +91 -0
  67. package/docs/modules/rust/overview.md +56 -21
  68. package/docs/modules/rust/query-parser/functions/module.md +7 -5
  69. package/docs/modules/rust/query-parser/functions/pipeline.md +6 -138
  70. package/docs/modules/rust/query-parser/module.md +16 -22
  71. package/docs/modules/rust/query-parser/types/module.md +5 -4
  72. package/docs/modules/rust/query-parser/types/token.md +5 -1
  73. package/docs/modules/rust/shared/content-parser/functions.md +1 -1
  74. package/docs/modules/rust/shared/memory/module.md +1 -1
  75. package/docs/modules/rust/shared/module.md +33 -5
  76. package/docs/modules/rust/shared/pipeline/functions.md +141 -0
  77. package/docs/modules/rust/shared/pipeline/module.md +62 -0
  78. package/docs/modules/rust/shared/pipeline/types.md +43 -0
  79. package/docs/modules/rust/shared/section/module.md +1 -1
  80. package/docs/modules/rust/shared/section/types.md +1 -1
  81. package/docs/modules/typescript/cli.md +4 -2
  82. package/docs/modules/typescript/kbdb-worker.md +20 -5
  83. package/docs/modules/typescript/overview.md +28 -6
  84. package/docs/modules/typescript/shared/cli/functions.md +15 -4
  85. package/docs/modules/typescript/shared/cli/typings.md +21 -0
  86. package/docs/modules/typescript/shared/embedding/functions.md +30 -3
  87. package/docs/modules/typescript/shared/embedding/module.md +10 -4
  88. package/docs/modules/typescript/shared/embedding/typings.md +7 -5
  89. package/docs/modules/typescript/shared/log/constants.md +82 -0
  90. package/docs/modules/typescript/shared/log/functions.md +131 -0
  91. package/docs/modules/typescript/shared/log/module.md +153 -0
  92. package/docs/modules/typescript/shared/log/typings.md +82 -0
  93. package/docs/modules/typescript/shared/module.md +22 -6
  94. package/docs/modules/typescript/shared/worker-daemon/functions.md +19 -6
  95. package/docs/modules/typescript/shared/worker-daemon/module.md +5 -2
  96. package/docs/modules/typescript/shared/worker-daemon/typings.md +13 -7
  97. package/docs/release-notes/0.4.1.md +149 -0
  98. package/package.json +2 -2
  99. package/dist/chunk-BJPSPNGX.mjs.map +0 -7
@@ -12,9 +12,10 @@ final `dist/` output.*
12
12
 
13
13
  engine/crates/ src/shared/
14
14
  ├── shared (rlib) ├── worker-daemon/
15
- ├── fs-database (cdylib) │ ├── wasm/ ← 3 WASM modules
15
+ ├── fs-database (cdylib) │ ├── wasm/ ← 4 WASM modules
16
16
  ├── query-parser (cdylib) │ │ ├── fs-database.*
17
- └── kb-worker (cdylib) │ ├── query-parser.*
17
+ ├── default-embedding (cdylib)│ │ ├── query-parser.*
18
+ └── kb-worker (cdylib) │ │ ├── default-embedding.*
18
19
  │ │ │ └── kb-worker.*
19
20
  │ wasm-pack build │ └── functions/
20
21
  └─────────────────────┘ └── load-wasm-modules
@@ -31,7 +32,7 @@ final `dist/` output.*
31
32
 
32
33
  ## Phase 1 -- Build Rust to WASM
33
34
 
34
- The Rust engine compiles to three standalone `.wasm`
35
+ The Rust engine compiles to four standalone `.wasm`
35
36
  files. The `kbdb-shared` crate is an `rlib` -- it
36
37
  produces no artifact, compiled **into** each consumer
37
38
  via dead code elimination.
@@ -43,15 +44,17 @@ via dead code elimination.
43
44
  | `kbdb-shared` | `rlib` | none (compiled into consumers) |
44
45
  | `kbdb-fs-database` | `cdylib` | `fs-database.wasm` |
45
46
  | `kbdb-query-parser`| `cdylib` | `query-parser.wasm` |
47
+ | `kbdb-default-embedding` | `cdylib` | `default-embedding.wasm` |
46
48
  | `kbdb-worker` | `cdylib` | `kb-worker.wasm` |
47
49
 
48
50
  ### Build Order
49
51
 
50
52
  ```
51
- 1. kbdb-shared (leaf, no deps)
52
- 2. kbdb-fs-database ┐ (both depend on shared,
53
- kbdb-query-parser built in parallel)
54
- 3. kbdb-worker (depends on all three)
53
+ 1. kbdb-shared (leaf, no deps)
54
+ 2. kbdb-fs-database ┐ (all depend on shared,
55
+ kbdb-query-parser built in parallel)
56
+ kbdb-default-embedding
57
+ 3. kbdb-worker (depends on all above)
55
58
  ```
56
59
 
57
60
  ### Build Command
@@ -62,20 +65,24 @@ npm run build:wasm
62
65
 
63
66
  This runs `wasm-pack build` for each cdylib crate.
64
67
  Output lands in the TypeScript source tree at
65
- `src/shared/worker-daemon/wasm/`:
68
+ `src/wasm/`:
66
69
 
67
70
  ```sh
68
71
  wasm-pack build crates/fs-database \
69
72
  --target no-modules \
70
- --out-dir ../../../../src/shared/worker-daemon/wasm/fs-database
73
+ --out-dir ../../../src/wasm/fs-database
71
74
 
72
75
  wasm-pack build crates/query-parser \
73
76
  --target no-modules \
74
- --out-dir ../../../../src/shared/worker-daemon/wasm/query-parser
77
+ --out-dir ../../../src/wasm/query-parser
78
+
79
+ wasm-pack build crates/default-embedding \
80
+ --target no-modules \
81
+ --out-dir ../../../src/wasm/default-embedding
75
82
 
76
83
  wasm-pack build crates/kb-worker \
77
84
  --target no-modules \
78
- --out-dir ../../../../src/shared/worker-daemon/wasm/kb-worker
85
+ --out-dir ../../../src/wasm/kb-worker
79
86
  ```
80
87
 
81
88
  ### Size Optimization
@@ -115,6 +122,10 @@ src/shared/worker-daemon/
115
122
  │ │ ├── query-parser.wasm
116
123
  │ │ ├── query-parser.js
117
124
  │ │ └── query-parser.d.ts
125
+ │ ├── default-embedding/
126
+ │ │ ├── default-embedding.wasm
127
+ │ │ ├── default-embedding.js
128
+ │ │ └── default-embedding.d.ts
118
129
  │ └── kb-worker/
119
130
  │ ├── kb-worker.wasm
120
131
  │ ├── kb-worker.js
@@ -145,11 +156,14 @@ loadWasmModules(config)
145
156
  │ (standalone, shared memory + host I/O)
146
157
  │ ↑ steps 2 and 3 run in parallel
147
158
 
148
- └─ 4. Compile + instantiate kb-worker.wasm
159
+ ├─ 4. Compile + instantiate default-embedding.wasm
160
+ │ (standalone, no host imports -- pure computation)
161
+
162
+ └─ 5. Compile + instantiate kb-worker.wasm
149
163
  (imports query-parser + fs-database exports)
150
164
  ```
151
165
 
152
- All three modules share one `WebAssembly.Memory`
166
+ All four WASM modules share one `WebAssembly.Memory`
153
167
  instance. Data crosses module boundaries via
154
168
  `(pointer, length)` pairs encoded with the `Encode`
155
169
  trait from `kbdb-shared`.
@@ -163,7 +177,7 @@ TypeScript module directly accesses WASM files or the
163
177
  ## Phase 3 -- TypeScript Modules
164
178
 
165
179
  All TypeScript logic lives under `src/shared/` in
166
- 8 sub-modules. Two thin entry points at the project
180
+ 9 sub-modules. Two thin entry points at the project
167
181
  root dispatch into them.
168
182
 
169
183
  ### Entry Points
@@ -186,24 +200,31 @@ root dispatch into them.
186
200
  | `runtime/` | Deno / Node.js detection |
187
201
  | `platform/` | OS abstractions (tmpdir, PID, IPC paths) |
188
202
  | `hash/` | SHA-256 via Web Crypto API |
203
+ | `log/` | Structured logging with configurable levels and ANSI formatting |
189
204
 
190
205
  ### Module Dependencies
191
206
 
192
207
  ```
193
208
  src/cli.ts
194
209
  ├── shared/cli/ ──→ shared/worker-client/
210
+ │ └── shared/log/
195
211
  └── shared/mcp/ ──→ shared/worker-client/
196
- ├── shared/platform/
197
- └── shared/hash/
212
+ ├── shared/platform/
213
+ │ ├── shared/hash/
214
+ │ └── shared/log/
215
+ └── shared/log/
198
216
 
199
217
  src/worker.ts
200
218
  └── shared/worker-daemon/
201
219
  ├── shared/platform/
220
+ ├── shared/log/
202
221
  └── wasm/ (fs-database, query-parser,
203
- kb-worker)
222
+ default-embedding, kb-worker)
204
223
 
205
224
  mod.ts
206
225
  └── shared/version/
226
+
227
+ shared/log/ (no dependencies -- standalone)
207
228
  ```
208
229
 
209
230
  **Full TypeScript architecture:**
@@ -266,7 +287,7 @@ are loaded at runtime by the daemon via
266
287
  ## Full Build Sequence
267
288
 
268
289
  ```sh
269
- # 1. Build WASM (Rust → .wasm → src/shared/worker-daemon/wasm/)
290
+ # 1. Build WASM (Rust → .wasm → src/wasm/)
270
291
  npm run build:wasm
271
292
 
272
293
  # 2. Build TypeScript (src/ → dist/)
@@ -282,8 +303,8 @@ npm run build:all
282
303
  build:all
283
304
 
284
305
  ├─ build:wasm
285
- │ ├─ cargo build (4 crates)
286
- │ └─ wasm-pack build (3 cdylib → wasm/)
306
+ │ ├─ cargo build (5 crates)
307
+ │ └─ wasm-pack build (4 cdylib → wasm/)
287
308
 
288
309
  └─ build
289
310
  ├─ esbuild (2 entry points → dist/)
@@ -294,5 +315,5 @@ build:all
294
315
 
295
316
  | Layer | Overview | Modules |
296
317
  |------------|-----------------------------------|---------|
297
- | Rust/WASM | [rust/overview.md](rust/overview.md) | 4 crates, 9 shared namespaces |
298
- | TypeScript | [typescript/overview.md](typescript/overview.md) | 2 entry points, 8 shared modules |
318
+ | Rust/WASM | [rust/overview.md](rust/overview.md) | 5 crates, 9 shared namespaces |
319
+ | TypeScript | [typescript/overview.md](typescript/overview.md) | 2 entry points, 9 shared modules |
@@ -0,0 +1,91 @@
1
+ # default-embedding -- TF-IDF Vector Computation
2
+
3
+ **Source:** `engine/crates/default-embedding/`
4
+ **Crate type:** `cdylib` + `rlib`
5
+ **Output:** `default-embedding.wasm`
6
+
7
+ ## Responsibility
8
+
9
+ Computes feature-hashed sublinear TF vectors for the
10
+ default embedding provider. Reuses kbdb-shared's
11
+ 9-stage tokenization pipeline (NFC normalization,
12
+ Unicode segmentation, camelCase splitting, stop-word
13
+ removal, synonym expansion, Snowball stemming) so
14
+ that TF-IDF vectors are token-consistent with the
15
+ lexical index.
16
+
17
+ No host imports -- pure computation with no file I/O.
18
+ The WASM module is instantiated without an import
19
+ object.
20
+
21
+ ## Algorithm
22
+
23
+ 1. Tokenize text via `kbdb_shared::pipeline::tokenize`
24
+ 2. Count term frequencies on stemmed tokens
25
+ 3. Hash each stemmed token to a bucket using FNV-1a:
26
+ `bucket = fnv1a(token) % 256`
27
+ 4. Apply sign trick to reduce collision bias:
28
+ `sign = if fnv1a(token + "_s") % 2 == 0 { 1 } else { -1 }`
29
+ 5. Accumulate `sign * (1.0 + tf.ln())` per bucket
30
+ (sublinear TF provides diminishing returns for
31
+ repeated terms)
32
+ 6. L2-normalize the vector
33
+
34
+ Output: 256-dimensional `Float32Array`, suitable for
35
+ cosine similarity via `cosineSimilarity()` in the
36
+ TypeScript embedding module.
37
+
38
+ ## Directory Layout
39
+
40
+ ```
41
+ engine/crates/default-embedding/
42
+ ├── Cargo.toml
43
+ └── src/
44
+ ├── lib.rs ← WASM exports
45
+ ├── mem.rs ← shared-memory helpers
46
+ ├── fnv1a.rs ← FNV-1a hash function
47
+ └── feature_hash.rs ← feature hashing + L2 norm
48
+ ```
49
+
50
+ ## WASM Exports
51
+
52
+ | Export | Signature | Description |
53
+ |-------------------------------|------------------------|-------------|
54
+ | `embedding_tfidf` | `(ptr, len) -> u32` | Single text → 256×f32 vector |
55
+ | `embedding_tfidf_batch` | `(ptr, len) -> u32` | Newline-delimited texts → count + count×256 f32s |
56
+ | `embedding_dimensions` | `() -> u32` | Returns 256 |
57
+ | `embedding_model_name` | `(ptr, len) -> u32` | Writes `tfidf-v1` to return slot |
58
+
59
+ All exports use the standard return-slot protocol:
60
+ result data is written via `mem::set_return(ptr, len)`
61
+ and read by TypeScript via `get_return_ptr` /
62
+ `get_return_len`.
63
+
64
+ ## Dependencies
65
+
66
+ ```toml
67
+ [dependencies]
68
+ kbdb-shared = { path = "../shared" }
69
+ wasm-bindgen = "0.2"
70
+ ```
71
+
72
+ - **kbdb-shared** -- memory management (`kbdb_alloc`,
73
+ `kbdb_free`, `set_return`, `read_str`) and
74
+ tokenization pipeline (`pipeline::tokenize`,
75
+ `pipeline::TokenResult`)
76
+
77
+ ## Dependency Direction
78
+
79
+ ```
80
+ kbdb-shared (rlib)
81
+ │ provides: memory, pipeline::tokenize
82
+
83
+ └──→ kbdb-default-embedding (cdylib)
84
+ uses: shared memory + shared tokenization
85
+ consumed by: TypeScript TfidfEmbeddingProvider
86
+ ```
87
+
88
+ The embedding crate is a leaf in the dependency graph.
89
+ No other Rust crate depends on it. It is loaded as a
90
+ standalone WASM instance by the TypeScript worker
91
+ daemon.
@@ -27,7 +27,7 @@ other file. Code sharing requires a crate dependency.
27
27
  ## Workspace
28
28
 
29
29
  All Rust code lives in `engine/`. The workspace
30
- contains four crates under `engine/crates/`:
30
+ contains six crates under `engine/crates/`:
31
31
 
32
32
  ```
33
33
  engine/
@@ -38,6 +38,8 @@ engine/
38
38
  └── crates/
39
39
  ├── shared/ ← rlib (library)
40
40
  ├── fs-database/ ← cdylib (→ .wasm)
41
+ ├── fs-migration/ ← cdylib (→ .wasm)
42
+ ├── default-embedding/ ← cdylib (→ .wasm)
41
43
  ├── query-parser/ ← cdylib (→ .wasm)
42
44
  └── kb-worker/ ← cdylib (→ .wasm)
43
45
  ```
@@ -61,6 +63,7 @@ WASM binary.
61
63
 
62
64
  - **`kbdb-fs-database`** → `fs-database.wasm`
63
65
  - **`kbdb-query-parser`** → `query-parser.wasm`
66
+ - **`kbdb-default-embedding`** → `default-embedding.wasm`
64
67
  - **`kbdb-worker`** → `kb-worker.wasm`
65
68
 
66
69
  ## Crate Dependency Graph
@@ -74,6 +77,9 @@ kbdb-shared (rlib)
74
77
  ├──→ kbdb-query-parser (cdylib)
75
78
  │ produces: query-parser.wasm
76
79
 
80
+ ├──→ kbdb-default-embedding (cdylib)
81
+ │ produces: default-embedding.wasm
82
+
77
83
  └──→ kbdb-worker (cdylib)
78
84
  produces: kb-worker.wasm
79
85
  also depends on:
@@ -102,11 +108,11 @@ have **no dependency** on each other or on `kb-worker`.
102
108
  ## Build Order
103
109
 
104
110
  ```
105
- 1. kbdb-shared (no deps, builds first)
106
- 2. kbdb-fs-database (depends on shared)
107
- kbdb-query-parser (depends on shared)
108
- ↑ these two build in parallel
109
- 3. kbdb-worker (depends on all three)
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)
110
116
  ```
111
117
 
112
118
  ## WASM Output
@@ -119,12 +125,15 @@ dist/wasm/
119
125
  ├── query-parser/
120
126
  │ ├── query-parser.wasm
121
127
  │ └── query-parser.js
128
+ ├── embedding/
129
+ │ ├── default-embedding.wasm
130
+ │ └── default-embedding.js
122
131
  └── kb-worker/
123
132
  ├── kb-worker.wasm
124
133
  └── kb-worker.js
125
134
  ```
126
135
 
127
- All three modules share one `WebAssembly.Memory`
136
+ All modules share one `WebAssembly.Memory`
128
137
  instance at runtime. Data crosses module boundaries
129
138
  via `(pointer, length)` pairs encoded with the
130
139
  `Encode` trait from `kbdb-shared`.
@@ -209,6 +218,19 @@ engine/crates/shared/
209
218
  │ ├── compose.rs
210
219
  │ └── render.rs
211
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
+
212
234
  └── error/ ← error hierarchy
213
235
  ├── mod.rs
214
236
  └── error.rs
@@ -256,8 +278,9 @@ Detailed docs:
256
278
 
257
279
  ### kbdb-query-parser (cdylib → .wasm)
258
280
 
259
- Tokenization pipeline, query parsing, keyword
260
- extraction, and ranking.
281
+ Query parsing, keyword extraction, and ranking.
282
+ Tokenization is imported from `kbdb-shared`'s
283
+ `pipeline` module.
261
284
 
262
285
  ```
263
286
  engine/crates/query-parser/
@@ -266,18 +289,6 @@ engine/crates/query-parser/
266
289
  ├── lib.rs ← WASM exports
267
290
  ├── mem.rs ← shared-memory helpers
268
291
 
269
- ├── pipeline/ ← 9-stage tokenizer
270
- │ ├── mod.rs
271
- │ ├── markers.rs
272
- │ ├── unicode.rs
273
- │ ├── segment.rs
274
- │ ├── identifiers.rs
275
- │ ├── case.rs
276
- │ ├── stopwords.rs
277
- │ ├── synonyms.rs
278
- │ ├── stem.rs
279
- │ └── ngram.rs
280
-
281
292
  ├── parse.rs ← query → QueryPlan
282
293
 
283
294
  ├── extract/ ← keyword extraction
@@ -298,6 +309,27 @@ engine/crates/query-parser/
298
309
  Detailed docs:
299
310
  [query-parser/module.md](query-parser/module.md)
300
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
+
301
333
  ### kbdb-worker (cdylib → .wasm)
302
334
 
303
335
  Orchestration layer. Imports the other two WASM
@@ -483,6 +515,9 @@ docs/modules/rust/
483
515
  │ ├── functions/
484
516
  │ └── ...
485
517
 
518
+ ├── embedding/ ← kbdb-default-embedding crate
519
+ │ └── module.md
520
+
486
521
  └── kb-worker/ ← kbdb-worker crate
487
522
  ├── module.md
488
523
  ├── types/
@@ -1,16 +1,18 @@
1
1
  # query-parser/functions -- Operations
2
2
 
3
- *Functions for tokenization, query parsing, keyword
4
- extraction, and ranking.*
3
+ *Functions for query parsing, keyword extraction,
4
+ and ranking.*
5
5
 
6
6
  ## Modules
7
7
 
8
- - **[pipeline](pipeline.md)** -- 9-stage tokenization
9
- pipeline. Converts raw text into normalized, stemmed
10
- tokens with synonym expansion and n-grams.
11
8
  - **[parse](parse.md)** -- Query string parsing into
12
9
  structured `QueryPlan`.
13
10
  - **[extract](extract.md)** -- RAKE keyphrase
14
11
  extraction and TF-IDF term weighting.
15
12
  - **[rank](rank.md)** -- BM25F, proximity, zone, and
16
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,141 +1,9 @@
1
- # functions::pipeline -- Tokenization Pipeline
1
+ # functions::pipeline -- Moved to kbdb-shared
2
2
 
3
- *9-stage pipeline that converts raw text into
4
- normalized, stemmed tokens with synonym expansion.
5
- Used for both indexing and query processing.*
3
+ The tokenization pipeline has moved to `kbdb-shared`.
6
4
 
7
- ## Source
5
+ See [shared/pipeline/functions.md](../../shared/pipeline/functions.md)
6
+ for the full documentation.
8
7
 
9
- `engine/crates/query-parser/src/pipeline/`
10
-
11
- ## Entry Point
12
-
13
- ```rust
14
- pub fn tokenize(input: &str) -> TokenStream;
15
- ```
16
-
17
- Runs all nine stages in sequence. Each stage is a
18
- pure function.
19
-
20
- ## Stages
21
-
22
- ### 1. Content Marker Stripping
23
-
24
- ```rust
25
- use kbdb_shared::content_parser::strip_content_markers;
26
- ```
27
-
28
- Removes all six content marker types from the input
29
- text before tokenization:
30
- `$(image:)`, `$(code:)`, `$(text:)`, `$(document:)`,
31
- `$(link:)`, `$(doc-link:)`.
32
-
33
- Delegates to `strip_content_markers()` imported from
34
- `kbdb_shared::content_parser` (see
35
- [Content Parser](../../shared/content-parser/module.md)).
36
- These are structural references, not searchable
37
- content.
38
-
39
- ### 2. Unicode Normalization (`unicode.rs`)
40
-
41
- ```rust
42
- pub fn normalize_nfc(input: &str) -> String;
43
- ```
44
-
45
- NFC normalization for consistent codepoints.
46
-
47
- ### 3. Word Boundary Detection (`segment.rs`)
48
-
49
- ```rust
50
- pub fn segment_words(input: &str) -> Vec<&str>;
51
- ```
52
-
53
- Unicode Segmentation (UAX #29).
54
-
55
- ### 4. Identifier Splitting (`identifiers.rs`)
56
-
57
- ```rust
58
- pub fn split_identifiers(word: &str) -> Vec<String>;
59
- ```
60
-
61
- - `camelCase` → `["camel", "case"]`
62
- - `snake_case` → `["snake", "case"]`
63
- - `PascalCase` → `["pascal", "case"]`
64
- - `HTMLParser` → `["html", "parser"]`
65
-
66
- ### 5. Case Folding (`case.rs`)
67
-
68
- ```rust
69
- pub fn fold_case(word: &str) -> String;
70
- ```
71
-
72
- Unicode case folding (lowercase).
73
-
74
- ### 6. Stop Word Removal (`stopwords.rs`)
75
-
76
- ```rust
77
- pub fn is_stop_word(word: &str) -> bool;
78
- pub fn remove_stop_words(
79
- words: &[String],
80
- ) -> Vec<String>;
81
- ```
82
-
83
- Filters common function words. Single-character
84
- tokens also removed.
85
-
86
- ### 7. Synonym Expansion (`synonyms.rs`)
87
-
88
- ```rust
89
- pub fn expand_synonyms(
90
- word: &str,
91
- map: &SynonymMap,
92
- ) -> Vec<String>;
93
- ```
94
-
95
- Looks up the lowercased word in the built-in synonym
96
- map. Returns a vector containing the original word
97
- plus any synonyms. When no synonyms exist, returns a
98
- single-element vector containing only the original.
99
-
100
- The synonym map is a bidirectional
101
- `HashMap<String, Vec<String>>` built at compile time.
102
- Expansion is applied after stop-word removal and
103
- before stemming, so both original and synonym tokens
104
- are stemmed consistently.
105
-
106
- The map is small (~30-50 entries) and focused on
107
- common IT/development vocabulary mismatches:
108
- login/sign-in, auth/authentication, remove/delete,
109
- config/configuration, credential/password, etc.
110
-
111
- ### 8. Stemming (`stem.rs`)
112
-
113
- ```rust
114
- pub fn stem_word(word: &str) -> StemResult;
115
- ```
116
-
117
- Snowball / Porter2. Preserves both original and
118
- stemmed forms.
119
-
120
- ### 9. N-gram Extraction (`ngram.rs`)
121
-
122
- ```rust
123
- pub fn extract_ngrams(
124
- tokens: &[Token],
125
- ) -> Vec<Ngram>;
126
- ```
127
-
128
- Bigrams and trigrams for phrase indexing.
129
-
130
- ## Relaxed Query Mode
131
-
132
- The tokenization pipeline is used for both the
133
- primary AND-mode query plan and the relaxed OR-mode
134
- fallback plan. `qp_parse_query` produces a
135
- `QueryPlan` with a `match_mode` field (`All` | `Any`).
136
- When the AND plan returns zero matches,
137
- `kb-worker.wasm` retries with the OR plan using the
138
- same tokenized terms. No additional pipeline stage or
139
- WASM export is needed. See
140
- [Query Parser -- Relaxed Query
141
- Mode](../../../goals/query-parser.md).
8
+ This crate re-exports the pipeline via the
9
+ `qp_tokenize` WASM FFI export.
@@ -1,8 +1,9 @@
1
1
  # query-parser -- Query Processing and Tokenization
2
2
 
3
- *Rust crate that provides the tokenization pipeline,
4
- query parsing, keyword extraction, and ranking
5
- functions. Compiles to `query-parser.wasm`.*
3
+ *Rust crate that provides query parsing, keyword
4
+ extraction, and ranking functions. Tokenization is
5
+ imported from `kbdb-shared`'s `pipeline` module.
6
+ Compiles to `query-parser.wasm`.*
6
7
 
7
8
  ## Crate
8
9
 
@@ -41,17 +42,6 @@ engine/crates/query-parser/
41
42
  └── src/
42
43
  ├── lib.rs # crate root, WASM exports
43
44
  ├── mem.rs # shared-memory helpers
44
- ├── pipeline/
45
- │ ├── mod.rs # pipeline orchestrator
46
- │ ├── markers.rs # stage 1: strip markers
47
- │ ├── unicode.rs # stage 2: NFC normalize
48
- │ ├── segment.rs # stage 3: word boundaries
49
- │ ├── identifiers.rs # stage 4: camelCase split
50
- │ ├── case.rs # stage 5: case folding
51
- │ ├── stopwords.rs # stage 6: stop words
52
- │ ├── synonyms.rs # stage 7: synonym expansion
53
- │ ├── stem.rs # stage 8: Snowball stemmer
54
- │ └── ngram.rs # stage 9: n-gram extract
55
45
  ├── parse.rs # query string → QueryPlan
56
46
  ├── extract/
57
47
  │ ├── mod.rs # extraction facade
@@ -66,6 +56,11 @@ engine/crates/query-parser/
66
56
  └── cache.rs # query-scoped cache
67
57
  ```
68
58
 
59
+ The tokenization pipeline lives in `kbdb-shared`'s
60
+ [pipeline](../shared/pipeline/module.md) module.
61
+ This crate re-exports it via WASM FFI
62
+ (`qp_tokenize`).
63
+
69
64
  ## Modules
70
65
 
71
66
  ### [types/](types/module.md) -- Structs
@@ -79,10 +74,6 @@ engine/crates/query-parser/
79
74
 
80
75
  ### [functions/](functions/module.md) -- Operations
81
76
 
82
- - **[pipeline](functions/pipeline.md)** -- 9-stage
83
- tokenization pipeline. Marker stripping, NFC,
84
- segmentation, identifier splitting, case folding,
85
- stop words, synonym expansion, stemming, n-grams.
86
77
  - **[parse](functions/parse.md)** -- Query string
87
78
  parsing into `QueryPlan`.
88
79
  - **[extract](functions/extract.md)** -- RAKE
@@ -90,6 +81,9 @@ engine/crates/query-parser/
90
81
  - **[rank](functions/rank.md)** -- BM25F, proximity,
91
82
  zone, and freshness scoring functions.
92
83
 
84
+ Tokenization is provided by
85
+ [kbdb-shared pipeline](../shared/pipeline/module.md).
86
+
93
87
  ## WASM Exports
94
88
 
95
89
  | Export | Description |
@@ -114,12 +108,12 @@ engine/crates/query-parser/
114
108
  ```toml
115
109
  [dependencies]
116
110
  kbdb-shared = { path = "../shared" }
117
- unicode-segmentation = "1"
118
- unicode-normalization = "0.1"
119
- rust-stemmers = "1"
120
- regex = { version = "1", default-features = false }
121
111
  ```
122
112
 
113
+ Tokenization dependencies (`unicode-segmentation`,
114
+ `unicode-normalization`, `rust-stemmers`) are now in
115
+ `kbdb-shared` alongside the `pipeline` module.
116
+
123
117
  ## Build
124
118
 
125
119
  ```sh
@@ -1,13 +1,10 @@
1
1
  # query-parser/types -- Type Definitions
2
2
 
3
3
  *Structs defined in the query-parser crate for
4
- tokenization, keyword extraction, and ranking.*
4
+ keyword extraction and ranking.*
5
5
 
6
6
  ## Modules
7
7
 
8
- - **[token](token.md)** -- `Token`, `TokenStream`,
9
- `Ngram`, `NgramType`, `StemResult`. Output types
10
- from the tokenization pipeline.
11
8
  - **[keyphrase](keyphrase.md)** -- `Keyphrase`,
12
9
  `WeightedTerm`, `BM25FParams`, `FieldWeights`,
13
10
  `SynonymMap`. Types for keyword extraction, ranking
@@ -15,3 +12,7 @@ tokenization, keyword extraction, and ranking.*
15
12
  - **[cache](cache.md)** -- `QueryCache`. Short-lived
16
13
  cache scoped to a single query or indexing
17
14
  operation.
15
+
16
+ Token types (`Token`, `TokenStream`, `Ngram`,
17
+ `NgramType`, `StemResult`) are defined in
18
+ [kbdb-shared pipeline](../../shared/pipeline/types.md).