@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.
- package/CLA.md +68 -0
- package/LICENSE +676 -12
- package/LICENSING.md +58 -0
- package/README.md +50 -25
- package/README.md.bak +322 -0
- package/dist/README.md +322 -0
- package/dist/{chunk-BJXEVALU.mjs → chunk-QLJ33C74.mjs} +44 -44
- package/dist/chunk-QLJ33C74.mjs.map +7 -0
- package/dist/cli.cjs +550 -232
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.d.ts +0 -8
- package/dist/cli.mjs +483 -154
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +36 -5
- package/dist/kbdb-worker.cjs.map +3 -3
- package/dist/mod.cjs +89 -30
- package/dist/mod.cjs.map +4 -4
- package/dist/mod.mjs +88 -30
- package/dist/mod.mjs.map +4 -4
- package/dist/src/cli.d.ts +0 -8
- package/dist/src/shared/cli/constants/defaults.constant.d.ts +1 -1
- package/dist/src/shared/cli/constants/recfile-command-field-map.constant.d.ts +8 -0
- package/dist/src/shared/cli/constants/recfile-field-maps.constant.d.ts +21 -0
- package/dist/src/shared/cli/functions/compute-directory-level.function.d.ts +14 -0
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +2 -28
- package/dist/src/shared/cli/functions/format-command-output.function.d.ts +14 -0
- package/dist/src/shared/cli/functions/format-db-not-found.function.d.ts +20 -0
- package/dist/src/shared/cli/functions/format-output.function.d.ts +1 -0
- package/dist/src/shared/cli/functions/format-recfile-output.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/render-recfile-value.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/resolve-db-dir.function.d.ts +24 -0
- package/dist/src/shared/cli/functions/resolve-recfile-key.function.d.ts +9 -0
- package/dist/src/shared/cli/functions/run-db-path.function.d.ts +10 -0
- package/dist/src/shared/cli/functions/run-export.function.d.ts +8 -4
- package/dist/src/shared/cli/functions/run-import.function.d.ts +4 -0
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +12 -0
- package/dist/src/shared/cli/index.d.ts +4 -1
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +9 -2
- package/dist/src/shared/cli/typings/db-resolution.interface.d.ts +9 -0
- package/dist/src/shared/cli/typings/recfile-field-map.type.d.ts +10 -0
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/functions/decode-option-u8.function.d.ts +9 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +4 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +2 -45
- package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +10 -1
- package/dist/src/shared/wasm-codec/index.d.ts +1 -1
- package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +6 -0
- package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +5 -0
- package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +5 -0
- package/dist/src/shared/worker-client/functions/build-deno-permissions.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/read-crash-reason.function.d.ts +9 -0
- package/dist/src/shared/worker-client/functions/resolve-spawn-script.function.d.ts +6 -0
- package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +1 -1
- package/dist/src/shared/worker-client/typings/section.model.d.ts +5 -0
- package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +0 -6
- package/dist/src/shared/worker-daemon/functions/count-files.function.d.ts +12 -0
- package/dist/src/shared/worker-daemon/functions/handle-import.function.d.ts +2 -0
- package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +8 -0
- package/dist/src/shared/worker-daemon/functions/validate-daemon-path.function.d.ts +15 -0
- package/dist/src/worker.d.ts +0 -7
- package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
- package/dist/wasm/default-embedding/package.json +1 -1
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/package.json +1 -1
- package/dist/wasm/fs-migration/package.json +1 -1
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/package.json +1 -1
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/wasm/query-parser/package.json +1 -1
- package/dist/worker.d.ts +0 -7
- package/dist/worker.mjs +37 -6
- package/dist/worker.mjs.map +3 -3
- package/package.json +11 -10
- package/dist/chunk-BJXEVALU.mjs.map +0 -7
- package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +0 -10
- package/docs/details/README.md +0 -30
- package/docs/details/agent-tooling.md +0 -132
- package/docs/details/cli.md +0 -777
- package/docs/details/knowledge-base.md +0 -180
- package/docs/details/library-api.md +0 -495
- package/docs/details/mcp-server.md +0 -482
- package/docs/details/search-and-ranking.md +0 -575
- package/docs/details/storage.md +0 -531
- package/docs/goals/agents.md +0 -751
- package/docs/goals/architecture.svg +0 -198
- package/docs/goals/auto-capture.md +0 -378
- package/docs/goals/benchmarking.md +0 -296
- package/docs/goals/cli.md +0 -2654
- package/docs/goals/concurrency.md +0 -259
- package/docs/goals/content-composer.md +0 -609
- package/docs/goals/content-parser.md +0 -279
- package/docs/goals/database.md +0 -1679
- package/docs/goals/document.md +0 -368
- package/docs/goals/hybrid-search.md +0 -465
- package/docs/goals/mcp.md +0 -1541
- package/docs/goals/overview.md +0 -124
- package/docs/goals/query-parser.md +0 -373
- package/docs/goals/query-result.md +0 -860
- package/docs/goals/semantic-dedup.md +0 -233
- package/docs/goals/skills.md +0 -810
- package/docs/goals/sync.md +0 -217
- package/docs/goals/worker-client.md +0 -1005
- package/docs/goals/worker-daemon.md +0 -1547
- package/docs/modules/overview.md +0 -319
- package/docs/modules/rust/embedding/module.md +0 -91
- package/docs/modules/rust/fs-database/functions/document.md +0 -48
- package/docs/modules/rust/fs-database/functions/integrity.md +0 -79
- package/docs/modules/rust/fs-database/functions/io.md +0 -87
- package/docs/modules/rust/fs-database/functions/module.md +0 -22
- package/docs/modules/rust/fs-database/functions/query-exec.md +0 -44
- package/docs/modules/rust/fs-database/functions/section.md +0 -76
- package/docs/modules/rust/fs-database/indexes/btree.md +0 -35
- package/docs/modules/rust/fs-database/indexes/corpus.md +0 -61
- package/docs/modules/rust/fs-database/indexes/inverted.md +0 -60
- package/docs/modules/rust/fs-database/indexes/module.md +0 -64
- package/docs/modules/rust/fs-database/indexes/positional.md +0 -39
- package/docs/modules/rust/fs-database/indexes/vectors.md +0 -110
- package/docs/modules/rust/fs-database/module.md +0 -150
- package/docs/modules/rust/fs-database/types/catalog.md +0 -53
- package/docs/modules/rust/fs-database/types/module.md +0 -12
- package/docs/modules/rust/fs-database/types/section.md +0 -127
- package/docs/modules/rust/kb-worker/functions/compose.md +0 -57
- package/docs/modules/rust/kb-worker/functions/module.md +0 -20
- package/docs/modules/rust/kb-worker/functions/retrieve.md +0 -194
- package/docs/modules/rust/kb-worker/functions/search.md +0 -173
- package/docs/modules/rust/kb-worker/functions/write.md +0 -172
- package/docs/modules/rust/kb-worker/module.md +0 -171
- package/docs/modules/rust/kb-worker/types/cache.md +0 -90
- package/docs/modules/rust/kb-worker/types/context.md +0 -26
- package/docs/modules/rust/kb-worker/types/module.md +0 -16
- package/docs/modules/rust/kb-worker/types/status.md +0 -29
- package/docs/modules/rust/kb-worker/types/token.md +0 -50
- package/docs/modules/rust/overview.md +0 -531
- package/docs/modules/rust/query-parser/functions/extract.md +0 -56
- package/docs/modules/rust/query-parser/functions/module.md +0 -18
- package/docs/modules/rust/query-parser/functions/parse.md +0 -33
- package/docs/modules/rust/query-parser/functions/pipeline.md +0 -9
- package/docs/modules/rust/query-parser/functions/rank.md +0 -85
- package/docs/modules/rust/query-parser/module.md +0 -131
- package/docs/modules/rust/query-parser/types/cache.md +0 -39
- package/docs/modules/rust/query-parser/types/keyphrase.md +0 -71
- package/docs/modules/rust/query-parser/types/module.md +0 -18
- package/docs/modules/rust/query-parser/types/token.md +0 -46
- package/docs/modules/rust/shared/content-composer/functions.md +0 -114
- package/docs/modules/rust/shared/content-composer/module.md +0 -147
- package/docs/modules/rust/shared/content-composer/types.md +0 -93
- package/docs/modules/rust/shared/content-parser/functions.md +0 -72
- package/docs/modules/rust/shared/content-parser/module.md +0 -99
- package/docs/modules/rust/shared/content-parser/types.md +0 -71
- package/docs/modules/rust/shared/corpus/module.md +0 -24
- package/docs/modules/rust/shared/corpus/types.md +0 -141
- package/docs/modules/rust/shared/document/module.md +0 -25
- package/docs/modules/rust/shared/document/types.md +0 -154
- package/docs/modules/rust/shared/encode/module.md +0 -22
- package/docs/modules/rust/shared/encode/traits.md +0 -304
- package/docs/modules/rust/shared/error/module.md +0 -28
- package/docs/modules/rust/shared/error/types.md +0 -302
- package/docs/modules/rust/shared/kbid/module.md +0 -24
- package/docs/modules/rust/shared/kbid/types.md +0 -147
- package/docs/modules/rust/shared/memory/functions.md +0 -209
- package/docs/modules/rust/shared/memory/module.md +0 -24
- package/docs/modules/rust/shared/module.md +0 -196
- package/docs/modules/rust/shared/pipeline/functions.md +0 -141
- package/docs/modules/rust/shared/pipeline/module.md +0 -62
- package/docs/modules/rust/shared/pipeline/types.md +0 -43
- package/docs/modules/rust/shared/query/module.md +0 -27
- package/docs/modules/rust/shared/query/types.md +0 -236
- package/docs/modules/rust/shared/section/module.md +0 -25
- package/docs/modules/rust/shared/section/types.md +0 -294
- package/docs/modules/rust/shared/term/module.md +0 -25
- package/docs/modules/rust/shared/term/types.md +0 -139
- package/docs/modules/typescript/cli.md +0 -131
- package/docs/modules/typescript/kbdb-worker.md +0 -150
- package/docs/modules/typescript/overview.md +0 -400
- package/docs/modules/typescript/shared/auto-capture/module.md +0 -73
- package/docs/modules/typescript/shared/cli/constants.md +0 -23
- package/docs/modules/typescript/shared/cli/functions.md +0 -809
- package/docs/modules/typescript/shared/cli/module.md +0 -138
- package/docs/modules/typescript/shared/cli/typings.md +0 -197
- package/docs/modules/typescript/shared/embedding/functions.md +0 -200
- package/docs/modules/typescript/shared/embedding/module.md +0 -77
- package/docs/modules/typescript/shared/embedding/typings.md +0 -124
- package/docs/modules/typescript/shared/hash/functions.md +0 -20
- package/docs/modules/typescript/shared/hash/module.md +0 -21
- package/docs/modules/typescript/shared/log/constants.md +0 -82
- package/docs/modules/typescript/shared/log/functions.md +0 -131
- package/docs/modules/typescript/shared/log/module.md +0 -153
- package/docs/modules/typescript/shared/log/typings.md +0 -82
- package/docs/modules/typescript/shared/mcp/classes.md +0 -179
- package/docs/modules/typescript/shared/mcp/functions.md +0 -386
- package/docs/modules/typescript/shared/mcp/module.md +0 -160
- package/docs/modules/typescript/shared/mcp/typings.md +0 -529
- package/docs/modules/typescript/shared/module.md +0 -110
- package/docs/modules/typescript/shared/platform/functions.md +0 -42
- package/docs/modules/typescript/shared/platform/module.md +0 -25
- package/docs/modules/typescript/shared/runtime/functions.md +0 -26
- package/docs/modules/typescript/shared/runtime/module.md +0 -27
- package/docs/modules/typescript/shared/runtime/typings.md +0 -13
- package/docs/modules/typescript/shared/version/module.md +0 -27
- package/docs/modules/typescript/shared/wasm-codec/functions.md +0 -391
- package/docs/modules/typescript/shared/wasm-codec/module.md +0 -98
- package/docs/modules/typescript/shared/worker-client/classes.md +0 -264
- package/docs/modules/typescript/shared/worker-client/functions.md +0 -175
- package/docs/modules/typescript/shared/worker-client/module.md +0 -92
- package/docs/modules/typescript/shared/worker-client/typings.md +0 -511
- package/docs/modules/typescript/shared/worker-daemon/classes.md +0 -239
- package/docs/modules/typescript/shared/worker-daemon/constants.md +0 -37
- package/docs/modules/typescript/shared/worker-daemon/functions.md +0 -234
- package/docs/modules/typescript/shared/worker-daemon/module.md +0 -118
- package/docs/modules/typescript/shared/worker-daemon/typings.md +0 -132
- package/docs/overview.md +0 -191
- package/docs/release-notes/0.1.0.md +0 -189
- package/docs/release-notes/0.1.1.md +0 -46
- package/docs/release-notes/0.1.2.md +0 -38
- package/docs/release-notes/0.1.3.md +0 -42
- package/docs/release-notes/0.2.0.md +0 -147
- package/docs/release-notes/0.3.0.md +0 -89
- package/docs/release-notes/0.3.1.md +0 -121
- package/docs/release-notes/0.3.2.md +0 -64
- package/docs/release-notes/0.4.0.md +0 -80
- package/docs/release-notes/0.4.1.md +0 -149
- package/docs/release-notes/0.4.3.md +0 -60
- package/docs/release-notes/0.5.0.md +0 -41
- 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.
|