@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.
- package/CLA.md +68 -0
- package/LICENSE +676 -12
- package/LICENSING.md +58 -0
- package/README.md +50 -27
- package/README.md.bak +320 -0
- package/dist/README.md +320 -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/kbdb_fs_migration_bg.wasm +0 -0
- 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 +13 -12
- 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/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.
|