@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,127 +0,0 @@
|
|
|
1
|
-
# types::section -- Section Header and Parsing
|
|
2
|
-
|
|
3
|
-
*The `SectionHeader` struct and `IntegrityReport`
|
|
4
|
-
struct, plus TOML frontmatter parse/serialize and
|
|
5
|
-
hash-sharded path resolution.*
|
|
6
|
-
|
|
7
|
-
## Source
|
|
8
|
-
|
|
9
|
-
`engine/crates/fs-database/src/section/`
|
|
10
|
-
|
|
11
|
-
## Type Definitions
|
|
12
|
-
|
|
13
|
-
### `SectionHeader`
|
|
14
|
-
|
|
15
|
-
```rust
|
|
16
|
-
pub struct SectionHeader {
|
|
17
|
-
pub kbid: KbId,
|
|
18
|
-
pub docids: Vec<String>,
|
|
19
|
-
pub section_type: SectionType,
|
|
20
|
-
pub title: Option<String>,
|
|
21
|
-
pub description: Option<String>,
|
|
22
|
-
pub size: u32,
|
|
23
|
-
pub created_at: String,
|
|
24
|
-
pub checksum: String,
|
|
25
|
-
pub token_count: u32,
|
|
26
|
-
pub heading_token_count: u32,
|
|
27
|
-
pub body_token_count: u32,
|
|
28
|
-
pub code_token_count: u32,
|
|
29
|
-
pub source_key: Option<String>,
|
|
30
|
-
pub source_path: Option<String>,
|
|
31
|
-
pub source_mtime: Option<String>,
|
|
32
|
-
pub updated_at: Option<String>,
|
|
33
|
-
pub tags: Vec<String>,
|
|
34
|
-
pub supersedes: Option<KbId>,
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
TOML frontmatter fields from a section file. Parsed
|
|
39
|
-
by `parse_section_file`, serialized by
|
|
40
|
-
`serialize_section_file`.
|
|
41
|
-
|
|
42
|
-
`docids` lists the document IDs this section belongs
|
|
43
|
-
to (may be empty, one, or many -- many-to-many
|
|
44
|
-
relationship). `title` is required for image sections
|
|
45
|
-
and optional for text/code sections. `description` is
|
|
46
|
-
always optional. Token counts are computed by
|
|
47
|
-
`query-parser.wasm` during per-field tokenization
|
|
48
|
-
and stored in the header for query-time retrieval.
|
|
49
|
-
See [FieldTokenCounts](../../shared/query/types.md)
|
|
50
|
-
for the shared struct.
|
|
51
|
-
|
|
52
|
-
`source_key` is a stable logical identity derived
|
|
53
|
-
from `sha256("${source_path}\0${heading}")`,
|
|
54
|
-
truncated to 16 hex chars. Separate from `kbid`
|
|
55
|
-
(content hash) -- identifies *what the section is
|
|
56
|
-
about* rather than *what it currently says*. `null`
|
|
57
|
-
for stdin input. `source_path` is the original file
|
|
58
|
-
path that was learned. `source_mtime` is the ISO 8601
|
|
59
|
-
modified time of the source file at learn time.
|
|
60
|
-
`updated_at` is the ISO 8601 timestamp of the last
|
|
61
|
-
supersession (`null` on first create). `tags` are
|
|
62
|
-
user-supplied strings for scoping and filtering.
|
|
63
|
-
`supersedes` is the kbid of the section this one
|
|
64
|
-
replaced (`null` on first create). See
|
|
65
|
-
[Database -- Logical Identity](../../../goals/database.md).
|
|
66
|
-
|
|
67
|
-
### `IntegrityReport`
|
|
68
|
-
|
|
69
|
-
```rust
|
|
70
|
-
pub struct IntegrityReport {
|
|
71
|
-
pub checksum_failures: Vec<KbId>,
|
|
72
|
-
pub orphaned_sections: Vec<KbId>,
|
|
73
|
-
pub orphaned_documents: Vec<String>,
|
|
74
|
-
pub broken_refs: Vec<(KbId, String, KbId)>,
|
|
75
|
-
pub type_mismatches: Vec<(KbId, String, KbId)>,
|
|
76
|
-
pub circular_refs: Vec<(KbId, Vec<KbId>)>,
|
|
77
|
-
pub divergent_content: Vec<(String, Vec<KbId>)>,
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Returned by `check_integrity`. `broken_refs`
|
|
82
|
-
entries are `(source_kbid, marker_type, target_kbid)`
|
|
83
|
-
covering all six marker types (`text`, `code`,
|
|
84
|
-
`image`, `document`, `link`, `doc-link`).
|
|
85
|
-
`type_mismatches` are `(source_kbid, marker_type,
|
|
86
|
-
target_kbid)` where the target section type does
|
|
87
|
-
not match the marker type. `circular_refs` are
|
|
88
|
-
`(start_kbid, cycle_path)` for reference chains
|
|
89
|
-
that form loops. `divergent_content` entries are
|
|
90
|
-
`(source_key, conflicting_kbids)` -- sections
|
|
91
|
-
sharing the same `source_key` that have different
|
|
92
|
-
content, indicating contradictory versions that
|
|
93
|
-
should be resolved via supersession.
|
|
94
|
-
|
|
95
|
-
## Functions
|
|
96
|
-
|
|
97
|
-
### Frontmatter Parsing (`section/parse.rs`)
|
|
98
|
-
|
|
99
|
-
```rust
|
|
100
|
-
pub fn parse_section_file(data: &[u8])
|
|
101
|
-
-> Result<(SectionHeader, &[u8]), ParseError>;
|
|
102
|
-
|
|
103
|
-
pub fn serialize_section_file(
|
|
104
|
-
header: &SectionHeader,
|
|
105
|
-
body: &[u8],
|
|
106
|
-
) -> Vec<u8>;
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
Splits on `---\n` separator. Header is TOML; body
|
|
110
|
-
is raw bytes stored verbatim.
|
|
111
|
-
|
|
112
|
-
### Content Hashing (`section/hash.rs`)
|
|
113
|
-
|
|
114
|
-
```rust
|
|
115
|
-
pub fn compute_kbid(content: &[u8]) -> KbId;
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
SHA-256 → truncate to 16 bytes → base32 (Crockford)
|
|
119
|
-
→ 26-character kb-id.
|
|
120
|
-
|
|
121
|
-
### Path Resolution (`section/shard.rs`)
|
|
122
|
-
|
|
123
|
-
```rust
|
|
124
|
-
pub fn section_path(kbid: &KbId) -> String;
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
Returns `sections/{first_two_chars}/{kbid}.sec`.
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# functions::compose -- Content Composition Flow
|
|
2
|
-
|
|
3
|
-
*Orchestrates content composition: resolve identifiers,
|
|
4
|
-
fetch content, compose rendered Markdown.*
|
|
5
|
-
|
|
6
|
-
## Source
|
|
7
|
-
|
|
8
|
-
`engine/crates/kb-worker/src/orchestrate/compose.rs`
|
|
9
|
-
|
|
10
|
-
## Exported WASM Function
|
|
11
|
-
|
|
12
|
-
### `worker_compose`
|
|
13
|
-
|
|
14
|
-
```rust
|
|
15
|
-
pub fn worker_compose(
|
|
16
|
-
ids_ptr: *const u8,
|
|
17
|
-
ids_len: u32,
|
|
18
|
-
) -> u64;
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Composes a rendered Markdown document from one or
|
|
22
|
-
more kbid or docid identifiers. Returns a result
|
|
23
|
-
token (same async pattern as `worker_query`).
|
|
24
|
-
|
|
25
|
-
## Compose Flow
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
1. Receive identifiers from IPC `compose` method
|
|
29
|
-
↓
|
|
30
|
-
2. Resolve identifiers via fs-database
|
|
31
|
-
(try kbid first, then docid)
|
|
32
|
-
↓
|
|
33
|
-
3. Expand documents to section kbids, deduplicate
|
|
34
|
-
↓
|
|
35
|
-
4. Fetch section/document content from fs-database
|
|
36
|
-
↓
|
|
37
|
-
5. Extract content markers recursively using
|
|
38
|
-
extract_content_markers() from content-parser
|
|
39
|
-
↓
|
|
40
|
-
6. Build ComposeRequest with all resolved data
|
|
41
|
-
↓
|
|
42
|
-
7. Call compose_content() from content-composer
|
|
43
|
-
↓
|
|
44
|
-
8. Return ComposeResult to daemon
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
The caller retrieves the composed document via
|
|
48
|
-
`worker_get_result` with type `"content"`.
|
|
49
|
-
|
|
50
|
-
Individual sections fetched during composition are
|
|
51
|
-
cached. The composed result itself is NOT cached --
|
|
52
|
-
it is computed fresh on each request because
|
|
53
|
-
composition depends on the full set of input
|
|
54
|
-
identifiers.
|
|
55
|
-
|
|
56
|
-
See [Content Composer](../../shared/content-composer/module.md)
|
|
57
|
-
for the full composition specification.
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# kb-worker/functions -- Orchestration Functions
|
|
2
|
-
|
|
3
|
-
*Functions that coordinate calls between
|
|
4
|
-
query-parser.wasm and fs-database.wasm to implement
|
|
5
|
-
full database operations.*
|
|
6
|
-
|
|
7
|
-
## Modules
|
|
8
|
-
|
|
9
|
-
- **[search](search.md)** -- Search orchestration.
|
|
10
|
-
Parse query → build plan → execute → rank →
|
|
11
|
-
return results.
|
|
12
|
-
- **[write](write.md)** -- Write orchestration.
|
|
13
|
-
Add/update/remove text, code, and image sections.
|
|
14
|
-
- **[retrieve](retrieve.md)** -- Read orchestration.
|
|
15
|
-
Retrieve sections and documents, with cache.
|
|
16
|
-
Progressive context expansion (`worker_recall`).
|
|
17
|
-
Status reporting.
|
|
18
|
-
- **[compose](compose.md)** -- Content composition.
|
|
19
|
-
Resolve identifiers, fetch content, compose
|
|
20
|
-
rendered Markdown via content-composer.
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
# functions::retrieve -- Read & Status Orchestration
|
|
2
|
-
|
|
3
|
-
*Read sections and documents from cache or disk.
|
|
4
|
-
Report database status.*
|
|
5
|
-
|
|
6
|
-
## Source
|
|
7
|
-
|
|
8
|
-
`engine/crates/kb-worker/src/orchestrate/retrieve.rs`
|
|
9
|
-
|
|
10
|
-
## Exported WASM Functions
|
|
11
|
-
|
|
12
|
-
### `worker_read_sections`
|
|
13
|
-
|
|
14
|
-
```rust
|
|
15
|
-
pub fn worker_read_sections(
|
|
16
|
-
kbid_ptr: *const u8,
|
|
17
|
-
kbid_len: u32,
|
|
18
|
-
) -> u64;
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Read one or more sections by KbId. Returns Encode'd
|
|
22
|
-
`Vec<SectionRecord>`.
|
|
23
|
-
|
|
24
|
-
### `worker_retrieve_doc`
|
|
25
|
-
|
|
26
|
-
```rust
|
|
27
|
-
pub fn worker_retrieve_doc(
|
|
28
|
-
doc_id_ptr: *const u8,
|
|
29
|
-
doc_id_len: u32,
|
|
30
|
-
) -> u64;
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
Read a document manifest and all its sections.
|
|
34
|
-
Returns Encode'd `DocumentRecord`.
|
|
35
|
-
|
|
36
|
-
### `worker_status`
|
|
37
|
-
|
|
38
|
-
```rust
|
|
39
|
-
pub fn worker_status() -> u64;
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Returns Encode'd `StatusResult` (see
|
|
43
|
-
[types/status](../types/status.md)).
|
|
44
|
-
|
|
45
|
-
### `worker_result_status`
|
|
46
|
-
|
|
47
|
-
```rust
|
|
48
|
-
pub fn worker_result_status(
|
|
49
|
-
token_ptr: *const u8,
|
|
50
|
-
token_len: u32,
|
|
51
|
-
) -> u32;
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Poll an async token. Returns `0` = busy,
|
|
55
|
-
`1` = success, `2` = fail.
|
|
56
|
-
|
|
57
|
-
### `worker_get_result`
|
|
58
|
-
|
|
59
|
-
```rust
|
|
60
|
-
pub fn worker_get_result(
|
|
61
|
-
token_ptr: *const u8,
|
|
62
|
-
token_len: u32,
|
|
63
|
-
) -> u64;
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Fetch the result buffer for a completed token.
|
|
67
|
-
Returns `(ptr, len)`. Consumes the token (one-shot).
|
|
68
|
-
|
|
69
|
-
### `worker_invalidate`
|
|
70
|
-
|
|
71
|
-
```rust
|
|
72
|
-
pub fn worker_invalidate(
|
|
73
|
-
keys_ptr: *const u8,
|
|
74
|
-
keys_len: u32,
|
|
75
|
-
) -> u32;
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
Evict specific cache entries. Returns count evicted.
|
|
79
|
-
|
|
80
|
-
### `worker_invalidate_all`
|
|
81
|
-
|
|
82
|
-
```rust
|
|
83
|
-
pub fn worker_invalidate_all() -> u32;
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Evict entire cache. Returns count evicted.
|
|
87
|
-
|
|
88
|
-
## `worker_recall` -- Progressive Context Expansion
|
|
89
|
-
|
|
90
|
-
```rust
|
|
91
|
-
pub fn worker_recall(
|
|
92
|
-
params_ptr: *const u8,
|
|
93
|
-
params_len: u32,
|
|
94
|
-
) -> u64;
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
WASM export for the `recall` IPC method. Accepts
|
|
98
|
-
a serialized `RecallParams` (kbid or kbids array,
|
|
99
|
-
depth 0--3). Returns serialized `RecallResult`
|
|
100
|
-
(single) or `RecallResult[]` (batch) via the shared
|
|
101
|
-
memory return slot.
|
|
102
|
-
|
|
103
|
-
### Recall Flow
|
|
104
|
-
|
|
105
|
-
```
|
|
106
|
-
1. Receive kbid(s) + depth
|
|
107
|
-
|
|
|
108
|
-
2. For each kbid: read section from cache
|
|
109
|
-
(disk fallback)
|
|
110
|
-
-> SectionRecord with heading, type, docids,
|
|
111
|
-
content
|
|
112
|
-
|
|
|
113
|
-
3. If depth == 0: return section data
|
|
114
|
-
|
|
|
115
|
-
4. If depth >= 1: for each docid in section's
|
|
116
|
-
docids, read document manifest -> list of all
|
|
117
|
-
section kbids with headings and types.
|
|
118
|
-
Query references.idx for back-references
|
|
119
|
-
(entries where target_id == kbid and
|
|
120
|
-
direction == back).
|
|
121
|
-
|
|
|
122
|
-
5. If depth >= 2: read full content of sibling
|
|
123
|
-
sections (other sections in the same documents).
|
|
124
|
-
Query references.idx for forward references
|
|
125
|
-
(entries where source_kbid == kbid and
|
|
126
|
-
direction == forward).
|
|
127
|
-
|
|
|
128
|
-
6. If depth >= 3: for each forward-referenced
|
|
129
|
-
section, read its full content. Query
|
|
130
|
-
references.idx for their back-references.
|
|
131
|
-
|
|
|
132
|
-
Return RecallResult(s) via shared memory
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
**Cache interaction:** Recall is read-heavy and
|
|
136
|
-
benefits from the LRU cache. Section reads at
|
|
137
|
-
depth 0 hit the cache populated by recent searches.
|
|
138
|
-
Sibling and reference reads at depth 2--3 may cause
|
|
139
|
-
cache misses on first access.
|
|
140
|
-
|
|
141
|
-
**Reference graph lookup:** Forward and back
|
|
142
|
-
references are read from `references.idx` via
|
|
143
|
-
`fs-database.wasm` index lookup functions. This is
|
|
144
|
-
O(1) per kbid via the B+ tree index -- no content
|
|
145
|
-
re-parsing needed.
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
## Retrieve Flow
|
|
150
|
-
|
|
151
|
-
```
|
|
152
|
-
1. Receive KbId
|
|
153
|
-
↓
|
|
154
|
-
2. Check cache → hit? → return cached
|
|
155
|
-
↓ miss
|
|
156
|
-
3. db_read_section → SectionRecord from disk
|
|
157
|
-
↓
|
|
158
|
-
4. Put into cache
|
|
159
|
-
↓
|
|
160
|
-
Return SectionRecord
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
Document retrieval follows the same pattern but calls
|
|
164
|
-
`db_read_document` and caches the manifest separately
|
|
165
|
-
from individual sections.
|
|
166
|
-
|
|
167
|
-
## Maintenance Exports
|
|
168
|
-
|
|
169
|
-
### `worker_check_integrity`
|
|
170
|
-
|
|
171
|
-
```rust
|
|
172
|
-
pub fn worker_check_integrity() -> u64;
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
Delegates to `db_check_integrity`. Returns Encode'd
|
|
176
|
-
`IntegrityReport`.
|
|
177
|
-
|
|
178
|
-
### `worker_garbage_collect`
|
|
179
|
-
|
|
180
|
-
```rust
|
|
181
|
-
pub fn worker_garbage_collect() -> u64;
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
Delegates to `db_garbage_collect`. Returns count of
|
|
185
|
-
removed orphans.
|
|
186
|
-
|
|
187
|
-
### `worker_rebuild_indexes`
|
|
188
|
-
|
|
189
|
-
```rust
|
|
190
|
-
pub fn worker_rebuild_indexes() -> u64;
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
Delegates to `db_index_rebuild`. Invalidates entire
|
|
194
|
-
cache afterward.
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
# functions::search -- Search Orchestration
|
|
2
|
-
|
|
3
|
-
*End-to-end search flow: query string in, ranked
|
|
4
|
-
results out.*
|
|
5
|
-
|
|
6
|
-
## Source
|
|
7
|
-
|
|
8
|
-
`engine/crates/kb-worker/src/orchestrate/search.rs`
|
|
9
|
-
|
|
10
|
-
## Exported WASM Functions
|
|
11
|
-
|
|
12
|
-
### `worker_search`
|
|
13
|
-
|
|
14
|
-
```rust
|
|
15
|
-
pub fn worker_search(
|
|
16
|
-
query_ptr: *const u8,
|
|
17
|
-
query_len: u32,
|
|
18
|
-
limit: u32,
|
|
19
|
-
) -> u64;
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Synchronous search. Returns `(ptr, len)` packed into
|
|
23
|
-
`u64`. The result buffer contains Encode'd ranked
|
|
24
|
-
matches.
|
|
25
|
-
|
|
26
|
-
### `worker_query`
|
|
27
|
-
|
|
28
|
-
```rust
|
|
29
|
-
pub fn worker_query(
|
|
30
|
-
query_ptr: *const u8,
|
|
31
|
-
query_len: u32,
|
|
32
|
-
limit: u32,
|
|
33
|
-
) -> u64;
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Async search. Returns a `(ptr, len)` token string.
|
|
37
|
-
Poll with `worker_result_status`, fetch with
|
|
38
|
-
`worker_get_result`.
|
|
39
|
-
|
|
40
|
-
## Search Flow (13 Steps)
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
1. Receive query string from TypeScript IPC
|
|
44
|
-
↓
|
|
45
|
-
2. qp_tokenize → token stream
|
|
46
|
-
↓
|
|
47
|
-
3. qp_parse_query → QueryPlan
|
|
48
|
-
↓
|
|
49
|
-
4. db_execute_plan → Vec<RawMatch>
|
|
50
|
-
↓
|
|
51
|
-
5. db_corpus_stats → CorpusStats
|
|
52
|
-
↓
|
|
53
|
-
6. qp_score_bm25f → base scores
|
|
54
|
-
↓
|
|
55
|
-
7. qp_score_proximity → proximity boost
|
|
56
|
-
↓
|
|
57
|
-
8. qp_score_zone → zone/field boost
|
|
58
|
-
↓
|
|
59
|
-
9. Sort by combined score descending
|
|
60
|
-
↓
|
|
61
|
-
10. Apply offset: skip first `offset` entries
|
|
62
|
-
↓
|
|
63
|
-
11. Truncate to `limit`
|
|
64
|
-
↓
|
|
65
|
-
12. Shape results: for each scored section, read
|
|
66
|
-
heading, type, and docids from the section
|
|
67
|
-
header; generate KWIC snippet (~150 chars
|
|
68
|
-
centered on the highest-scoring matched term
|
|
69
|
-
position from the positional index)
|
|
70
|
-
↓
|
|
71
|
-
13. Build paged envelope: wrap shaped items with
|
|
72
|
-
`total` (pre-offset/limit count), `offset`,
|
|
73
|
-
`limit`, `has_more`
|
|
74
|
-
↓
|
|
75
|
-
Return PagedSearchResult via shared memory
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### Step Details
|
|
79
|
-
|
|
80
|
-
1. **Receive query** -- TypeScript writes the UTF-8
|
|
81
|
-
query into shared memory and calls
|
|
82
|
-
`worker_search(ptr, len, limit)`.
|
|
83
|
-
|
|
84
|
-
2. **Tokenize** -- Calls `qp_tokenize` from
|
|
85
|
-
query-parser. Produces a `TokenStream` with
|
|
86
|
-
normalized, stemmed tokens.
|
|
87
|
-
|
|
88
|
-
3. **Parse** -- Calls `qp_parse_query`. Interprets
|
|
89
|
-
boolean operators, phrase markers, field
|
|
90
|
-
qualifiers. Produces a `QueryPlan`.
|
|
91
|
-
|
|
92
|
-
4. **Execute plan** -- Calls `db_execute_plan` from
|
|
93
|
-
fs-database. Walks the inverted index and
|
|
94
|
-
positional index. Returns `Vec<RawMatch>` with
|
|
95
|
-
per-field TFs (`field_tfs`), positions,
|
|
96
|
-
`token_count`, and `field_token_counts` per
|
|
97
|
-
matching section.
|
|
98
|
-
|
|
99
|
-
5. **Corpus stats** -- Calls `db_corpus_stats`. Gets
|
|
100
|
-
document count, term frequencies for IDF
|
|
101
|
-
computation, and per-field average lengths
|
|
102
|
-
(`avg_heading_length`, `avg_body_length`,
|
|
103
|
-
`avg_code_length`) for BM25F normalization.
|
|
104
|
-
|
|
105
|
-
6. **BM25F** -- Calls `qp_score_bm25f`. Computes
|
|
106
|
-
per-field BM25 using `FieldTf` values from each
|
|
107
|
-
`RawMatch` and per-field corpus averages. Field
|
|
108
|
-
weights (heading 2.0x, body 1.0x, code 1.5x) are
|
|
109
|
-
applied at query time. See
|
|
110
|
-
[Query Result](../../../../goals/query-result.md)
|
|
111
|
-
for the full scoring specification.
|
|
112
|
-
|
|
113
|
-
7. **Proximity** -- Calls `qp_score_proximity`.
|
|
114
|
-
Boosts documents where query terms appear close
|
|
115
|
-
together.
|
|
116
|
-
|
|
117
|
-
8. **Zone scoring** -- Calls `qp_score_zone`. Boosts
|
|
118
|
-
matches in high-value zones (title, headings,
|
|
119
|
-
first paragraph).
|
|
120
|
-
|
|
121
|
-
9. **Sort** -- Combines all scores, sorts descending.
|
|
122
|
-
|
|
123
|
-
10. **Apply offset** -- Skips the first `offset`
|
|
124
|
-
entries from the sorted result list. Enables
|
|
125
|
-
cursor-based pagination without re-executing the
|
|
126
|
-
query.
|
|
127
|
-
|
|
128
|
-
11. **Truncate** -- Takes at most `limit` entries
|
|
129
|
-
from the offset-adjusted list.
|
|
130
|
-
|
|
131
|
-
12. **Shape results** -- For each scored section,
|
|
132
|
-
reads heading, type, and docids from the section
|
|
133
|
-
header. Generates a KWIC snippet (~150 chars
|
|
134
|
-
centered on the highest-scoring matched term
|
|
135
|
-
position from the positional index). See
|
|
136
|
-
[Snippet Generation](#snippet-generation) below.
|
|
137
|
-
|
|
138
|
-
13. **Build paged envelope** -- Wraps shaped items
|
|
139
|
-
with `total` (pre-offset/limit count), `offset`,
|
|
140
|
-
`limit`, and `has_more`. Encodes as
|
|
141
|
-
`PagedSearchResult` via the `Encode` trait into
|
|
142
|
-
shared memory.
|
|
143
|
-
|
|
144
|
-
---
|
|
145
|
-
|
|
146
|
-
### Snippet Generation
|
|
147
|
-
|
|
148
|
-
Snippets are generated during step 12 (result
|
|
149
|
-
shaping), using data already available from the
|
|
150
|
-
search pipeline:
|
|
151
|
-
|
|
152
|
-
- The positional index provides the token offset
|
|
153
|
-
of each matched term in each section.
|
|
154
|
-
- The section content is read from cache (or disk
|
|
155
|
-
fallback).
|
|
156
|
-
|
|
157
|
-
**Algorithm:**
|
|
158
|
-
|
|
159
|
-
1. For each matched section, find the position of
|
|
160
|
-
the highest-scoring matched term (the term with
|
|
161
|
-
the highest BM25F contribution).
|
|
162
|
-
2. Convert the token position to a byte offset in
|
|
163
|
-
the section content.
|
|
164
|
-
3. Extract ~150 characters centered on that byte
|
|
165
|
-
offset. If the offset is near the start or end,
|
|
166
|
-
shift the window accordingly.
|
|
167
|
-
4. Trim to word boundaries and add `...` ellipsis
|
|
168
|
-
at truncated boundaries.
|
|
169
|
-
5. If the highest-scoring match is in the heading
|
|
170
|
-
(not body), use the first ~150 characters of
|
|
171
|
-
the body content instead.
|
|
172
|
-
6. For image sections (`image/*`) or sections with
|
|
173
|
-
no body content, the snippet is empty string.
|