@dikolab/kbdb 0.1.6 → 0.2.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/README.md +30 -9
- package/dist/cli.cjs +181 -50
- package/dist/cli.cjs.map +3 -3
- package/dist/cli.mjs +181 -50
- package/dist/cli.mjs.map +3 -3
- package/dist/kbdb-worker.cjs +283 -29
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +13 -2
- package/dist/mod.cjs.map +2 -2
- package/dist/mod.mjs +13 -2
- package/dist/mod.mjs.map +2 -2
- package/dist/src/shared/cli/functions/format-output.function.d.ts +7 -7
- package/dist/src/shared/cli/functions/run-search.function.d.ts +25 -16
- package/dist/src/shared/cli/index.d.ts +1 -1
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +2 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +25 -7
- package/dist/src/shared/mcp/functions/handle-recall.function.d.ts +29 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +30 -11
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +28 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +14 -7
- package/dist/src/shared/wasm-codec/functions/encode-recall-params.function.d.ts +21 -0
- package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -1
- package/dist/src/shared/wasm-codec/index.d.ts +5 -2
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +13 -3
- package/dist/src/shared/worker-client/index.d.ts +2 -1
- package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +94 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +2 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +23 -7
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
- package/dist/wasm/fs-database/kbdb_fs_database.js +30 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +38 -0
- package/dist/wasm/kb-worker/kbdb_worker.js +56 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
- package/dist/worker.mjs +283 -29
- package/dist/worker.mjs.map +4 -4
- package/docs/details/README.md +26 -0
- package/docs/details/cli.md +608 -0
- package/docs/details/library-api.md +406 -0
- package/docs/details/mcp-server.md +430 -0
- package/docs/details/search-and-ranking.md +457 -0
- package/docs/details/storage.md +529 -0
- package/docs/goals/agents.md +751 -0
- package/docs/goals/architecture.svg +198 -0
- package/docs/goals/cli.md +2308 -0
- package/docs/goals/content-composer.md +609 -0
- package/docs/goals/content-parser.md +279 -0
- package/docs/goals/database.md +1452 -0
- package/docs/goals/document.md +368 -0
- package/docs/goals/mcp.md +1467 -0
- package/docs/goals/overview.md +124 -0
- package/docs/goals/query-parser.md +271 -0
- package/docs/goals/query-result.md +693 -0
- package/docs/goals/skills.md +738 -0
- package/docs/goals/worker-client.md +944 -0
- package/docs/goals/worker-daemon.md +1447 -0
- package/docs/modules/overview.md +298 -0
- package/docs/modules/rust/fs-database/functions/document.md +48 -0
- package/docs/modules/rust/fs-database/functions/integrity.md +68 -0
- package/docs/modules/rust/fs-database/functions/io.md +87 -0
- package/docs/modules/rust/fs-database/functions/module.md +22 -0
- package/docs/modules/rust/fs-database/functions/query-exec.md +44 -0
- package/docs/modules/rust/fs-database/functions/section.md +59 -0
- package/docs/modules/rust/fs-database/indexes/btree.md +35 -0
- package/docs/modules/rust/fs-database/indexes/corpus.md +61 -0
- package/docs/modules/rust/fs-database/indexes/inverted.md +60 -0
- package/docs/modules/rust/fs-database/indexes/module.md +64 -0
- package/docs/modules/rust/fs-database/indexes/positional.md +39 -0
- package/docs/modules/rust/fs-database/module.md +149 -0
- package/docs/modules/rust/fs-database/types/catalog.md +53 -0
- package/docs/modules/rust/fs-database/types/module.md +12 -0
- package/docs/modules/rust/fs-database/types/section.md +101 -0
- package/docs/modules/rust/kb-worker/functions/compose.md +57 -0
- package/docs/modules/rust/kb-worker/functions/module.md +20 -0
- package/docs/modules/rust/kb-worker/functions/retrieve.md +194 -0
- package/docs/modules/rust/kb-worker/functions/search.md +173 -0
- package/docs/modules/rust/kb-worker/functions/write.md +172 -0
- package/docs/modules/rust/kb-worker/module.md +171 -0
- package/docs/modules/rust/kb-worker/types/cache.md +90 -0
- package/docs/modules/rust/kb-worker/types/context.md +26 -0
- package/docs/modules/rust/kb-worker/types/module.md +16 -0
- package/docs/modules/rust/kb-worker/types/status.md +29 -0
- package/docs/modules/rust/kb-worker/types/token.md +50 -0
- package/docs/modules/rust/overview.md +495 -0
- package/docs/modules/rust/query-parser/functions/extract.md +56 -0
- package/docs/modules/rust/query-parser/functions/module.md +16 -0
- package/docs/modules/rust/query-parser/functions/parse.md +33 -0
- package/docs/modules/rust/query-parser/functions/pipeline.md +103 -0
- package/docs/modules/rust/query-parser/functions/rank.md +85 -0
- package/docs/modules/rust/query-parser/module.md +136 -0
- package/docs/modules/rust/query-parser/types/cache.md +39 -0
- package/docs/modules/rust/query-parser/types/keyphrase.md +60 -0
- package/docs/modules/rust/query-parser/types/module.md +17 -0
- package/docs/modules/rust/query-parser/types/token.md +42 -0
- package/docs/modules/rust/shared/content-composer/functions.md +114 -0
- package/docs/modules/rust/shared/content-composer/module.md +147 -0
- package/docs/modules/rust/shared/content-composer/types.md +93 -0
- package/docs/modules/rust/shared/content-parser/functions.md +72 -0
- package/docs/modules/rust/shared/content-parser/module.md +99 -0
- package/docs/modules/rust/shared/content-parser/types.md +71 -0
- package/docs/modules/rust/shared/corpus/module.md +24 -0
- package/docs/modules/rust/shared/corpus/types.md +141 -0
- package/docs/modules/rust/shared/document/module.md +25 -0
- package/docs/modules/rust/shared/document/types.md +154 -0
- package/docs/modules/rust/shared/encode/module.md +22 -0
- package/docs/modules/rust/shared/encode/traits.md +304 -0
- package/docs/modules/rust/shared/error/module.md +28 -0
- package/docs/modules/rust/shared/error/types.md +302 -0
- package/docs/modules/rust/shared/kbid/module.md +24 -0
- package/docs/modules/rust/shared/kbid/types.md +147 -0
- package/docs/modules/rust/shared/memory/functions.md +209 -0
- package/docs/modules/rust/shared/memory/module.md +24 -0
- package/docs/modules/rust/shared/module.md +168 -0
- package/docs/modules/rust/shared/query/module.md +27 -0
- package/docs/modules/rust/shared/query/types.md +236 -0
- package/docs/modules/rust/shared/section/module.md +25 -0
- package/docs/modules/rust/shared/section/types.md +294 -0
- package/docs/modules/rust/shared/term/module.md +25 -0
- package/docs/modules/rust/shared/term/types.md +139 -0
- package/docs/modules/typescript/cli.md +129 -0
- package/docs/modules/typescript/kbdb-worker.md +135 -0
- package/docs/modules/typescript/overview.md +378 -0
- package/docs/modules/typescript/shared/cli/constants.md +23 -0
- package/docs/modules/typescript/shared/cli/functions.md +630 -0
- package/docs/modules/typescript/shared/cli/module.md +125 -0
- package/docs/modules/typescript/shared/cli/typings.md +172 -0
- package/docs/modules/typescript/shared/hash/functions.md +20 -0
- package/docs/modules/typescript/shared/hash/module.md +21 -0
- package/docs/modules/typescript/shared/mcp/classes.md +179 -0
- package/docs/modules/typescript/shared/mcp/functions.md +386 -0
- package/docs/modules/typescript/shared/mcp/module.md +160 -0
- package/docs/modules/typescript/shared/mcp/typings.md +522 -0
- package/docs/modules/typescript/shared/module.md +94 -0
- package/docs/modules/typescript/shared/platform/functions.md +42 -0
- package/docs/modules/typescript/shared/platform/module.md +25 -0
- package/docs/modules/typescript/shared/runtime/functions.md +26 -0
- package/docs/modules/typescript/shared/runtime/module.md +27 -0
- package/docs/modules/typescript/shared/runtime/typings.md +13 -0
- package/docs/modules/typescript/shared/version/module.md +27 -0
- package/docs/modules/typescript/shared/wasm-codec/functions.md +391 -0
- package/docs/modules/typescript/shared/wasm-codec/module.md +98 -0
- package/docs/modules/typescript/shared/worker-client/classes.md +264 -0
- package/docs/modules/typescript/shared/worker-client/functions.md +175 -0
- package/docs/modules/typescript/shared/worker-client/module.md +84 -0
- package/docs/modules/typescript/shared/worker-client/typings.md +508 -0
- package/docs/modules/typescript/shared/worker-daemon/classes.md +239 -0
- package/docs/modules/typescript/shared/worker-daemon/constants.md +37 -0
- package/docs/modules/typescript/shared/worker-daemon/functions.md +221 -0
- package/docs/modules/typescript/shared/worker-daemon/module.md +112 -0
- package/docs/modules/typescript/shared/worker-daemon/typings.md +126 -0
- package/docs/overview.md +188 -0
- package/docs/release-notes/0.1.0.md +189 -0
- package/docs/release-notes/0.1.1.md +46 -0
- package/docs/release-notes/0.1.2.md +38 -0
- package/docs/release-notes/0.1.3.md +42 -0
- package/docs/release-notes/0.2.0.md +147 -0
- package/docs/release-notes/README.md +9 -0
- package/package.json +8 -2
- package/src/shared/cli/functions/dispatch-command.function.ts +3 -3
- package/src/shared/cli/functions/format-output.function.ts +41 -34
- package/src/shared/cli/functions/parse-args.function.ts +7 -0
- package/src/shared/cli/functions/run-search.function.ts +53 -27
- package/src/shared/cli/index.ts +4 -1
- package/src/shared/cli/typings/cli-options.interface.ts +2 -0
- package/src/shared/cli/typings/search-display.model.ts +26 -7
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +64 -4
- package/src/shared/mcp/functions/handle-recall.function.ts +66 -0
- package/src/shared/mcp/functions/handle-tool-call.function.ts +11 -1
- package/src/shared/mcp/typings/mcp-client.interface.ts +33 -15
- package/src/shared/version/constants/version.constant.ts +1 -1
- package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +267 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +81 -27
- package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +68 -0
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +4 -1
- package/src/shared/wasm-codec/index.ts +11 -3
- package/src/shared/worker-client/classes/worker-client.class.ts +24 -4
- package/src/shared/worker-client/index.ts +11 -1
- package/src/shared/worker-client/typings/recall-result.model.ts +98 -0
- package/src/shared/worker-client/typings/search-params.model.ts +2 -0
- package/src/shared/worker-client/typings/search-result.model.ts +24 -7
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +25 -4
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
- package/src/wasm/fs-database/kbdb_fs_database.js +30 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
- package/src/wasm/kb-worker/kbdb_worker.d.ts +38 -0
- package/src/wasm/kb-worker/kbdb_worker.js +56 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# shared -- Shared Types and Utilities
|
|
2
|
+
|
|
3
|
+
*Rust crate that provides types, memory helpers, error
|
|
4
|
+
types, and serialization utilities shared across all
|
|
5
|
+
three WASM modules.*
|
|
6
|
+
|
|
7
|
+
## Crate
|
|
8
|
+
|
|
9
|
+
| Field | Value |
|
|
10
|
+
|-------------|------------------------------------|
|
|
11
|
+
| Name | `kbdb-shared` |
|
|
12
|
+
| Path | `engine/crates/shared/` |
|
|
13
|
+
| Crate type | `rlib` (library only, not WASM) |
|
|
14
|
+
| Depends on | nothing (leaf crate) |
|
|
15
|
+
|
|
16
|
+
`kbdb-shared` is a pure Rust library. It is **not**
|
|
17
|
+
compiled to WASM on its own -- it is compiled into
|
|
18
|
+
each of the three WASM modules that depend on it
|
|
19
|
+
(`kbdb-fs-database`, `kbdb-query-parser`,
|
|
20
|
+
`kbdb-worker`). It has no external dependencies beyond
|
|
21
|
+
`wasm-bindgen` for the `alloc`/`free` exports.
|
|
22
|
+
|
|
23
|
+
## Workspace Position
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
engine/
|
|
27
|
+
├── Cargo.toml # workspace root
|
|
28
|
+
└── crates/
|
|
29
|
+
├── shared/ # this crate (leaf)
|
|
30
|
+
├── fs-database/ # depends on shared
|
|
31
|
+
├── query-parser/ # depends on shared
|
|
32
|
+
└── kb-worker/ # depends on shared
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Directory Layout
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
engine/crates/shared/
|
|
39
|
+
├── Cargo.toml
|
|
40
|
+
└── src/
|
|
41
|
+
├── lib.rs # crate root, re-exports
|
|
42
|
+
├── memory/
|
|
43
|
+
│ ├── mod.rs # memory module facade
|
|
44
|
+
│ └── alloc.rs # kbdb_alloc, kbdb_free
|
|
45
|
+
├── encode/
|
|
46
|
+
│ ├── mod.rs # encode module facade
|
|
47
|
+
│ └── encode.rs # Encode trait + impls
|
|
48
|
+
├── kbid/
|
|
49
|
+
│ ├── mod.rs # kbid module facade
|
|
50
|
+
│ └── kbid.rs # KbId newtype
|
|
51
|
+
├── term/
|
|
52
|
+
│ ├── mod.rs # term module facade
|
|
53
|
+
│ └── term.rs # Term newtype
|
|
54
|
+
├── section/
|
|
55
|
+
│ ├── mod.rs # section module facade
|
|
56
|
+
│ └── section.rs # SectionType, records
|
|
57
|
+
├── document/
|
|
58
|
+
│ ├── mod.rs # document module facade
|
|
59
|
+
│ └── document.rs # DocumentManifest, records
|
|
60
|
+
├── query/
|
|
61
|
+
│ ├── mod.rs # query module facade
|
|
62
|
+
│ └── query.rs # QueryPlan, RawMatch
|
|
63
|
+
├── corpus/
|
|
64
|
+
│ ├── mod.rs # corpus module facade
|
|
65
|
+
│ └── corpus.rs # CorpusStats
|
|
66
|
+
├── content-parser/
|
|
67
|
+
│ ├── mod.rs # content-parser facade
|
|
68
|
+
│ ├── types.rs # ContentMarkerType,
|
|
69
|
+
│ │ # ExtractedContentMarker
|
|
70
|
+
│ ├── extract.rs # extract_content_markers()
|
|
71
|
+
│ └── strip.rs # strip_content_markers()
|
|
72
|
+
├── content-composer/
|
|
73
|
+
│ ├── mod.rs # content-composer facade
|
|
74
|
+
│ ├── types.rs # ComposeRequest, etc.
|
|
75
|
+
│ ├── compose.rs # compose_content()
|
|
76
|
+
│ └── render.rs # marker rendering
|
|
77
|
+
└── error/
|
|
78
|
+
├── mod.rs # error module facade
|
|
79
|
+
└── error.rs # FsError, IndexError, etc.
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Modules
|
|
83
|
+
|
|
84
|
+
Each sub-module has a single responsibility. Files
|
|
85
|
+
within each module mirror their Rust source
|
|
86
|
+
counterparts: `module.md` = `mod.rs`,
|
|
87
|
+
`types.md` = type definitions,
|
|
88
|
+
`functions.md` = function definitions,
|
|
89
|
+
`traits.md` = trait definitions.
|
|
90
|
+
|
|
91
|
+
### [memory/](memory/module.md) -- Memory Management
|
|
92
|
+
|
|
93
|
+
- [functions.md](memory/functions.md) --
|
|
94
|
+
`kbdb_alloc`, `kbdb_free`, read/write helpers,
|
|
95
|
+
return value convention.
|
|
96
|
+
|
|
97
|
+
### [encode/](encode/module.md) -- Binary Encoding
|
|
98
|
+
|
|
99
|
+
- [traits.md](encode/traits.md) -- `Encode` trait,
|
|
100
|
+
wire format, per-type implementations.
|
|
101
|
+
|
|
102
|
+
### [kbid/](kbid/module.md) -- Content-Addressed ID
|
|
103
|
+
|
|
104
|
+
- [types.md](kbid/types.md) -- `KbId` newtype,
|
|
105
|
+
`from_content`, `shard_prefix`, `KbIdError`.
|
|
106
|
+
|
|
107
|
+
### [term/](term/module.md) -- Search Term
|
|
108
|
+
|
|
109
|
+
- [types.md](term/types.md) -- `Term` newtype,
|
|
110
|
+
`Ord` for B+ tree keys, `TermError`.
|
|
111
|
+
|
|
112
|
+
### [section/](section/module.md) -- Section Types
|
|
113
|
+
|
|
114
|
+
- [types.md](section/types.md) -- `SectionType`,
|
|
115
|
+
`MimeType`, `SectionRecord`, CRUD params/results.
|
|
116
|
+
|
|
117
|
+
### [document/](document/module.md) -- Document Records
|
|
118
|
+
|
|
119
|
+
- [types.md](document/types.md) --
|
|
120
|
+
`DocumentManifest`, `DocumentSection`,
|
|
121
|
+
`DocumentRecord`.
|
|
122
|
+
|
|
123
|
+
### [query/](query/module.md) -- Query Plan
|
|
124
|
+
|
|
125
|
+
- [types.md](query/types.md) -- `QueryPlan`,
|
|
126
|
+
`RawMatch`, `MatchMode`.
|
|
127
|
+
|
|
128
|
+
### [corpus/](corpus/module.md) -- Corpus Statistics
|
|
129
|
+
|
|
130
|
+
- [types.md](corpus/types.md) -- `CorpusStats`.
|
|
131
|
+
|
|
132
|
+
### [content-parser/](content-parser/module.md) -- Content Parser
|
|
133
|
+
|
|
134
|
+
- [types.md](content-parser/types.md) --
|
|
135
|
+
`ContentMarkerType` enum,
|
|
136
|
+
`ExtractedContentMarker` struct.
|
|
137
|
+
- [functions.md](content-parser/functions.md) --
|
|
138
|
+
`extract_content_markers()`,
|
|
139
|
+
`strip_content_markers()`.
|
|
140
|
+
|
|
141
|
+
### [content-composer/](content-composer/module.md) -- Content Composer
|
|
142
|
+
|
|
143
|
+
- [types.md](content-composer/types.md) --
|
|
144
|
+
`ComposeRequest`, `ComposeResult`,
|
|
145
|
+
`RenderedSection`, `ResolvedId`, `SectionData`,
|
|
146
|
+
`DocumentData`.
|
|
147
|
+
- [functions.md](content-composer/functions.md) --
|
|
148
|
+
`compose_content()`.
|
|
149
|
+
|
|
150
|
+
### [error/](error/module.md) -- Error Types
|
|
151
|
+
|
|
152
|
+
- [types.md](error/types.md) -- `FsError`,
|
|
153
|
+
`IndexError`, `ParseError`, `WorkerError`.
|
|
154
|
+
|
|
155
|
+
## Dependencies
|
|
156
|
+
|
|
157
|
+
```toml
|
|
158
|
+
[dependencies]
|
|
159
|
+
wasm-bindgen = "0.2"
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Testing
|
|
163
|
+
|
|
164
|
+
```sh
|
|
165
|
+
cd engine && cargo test -p kbdb-shared
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
See each module doc for detailed test descriptions.
|
|
@@ -0,0 +1,27 @@
|
|
|
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`.
|
|
@@ -0,0 +1,236 @@
|
|
|
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.
|
|
@@ -0,0 +1,25 @@
|
|
|
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 three 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`.
|