@dikolab/kbdb 0.4.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/CLA.md +68 -0
  2. package/LICENSE +676 -12
  3. package/LICENSING.md +58 -0
  4. package/README.md +50 -27
  5. package/README.md.bak +320 -0
  6. package/dist/README.md +320 -0
  7. package/dist/{chunk-BJXEVALU.mjs → chunk-QLJ33C74.mjs} +44 -44
  8. package/dist/chunk-QLJ33C74.mjs.map +7 -0
  9. package/dist/cli.cjs +550 -232
  10. package/dist/cli.cjs.map +4 -4
  11. package/dist/cli.d.ts +0 -8
  12. package/dist/cli.mjs +483 -154
  13. package/dist/cli.mjs.map +4 -4
  14. package/dist/kbdb-worker.cjs +36 -5
  15. package/dist/kbdb-worker.cjs.map +3 -3
  16. package/dist/mod.cjs +89 -30
  17. package/dist/mod.cjs.map +4 -4
  18. package/dist/mod.mjs +88 -30
  19. package/dist/mod.mjs.map +4 -4
  20. package/dist/src/cli.d.ts +0 -8
  21. package/dist/src/shared/cli/constants/defaults.constant.d.ts +1 -1
  22. package/dist/src/shared/cli/constants/recfile-command-field-map.constant.d.ts +8 -0
  23. package/dist/src/shared/cli/constants/recfile-field-maps.constant.d.ts +21 -0
  24. package/dist/src/shared/cli/functions/compute-directory-level.function.d.ts +14 -0
  25. package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +2 -28
  26. package/dist/src/shared/cli/functions/format-command-output.function.d.ts +14 -0
  27. package/dist/src/shared/cli/functions/format-db-not-found.function.d.ts +20 -0
  28. package/dist/src/shared/cli/functions/format-output.function.d.ts +1 -0
  29. package/dist/src/shared/cli/functions/format-recfile-output.function.d.ts +11 -0
  30. package/dist/src/shared/cli/functions/render-recfile-value.function.d.ts +11 -0
  31. package/dist/src/shared/cli/functions/resolve-db-dir.function.d.ts +24 -0
  32. package/dist/src/shared/cli/functions/resolve-recfile-key.function.d.ts +9 -0
  33. package/dist/src/shared/cli/functions/run-db-path.function.d.ts +10 -0
  34. package/dist/src/shared/cli/functions/run-export.function.d.ts +8 -4
  35. package/dist/src/shared/cli/functions/run-import.function.d.ts +4 -0
  36. package/dist/src/shared/cli/functions/run-learn.function.d.ts +12 -0
  37. package/dist/src/shared/cli/index.d.ts +4 -1
  38. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +9 -2
  39. package/dist/src/shared/cli/typings/db-resolution.interface.d.ts +9 -0
  40. package/dist/src/shared/cli/typings/recfile-field-map.type.d.ts +10 -0
  41. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  42. package/dist/src/shared/wasm-codec/functions/decode-option-u8.function.d.ts +9 -0
  43. package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +4 -0
  44. package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +2 -45
  45. package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +10 -1
  46. package/dist/src/shared/wasm-codec/index.d.ts +1 -1
  47. package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +6 -0
  48. package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +5 -0
  49. package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +5 -0
  50. package/dist/src/shared/worker-client/functions/build-deno-permissions.function.d.ts +11 -0
  51. package/dist/src/shared/worker-client/functions/read-crash-reason.function.d.ts +9 -0
  52. package/dist/src/shared/worker-client/functions/resolve-spawn-script.function.d.ts +6 -0
  53. package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +1 -1
  54. package/dist/src/shared/worker-client/typings/section.model.d.ts +5 -0
  55. package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +0 -6
  56. package/dist/src/shared/worker-daemon/functions/count-files.function.d.ts +12 -0
  57. package/dist/src/shared/worker-daemon/functions/handle-import.function.d.ts +2 -0
  58. package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +8 -0
  59. package/dist/src/shared/worker-daemon/functions/validate-daemon-path.function.d.ts +15 -0
  60. package/dist/src/worker.d.ts +0 -7
  61. package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
  62. package/dist/wasm/default-embedding/package.json +1 -1
  63. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  64. package/dist/wasm/fs-database/package.json +1 -1
  65. package/dist/wasm/fs-migration/kbdb_fs_migration_bg.wasm +0 -0
  66. package/dist/wasm/fs-migration/package.json +1 -1
  67. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  68. package/dist/wasm/kb-worker/package.json +1 -1
  69. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  70. package/dist/wasm/query-parser/package.json +1 -1
  71. package/dist/worker.d.ts +0 -7
  72. package/dist/worker.mjs +37 -6
  73. package/dist/worker.mjs.map +3 -3
  74. package/package.json +13 -12
  75. package/dist/chunk-BJXEVALU.mjs.map +0 -7
  76. package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +0 -10
  77. package/docs/details/README.md +0 -30
  78. package/docs/details/agent-tooling.md +0 -132
  79. package/docs/details/cli.md +0 -777
  80. package/docs/details/knowledge-base.md +0 -180
  81. package/docs/details/library-api.md +0 -495
  82. package/docs/details/mcp-server.md +0 -482
  83. package/docs/details/search-and-ranking.md +0 -575
  84. package/docs/details/storage.md +0 -531
  85. package/docs/goals/agents.md +0 -751
  86. package/docs/goals/architecture.svg +0 -198
  87. package/docs/goals/auto-capture.md +0 -378
  88. package/docs/goals/benchmarking.md +0 -296
  89. package/docs/goals/cli.md +0 -2654
  90. package/docs/goals/concurrency.md +0 -259
  91. package/docs/goals/content-composer.md +0 -609
  92. package/docs/goals/content-parser.md +0 -279
  93. package/docs/goals/database.md +0 -1679
  94. package/docs/goals/document.md +0 -368
  95. package/docs/goals/hybrid-search.md +0 -465
  96. package/docs/goals/mcp.md +0 -1541
  97. package/docs/goals/overview.md +0 -124
  98. package/docs/goals/query-parser.md +0 -373
  99. package/docs/goals/query-result.md +0 -860
  100. package/docs/goals/semantic-dedup.md +0 -233
  101. package/docs/goals/skills.md +0 -810
  102. package/docs/goals/sync.md +0 -217
  103. package/docs/goals/worker-client.md +0 -1005
  104. package/docs/goals/worker-daemon.md +0 -1547
  105. package/docs/modules/overview.md +0 -319
  106. package/docs/modules/rust/embedding/module.md +0 -91
  107. package/docs/modules/rust/fs-database/functions/document.md +0 -48
  108. package/docs/modules/rust/fs-database/functions/integrity.md +0 -79
  109. package/docs/modules/rust/fs-database/functions/io.md +0 -87
  110. package/docs/modules/rust/fs-database/functions/module.md +0 -22
  111. package/docs/modules/rust/fs-database/functions/query-exec.md +0 -44
  112. package/docs/modules/rust/fs-database/functions/section.md +0 -76
  113. package/docs/modules/rust/fs-database/indexes/btree.md +0 -35
  114. package/docs/modules/rust/fs-database/indexes/corpus.md +0 -61
  115. package/docs/modules/rust/fs-database/indexes/inverted.md +0 -60
  116. package/docs/modules/rust/fs-database/indexes/module.md +0 -64
  117. package/docs/modules/rust/fs-database/indexes/positional.md +0 -39
  118. package/docs/modules/rust/fs-database/indexes/vectors.md +0 -110
  119. package/docs/modules/rust/fs-database/module.md +0 -150
  120. package/docs/modules/rust/fs-database/types/catalog.md +0 -53
  121. package/docs/modules/rust/fs-database/types/module.md +0 -12
  122. package/docs/modules/rust/fs-database/types/section.md +0 -127
  123. package/docs/modules/rust/kb-worker/functions/compose.md +0 -57
  124. package/docs/modules/rust/kb-worker/functions/module.md +0 -20
  125. package/docs/modules/rust/kb-worker/functions/retrieve.md +0 -194
  126. package/docs/modules/rust/kb-worker/functions/search.md +0 -173
  127. package/docs/modules/rust/kb-worker/functions/write.md +0 -172
  128. package/docs/modules/rust/kb-worker/module.md +0 -171
  129. package/docs/modules/rust/kb-worker/types/cache.md +0 -90
  130. package/docs/modules/rust/kb-worker/types/context.md +0 -26
  131. package/docs/modules/rust/kb-worker/types/module.md +0 -16
  132. package/docs/modules/rust/kb-worker/types/status.md +0 -29
  133. package/docs/modules/rust/kb-worker/types/token.md +0 -50
  134. package/docs/modules/rust/overview.md +0 -531
  135. package/docs/modules/rust/query-parser/functions/extract.md +0 -56
  136. package/docs/modules/rust/query-parser/functions/module.md +0 -18
  137. package/docs/modules/rust/query-parser/functions/parse.md +0 -33
  138. package/docs/modules/rust/query-parser/functions/pipeline.md +0 -9
  139. package/docs/modules/rust/query-parser/functions/rank.md +0 -85
  140. package/docs/modules/rust/query-parser/module.md +0 -131
  141. package/docs/modules/rust/query-parser/types/cache.md +0 -39
  142. package/docs/modules/rust/query-parser/types/keyphrase.md +0 -71
  143. package/docs/modules/rust/query-parser/types/module.md +0 -18
  144. package/docs/modules/rust/query-parser/types/token.md +0 -46
  145. package/docs/modules/rust/shared/content-composer/functions.md +0 -114
  146. package/docs/modules/rust/shared/content-composer/module.md +0 -147
  147. package/docs/modules/rust/shared/content-composer/types.md +0 -93
  148. package/docs/modules/rust/shared/content-parser/functions.md +0 -72
  149. package/docs/modules/rust/shared/content-parser/module.md +0 -99
  150. package/docs/modules/rust/shared/content-parser/types.md +0 -71
  151. package/docs/modules/rust/shared/corpus/module.md +0 -24
  152. package/docs/modules/rust/shared/corpus/types.md +0 -141
  153. package/docs/modules/rust/shared/document/module.md +0 -25
  154. package/docs/modules/rust/shared/document/types.md +0 -154
  155. package/docs/modules/rust/shared/encode/module.md +0 -22
  156. package/docs/modules/rust/shared/encode/traits.md +0 -304
  157. package/docs/modules/rust/shared/error/module.md +0 -28
  158. package/docs/modules/rust/shared/error/types.md +0 -302
  159. package/docs/modules/rust/shared/kbid/module.md +0 -24
  160. package/docs/modules/rust/shared/kbid/types.md +0 -147
  161. package/docs/modules/rust/shared/memory/functions.md +0 -209
  162. package/docs/modules/rust/shared/memory/module.md +0 -24
  163. package/docs/modules/rust/shared/module.md +0 -196
  164. package/docs/modules/rust/shared/pipeline/functions.md +0 -141
  165. package/docs/modules/rust/shared/pipeline/module.md +0 -62
  166. package/docs/modules/rust/shared/pipeline/types.md +0 -43
  167. package/docs/modules/rust/shared/query/module.md +0 -27
  168. package/docs/modules/rust/shared/query/types.md +0 -236
  169. package/docs/modules/rust/shared/section/module.md +0 -25
  170. package/docs/modules/rust/shared/section/types.md +0 -294
  171. package/docs/modules/rust/shared/term/module.md +0 -25
  172. package/docs/modules/rust/shared/term/types.md +0 -139
  173. package/docs/modules/typescript/cli.md +0 -131
  174. package/docs/modules/typescript/kbdb-worker.md +0 -150
  175. package/docs/modules/typescript/overview.md +0 -400
  176. package/docs/modules/typescript/shared/auto-capture/module.md +0 -73
  177. package/docs/modules/typescript/shared/cli/constants.md +0 -23
  178. package/docs/modules/typescript/shared/cli/functions.md +0 -809
  179. package/docs/modules/typescript/shared/cli/module.md +0 -138
  180. package/docs/modules/typescript/shared/cli/typings.md +0 -197
  181. package/docs/modules/typescript/shared/embedding/functions.md +0 -200
  182. package/docs/modules/typescript/shared/embedding/module.md +0 -77
  183. package/docs/modules/typescript/shared/embedding/typings.md +0 -124
  184. package/docs/modules/typescript/shared/hash/functions.md +0 -20
  185. package/docs/modules/typescript/shared/hash/module.md +0 -21
  186. package/docs/modules/typescript/shared/log/constants.md +0 -82
  187. package/docs/modules/typescript/shared/log/functions.md +0 -131
  188. package/docs/modules/typescript/shared/log/module.md +0 -153
  189. package/docs/modules/typescript/shared/log/typings.md +0 -82
  190. package/docs/modules/typescript/shared/mcp/classes.md +0 -179
  191. package/docs/modules/typescript/shared/mcp/functions.md +0 -386
  192. package/docs/modules/typescript/shared/mcp/module.md +0 -160
  193. package/docs/modules/typescript/shared/mcp/typings.md +0 -529
  194. package/docs/modules/typescript/shared/module.md +0 -110
  195. package/docs/modules/typescript/shared/platform/functions.md +0 -42
  196. package/docs/modules/typescript/shared/platform/module.md +0 -25
  197. package/docs/modules/typescript/shared/runtime/functions.md +0 -26
  198. package/docs/modules/typescript/shared/runtime/module.md +0 -27
  199. package/docs/modules/typescript/shared/runtime/typings.md +0 -13
  200. package/docs/modules/typescript/shared/version/module.md +0 -27
  201. package/docs/modules/typescript/shared/wasm-codec/functions.md +0 -391
  202. package/docs/modules/typescript/shared/wasm-codec/module.md +0 -98
  203. package/docs/modules/typescript/shared/worker-client/classes.md +0 -264
  204. package/docs/modules/typescript/shared/worker-client/functions.md +0 -175
  205. package/docs/modules/typescript/shared/worker-client/module.md +0 -92
  206. package/docs/modules/typescript/shared/worker-client/typings.md +0 -511
  207. package/docs/modules/typescript/shared/worker-daemon/classes.md +0 -239
  208. package/docs/modules/typescript/shared/worker-daemon/constants.md +0 -37
  209. package/docs/modules/typescript/shared/worker-daemon/functions.md +0 -234
  210. package/docs/modules/typescript/shared/worker-daemon/module.md +0 -118
  211. package/docs/modules/typescript/shared/worker-daemon/typings.md +0 -132
  212. package/docs/overview.md +0 -191
  213. package/docs/release-notes/0.1.0.md +0 -189
  214. package/docs/release-notes/0.1.1.md +0 -46
  215. package/docs/release-notes/0.1.2.md +0 -38
  216. package/docs/release-notes/0.1.3.md +0 -42
  217. package/docs/release-notes/0.2.0.md +0 -147
  218. package/docs/release-notes/0.3.0.md +0 -89
  219. package/docs/release-notes/0.3.1.md +0 -121
  220. package/docs/release-notes/0.3.2.md +0 -64
  221. package/docs/release-notes/0.4.0.md +0 -80
  222. package/docs/release-notes/0.4.1.md +0 -149
  223. package/docs/release-notes/0.4.3.md +0 -60
  224. package/docs/release-notes/README.md +0 -13
@@ -1,62 +0,0 @@
1
- # pipeline -- Tokenization Pipeline
2
-
3
- *9-stage pipeline that converts raw text into
4
- normalized, stemmed tokens with synonym expansion.
5
- Shared across all crates that need text
6
- tokenization.*
7
-
8
- ## Source
9
-
10
- `engine/crates/shared/src/pipeline/`
11
-
12
- ## Responsibility
13
-
14
- The pipeline module provides the canonical
15
- tokenization function used for both indexing and
16
- query processing. All crates that need to tokenize
17
- text import from this single source of truth.
18
-
19
- ## Consumers
20
-
21
- - **kbdb-query-parser** -- re-exports via the
22
- `qp_tokenize` WASM FFI export. Uses internally
23
- for query parsing (`parse`), keyword extraction
24
- (`extract/rake`), and n-gram generation.
25
- - **kbdb-default-embedding** -- tokenizes text
26
- before feature hashing to produce TF-IDF vectors
27
- that are token-consistent with the lexical index.
28
-
29
- ## Directory Layout
30
-
31
- ```
32
- engine/crates/shared/src/pipeline/
33
- ├── mod.rs # pipeline orchestrator
34
- ├── markers.rs # stage 1: strip markers
35
- ├── unicode.rs # stage 2: NFC normalize
36
- ├── segment.rs # stage 3: word boundaries
37
- ├── identifiers.rs # stage 4: camelCase split
38
- ├── case.rs # stage 5: case folding
39
- ├── stopwords.rs # stage 6: stop words
40
- ├── synonyms.rs # stage 7: synonym expansion
41
- ├── stem.rs # stage 8: Snowball stemmer
42
- ├── ngram.rs # stage 9: n-gram extract
43
- └── token_result.rs # TokenResult struct
44
- ```
45
-
46
- ## Exports
47
-
48
- - **[functions.md](functions.md)** -- `tokenize()`,
49
- `bigrams()`, `trigrams()`. Full 9-stage pipeline.
50
- - **[types.md](types.md)** -- `TokenResult`,
51
- `TokenStream`, `Ngram`, `NgramType`, `StemResult`.
52
-
53
- ## Dependencies
54
-
55
- The pipeline brings three external crates into
56
- `kbdb-shared`:
57
-
58
- ```toml
59
- unicode-segmentation = "1" # stage 3
60
- unicode-normalization = "0.1" # stage 2
61
- rust-stemmers = "1" # stage 8
62
- ```
@@ -1,43 +0,0 @@
1
- # pipeline -- Tokenization Types
2
-
3
- *Output types from the tokenization pipeline.*
4
-
5
- ## Source
6
-
7
- `engine/crates/shared/src/pipeline/`
8
-
9
- ## Type Definitions
10
-
11
- ```rust
12
- pub struct TokenResult {
13
- pub original: String,
14
- pub stemmed: String,
15
- pub position: u32,
16
- }
17
-
18
- pub struct TokenStream {
19
- pub tokens: Vec<TokenResult>,
20
- pub ngrams: Vec<Ngram>,
21
- }
22
-
23
- pub struct Ngram {
24
- pub terms: Vec<String>,
25
- pub gram_type: NgramType,
26
- }
27
-
28
- pub enum NgramType { Bigram, Trigram }
29
-
30
- pub struct StemResult {
31
- pub original: String,
32
- pub stemmed: String,
33
- }
34
- ```
35
-
36
- `TokenResult` preserves both original and stemmed
37
- forms so the index can support exact-match and
38
- stem-match queries. `position` is the zero-based
39
- token offset.
40
-
41
- `TokenStream` is the output of `tokenize()` -- the
42
- full set of tokens and extracted n-grams from a
43
- single input text.
@@ -1,27 +0,0 @@
1
- # query -- Query Plan and Match Results
2
-
3
- *Data structures that flow between query-parser and
4
- fs-database via kb-worker: the structured query plan
5
- and the raw index match results.*
6
-
7
- ## Source
8
-
9
- `engine/crates/shared/src/query/`
10
-
11
- ## Responsibility
12
-
13
- Defines the query plan and raw match types that cross
14
- WASM module boundaries during the search lifecycle.
15
- `query-parser` produces `QueryPlan`, `fs-database`
16
- executes it and returns `Vec<RawMatch>`, then
17
- `query-parser` scores the matches.
18
-
19
- See [Query Parser -- Query Parsing](
20
- ../../../../goals/query-parser.md) for parsing stages.
21
- See [Database -- Search](
22
- ../../../../goals/database.md) for query plan execution.
23
-
24
- ## Exports
25
-
26
- - **[types.md](types.md)** -- `QueryPlan`,
27
- `RawMatch`, `MatchMode`.
@@ -1,236 +0,0 @@
1
- # types::query -- Query Plan and Raw Match Results
2
-
3
- *Data structures that flow between query-parser and
4
- fs-database via kb-worker: the structured query plan
5
- and the raw index match results.*
6
-
7
- ## File
8
-
9
- `engine/crates/shared/src/query/query.rs`
10
-
11
- ## Overview
12
-
13
- The query lifecycle splits across two standalone WASM
14
- modules:
15
-
16
- 1. `query-parser.wasm` parses a search string into a
17
- **QueryPlan**.
18
- 2. `fs-database.wasm` executes the plan against
19
- indexes and returns **RawMatch** results.
20
- 3. `query-parser.wasm` scores the raw matches into
21
- ranked results.
22
-
23
- `kb-worker.wasm` orchestrates these steps. The types
24
- in this module define the data shapes that cross
25
- module boundaries at steps 1->2 and 2->3.
26
-
27
- See [Query Parser -- Query Parsing](
28
- ../../../../../goals/query-parser.md) for parsing stages.
29
- See [Database -- Search](
30
- ../../../../../goals/database.md) for query plan execution.
31
-
32
- ## Type Definitions
33
-
34
- ### `QueryPlan`
35
-
36
- ```rust
37
- pub struct QueryPlan {
38
- pub terms: Vec<Term>,
39
- pub phrases: Vec<Vec<Term>>,
40
- pub exclusions: Vec<Term>,
41
- pub mode: MatchMode,
42
- }
43
- ```
44
-
45
- The output of `qp_parse_query`. A data retrieval
46
- strategy that describes which terms to look up, how
47
- to combine them, and what to exclude.
48
-
49
- | Field | Description |
50
- |--------------|-------------------------------------|
51
- | `terms` | Individual terms to match |
52
- | `phrases` | Ordered term sequences for exact phrase matching |
53
- | `exclusions` | Terms to exclude from results |
54
- | `mode` | How to combine term matches |
55
-
56
- #### `terms`
57
-
58
- The tokenized, stemmed terms from the query string.
59
- Each term is looked up in the inverted index. A query
60
- like `"rust wasm engine"` produces three terms.
61
-
62
- #### `phrases`
63
-
64
- Quoted phrases from the query. `"file database"`
65
- produces `vec![vec![Term("file"), Term("databas")]]`
66
- (stemmed). Phrase matching uses the positional index
67
- to verify that terms appear adjacent and in order.
68
-
69
- #### `exclusions`
70
-
71
- Terms prefixed with `-` in the query. `-draft`
72
- produces `vec![Term("draft")]`. Sections matching
73
- excluded terms are removed from results.
74
-
75
- #### `mode`
76
-
77
- ```rust
78
- pub enum MatchMode {
79
- And,
80
- Or,
81
- }
82
- ```
83
-
84
- - `And` -- All non-excluded terms must appear
85
- (default).
86
- - `Or` -- Any non-excluded term may appear.
87
-
88
- `fs-database` uses this to decide whether to
89
- intersect or union posting lists.
90
-
91
- ### `RawMatch`
92
-
93
- ```rust
94
- pub struct RawMatch {
95
- pub kbid: KbId,
96
- pub field_tfs: Vec<(Term, FieldTf)>,
97
- pub positions: Vec<(Term, Vec<u32>)>,
98
- pub token_count: u32,
99
- pub field_token_counts: FieldTokenCounts,
100
- }
101
- ```
102
-
103
- The output of `db_execute_plan`. One `RawMatch` per
104
- section that passed the query plan's term and
105
- exclusion filters.
106
-
107
- | Field | Description |
108
- |----------------------|--------------------------------|
109
- | `kbid` | The matching section |
110
- | `field_tfs` | Per-term per-field TF values |
111
- | `positions` | Per-term position lists for proximity/phrase scoring |
112
- | `token_count` | Total token count of the section |
113
- | `field_token_counts` | Per-field token counts |
114
-
115
- #### `field_tfs`
116
-
117
- A list of (term, `FieldTf`) pairs. Each `FieldTf`
118
- contains the term's frequency in the heading, body,
119
- and code fields separately. Pre-computed during
120
- indexing and stored in the inverted index. Used by
121
- `qp_score_bm25f` for per-field BM25 scoring with
122
- field-specific weights.
123
-
124
- #### `positions`
125
-
126
- A list of (term, positions) pairs. Each position is
127
- the zero-based token offset where the term occurs.
128
- Used by:
129
-
130
- - `qp_score_proximity` -- to measure how close query
131
- terms appear to each other.
132
- - `qp_score_zone` -- to determine whether terms fall
133
- in heading zones (early positions).
134
- - Phrase verification -- to confirm that phrase terms
135
- appear adjacent and in order.
136
-
137
- #### `token_count`
138
-
139
- Total token count of the matching section. Read
140
- from the section header (pre-computed during
141
- indexing). Used by `qp_score_zone` to determine
142
- the heading zone boundary (~20% of section length).
143
-
144
- #### `field_token_counts`
145
-
146
- Per-field token counts read from the section header.
147
- Used by `qp_score_bm25f` for per-field length
148
- normalization: each field's token count is compared
149
- to the corpus average for that field.
150
-
151
- ### `FieldTf`
152
-
153
- ```rust
154
- pub struct FieldTf {
155
- pub heading: f32,
156
- pub body: f32,
157
- pub code: f32,
158
- }
159
- ```
160
-
161
- Per-field term frequency. Each field stores the
162
- count of how many times a term appears in that
163
- field of a section, computed during per-field
164
- tokenization at indexing time. See
165
- [Inverted Index](../../fs-database/indexes/inverted.md)
166
- for storage format.
167
-
168
- | Field | Source content | Default weight |
169
- |-----------|-----------------------------|----------------|
170
- | `heading` | Section title | 2.0x |
171
- | `body` | Body text + description | 1.0x |
172
- | `code` | Code / source content | 1.5x |
173
-
174
- ### `FieldTokenCounts`
175
-
176
- ```rust
177
- pub struct FieldTokenCounts {
178
- pub heading: u32,
179
- pub body: u32,
180
- pub code: u32,
181
- }
182
- ```
183
-
184
- Per-field token counts stored in section headers.
185
- Pre-computed during indexing and used at query time
186
- for per-field BM25 length normalization.
187
-
188
- ## Relationships
189
-
190
- ```
191
- qp_parse_query
192
- query string ──────────→ QueryPlan
193
-
194
- db_execute_plan
195
-
196
-
197
- Vec<RawMatch>
198
-
199
- qp_score_bm25f / proximity / zone
200
-
201
-
202
- ranked results
203
- ```
204
-
205
- Both `QueryPlan` and `RawMatch` are serialized
206
- through shared `WebAssembly.Memory` via the `Encode`
207
- trait (see [encode](../encode/traits.md))
208
- when crossing module boundaries. `kb-worker` handles
209
- the serialization and deserialization at each step.
210
-
211
- ## Trait Implementations
212
-
213
- | Trait | Types |
214
- |----------|--------------------------|
215
- | `Clone` | `QueryPlan`, `MatchMode`, `RawMatch`, `FieldTf`, `FieldTokenCounts` |
216
- | `Debug` | All types |
217
- | `Encode` | `QueryPlan`, `MatchMode`, `RawMatch`, `FieldTf`, `FieldTokenCounts` |
218
- | `Copy` | `MatchMode`, `FieldTf`, `FieldTokenCounts` |
219
-
220
- `MatchMode` also derives `PartialEq` and `Eq`.
221
-
222
- ## Testing
223
-
224
- Unit tests:
225
-
226
- - `QueryPlan` construction with terms, phrases,
227
- exclusions, and both match modes.
228
- - `Encode` round-trip for `QueryPlan` with all
229
- fields populated.
230
- - `Encode` round-trip for `RawMatch` with
231
- `field_tfs`, positions, `token_count`, and
232
- `field_token_counts`.
233
- - `FieldTf` and `FieldTokenCounts` construction
234
- and `Encode` round-trip.
235
- - Empty edge cases: plan with no terms, match with
236
- no positions, zero field counts.
@@ -1,25 +0,0 @@
1
- # section -- Section Types and Records
2
-
3
- *Section type enum, MIME type wrapper, and data
4
- structures for section CRUD operations.*
5
-
6
- ## Source
7
-
8
- `engine/crates/shared/src/section/`
9
-
10
- ## Responsibility
11
-
12
- Defines the content type system (`SectionType`,
13
- `MimeType`) and the data structures for section CRUD
14
- operations (`SectionRecord`, `AddSectionParams`,
15
- etc.) shared across all four WASM modules.
16
-
17
- See [Database -- Sections](../../../../goals/database.md)
18
- for the behavioral specification of section types.
19
-
20
- ## Exports
21
-
22
- - **[types.md](types.md)** -- `SectionType`,
23
- `MimeType`, `SectionRecord`, `AddSectionParams`,
24
- `AddSectionResult`, `UpdateSectionResult`,
25
- `RemoveSectionResult`, `MimeError`.
@@ -1,294 +0,0 @@
1
- # types::section -- Section Types and Records
2
-
3
- *Section type enum, MIME type wrapper, and the data
4
- structures for section CRUD operations across all
5
- four WASM modules.*
6
-
7
- ## File
8
-
9
- `engine/crates/shared/src/section/section.rs`
10
-
11
- ## Overview
12
-
13
- Sections are the atomic content units in the
14
- knowledge base. Each section has a **type** that
15
- determines how it is stored, whether it is indexed,
16
- and how it is rendered. The types in this module are
17
- shared across `fs-database` (storage), `query-parser`
18
- (indexing decisions), and `kb-worker` (orchestration).
19
-
20
- See [Database -- Sections](../../../../../goals/database.md)
21
- for the behavioral specification of section types,
22
- embedding markers, and MIME-to-language mapping.
23
-
24
- ## Type Definitions
25
-
26
- ### `MimeType`
27
-
28
- ```rust
29
- #[derive(Clone, Debug, PartialEq, Eq)]
30
- pub struct MimeType(String);
31
-
32
- impl MimeType {
33
- pub fn new(mime: &str) -> Result<Self, MimeError>;
34
- pub fn as_str(&self) -> &str;
35
- pub fn subtype(&self) -> &str;
36
- }
37
- ```
38
-
39
- Newtype wrapper for MIME type strings. Validates
40
- that the string contains a `/` separator (e.g.
41
- `"text/typescript"`, `"image/png"`,
42
- `"application/json"`).
43
-
44
- `subtype()` returns the part after the `/`:
45
- `"text/typescript"` -> `"typescript"`,
46
- `"application/json"` -> `"json"`.
47
-
48
- ### `SectionType`
49
-
50
- ```rust
51
- #[derive(Clone, Debug, PartialEq, Eq)]
52
- pub enum SectionType {
53
- Text,
54
- Code(MimeType),
55
- Image(MimeType),
56
- }
57
- ```
58
-
59
- Three variants corresponding to the three content
60
- kinds in the knowledge base:
61
-
62
- | Variant | Content | Indexed | Embeddable via |
63
- |---------------|--------------|---------|-------------------|
64
- | `Text` | Raw text | Yes | `$(text: {kbid})` |
65
- | `Code(mime)` | Raw source | Yes | `$(code: {kbid})` |
66
- | `Image(mime)` | Base64 bytes | title/description only | `$(image: {kbid})`|
67
-
68
- ### `SectionType` Methods
69
-
70
- ```rust
71
- impl SectionType {
72
- pub fn is_indexable(&self) -> bool;
73
- pub fn as_mime_str(&self) -> &str;
74
- pub fn from_mime(mime: &str) -> Self;
75
- pub fn language_tag(&self) -> Option<&str>;
76
- }
77
- ```
78
-
79
- #### `is_indexable`
80
-
81
- ```rust
82
- pub fn is_indexable(&self) -> bool {
83
- matches!(self, Self::Text | Self::Code(_))
84
- }
85
- ```
86
-
87
- Returns `true` for `Text` and `Code`, `false` for
88
- `Image`. Used by `kb-worker` to decide whether to
89
- tokenize the section body content. Note:
90
- `kb-worker` independently indexes image sections'
91
- `title` (required, heading field 2.0x) and
92
- `description` (optional, body field 1.0x)
93
- regardless of `is_indexable()` returning `false`.
94
-
95
- #### `as_mime_str`
96
-
97
- Returns the MIME string representation:
98
-
99
- - `Text` -> `"text/markdown"`
100
- - `Code(mime)` -> the inner MIME string
101
- (e.g. `"text/typescript"`)
102
- - `Image(mime)` -> the inner MIME string
103
- (e.g. `"image/png"`)
104
-
105
- #### `from_mime`
106
-
107
- Parses a MIME string into the appropriate variant:
108
-
109
- | Input | Result |
110
- |----------------------|-------------------------------------|
111
- | `"text/markdown"` | `SectionType::Text` |
112
- | `"text/typescript"` | `SectionType::Code("text/typescript")` |
113
- | `"text/javascript"` | `SectionType::Code("text/javascript")` |
114
- | `"text/html"` | `SectionType::Code("text/html")` |
115
- | `"text/css"` | `SectionType::Code("text/css")` |
116
- | `"text/xml"` | `SectionType::Code("text/xml")` |
117
- | `"text/plain"` | `SectionType::Code("text/plain")` |
118
- | `"text/*"` (other) | `SectionType::Code("text/{subtype}")` |
119
- | `"application/json"` | `SectionType::Code("application/json")` |
120
- | `"image/png"` | `SectionType::Image("image/png")` |
121
- | `"image/jpeg"` | `SectionType::Image("image/jpeg")` |
122
- | `"image/*"` (other) | `SectionType::Image("image/{subtype}")` |
123
-
124
- `"text/markdown"` is the canonical type for
125
- natural-language text sections. Any other `text/*`
126
- subtype maps to `Code`.
127
-
128
- #### `language_tag`
129
-
130
- Returns the fenced code block language tag for code
131
- sections. Returns `None` for `Text` and `Image`.
132
-
133
- | MIME Type | Language Tag |
134
- |----------------------|--------------|
135
- | `text/typescript` | `"ts"` |
136
- | `text/javascript` | `"js"` |
137
- | `text/html` | `"html"` |
138
- | `text/css` | `"css"` |
139
- | `text/xml` | `"xml"` |
140
- | `text/plain` | `None` |
141
- | `application/json` | `"json"` |
142
-
143
- Other `text/*` subtypes return the subtype as the
144
- language tag (e.g. `"text/python"` -> `"python"`,
145
- `"text/rust"` -> `"rust"`).
146
-
147
- ## Section Records
148
-
149
- Data structures for section CRUD operations. Used in
150
- IPC request/response payloads and as cache entries.
151
-
152
- ### `SectionRecord`
153
-
154
- ```rust
155
- pub struct SectionRecord {
156
- pub kbid: KbId,
157
- pub docids: Vec<String>,
158
- pub section_type: SectionType,
159
- pub title: Option<String>,
160
- pub description: Option<String>,
161
- pub content: Vec<u8>,
162
- pub size: u32,
163
- pub created_at: String,
164
- pub checksum: String,
165
- pub token_count: u32,
166
- pub heading_token_count: u32,
167
- pub body_token_count: u32,
168
- pub code_token_count: u32,
169
- }
170
- ```
171
-
172
- Full section data as read from disk. `docids` lists
173
- the document IDs this section belongs to (may be
174
- empty, one, or many -- many-to-many relationship).
175
- `content` is raw UTF-8 bytes for text and code
176
- sections, or base64-encoded bytes for image sections.
177
- `size` is the byte length of the content body.
178
- `title` is required for image sections and optional
179
- for text/code. `description` is always optional.
180
- Token counts are pre-computed during per-field
181
- tokenization at indexing time.
182
-
183
- ### `AddSectionParams`
184
-
185
- ```rust
186
- pub struct AddSectionParams {
187
- pub content: Vec<u8>,
188
- pub section_type: SectionType,
189
- pub title: Option<String>,
190
- pub description: Option<String>,
191
- pub docid: Option<String>,
192
- }
193
- ```
194
-
195
- Input for creating a new section. The caller passes
196
- raw content; `fs-database.wasm` applies the
197
- preprocessing pipeline internally to text and code
198
- sections (BOM removal, line ending normalization,
199
- Unicode NFC, whitespace trimming) before computing
200
- the kbid. Image content is stored verbatim. The
201
- kbid is derived from the preprocessed `content` by
202
- `fs-database` during creation -- it is not provided
203
- by the caller.
204
-
205
- `title` is required when `section_type` is
206
- `Image(*)` -- validation fails without it.
207
- `description` is always optional. Both are
208
- tokenized during indexing: title into the heading
209
- field (2.0x weight), description into the body
210
- field (1.0x weight).
211
-
212
- ### `AddSectionResult`
213
-
214
- ```rust
215
- pub struct AddSectionResult {
216
- pub kbid: KbId,
217
- pub section_type: SectionType,
218
- pub title: Option<String>,
219
- pub description: Option<String>,
220
- pub indexed_terms_count: u32,
221
- pub token_count: u32,
222
- pub elapsed_ms: u64,
223
- pub attached: bool,
224
- }
225
- ```
226
-
227
- `indexed_terms_count` reflects the number of
228
- distinct terms indexed across all fields. For
229
- image sections, this is the count from
230
- title/description tokenization (zero only when
231
- both produce no terms). `token_count` is the total
232
- token count across all fields. `attached` is `true`
233
- when the content already existed and a new docid
234
- was added to the section's `docids` list instead of
235
- creating a new section.
236
-
237
- ### `UpdateSectionResult`
238
-
239
- ```rust
240
- pub struct UpdateSectionResult {
241
- pub old_kbid: KbId,
242
- pub new_kbid: KbId,
243
- pub reindexed_terms_count: u32,
244
- pub elapsed_ms: u64,
245
- }
246
- ```
247
-
248
- Updates produce a new section file with a new kb-id
249
- (content-addressable). The old kb-id is returned so
250
- the caller and cache can invalidate stale references.
251
-
252
- ### `RemoveSectionResult`
253
-
254
- ```rust
255
- pub struct RemoveSectionResult {
256
- pub removed: bool,
257
- pub elapsed_ms: u64,
258
- }
259
- ```
260
-
261
- `removed` is `false` if the kb-id was not found.
262
-
263
- ## Trait Implementations
264
-
265
- All structs implement `Clone`, `Debug`, and `Encode`
266
- (see [encode](../encode/traits.md)).
267
- `SectionType` also implements `PartialEq` and `Eq`
268
- for type comparison.
269
-
270
- ## Error Type
271
-
272
- ```rust
273
- #[derive(Debug)]
274
- pub enum MimeError {
275
- MissingSeparator(String),
276
- EmptyType(String),
277
- EmptySubtype(String),
278
- }
279
- ```
280
-
281
- ## Testing
282
-
283
- Unit tests:
284
-
285
- - `SectionType::from_mime` mapping for all documented
286
- MIME types.
287
- - `is_indexable` returns `true` for `Text` and `Code`,
288
- `false` for `Image`.
289
- - `language_tag` returns correct tags for known MIME
290
- types and subtype-as-fallback for unknown ones.
291
- - `from_mime` with `"text/markdown"` produces `Text`,
292
- not `Code`.
293
- - `MimeType::subtype` extracts correctly.
294
- - `Encode` round-trip for all record types.