@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.
Files changed (193) hide show
  1. package/README.md +30 -9
  2. package/dist/cli.cjs +181 -50
  3. package/dist/cli.cjs.map +3 -3
  4. package/dist/cli.mjs +181 -50
  5. package/dist/cli.mjs.map +3 -3
  6. package/dist/kbdb-worker.cjs +283 -29
  7. package/dist/kbdb-worker.cjs.map +4 -4
  8. package/dist/mod.cjs +13 -2
  9. package/dist/mod.cjs.map +2 -2
  10. package/dist/mod.mjs +13 -2
  11. package/dist/mod.mjs.map +2 -2
  12. package/dist/src/shared/cli/functions/format-output.function.d.ts +7 -7
  13. package/dist/src/shared/cli/functions/run-search.function.d.ts +25 -16
  14. package/dist/src/shared/cli/index.d.ts +1 -1
  15. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +2 -0
  16. package/dist/src/shared/cli/typings/search-display.model.d.ts +25 -7
  17. package/dist/src/shared/mcp/functions/handle-recall.function.d.ts +29 -0
  18. package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +30 -11
  19. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  20. package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +28 -0
  21. package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +14 -7
  22. package/dist/src/shared/wasm-codec/functions/encode-recall-params.function.d.ts +21 -0
  23. package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -1
  24. package/dist/src/shared/wasm-codec/index.d.ts +5 -2
  25. package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +13 -3
  26. package/dist/src/shared/worker-client/index.d.ts +2 -1
  27. package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +94 -0
  28. package/dist/src/shared/worker-client/typings/search-params.model.d.ts +2 -0
  29. package/dist/src/shared/worker-client/typings/search-result.model.d.ts +23 -7
  30. package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
  31. package/dist/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
  32. package/dist/wasm/fs-database/kbdb_fs_database.js +30 -0
  33. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  34. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
  35. package/dist/wasm/kb-worker/kbdb_worker.d.ts +38 -0
  36. package/dist/wasm/kb-worker/kbdb_worker.js +56 -0
  37. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  38. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
  39. package/dist/worker.mjs +283 -29
  40. package/dist/worker.mjs.map +4 -4
  41. package/docs/details/README.md +26 -0
  42. package/docs/details/cli.md +608 -0
  43. package/docs/details/library-api.md +406 -0
  44. package/docs/details/mcp-server.md +430 -0
  45. package/docs/details/search-and-ranking.md +457 -0
  46. package/docs/details/storage.md +529 -0
  47. package/docs/goals/agents.md +751 -0
  48. package/docs/goals/architecture.svg +198 -0
  49. package/docs/goals/cli.md +2308 -0
  50. package/docs/goals/content-composer.md +609 -0
  51. package/docs/goals/content-parser.md +279 -0
  52. package/docs/goals/database.md +1452 -0
  53. package/docs/goals/document.md +368 -0
  54. package/docs/goals/mcp.md +1467 -0
  55. package/docs/goals/overview.md +124 -0
  56. package/docs/goals/query-parser.md +271 -0
  57. package/docs/goals/query-result.md +693 -0
  58. package/docs/goals/skills.md +738 -0
  59. package/docs/goals/worker-client.md +944 -0
  60. package/docs/goals/worker-daemon.md +1447 -0
  61. package/docs/modules/overview.md +298 -0
  62. package/docs/modules/rust/fs-database/functions/document.md +48 -0
  63. package/docs/modules/rust/fs-database/functions/integrity.md +68 -0
  64. package/docs/modules/rust/fs-database/functions/io.md +87 -0
  65. package/docs/modules/rust/fs-database/functions/module.md +22 -0
  66. package/docs/modules/rust/fs-database/functions/query-exec.md +44 -0
  67. package/docs/modules/rust/fs-database/functions/section.md +59 -0
  68. package/docs/modules/rust/fs-database/indexes/btree.md +35 -0
  69. package/docs/modules/rust/fs-database/indexes/corpus.md +61 -0
  70. package/docs/modules/rust/fs-database/indexes/inverted.md +60 -0
  71. package/docs/modules/rust/fs-database/indexes/module.md +64 -0
  72. package/docs/modules/rust/fs-database/indexes/positional.md +39 -0
  73. package/docs/modules/rust/fs-database/module.md +149 -0
  74. package/docs/modules/rust/fs-database/types/catalog.md +53 -0
  75. package/docs/modules/rust/fs-database/types/module.md +12 -0
  76. package/docs/modules/rust/fs-database/types/section.md +101 -0
  77. package/docs/modules/rust/kb-worker/functions/compose.md +57 -0
  78. package/docs/modules/rust/kb-worker/functions/module.md +20 -0
  79. package/docs/modules/rust/kb-worker/functions/retrieve.md +194 -0
  80. package/docs/modules/rust/kb-worker/functions/search.md +173 -0
  81. package/docs/modules/rust/kb-worker/functions/write.md +172 -0
  82. package/docs/modules/rust/kb-worker/module.md +171 -0
  83. package/docs/modules/rust/kb-worker/types/cache.md +90 -0
  84. package/docs/modules/rust/kb-worker/types/context.md +26 -0
  85. package/docs/modules/rust/kb-worker/types/module.md +16 -0
  86. package/docs/modules/rust/kb-worker/types/status.md +29 -0
  87. package/docs/modules/rust/kb-worker/types/token.md +50 -0
  88. package/docs/modules/rust/overview.md +495 -0
  89. package/docs/modules/rust/query-parser/functions/extract.md +56 -0
  90. package/docs/modules/rust/query-parser/functions/module.md +16 -0
  91. package/docs/modules/rust/query-parser/functions/parse.md +33 -0
  92. package/docs/modules/rust/query-parser/functions/pipeline.md +103 -0
  93. package/docs/modules/rust/query-parser/functions/rank.md +85 -0
  94. package/docs/modules/rust/query-parser/module.md +136 -0
  95. package/docs/modules/rust/query-parser/types/cache.md +39 -0
  96. package/docs/modules/rust/query-parser/types/keyphrase.md +60 -0
  97. package/docs/modules/rust/query-parser/types/module.md +17 -0
  98. package/docs/modules/rust/query-parser/types/token.md +42 -0
  99. package/docs/modules/rust/shared/content-composer/functions.md +114 -0
  100. package/docs/modules/rust/shared/content-composer/module.md +147 -0
  101. package/docs/modules/rust/shared/content-composer/types.md +93 -0
  102. package/docs/modules/rust/shared/content-parser/functions.md +72 -0
  103. package/docs/modules/rust/shared/content-parser/module.md +99 -0
  104. package/docs/modules/rust/shared/content-parser/types.md +71 -0
  105. package/docs/modules/rust/shared/corpus/module.md +24 -0
  106. package/docs/modules/rust/shared/corpus/types.md +141 -0
  107. package/docs/modules/rust/shared/document/module.md +25 -0
  108. package/docs/modules/rust/shared/document/types.md +154 -0
  109. package/docs/modules/rust/shared/encode/module.md +22 -0
  110. package/docs/modules/rust/shared/encode/traits.md +304 -0
  111. package/docs/modules/rust/shared/error/module.md +28 -0
  112. package/docs/modules/rust/shared/error/types.md +302 -0
  113. package/docs/modules/rust/shared/kbid/module.md +24 -0
  114. package/docs/modules/rust/shared/kbid/types.md +147 -0
  115. package/docs/modules/rust/shared/memory/functions.md +209 -0
  116. package/docs/modules/rust/shared/memory/module.md +24 -0
  117. package/docs/modules/rust/shared/module.md +168 -0
  118. package/docs/modules/rust/shared/query/module.md +27 -0
  119. package/docs/modules/rust/shared/query/types.md +236 -0
  120. package/docs/modules/rust/shared/section/module.md +25 -0
  121. package/docs/modules/rust/shared/section/types.md +294 -0
  122. package/docs/modules/rust/shared/term/module.md +25 -0
  123. package/docs/modules/rust/shared/term/types.md +139 -0
  124. package/docs/modules/typescript/cli.md +129 -0
  125. package/docs/modules/typescript/kbdb-worker.md +135 -0
  126. package/docs/modules/typescript/overview.md +378 -0
  127. package/docs/modules/typescript/shared/cli/constants.md +23 -0
  128. package/docs/modules/typescript/shared/cli/functions.md +630 -0
  129. package/docs/modules/typescript/shared/cli/module.md +125 -0
  130. package/docs/modules/typescript/shared/cli/typings.md +172 -0
  131. package/docs/modules/typescript/shared/hash/functions.md +20 -0
  132. package/docs/modules/typescript/shared/hash/module.md +21 -0
  133. package/docs/modules/typescript/shared/mcp/classes.md +179 -0
  134. package/docs/modules/typescript/shared/mcp/functions.md +386 -0
  135. package/docs/modules/typescript/shared/mcp/module.md +160 -0
  136. package/docs/modules/typescript/shared/mcp/typings.md +522 -0
  137. package/docs/modules/typescript/shared/module.md +94 -0
  138. package/docs/modules/typescript/shared/platform/functions.md +42 -0
  139. package/docs/modules/typescript/shared/platform/module.md +25 -0
  140. package/docs/modules/typescript/shared/runtime/functions.md +26 -0
  141. package/docs/modules/typescript/shared/runtime/module.md +27 -0
  142. package/docs/modules/typescript/shared/runtime/typings.md +13 -0
  143. package/docs/modules/typescript/shared/version/module.md +27 -0
  144. package/docs/modules/typescript/shared/wasm-codec/functions.md +391 -0
  145. package/docs/modules/typescript/shared/wasm-codec/module.md +98 -0
  146. package/docs/modules/typescript/shared/worker-client/classes.md +264 -0
  147. package/docs/modules/typescript/shared/worker-client/functions.md +175 -0
  148. package/docs/modules/typescript/shared/worker-client/module.md +84 -0
  149. package/docs/modules/typescript/shared/worker-client/typings.md +508 -0
  150. package/docs/modules/typescript/shared/worker-daemon/classes.md +239 -0
  151. package/docs/modules/typescript/shared/worker-daemon/constants.md +37 -0
  152. package/docs/modules/typescript/shared/worker-daemon/functions.md +221 -0
  153. package/docs/modules/typescript/shared/worker-daemon/module.md +112 -0
  154. package/docs/modules/typescript/shared/worker-daemon/typings.md +126 -0
  155. package/docs/overview.md +188 -0
  156. package/docs/release-notes/0.1.0.md +189 -0
  157. package/docs/release-notes/0.1.1.md +46 -0
  158. package/docs/release-notes/0.1.2.md +38 -0
  159. package/docs/release-notes/0.1.3.md +42 -0
  160. package/docs/release-notes/0.2.0.md +147 -0
  161. package/docs/release-notes/README.md +9 -0
  162. package/package.json +8 -2
  163. package/src/shared/cli/functions/dispatch-command.function.ts +3 -3
  164. package/src/shared/cli/functions/format-output.function.ts +41 -34
  165. package/src/shared/cli/functions/parse-args.function.ts +7 -0
  166. package/src/shared/cli/functions/run-search.function.ts +53 -27
  167. package/src/shared/cli/index.ts +4 -1
  168. package/src/shared/cli/typings/cli-options.interface.ts +2 -0
  169. package/src/shared/cli/typings/search-display.model.ts +26 -7
  170. package/src/shared/mcp/functions/create-tool-definitions.function.ts +64 -4
  171. package/src/shared/mcp/functions/handle-recall.function.ts +66 -0
  172. package/src/shared/mcp/functions/handle-tool-call.function.ts +11 -1
  173. package/src/shared/mcp/typings/mcp-client.interface.ts +33 -15
  174. package/src/shared/version/constants/version.constant.ts +1 -1
  175. package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +267 -0
  176. package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +81 -27
  177. package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +68 -0
  178. package/src/shared/wasm-codec/functions/encode-search-params.function.ts +4 -1
  179. package/src/shared/wasm-codec/index.ts +11 -3
  180. package/src/shared/worker-client/classes/worker-client.class.ts +24 -4
  181. package/src/shared/worker-client/index.ts +11 -1
  182. package/src/shared/worker-client/typings/recall-result.model.ts +98 -0
  183. package/src/shared/worker-client/typings/search-params.model.ts +2 -0
  184. package/src/shared/worker-client/typings/search-result.model.ts +24 -7
  185. package/src/shared/worker-daemon/classes/worker-daemon.class.ts +25 -4
  186. package/src/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
  187. package/src/wasm/fs-database/kbdb_fs_database.js +30 -0
  188. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  189. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
  190. package/src/wasm/kb-worker/kbdb_worker.d.ts +38 -0
  191. package/src/wasm/kb-worker/kbdb_worker.js +56 -0
  192. package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  193. package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
@@ -73,19 +73,23 @@ export interface McpWorkerClient {
73
73
  readonly mode?: string;
74
74
  /** Maximum number of results to return. */
75
75
  readonly limit?: number;
76
+ /** Number of results to skip for pagination. */
77
+ readonly offset?: number;
76
78
  }): Promise<{
77
- /** Knowledge-base identifier of the matched section. */
78
- kbid: string;
79
- /** Relevance score assigned by the ranking engine. */
80
- score: number;
81
- /** Terms that matched within this section. */
82
- readonly matches: readonly {
83
- /** The matched term. */
84
- readonly term: string;
85
- /** Number of times the term appears in the section. */
86
- readonly frequency: number;
79
+ readonly items: readonly {
80
+ readonly kbid: string;
81
+ readonly heading: string | null;
82
+ readonly type: string;
83
+ readonly docids: readonly string[];
84
+ readonly score: number;
85
+ readonly snippet: string;
86
+ readonly matched_terms: readonly string[];
87
87
  }[];
88
- }[]>;
88
+ readonly total: number;
89
+ readonly offset: number;
90
+ readonly limit: number;
91
+ readonly has_more: boolean;
92
+ }>;
89
93
  /**
90
94
  * Adds a new section to the knowledge base.
91
95
  *
@@ -211,6 +215,21 @@ export interface McpWorkerClient {
211
215
  * @param docid - identifier of the document grouping to remove
212
216
  */
213
217
  removeGrouping(docid: string): Promise<void>;
218
+ /**
219
+ * Retrieves full content and context for one or more sections by
220
+ * their knowledge-base identifiers.
221
+ *
222
+ * @param params - section identifier(s) and optional expansion depth
223
+ * @returns a single result or array of results depending on input
224
+ */
225
+ recall(params: {
226
+ /** Single section identifier. */
227
+ readonly kbid?: string;
228
+ /** Batch section identifiers. */
229
+ readonly kbids?: readonly string[];
230
+ /** Expansion depth (0-3, default: 0). */
231
+ readonly depth?: number;
232
+ }): Promise<unknown>;
214
233
  /** Destroys the IPC socket and clears the connection state. */
215
234
  disconnect(): void;
216
235
  }
@@ -1,2 +1,2 @@
1
1
  /** Current package version, kept in sync with package.json. */
2
- export declare const VERSION = "0.1.5";
2
+ export declare const VERSION = "0.2.0";
@@ -0,0 +1,28 @@
1
+ import type { RecallResult } from '../../worker-client/typings/recall-result.model.ts';
2
+ /**
3
+ * Decodes recall result binary output from the `worker_recall` WASM
4
+ * export.
5
+ *
6
+ * Binary layout:
7
+ * - `u8 tag`: `0` = single result, `1` = batch
8
+ * - If tag=0: one RecallResult record
9
+ * - If tag=1: `u32 count` + `count` RecallResult records
10
+ *
11
+ * Each RecallResult:
12
+ * ```
13
+ * String kbid
14
+ * Option<String> heading (0x00=null, 0x01 + String)
15
+ * String section_type
16
+ * String content
17
+ * u32 docids_count + String[] docids
18
+ * u32 documents_count + RecallDocument[]
19
+ * u32 back_references_count + RecallReference[]
20
+ * u32 siblings_count + RecallSibling[]
21
+ * u32 references_count + RecallReference[]
22
+ * ```
23
+ *
24
+ * @param bytes - raw binary output from the WASM export
25
+ * @returns a single `RecallResult` for tag=0, or `RecallResult[]`
26
+ * for tag=1
27
+ */
28
+ export declare function decodeRecallResult(bytes: Uint8Array): RecallResult | RecallResult[];
@@ -1,10 +1,17 @@
1
- export interface TermMatch {
2
- term: string;
3
- frequency: number;
4
- }
5
- export interface ScoredResult {
1
+ export interface SectionMatch {
6
2
  kbid: string;
3
+ heading: string | null;
4
+ type: string;
5
+ docids: string[];
7
6
  score: number;
8
- matches: TermMatch[];
7
+ snippet: string;
8
+ matched_terms: string[];
9
+ }
10
+ export interface PagedSearchResult {
11
+ items: SectionMatch[];
12
+ total: number;
13
+ offset: number;
14
+ limit: number;
15
+ has_more: boolean;
9
16
  }
10
- export declare function decodeScoredResults(bytes: Uint8Array): ScoredResult[];
17
+ export declare function decodePagedSearchResult(bytes: Uint8Array): PagedSearchResult;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Encodes recall parameters to the binary format expected by the
3
+ * `worker_recall` WASM export.
4
+ *
5
+ * Binary layout:
6
+ * - `u8 tag`: `0` = single kbid, `1` = batch
7
+ * - If tag=0: `u32 len + utf8` kbid
8
+ * - If tag=1: `u32 count` + (`u32 len + utf8`) per kbid
9
+ * - `u32 depth` (little-endian)
10
+ *
11
+ * When both `kbid` and `kbids` are provided, `kbids` takes precedence
12
+ * and `kbid` is appended to the batch.
13
+ *
14
+ * @param params - recall parameters; at least one of `kbid` or
15
+ * `kbids` must be present
16
+ */
17
+ export declare function encodeRecallParams(params: {
18
+ kbid?: string;
19
+ kbids?: readonly string[];
20
+ depth?: number;
21
+ }): Uint8Array;
@@ -1 +1 @@
1
- export declare function encodeSearchParams(query: string, mode?: string, limit?: number): Uint8Array;
1
+ export declare function encodeSearchParams(query: string, mode?: string, limit?: number, offset?: number): Uint8Array;
@@ -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 { decodeScoredResults } from './functions/decode-scored-results.function.ts';
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,9 +21,12 @@ 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
  export type { DecodeResult } from './functions/decode-string.function.ts';
25
27
  export type { AddSectionInput } from './functions/encode-add-section-params.function.ts';
26
- export type { ScoredResult, TermMatch, } from './functions/decode-scored-results.function.ts';
28
+ export type { SectionMatch, PagedSearchResult, } from './functions/decode-scored-results.function.ts';
27
29
  export type { SectionRecord } from './functions/decode-section-records.function.ts';
28
30
  export type { DocumentManifest, DocumentSection, } from './functions/decode-document-manifest.function.ts';
29
31
  export type { ComposeOutput } from './functions/decode-compose-output.function.ts';
32
+ export type { RecallResult, RecallDocument, RecallSibling, RecallReference, } from '../worker-client/typings/recall-result.model.ts';
@@ -1,5 +1,5 @@
1
1
  import type { SearchParams } from '../typings/search-params.model.ts';
2
- import type { SearchResult } from '../typings/search-result.model.ts';
2
+ import type { PagedSearchResult } from '../typings/search-result.model.ts';
3
3
  import type { AddSectionParams, Section } from '../typings/section.model.ts';
4
4
  import type { StatusResult } from '../typings/status-result.model.ts';
5
5
  import type { AddSectionResult } from '../typings/add-section-result.model.ts';
@@ -12,6 +12,7 @@ import type { MigrateResult } from '../typings/migrate-result.model.ts';
12
12
  import type { VersionStatus } from '../typings/version-status.model.ts';
13
13
  import type { SectionRecord } from '../../wasm-codec/functions/decode-section-records.function.ts';
14
14
  import type { DocumentManifest } from '../../wasm-codec/functions/decode-document-manifest.function.ts';
15
+ import type { RecallParams, RecallResult } from '../typings/recall-result.model.ts';
15
16
  /**
16
17
  * IPC client that communicates with the worker daemon over a Unix
17
18
  * domain socket (or Windows named pipe) using JSON-RPC 2.0 with
@@ -50,9 +51,18 @@ export declare class WorkerClient {
50
51
  * Searches the knowledge base.
51
52
  *
52
53
  * @param params - query parameters including the search string
53
- * @returns ranked list of matching sections
54
+ * @returns paginated search results with metadata
54
55
  */
55
- search(params: SearchParams): Promise<SearchResult[]>;
56
+ search(params: SearchParams): Promise<PagedSearchResult>;
57
+ /**
58
+ * Retrieves full content and context for one or more sections by
59
+ * their knowledge-base identifiers.
60
+ *
61
+ * @param params - section identifier(s) and optional expansion depth
62
+ * @returns a single `RecallResult` when `kbid` is provided without
63
+ * `kbids`, or a `RecallResult[]` when `kbids` is provided
64
+ */
65
+ recall(params: RecallParams): Promise<RecallResult | RecallResult[]>;
56
66
  /**
57
67
  * Adds a new section to the knowledge base.
58
68
  *
@@ -7,7 +7,7 @@ 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 { SearchResult } from './typings/search-result.model.ts';
10
+ export type { SearchResult, PagedSearchResult, } from './typings/search-result.model.ts';
11
11
  export type { Section, AddSectionParams, } from './typings/section.model.ts';
12
12
  export type { StatusResult } from './typings/status-result.model.ts';
13
13
  export type { WorkerClientError } from './typings/worker-client-error.interface.ts';
@@ -20,3 +20,4 @@ export type { GcResult } from './typings/gc-result.model.ts';
20
20
  export type { RebuildResult } from './typings/rebuild-result.model.ts';
21
21
  export type { MigrateResult } from './typings/migrate-result.model.ts';
22
22
  export type { VersionCompatibility, VersionStatus, } from './typings/version-status.model.ts';
23
+ export type { RecallParams, RecallResult, RecallDocument, RecallSibling, RecallReference, } from './typings/recall-result.model.ts';
@@ -0,0 +1,94 @@
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
+ /** A document record included at depth >= 1. */
17
+ export interface RecallDocument {
18
+ /** Unique document identifier. */
19
+ readonly docid: string;
20
+ /** Human-readable document title. */
21
+ readonly title: string;
22
+ /** Ordered list of section summaries belonging to this document. */
23
+ readonly sections: readonly {
24
+ /** Knowledge-base identifier of the section. */
25
+ readonly kbid: string;
26
+ /** Section heading text, or `null` when absent. */
27
+ readonly heading: string | null;
28
+ /** Semantic type label for the section. */
29
+ readonly type: string;
30
+ }[];
31
+ }
32
+ /** A sibling section adjacent to the recalled section. */
33
+ export interface RecallSibling {
34
+ /** Knowledge-base identifier of the sibling section. */
35
+ readonly kbid: string;
36
+ /** Sibling heading text, or `null` when absent. */
37
+ readonly heading: string | null;
38
+ /** Semantic type label for the sibling section. */
39
+ readonly type: string;
40
+ /** Full text content of the sibling section. */
41
+ readonly content: string;
42
+ }
43
+ /** A section that references or is referenced by the recalled section. */
44
+ export interface RecallReference {
45
+ /** Knowledge-base identifier of the referencing/referenced section. */
46
+ readonly kbid: string;
47
+ /** Heading text of the referencing section, or `null` when absent. */
48
+ readonly heading: string | null;
49
+ /** Semantic type label of the referencing section. */
50
+ readonly type: string;
51
+ /** Application-level marker type (e.g. `'see_also'`, `'link'`). */
52
+ readonly marker_type: string;
53
+ /** Short excerpt from the referencing section surrounding the marker. */
54
+ readonly context_snippet: string;
55
+ /** Whether the reference is `'forward'` (outgoing) or `'back'` (incoming). */
56
+ readonly direction: 'forward' | 'back';
57
+ }
58
+ /** Full content and context for a recalled knowledge-base section. */
59
+ export interface RecallResult {
60
+ /** Knowledge-base identifier of the recalled section. */
61
+ readonly kbid: string;
62
+ /** Section heading text, or `null` when absent. */
63
+ readonly heading: string | null;
64
+ /** Semantic type label for the section. */
65
+ readonly type: string;
66
+ /** Full text content of the section. */
67
+ readonly content: string;
68
+ /** Identifiers of documents that contain this section. */
69
+ readonly docids: readonly string[];
70
+ /**
71
+ * Full document records containing this section.
72
+ *
73
+ * Populated when `depth >= 1`.
74
+ */
75
+ readonly documents?: readonly RecallDocument[];
76
+ /**
77
+ * Sections that contain a marker pointing back to this section.
78
+ *
79
+ * Populated when `depth >= 1`.
80
+ */
81
+ readonly back_references?: readonly RecallReference[];
82
+ /**
83
+ * Sections adjacent to this section in the same document.
84
+ *
85
+ * Populated when `depth >= 1`.
86
+ */
87
+ readonly siblings?: readonly RecallSibling[];
88
+ /**
89
+ * Sections that this section points to via markers.
90
+ *
91
+ * Populated when `depth >= 1`.
92
+ */
93
+ readonly references?: readonly RecallReference[];
94
+ }
@@ -9,4 +9,6 @@ export interface SearchParams {
9
9
  readonly mode?: 'sections' | 'documents' | 'stats';
10
10
  /** Maximum number of results to return. */
11
11
  readonly limit?: number;
12
+ /** Number of results to skip (pagination offset). */
13
+ readonly offset?: number;
12
14
  }
@@ -2,13 +2,29 @@
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
- /** Terms that matched within this section. */
8
- readonly matches: readonly {
9
- /** The matched term. */
10
- readonly term: string;
11
- /** Number of times the term appears in the section. */
12
- readonly frequency: number;
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
+ /** Paginated search result envelope. */
19
+ export interface PagedSearchResult {
20
+ /** Matching sections for the current page. */
21
+ readonly items: readonly SearchResult[];
22
+ /** Total number of matches across all pages. */
23
+ readonly total: number;
24
+ /** Number of results skipped (pagination offset). */
25
+ readonly offset: number;
26
+ /** Maximum results per page. */
27
+ readonly limit: number;
28
+ /** Whether more results exist beyond this page. */
29
+ readonly has_more: boolean;
14
30
  }
@@ -127,6 +127,7 @@ export declare class WorkerDaemon {
127
127
  private handleInvalidate;
128
128
  private handleListByType;
129
129
  private handleListDocsByType;
130
+ private handleRecall;
130
131
  private handleInvalidateAll;
131
132
  private handleDbStatus;
132
133
  private handleIntegrityCheck;
@@ -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
  *
@@ -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;
@@ -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
  *
@@ -431,6 +447,20 @@ declare namespace wasm_bindgen {
431
447
  */
432
448
  export function worker_rebuild_indexes(): number;
433
449
 
450
+ /**
451
+ * Recalls section content with optional progressive context expansion.
452
+ *
453
+ * Input format (binary):
454
+ * - `u8 tag`: 0 = single kbid, 1 = batch kbids
455
+ * - If tag=0: `String kbid`
456
+ * - If tag=1: `u32 count` + `String[]` kbids
457
+ * - `u32 depth` (0-3, values above 3 are clamped to 3)
458
+ *
459
+ * On success writes the encoded result to the return slot and returns 0.
460
+ * On error writes an error message to the return slot and returns -1.
461
+ */
462
+ export function worker_recall(ptr: number, len: number): number;
463
+
434
464
  /**
435
465
  * Removes a document grouping. Returns 0 on success, -1 on error.
436
466
  */
@@ -457,6 +487,11 @@ declare namespace wasm_bindgen {
457
487
 
458
488
  /**
459
489
  * Performs a search, returning an async result token.
490
+ *
491
+ * Input format: `"query\nmode\nlimit\noffset"` (offset is optional,
492
+ * defaults to 0).
493
+ *
494
+ * The result is a `PagedSearchResult` envelope encoded as binary.
460
495
  */
461
496
  export function worker_search(ptr: number, len: number): number;
462
497
 
@@ -502,6 +537,7 @@ declare interface InitOutput {
502
537
  readonly worker_query: (a: number, b: number) => number;
503
538
  readonly worker_read_sections: (a: number, b: number) => number;
504
539
  readonly worker_rebuild_indexes: () => number;
540
+ readonly worker_recall: (a: number, b: number) => number;
505
541
  readonly worker_remove_grouping: (a: number, b: number) => number;
506
542
  readonly worker_remove_section: (a: number, b: number) => number;
507
543
  readonly worker_result_status: (a: number) => number;
@@ -530,6 +566,8 @@ declare interface InitOutput {
530
566
  readonly db_check_integrity: (a: number, b: number) => number;
531
567
  readonly db_check_version: (a: number, b: number) => number;
532
568
  readonly db_gc: (a: number, b: number) => number;
569
+ readonly db_get_back_refs: (a: number, b: number) => number;
570
+ readonly db_get_forward_refs: (a: number, b: number) => number;
533
571
  readonly db_init: (a: number, b: number) => number;
534
572
  readonly db_init_catalog: (a: number, b: number) => number;
535
573
  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
  *
@@ -813,6 +843,27 @@ let wasm_bindgen = (function(exports) {
813
843
  }
814
844
  exports.worker_rebuild_indexes = worker_rebuild_indexes;
815
845
 
846
+ /**
847
+ * Recalls section content with optional progressive context expansion.
848
+ *
849
+ * Input format (binary):
850
+ * - `u8 tag`: 0 = single kbid, 1 = batch kbids
851
+ * - If tag=0: `String kbid`
852
+ * - If tag=1: `u32 count` + `String[]` kbids
853
+ * - `u32 depth` (0-3, values above 3 are clamped to 3)
854
+ *
855
+ * On success writes the encoded result to the return slot and returns 0.
856
+ * On error writes an error message to the return slot and returns -1.
857
+ * @param {number} ptr
858
+ * @param {number} len
859
+ * @returns {number}
860
+ */
861
+ function worker_recall(ptr, len) {
862
+ const ret = wasm.worker_recall(ptr, len);
863
+ return ret;
864
+ }
865
+ exports.worker_recall = worker_recall;
866
+
816
867
  /**
817
868
  * Removes a document grouping. Returns 0 on success, -1 on error.
818
869
  * @param {number} ptr
@@ -866,6 +917,11 @@ let wasm_bindgen = (function(exports) {
866
917
 
867
918
  /**
868
919
  * Performs a search, returning an async result token.
920
+ *
921
+ * Input format: `"query\nmode\nlimit\noffset"` (offset is optional,
922
+ * defaults to 0).
923
+ *
924
+ * The result is a `PagedSearchResult` envelope encoded as binary.
869
925
  * @param {number} ptr
870
926
  * @param {number} len
871
927
  * @returns {number}
@@ -20,6 +20,7 @@ export const worker_list_docs_by_type: (a: number, b: number) => number;
20
20
  export const worker_query: (a: number, b: number) => number;
21
21
  export const worker_read_sections: (a: number, b: number) => number;
22
22
  export const worker_rebuild_indexes: () => number;
23
+ export const worker_recall: (a: number, b: number) => number;
23
24
  export const worker_remove_grouping: (a: number, b: number) => number;
24
25
  export const worker_remove_section: (a: number, b: number) => number;
25
26
  export const worker_result_status: (a: number) => number;
@@ -48,6 +49,8 @@ export const db_add_to_index: (a: number, b: number) => number;
48
49
  export const db_check_integrity: (a: number, b: number) => number;
49
50
  export const db_check_version: (a: number, b: number) => number;
50
51
  export const db_gc: (a: number, b: number) => number;
52
+ export const db_get_back_refs: (a: number, b: number) => number;
53
+ export const db_get_forward_refs: (a: number, b: number) => number;
51
54
  export const db_init: (a: number, b: number) => number;
52
55
  export const db_init_catalog: (a: number, b: number) => number;
53
56
  export const db_init_directory: (a: number, b: number) => number;