@dikolab/kbdb 0.1.5 → 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
|
@@ -2,53 +2,107 @@ import { decodeString } from './decode-string.function.ts';
|
|
|
2
2
|
import { decodeU32 } from './decode-u32.function.ts';
|
|
3
3
|
import { decodeF32 } from './decode-f32.function.ts';
|
|
4
4
|
|
|
5
|
-
export interface
|
|
6
|
-
term: string;
|
|
7
|
-
frequency: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface ScoredResult {
|
|
5
|
+
export interface SectionMatch {
|
|
11
6
|
kbid: string;
|
|
7
|
+
heading: string | null;
|
|
8
|
+
type: string;
|
|
9
|
+
docids: string[];
|
|
12
10
|
score: number;
|
|
13
|
-
|
|
11
|
+
snippet: string;
|
|
12
|
+
matched_terms: string[];
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
export
|
|
15
|
+
export interface PagedSearchResult {
|
|
16
|
+
items: SectionMatch[];
|
|
17
|
+
total: number;
|
|
18
|
+
offset: number;
|
|
19
|
+
limit: number;
|
|
20
|
+
has_more: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function decodeOptionString(
|
|
24
|
+
bytes: Uint8Array,
|
|
25
|
+
offset: number,
|
|
26
|
+
): { value: string | null; bytesRead: number } {
|
|
27
|
+
const tag = bytes[offset];
|
|
28
|
+
if (tag === 0x00) {
|
|
29
|
+
return { value: null, bytesRead: 1 };
|
|
30
|
+
}
|
|
31
|
+
const str = decodeString(bytes, offset + 1);
|
|
32
|
+
return { value: str.value, bytesRead: 1 + str.bytesRead };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function decodePagedSearchResult(
|
|
36
|
+
bytes: Uint8Array,
|
|
37
|
+
): PagedSearchResult {
|
|
17
38
|
let offset = 0;
|
|
18
|
-
const count = decodeU32(bytes, offset);
|
|
19
|
-
offset += count.bytesRead;
|
|
20
39
|
|
|
21
|
-
const
|
|
22
|
-
|
|
40
|
+
const total = decodeU32(bytes, offset);
|
|
41
|
+
offset += total.bytesRead;
|
|
42
|
+
|
|
43
|
+
const resultOffset = decodeU32(bytes, offset);
|
|
44
|
+
offset += resultOffset.bytesRead;
|
|
45
|
+
|
|
46
|
+
const limit = decodeU32(bytes, offset);
|
|
47
|
+
offset += limit.bytesRead;
|
|
48
|
+
|
|
49
|
+
const hasMore = bytes[offset] === 1;
|
|
50
|
+
offset += 1;
|
|
51
|
+
|
|
52
|
+
const itemCount = decodeU32(bytes, offset);
|
|
53
|
+
offset += itemCount.bytesRead;
|
|
54
|
+
|
|
55
|
+
const items: SectionMatch[] = [];
|
|
56
|
+
for (let i = 0; i < itemCount.value; i++) {
|
|
23
57
|
const kbid = decodeString(bytes, offset);
|
|
24
58
|
offset += kbid.bytesRead;
|
|
25
59
|
|
|
60
|
+
const heading = decodeOptionString(bytes, offset);
|
|
61
|
+
offset += heading.bytesRead;
|
|
62
|
+
|
|
63
|
+
const sectionType = decodeString(bytes, offset);
|
|
64
|
+
offset += sectionType.bytesRead;
|
|
65
|
+
|
|
66
|
+
const docidCount = decodeU32(bytes, offset);
|
|
67
|
+
offset += docidCount.bytesRead;
|
|
68
|
+
const docids: string[] = [];
|
|
69
|
+
for (let j = 0; j < docidCount.value; j++) {
|
|
70
|
+
const docid = decodeString(bytes, offset);
|
|
71
|
+
offset += docid.bytesRead;
|
|
72
|
+
docids.push(docid.value);
|
|
73
|
+
}
|
|
74
|
+
|
|
26
75
|
const score = decodeF32(bytes, offset);
|
|
27
76
|
offset += score.bytesRead;
|
|
28
77
|
|
|
29
|
-
const
|
|
30
|
-
offset +=
|
|
78
|
+
const snippet = decodeString(bytes, offset);
|
|
79
|
+
offset += snippet.bytesRead;
|
|
31
80
|
|
|
32
|
-
const
|
|
33
|
-
|
|
81
|
+
const termCount = decodeU32(bytes, offset);
|
|
82
|
+
offset += termCount.bytesRead;
|
|
83
|
+
const matched_terms: string[] = [];
|
|
84
|
+
for (let j = 0; j < termCount.value; j++) {
|
|
34
85
|
const term = decodeString(bytes, offset);
|
|
35
86
|
offset += term.bytesRead;
|
|
36
|
-
|
|
37
|
-
const freq = decodeF32(bytes, offset);
|
|
38
|
-
offset += freq.bytesRead;
|
|
39
|
-
|
|
40
|
-
matches.push({
|
|
41
|
-
term: term.value,
|
|
42
|
-
frequency: freq.value,
|
|
43
|
-
});
|
|
87
|
+
matched_terms.push(term.value);
|
|
44
88
|
}
|
|
45
89
|
|
|
46
|
-
|
|
90
|
+
items.push({
|
|
47
91
|
kbid: kbid.value,
|
|
92
|
+
heading: heading.value,
|
|
93
|
+
type: sectionType.value,
|
|
94
|
+
docids,
|
|
48
95
|
score: score.value,
|
|
49
|
-
|
|
96
|
+
snippet: snippet.value,
|
|
97
|
+
matched_terms,
|
|
50
98
|
});
|
|
51
99
|
}
|
|
52
100
|
|
|
53
|
-
return
|
|
101
|
+
return {
|
|
102
|
+
items,
|
|
103
|
+
total: total.value,
|
|
104
|
+
offset: resultOffset.value,
|
|
105
|
+
limit: limit.value,
|
|
106
|
+
has_more: hasMore,
|
|
107
|
+
};
|
|
54
108
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { encodeU32 } from './encode-u32.function.ts';
|
|
2
|
+
import { encodeString } from './encode-string.function.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Encodes recall parameters to the binary format expected by the
|
|
6
|
+
* `worker_recall` WASM export.
|
|
7
|
+
*
|
|
8
|
+
* Binary layout:
|
|
9
|
+
* - `u8 tag`: `0` = single kbid, `1` = batch
|
|
10
|
+
* - If tag=0: `u32 len + utf8` kbid
|
|
11
|
+
* - If tag=1: `u32 count` + (`u32 len + utf8`) per kbid
|
|
12
|
+
* - `u32 depth` (little-endian)
|
|
13
|
+
*
|
|
14
|
+
* When both `kbid` and `kbids` are provided, `kbids` takes precedence
|
|
15
|
+
* and `kbid` is appended to the batch.
|
|
16
|
+
*
|
|
17
|
+
* @param params - recall parameters; at least one of `kbid` or
|
|
18
|
+
* `kbids` must be present
|
|
19
|
+
*/
|
|
20
|
+
export function encodeRecallParams(params: {
|
|
21
|
+
kbid?: string;
|
|
22
|
+
kbids?: readonly string[];
|
|
23
|
+
depth?: number;
|
|
24
|
+
}): Uint8Array {
|
|
25
|
+
const depth = params.depth ?? 0;
|
|
26
|
+
const depthBytes = encodeU32(depth);
|
|
27
|
+
|
|
28
|
+
// Batch: kbids provided (kbid optionally appended)
|
|
29
|
+
if (params.kbids !== undefined) {
|
|
30
|
+
const allKbids: string[] =
|
|
31
|
+
params.kbid !== undefined
|
|
32
|
+
? [...params.kbids, params.kbid]
|
|
33
|
+
: [...params.kbids];
|
|
34
|
+
|
|
35
|
+
const countBytes = encodeU32(allKbids.length);
|
|
36
|
+
const encodedKbids = allKbids.map(encodeString);
|
|
37
|
+
|
|
38
|
+
const totalLen =
|
|
39
|
+
1 + // tag
|
|
40
|
+
countBytes.length +
|
|
41
|
+
encodedKbids.reduce((sum, b) => sum + b.length, 0) +
|
|
42
|
+
depthBytes.length;
|
|
43
|
+
|
|
44
|
+
const result = new Uint8Array(totalLen);
|
|
45
|
+
let offset = 0;
|
|
46
|
+
result[offset++] = 0x01; // tag = batch
|
|
47
|
+
result.set(countBytes, offset);
|
|
48
|
+
offset += countBytes.length;
|
|
49
|
+
for (const kbidBytes of encodedKbids) {
|
|
50
|
+
result.set(kbidBytes, offset);
|
|
51
|
+
offset += kbidBytes.length;
|
|
52
|
+
}
|
|
53
|
+
result.set(depthBytes, offset);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Single kbid
|
|
58
|
+
const kbid = params.kbid ?? '';
|
|
59
|
+
const kbidBytes = encodeString(kbid);
|
|
60
|
+
const totalLen = 1 + kbidBytes.length + depthBytes.length;
|
|
61
|
+
const result = new Uint8Array(totalLen);
|
|
62
|
+
let offset = 0;
|
|
63
|
+
result[offset++] = 0x00; // tag = single
|
|
64
|
+
result.set(kbidBytes, offset);
|
|
65
|
+
offset += kbidBytes.length;
|
|
66
|
+
result.set(depthBytes, offset);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
@@ -4,6 +4,9 @@ export function encodeSearchParams(
|
|
|
4
4
|
query: string,
|
|
5
5
|
mode = 'and',
|
|
6
6
|
limit = 20,
|
|
7
|
+
offset = 0,
|
|
7
8
|
): Uint8Array {
|
|
8
|
-
return encoder.encode(
|
|
9
|
+
return encoder.encode(
|
|
10
|
+
`${query}\n${mode}\n${String(limit)}\n${String(offset)}`,
|
|
11
|
+
);
|
|
9
12
|
}
|
|
@@ -13,7 +13,7 @@ export { decodeString } from './functions/decode-string.function.ts';
|
|
|
13
13
|
export { decodeU32 } from './functions/decode-u32.function.ts';
|
|
14
14
|
export { decodeF32 } from './functions/decode-f32.function.ts';
|
|
15
15
|
export { decodeU64 } from './functions/decode-u64.function.ts';
|
|
16
|
-
export {
|
|
16
|
+
export { decodePagedSearchResult } from './functions/decode-scored-results.function.ts';
|
|
17
17
|
export { decodeSectionRecords } from './functions/decode-section-records.function.ts';
|
|
18
18
|
export { decodeSectionRecordList } from './functions/decode-section-record-list.function.ts';
|
|
19
19
|
export { decodeDocumentManifest } from './functions/decode-document-manifest.function.ts';
|
|
@@ -21,12 +21,14 @@ export { decodeDocumentManifestList } from './functions/decode-document-manifest
|
|
|
21
21
|
export { decodeComposeOutput } from './functions/decode-compose-output.function.ts';
|
|
22
22
|
export { decodeKeyValueText } from './functions/decode-key-value-text.function.ts';
|
|
23
23
|
export { decodeRemoveFlag } from './functions/decode-remove-flag.function.ts';
|
|
24
|
+
export { encodeRecallParams } from './functions/encode-recall-params.function.ts';
|
|
25
|
+
export { decodeRecallResult } from './functions/decode-recall-result.function.ts';
|
|
24
26
|
|
|
25
27
|
export type { DecodeResult } from './functions/decode-string.function.ts';
|
|
26
28
|
export type { AddSectionInput } from './functions/encode-add-section-params.function.ts';
|
|
27
29
|
export type {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
SectionMatch,
|
|
31
|
+
PagedSearchResult,
|
|
30
32
|
} from './functions/decode-scored-results.function.ts';
|
|
31
33
|
export type { SectionRecord } from './functions/decode-section-records.function.ts';
|
|
32
34
|
export type {
|
|
@@ -34,3 +36,9 @@ export type {
|
|
|
34
36
|
DocumentSection,
|
|
35
37
|
} from './functions/decode-document-manifest.function.ts';
|
|
36
38
|
export type { ComposeOutput } from './functions/decode-compose-output.function.ts';
|
|
39
|
+
export type {
|
|
40
|
+
RecallResult,
|
|
41
|
+
RecallDocument,
|
|
42
|
+
RecallSibling,
|
|
43
|
+
RecallReference,
|
|
44
|
+
} from '../worker-client/typings/recall-result.model.ts';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { connect } from 'node:net';
|
|
2
2
|
import type { Socket } from 'node:net';
|
|
3
3
|
import type { SearchParams } from '../typings/search-params.model.ts';
|
|
4
|
-
import type {
|
|
4
|
+
import type { PagedSearchResult } from '../typings/search-result.model.ts';
|
|
5
5
|
import type {
|
|
6
6
|
AddSectionParams,
|
|
7
7
|
Section,
|
|
@@ -17,6 +17,10 @@ import type { MigrateResult } from '../typings/migrate-result.model.ts';
|
|
|
17
17
|
import type { VersionStatus } from '../typings/version-status.model.ts';
|
|
18
18
|
import type { SectionRecord } from '../../wasm-codec/functions/decode-section-records.function.ts';
|
|
19
19
|
import type { DocumentManifest } from '../../wasm-codec/functions/decode-document-manifest.function.ts';
|
|
20
|
+
import type {
|
|
21
|
+
RecallParams,
|
|
22
|
+
RecallResult,
|
|
23
|
+
} from '../typings/recall-result.model.ts';
|
|
20
24
|
|
|
21
25
|
/** Pending JSON-RPC call awaiting a response from the daemon. */
|
|
22
26
|
interface PendingCall {
|
|
@@ -100,10 +104,26 @@ export class WorkerClient {
|
|
|
100
104
|
* Searches the knowledge base.
|
|
101
105
|
*
|
|
102
106
|
* @param params - query parameters including the search string
|
|
103
|
-
* @returns
|
|
107
|
+
* @returns paginated search results with metadata
|
|
108
|
+
*/
|
|
109
|
+
async search(params: SearchParams): Promise<PagedSearchResult> {
|
|
110
|
+
return this.call('search', params) as Promise<PagedSearchResult>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Retrieves full content and context for one or more sections by
|
|
115
|
+
* their knowledge-base identifiers.
|
|
116
|
+
*
|
|
117
|
+
* @param params - section identifier(s) and optional expansion depth
|
|
118
|
+
* @returns a single `RecallResult` when `kbid` is provided without
|
|
119
|
+
* `kbids`, or a `RecallResult[]` when `kbids` is provided
|
|
104
120
|
*/
|
|
105
|
-
async
|
|
106
|
-
|
|
121
|
+
async recall(
|
|
122
|
+
params: RecallParams,
|
|
123
|
+
): Promise<RecallResult | RecallResult[]> {
|
|
124
|
+
return this.call('recall', params) as Promise<
|
|
125
|
+
RecallResult | RecallResult[]
|
|
126
|
+
>;
|
|
107
127
|
}
|
|
108
128
|
|
|
109
129
|
/**
|
|
@@ -7,7 +7,10 @@ export { spawnDaemon } from './functions/spawn-daemon.function.ts';
|
|
|
7
7
|
export { waitForDaemon } from './functions/wait-for-daemon.function.ts';
|
|
8
8
|
export type { WorkerClientOptions } from './typings/worker-client-options.interface.ts';
|
|
9
9
|
export type { SearchParams } from './typings/search-params.model.ts';
|
|
10
|
-
export type {
|
|
10
|
+
export type {
|
|
11
|
+
SearchResult,
|
|
12
|
+
PagedSearchResult,
|
|
13
|
+
} from './typings/search-result.model.ts';
|
|
11
14
|
export type {
|
|
12
15
|
Section,
|
|
13
16
|
AddSectionParams,
|
|
@@ -29,3 +32,10 @@ export type {
|
|
|
29
32
|
VersionCompatibility,
|
|
30
33
|
VersionStatus,
|
|
31
34
|
} from './typings/version-status.model.ts';
|
|
35
|
+
export type {
|
|
36
|
+
RecallParams,
|
|
37
|
+
RecallResult,
|
|
38
|
+
RecallDocument,
|
|
39
|
+
RecallSibling,
|
|
40
|
+
RecallReference,
|
|
41
|
+
} from './typings/recall-result.model.ts';
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Parameters for a recall operation. */
|
|
2
|
+
export interface RecallParams {
|
|
3
|
+
/** Single section identifier to recall. */
|
|
4
|
+
readonly kbid?: string;
|
|
5
|
+
/** Batch of section identifiers to recall. */
|
|
6
|
+
readonly kbids?: readonly string[];
|
|
7
|
+
/**
|
|
8
|
+
* Context expansion depth (0-3).
|
|
9
|
+
*
|
|
10
|
+
* At depth 0 only the section itself is returned.
|
|
11
|
+
* Higher values include progressively more context:
|
|
12
|
+
* documents, siblings, and references.
|
|
13
|
+
*/
|
|
14
|
+
readonly depth?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** A document record included at depth >= 1. */
|
|
18
|
+
export interface RecallDocument {
|
|
19
|
+
/** Unique document identifier. */
|
|
20
|
+
readonly docid: string;
|
|
21
|
+
/** Human-readable document title. */
|
|
22
|
+
readonly title: string;
|
|
23
|
+
/** Ordered list of section summaries belonging to this document. */
|
|
24
|
+
readonly sections: readonly {
|
|
25
|
+
/** Knowledge-base identifier of the section. */
|
|
26
|
+
readonly kbid: string;
|
|
27
|
+
/** Section heading text, or `null` when absent. */
|
|
28
|
+
readonly heading: string | null;
|
|
29
|
+
/** Semantic type label for the section. */
|
|
30
|
+
readonly type: string;
|
|
31
|
+
}[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A sibling section adjacent to the recalled section. */
|
|
35
|
+
export interface RecallSibling {
|
|
36
|
+
/** Knowledge-base identifier of the sibling section. */
|
|
37
|
+
readonly kbid: string;
|
|
38
|
+
/** Sibling heading text, or `null` when absent. */
|
|
39
|
+
readonly heading: string | null;
|
|
40
|
+
/** Semantic type label for the sibling section. */
|
|
41
|
+
readonly type: string;
|
|
42
|
+
/** Full text content of the sibling section. */
|
|
43
|
+
readonly content: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A section that references or is referenced by the recalled section. */
|
|
47
|
+
export interface RecallReference {
|
|
48
|
+
/** Knowledge-base identifier of the referencing/referenced section. */
|
|
49
|
+
readonly kbid: string;
|
|
50
|
+
/** Heading text of the referencing section, or `null` when absent. */
|
|
51
|
+
readonly heading: string | null;
|
|
52
|
+
/** Semantic type label of the referencing section. */
|
|
53
|
+
readonly type: string;
|
|
54
|
+
/** Application-level marker type (e.g. `'see_also'`, `'link'`). */
|
|
55
|
+
readonly marker_type: string;
|
|
56
|
+
/** Short excerpt from the referencing section surrounding the marker. */
|
|
57
|
+
readonly context_snippet: string;
|
|
58
|
+
/** Whether the reference is `'forward'` (outgoing) or `'back'` (incoming). */
|
|
59
|
+
readonly direction: 'forward' | 'back';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Full content and context for a recalled knowledge-base section. */
|
|
63
|
+
export interface RecallResult {
|
|
64
|
+
/** Knowledge-base identifier of the recalled section. */
|
|
65
|
+
readonly kbid: string;
|
|
66
|
+
/** Section heading text, or `null` when absent. */
|
|
67
|
+
readonly heading: string | null;
|
|
68
|
+
/** Semantic type label for the section. */
|
|
69
|
+
readonly type: string;
|
|
70
|
+
/** Full text content of the section. */
|
|
71
|
+
readonly content: string;
|
|
72
|
+
/** Identifiers of documents that contain this section. */
|
|
73
|
+
readonly docids: readonly string[];
|
|
74
|
+
/**
|
|
75
|
+
* Full document records containing this section.
|
|
76
|
+
*
|
|
77
|
+
* Populated when `depth >= 1`.
|
|
78
|
+
*/
|
|
79
|
+
readonly documents?: readonly RecallDocument[];
|
|
80
|
+
/**
|
|
81
|
+
* Sections that contain a marker pointing back to this section.
|
|
82
|
+
*
|
|
83
|
+
* Populated when `depth >= 1`.
|
|
84
|
+
*/
|
|
85
|
+
readonly back_references?: readonly RecallReference[];
|
|
86
|
+
/**
|
|
87
|
+
* Sections adjacent to this section in the same document.
|
|
88
|
+
*
|
|
89
|
+
* Populated when `depth >= 1`.
|
|
90
|
+
*/
|
|
91
|
+
readonly siblings?: readonly RecallSibling[];
|
|
92
|
+
/**
|
|
93
|
+
* Sections that this section points to via markers.
|
|
94
|
+
*
|
|
95
|
+
* Populated when `depth >= 1`.
|
|
96
|
+
*/
|
|
97
|
+
readonly references?: readonly RecallReference[];
|
|
98
|
+
}
|
|
@@ -2,13 +2,30 @@
|
|
|
2
2
|
export interface SearchResult {
|
|
3
3
|
/** Knowledge-base identifier for the matched section. */
|
|
4
4
|
readonly kbid: string;
|
|
5
|
+
/** Section heading, or null when untitled. */
|
|
6
|
+
readonly heading: string | null;
|
|
7
|
+
/** MIME type of the section content. */
|
|
8
|
+
readonly type: string;
|
|
9
|
+
/** Document IDs this section belongs to. */
|
|
10
|
+
readonly docids: readonly string[];
|
|
5
11
|
/** Relevance score assigned by the ranking engine. */
|
|
6
12
|
readonly score: number;
|
|
7
|
-
/**
|
|
8
|
-
readonly
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
/** KWIC snippet (~150 chars around the best match). */
|
|
14
|
+
readonly snippet: string;
|
|
15
|
+
/** Query terms that matched within this section. */
|
|
16
|
+
readonly matched_terms: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Paginated search result envelope. */
|
|
20
|
+
export interface PagedSearchResult {
|
|
21
|
+
/** Matching sections for the current page. */
|
|
22
|
+
readonly items: readonly SearchResult[];
|
|
23
|
+
/** Total number of matches across all pages. */
|
|
24
|
+
readonly total: number;
|
|
25
|
+
/** Number of results skipped (pagination offset). */
|
|
26
|
+
readonly offset: number;
|
|
27
|
+
/** Maximum results per page. */
|
|
28
|
+
readonly limit: number;
|
|
29
|
+
/** Whether more results exist beyond this page. */
|
|
30
|
+
readonly has_more: boolean;
|
|
14
31
|
}
|
|
@@ -28,7 +28,8 @@ import {
|
|
|
28
28
|
encodeGroupParams,
|
|
29
29
|
encodeIdentifierList,
|
|
30
30
|
encodeTypeFilterParam,
|
|
31
|
-
|
|
31
|
+
encodeRecallParams,
|
|
32
|
+
decodePagedSearchResult,
|
|
32
33
|
decodeSectionRecords,
|
|
33
34
|
decodeSectionRecordList,
|
|
34
35
|
decodeDocumentManifest,
|
|
@@ -36,6 +37,7 @@ import {
|
|
|
36
37
|
decodeComposeOutput,
|
|
37
38
|
decodeKeyValueText,
|
|
38
39
|
decodeRemoveFlag,
|
|
40
|
+
decodeRecallResult,
|
|
39
41
|
} from '../../wasm-codec/index.ts';
|
|
40
42
|
|
|
41
43
|
import type { AddSectionInput } from '../../wasm-codec/index.ts';
|
|
@@ -86,6 +88,7 @@ const WASM_METHOD_MAP: Readonly<Partial<Record<string, string>>> = {
|
|
|
86
88
|
list_by_type: 'worker_list_by_type',
|
|
87
89
|
listDocumentsByType: 'worker_list_docs_by_type',
|
|
88
90
|
list_docs_by_type: 'worker_list_docs_by_type',
|
|
91
|
+
recall: 'worker_recall',
|
|
89
92
|
};
|
|
90
93
|
|
|
91
94
|
/** Config method name prefix. */
|
|
@@ -564,6 +567,9 @@ export class WorkerDaemon {
|
|
|
564
567
|
) {
|
|
565
568
|
return this.handleListDocsByType(params);
|
|
566
569
|
}
|
|
570
|
+
if (method === 'recall') {
|
|
571
|
+
return this.handleRecall(params);
|
|
572
|
+
}
|
|
567
573
|
return this.invokeWasmRaw(wasmExport, new Uint8Array(0));
|
|
568
574
|
}
|
|
569
575
|
|
|
@@ -573,7 +579,8 @@ export class WorkerDaemon {
|
|
|
573
579
|
const query = (params['query'] as string | undefined) ?? '';
|
|
574
580
|
const mode = (params['mode'] as string | undefined) ?? 'and';
|
|
575
581
|
const limit = Number(params['limit'] ?? 20);
|
|
576
|
-
const
|
|
582
|
+
const offset = Number(params['offset'] ?? 0);
|
|
583
|
+
const encoded = encodeSearchParams(query, mode, limit, offset);
|
|
577
584
|
|
|
578
585
|
const searchFn = this.getExport('worker_search');
|
|
579
586
|
const ptr = this.wasmAlloc(encoded.length);
|
|
@@ -598,7 +605,7 @@ export class WorkerDaemon {
|
|
|
598
605
|
throw new IpcError(-32000, new TextDecoder().decode(errBytes));
|
|
599
606
|
}
|
|
600
607
|
const resultBytes = this.readReturnSlot();
|
|
601
|
-
return
|
|
608
|
+
return decodePagedSearchResult(resultBytes);
|
|
602
609
|
}
|
|
603
610
|
|
|
604
611
|
// -- Token status/result (u32 direct params) --
|
|
@@ -621,7 +628,7 @@ export class WorkerDaemon {
|
|
|
621
628
|
throw new IpcError(-32000, new TextDecoder().decode(errBytes));
|
|
622
629
|
}
|
|
623
630
|
const bytes = this.readReturnSlot();
|
|
624
|
-
return
|
|
631
|
+
return decodePagedSearchResult(bytes);
|
|
625
632
|
}
|
|
626
633
|
|
|
627
634
|
// -- Binary-encoded input methods --
|
|
@@ -776,6 +783,20 @@ export class WorkerDaemon {
|
|
|
776
783
|
return decodeDocumentManifestList(bytes);
|
|
777
784
|
}
|
|
778
785
|
|
|
786
|
+
private handleRecall(params: Record<string, unknown>): unknown {
|
|
787
|
+
const kbid =
|
|
788
|
+
typeof params['kbid'] === 'string'
|
|
789
|
+
? params['kbid']
|
|
790
|
+
: undefined;
|
|
791
|
+
const kbids = Array.isArray(params['kbids'])
|
|
792
|
+
? (params['kbids'] as string[])
|
|
793
|
+
: undefined;
|
|
794
|
+
const depth = Number(params['depth'] ?? 0);
|
|
795
|
+
const encoded = encodeRecallParams({ kbid, kbids, depth });
|
|
796
|
+
const bytes = this.callWasmSync('worker_recall', encoded);
|
|
797
|
+
return decodeRecallResult(bytes);
|
|
798
|
+
}
|
|
799
|
+
|
|
779
800
|
// -- Zero-arg methods --
|
|
780
801
|
|
|
781
802
|
private handleInvalidateAll(): unknown {
|
|
@@ -48,6 +48,22 @@ declare namespace wasm_bindgen {
|
|
|
48
48
|
*/
|
|
49
49
|
export function db_gc(_ptr: number, _len: number): number;
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Returns back-references pointing to a section.
|
|
53
|
+
* `ptr`/`len` point to a UTF-8 kbid string.
|
|
54
|
+
* On success encodes `u32 count` followed by entries (peer_id, marker_type,
|
|
55
|
+
* context_snippet) into the return slot.
|
|
56
|
+
*/
|
|
57
|
+
export function db_get_back_refs(ptr: number, len: number): number;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns forward references for a section.
|
|
61
|
+
* `ptr`/`len` point to a UTF-8 kbid string.
|
|
62
|
+
* On success encodes `u32 count` followed by entries (peer_id, marker_type,
|
|
63
|
+
* context_snippet) into the return slot.
|
|
64
|
+
*/
|
|
65
|
+
export function db_get_forward_refs(ptr: number, len: number): number;
|
|
66
|
+
|
|
51
67
|
/**
|
|
52
68
|
* Initialises the database context path.
|
|
53
69
|
*
|
|
@@ -185,6 +201,8 @@ declare interface InitOutput {
|
|
|
185
201
|
readonly db_check_integrity: (a: number, b: number) => number;
|
|
186
202
|
readonly db_check_version: (a: number, b: number) => number;
|
|
187
203
|
readonly db_gc: (a: number, b: number) => number;
|
|
204
|
+
readonly db_get_back_refs: (a: number, b: number) => number;
|
|
205
|
+
readonly db_get_forward_refs: (a: number, b: number) => number;
|
|
188
206
|
readonly db_init: (a: number, b: number) => number;
|
|
189
207
|
readonly db_init_catalog: (a: number, b: number) => number;
|
|
190
208
|
readonly db_init_directory: (a: number, b: number) => number;
|
|
@@ -85,6 +85,36 @@ let wasm_bindgen = (function(exports) {
|
|
|
85
85
|
}
|
|
86
86
|
exports.db_gc = db_gc;
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Returns back-references pointing to a section.
|
|
90
|
+
* `ptr`/`len` point to a UTF-8 kbid string.
|
|
91
|
+
* On success encodes `u32 count` followed by entries (peer_id, marker_type,
|
|
92
|
+
* context_snippet) into the return slot.
|
|
93
|
+
* @param {number} ptr
|
|
94
|
+
* @param {number} len
|
|
95
|
+
* @returns {number}
|
|
96
|
+
*/
|
|
97
|
+
function db_get_back_refs(ptr, len) {
|
|
98
|
+
const ret = wasm.db_get_back_refs(ptr, len);
|
|
99
|
+
return ret;
|
|
100
|
+
}
|
|
101
|
+
exports.db_get_back_refs = db_get_back_refs;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Returns forward references for a section.
|
|
105
|
+
* `ptr`/`len` point to a UTF-8 kbid string.
|
|
106
|
+
* On success encodes `u32 count` followed by entries (peer_id, marker_type,
|
|
107
|
+
* context_snippet) into the return slot.
|
|
108
|
+
* @param {number} ptr
|
|
109
|
+
* @param {number} len
|
|
110
|
+
* @returns {number}
|
|
111
|
+
*/
|
|
112
|
+
function db_get_forward_refs(ptr, len) {
|
|
113
|
+
const ret = wasm.db_get_forward_refs(ptr, len);
|
|
114
|
+
return ret;
|
|
115
|
+
}
|
|
116
|
+
exports.db_get_forward_refs = db_get_forward_refs;
|
|
117
|
+
|
|
88
118
|
/**
|
|
89
119
|
* Initialises the database context path.
|
|
90
120
|
*
|
|
Binary file
|
|
@@ -8,6 +8,8 @@ export const db_add_to_index: (a: number, b: number) => number;
|
|
|
8
8
|
export const db_check_integrity: (a: number, b: number) => number;
|
|
9
9
|
export const db_check_version: (a: number, b: number) => number;
|
|
10
10
|
export const db_gc: (a: number, b: number) => number;
|
|
11
|
+
export const db_get_back_refs: (a: number, b: number) => number;
|
|
12
|
+
export const db_get_forward_refs: (a: number, b: number) => number;
|
|
11
13
|
export const db_init: (a: number, b: number) => number;
|
|
12
14
|
export const db_init_catalog: (a: number, b: number) => number;
|
|
13
15
|
export const db_init_directory: (a: number, b: number) => number;
|