@dikolab/kbdb 0.2.2 → 0.3.1
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 +47 -31
- package/dist/bench/constants/corpus-defaults.constant.d.ts +3 -0
- package/dist/bench/functions/format-report.function.d.ts +11 -0
- package/dist/bench/functions/generate-corpus.function.d.ts +12 -0
- package/dist/bench/functions/measure-operation.function.d.ts +14 -0
- package/dist/bench/functions/seeded-rng.function.d.ts +11 -0
- package/dist/bench/functions/zipf-word.function.d.ts +13 -0
- package/dist/bench/index.d.ts +10 -0
- package/dist/bench/typings/bench-result.interface.d.ts +11 -0
- package/dist/bench/typings/bench-suite-result.interface.d.ts +10 -0
- package/dist/bench/typings/corpus-config.interface.d.ts +11 -0
- package/dist/bench/typings/corpus-section.interface.d.ts +9 -0
- package/dist/cli.cjs +523 -80
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.mjs +515 -72
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +395 -60
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +17 -0
- package/dist/mod.cjs.map +2 -2
- package/dist/mod.mjs +17 -0
- package/dist/mod.mjs.map +2 -2
- package/dist/src/shared/auto-capture/classes/auto-capture-controller.class.d.ts +33 -0
- package/dist/src/shared/auto-capture/constants/auto-capture-defaults.constant.d.ts +8 -0
- package/dist/src/shared/auto-capture/functions/build-capture-prompt.function.d.ts +11 -0
- package/dist/src/shared/auto-capture/functions/evaluate-trigger.function.d.ts +12 -0
- package/dist/src/shared/auto-capture/index.d.ts +7 -0
- package/dist/src/shared/auto-capture/typings/auto-capture-config.interface.d.ts +13 -0
- package/dist/src/shared/auto-capture/typings/auto-capture-state.interface.d.ts +13 -0
- package/dist/src/shared/auto-capture/typings/auto-capture-trigger.interface.d.ts +7 -0
- package/dist/src/shared/cli/constants/global-help.constant.d.ts +8 -0
- package/dist/src/shared/cli/constants/leaf-help.constant.d.ts +7 -0
- package/dist/src/shared/cli/constants/memory-protocol-body.constant.d.ts +7 -0
- package/dist/src/shared/cli/constants/query-guidance-body.constant.d.ts +7 -0
- package/dist/src/shared/cli/constants/subcommand-help.constant.d.ts +8 -0
- package/dist/src/shared/cli/functions/collect-files.function.d.ts +13 -0
- package/dist/src/shared/cli/functions/compute-section-kbid.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +3 -1
- package/dist/src/shared/cli/functions/format-mcp-output.function.d.ts +9 -0
- package/dist/src/shared/cli/functions/format-text-output.function.d.ts +9 -0
- package/dist/src/shared/cli/functions/generate-group-help.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/handle-data-command.function.d.ts +16 -0
- package/dist/src/shared/cli/functions/handle-mcp.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/handle-migrate.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/hydrate-search-previews.function.d.ts +14 -0
- package/dist/src/shared/cli/functions/install-default-skills.function.d.ts +12 -0
- package/dist/src/shared/cli/functions/resolve-skill-names.function.d.ts +16 -0
- package/dist/src/shared/cli/functions/run-check.function.d.ts +47 -5
- package/dist/src/shared/cli/functions/run-export.function.d.ts +34 -0
- package/dist/src/shared/cli/functions/run-gc.function.d.ts +6 -0
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +35 -6
- package/dist/src/shared/cli/functions/run-recall.function.d.ts +45 -0
- package/dist/src/shared/cli/functions/run-search.function.d.ts +53 -15
- package/dist/src/shared/cli/functions/version-gate.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/wrap-command.function.d.ts +15 -0
- package/dist/src/shared/cli/index.d.ts +4 -0
- package/dist/src/shared/cli/typings/agent-create-client.interface.d.ts +42 -0
- package/dist/src/shared/cli/typings/agent-get-client.interface.d.ts +36 -0
- package/dist/src/shared/cli/typings/check-client.interface.d.ts +58 -0
- package/dist/src/shared/cli/typings/cli-deps.interface.d.ts +48 -0
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +15 -0
- package/dist/src/shared/cli/typings/disconnectable-client.interface.d.ts +26 -0
- package/dist/src/shared/cli/typings/dispatch-client.type.d.ts +27 -0
- package/dist/src/shared/cli/typings/learn-client.interface.d.ts +52 -0
- package/dist/src/shared/cli/typings/learn-io.interface.d.ts +5 -0
- package/dist/src/shared/cli/typings/learn-result.model.d.ts +19 -0
- package/dist/src/shared/cli/typings/search-client.interface.d.ts +71 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +18 -0
- package/dist/src/shared/embedding/classes/null-embedding-provider.class.d.ts +20 -0
- package/dist/src/shared/embedding/constants/near-duplicate-thresholds.constant.d.ts +15 -0
- package/dist/src/shared/embedding/functions/build-vector-index.function.d.ts +14 -0
- package/dist/src/shared/embedding/functions/cosine-similarity.function.d.ts +10 -0
- package/dist/src/shared/embedding/functions/detect-near-duplicates.function.d.ts +18 -0
- package/dist/src/shared/embedding/functions/jaccard-coefficient.function.d.ts +9 -0
- package/dist/src/shared/embedding/functions/read-vector-index-meta.function.d.ts +10 -0
- package/dist/src/shared/embedding/functions/rrf-fuse.function.d.ts +14 -0
- package/dist/src/shared/embedding/functions/search-vectors.function.d.ts +14 -0
- package/dist/src/shared/embedding/index.d.ts +16 -0
- package/dist/src/shared/embedding/typings/embedding-config.interface.d.ts +20 -0
- package/dist/src/shared/embedding/typings/embedding-provider.interface.d.ts +23 -0
- package/dist/src/shared/embedding/typings/near-duplicate-candidate.model.d.ts +23 -0
- package/dist/src/shared/embedding/typings/near-duplicate-result.model.d.ts +24 -0
- package/dist/src/shared/embedding/typings/vector-index-entry.model.d.ts +12 -0
- package/dist/src/shared/embedding/typings/vector-index-meta.model.d.ts +11 -0
- package/dist/src/shared/embedding/typings/vector-search-result.model.d.ts +7 -0
- package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +8 -0
- package/dist/src/shared/mcp/constants/tool-agent-create.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-agent-delete.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-agent-get.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-agent-list.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-auto-capture-review.constant.d.ts +8 -0
- package/dist/src/shared/mcp/constants/tool-check.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-content.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-export.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-gc.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-learn.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-rebuild.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-recall.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-retrieve.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-search.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-skill-delete.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-skill-get.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-skill-learn.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-skill-list.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-status.constant.d.ts +3 -0
- package/dist/src/shared/mcp/constants/tool-unlearn.constant.d.ts +3 -0
- package/dist/src/shared/mcp/functions/as-boolean-or-undefined.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/as-string-array-or-undefined.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/as-string-array.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/as-string.function.d.ts +8 -0
- package/dist/src/shared/mcp/functions/build-skills-text.function.d.ts +18 -0
- package/dist/src/shared/mcp/functions/handle-agent-prompt.function.d.ts +14 -0
- package/dist/src/shared/mcp/functions/handle-mcp-request.function.d.ts +14 -0
- package/dist/src/shared/mcp/functions/handle-prompt-get.function.d.ts +4 -3
- package/dist/src/shared/mcp/functions/handle-skill-prompt.function.d.ts +16 -0
- package/dist/src/shared/mcp/functions/handle-tool-auto-capture-review.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-check.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/handle-tool-content.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-export.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-gc.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/handle-tool-learn.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-rebuild.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/handle-tool-retrieve.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-search.function.d.ts +13 -0
- package/dist/src/shared/mcp/functions/handle-tool-skill-delete.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/handle-tool-skill-get.function.d.ts +13 -0
- package/dist/src/shared/mcp/functions/handle-tool-skill-learn.function.d.ts +13 -0
- package/dist/src/shared/mcp/functions/handle-tool-skill-list.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/handle-tool-status.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/handle-tool-unlearn.function.d.ts +12 -0
- package/dist/src/shared/mcp/functions/parse-agent-meta.function.d.ts +14 -0
- package/dist/src/shared/mcp/functions/parse-skill-arguments.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/read-agent-meta.function.d.ts +17 -0
- package/dist/src/shared/mcp/functions/resolve-skill-refs.function.d.ts +23 -0
- package/dist/src/shared/mcp/functions/run-startup-health-check.function.d.ts +14 -0
- package/dist/src/shared/mcp/typings/mcp-capabilities.interface.d.ts +16 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +45 -0
- package/dist/src/shared/mcp/typings/mcp-completion.interface.d.ts +43 -0
- package/dist/src/shared/mcp/typings/mcp-content-result.model.d.ts +9 -0
- package/dist/src/shared/mcp/typings/mcp-export-result.model.d.ts +11 -0
- package/dist/src/shared/mcp/typings/mcp-gc-result.model.d.ts +15 -0
- package/dist/src/shared/mcp/typings/mcp-integrity-check-result.model.d.ts +16 -0
- package/dist/src/shared/mcp/typings/mcp-integrity-error.model.d.ts +9 -0
- package/dist/src/shared/mcp/typings/mcp-notification.interface.d.ts +9 -0
- package/dist/src/shared/mcp/typings/mcp-rebuild-result.model.d.ts +9 -0
- package/dist/src/shared/mcp/typings/mcp-request.interface.d.ts +11 -0
- package/dist/src/shared/mcp/typings/mcp-resource-result.interface.d.ts +12 -0
- package/dist/src/shared/mcp/typings/mcp-resource-template.interface.d.ts +11 -0
- package/dist/src/shared/mcp/typings/mcp-response.interface.d.ts +18 -0
- package/dist/src/shared/mcp/typings/mcp-server-info.interface.d.ts +7 -0
- package/dist/src/shared/mcp/typings/mcp-server-state.interface.d.ts +16 -0
- package/dist/src/shared/mcp/typings/mcp-tool-annotations.interface.d.ts +32 -0
- package/dist/src/shared/mcp/typings/mcp-tool-definition.interface.d.ts +15 -0
- package/dist/src/shared/mcp/typings/mcp-tool-result.interface.d.ts +19 -0
- package/dist/src/shared/mcp/typings/mcp-worker-client.interface.d.ts +220 -0
- package/dist/src/shared/mcp/typings/tool-call-result.model.d.ts +17 -0
- package/dist/src/shared/sync/functions/build-import-report.function.d.ts +18 -0
- package/dist/src/shared/sync/functions/parse-export-entry.function.d.ts +11 -0
- package/dist/src/shared/sync/functions/resolve-conflict.function.d.ts +13 -0
- package/dist/src/shared/sync/functions/serialize-export-entry.function.d.ts +8 -0
- package/dist/src/shared/sync/index.d.ts +9 -0
- package/dist/src/shared/sync/typings/conflict-resolution.type.d.ts +8 -0
- package/dist/src/shared/sync/typings/export-entry.interface.d.ts +13 -0
- package/dist/src/shared/sync/typings/export-options.interface.d.ts +9 -0
- package/dist/src/shared/sync/typings/import-options.interface.d.ts +7 -0
- package/dist/src/shared/sync/typings/import-report.interface.d.ts +15 -0
- package/dist/src/shared/wasm-codec/functions/decode-add-section-result.function.d.ts +48 -0
- package/dist/src/shared/wasm-codec/functions/decode-one-recall-result.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-option-string.function.d.ts +12 -0
- package/dist/src/shared/wasm-codec/functions/decode-recall-document.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-recall-reference.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-recall-sibling.function.d.ts +13 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +58 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-match.function.d.ts +15 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-record-trailing.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-record.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +33 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-type.function.d.ts +13 -0
- package/dist/src/shared/wasm-codec/functions/decode-wasm-list.function.d.ts +17 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +52 -0
- package/dist/src/shared/wasm-codec/index.d.ts +2 -0
- package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +45 -0
- package/dist/src/shared/wasm-codec/typings/add-section-result.model.d.ts +27 -0
- package/dist/src/shared/wasm-codec/typings/document-manifest.model.d.ts +19 -0
- package/dist/src/shared/wasm-codec/typings/document-section.model.d.ts +12 -0
- package/dist/src/shared/wasm-codec/typings/item-decoder.type.d.ts +6 -0
- package/dist/src/shared/wasm-codec/typings/near-duplicate.model.d.ts +16 -0
- package/dist/src/shared/wasm-codec/typings/paged-search-result.model.d.ts +21 -0
- package/dist/src/shared/wasm-codec/typings/section-match.model.d.ts +31 -0
- package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +38 -0
- package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +66 -0
- package/dist/src/shared/wasm-codec/typings/section-type-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +16 -0
- package/dist/src/shared/worker-client/functions/handle-ipc-data.function.d.ts +16 -0
- package/dist/src/shared/worker-client/functions/send-ipc-request.function.d.ts +19 -0
- package/dist/src/shared/worker-client/index.d.ts +1 -1
- package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +31 -15
- package/dist/src/shared/worker-client/typings/export-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/gc-result.model.d.ts +6 -0
- package/dist/src/shared/worker-client/typings/json-rpc-response.interface.d.ts +16 -0
- package/dist/src/shared/worker-client/typings/pending-call.interface.d.ts +7 -0
- package/dist/src/shared/worker-client/typings/recall-document.model.d.ts +16 -0
- package/dist/src/shared/worker-client/typings/recall-params.model.d.ts +15 -0
- package/dist/src/shared/worker-client/typings/recall-reference.model.d.ts +32 -0
- package/dist/src/shared/worker-client/typings/recall-sibling.model.d.ts +11 -0
- package/dist/src/shared/worker-client/typings/recall-single-result.model.d.ts +40 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/section.model.d.ts +16 -0
- package/dist/src/shared/worker-daemon/classes/ipc-error.class.d.ts +17 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +35 -0
- package/dist/src/shared/worker-daemon/constants/wasm-method-map.constant.d.ts +16 -0
- package/dist/src/shared/worker-daemon/functions/build-ipc-error-response.function.d.ts +9 -0
- package/dist/src/shared/worker-daemon/functions/check-catalog-version.function.d.ts +9 -0
- package/dist/src/shared/worker-daemon/functions/check-preconditions.function.d.ts +10 -0
- package/dist/src/shared/worker-daemon/functions/detect-stale-pid.function.d.ts +15 -0
- package/dist/src/shared/worker-daemon/functions/dispatch-request.function.d.ts +35 -0
- package/dist/src/shared/worker-daemon/functions/handle-check-version.function.d.ts +23 -0
- package/dist/src/shared/worker-daemon/functions/handle-config-method.function.d.ts +11 -0
- package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +52 -0
- package/dist/src/shared/worker-daemon/functions/handle-write-ops.function.d.ts +44 -0
- package/dist/src/shared/worker-daemon/functions/parse-auto-capture-section.function.d.ts +14 -0
- package/dist/src/shared/worker-daemon/functions/parse-catalog-version.function.d.ts +10 -0
- package/dist/src/shared/worker-daemon/functions/parse-embedding-section.function.d.ts +13 -0
- package/dist/src/shared/worker-daemon/functions/parse-worker-toml.function.d.ts +11 -0
- package/dist/src/shared/worker-daemon/functions/run-startup-integrity-check.function.d.ts +18 -0
- package/dist/src/shared/worker-daemon/functions/scan-near-duplicates.function.d.ts +21 -0
- package/dist/src/shared/worker-daemon/functions/wasm-bridge.function.d.ts +51 -0
- package/dist/src/shared/worker-daemon/functions/wasm-memory-helpers.function.d.ts +22 -0
- package/dist/src/shared/worker-daemon/functions/write-lock.function.d.ts +32 -0
- package/dist/src/shared/worker-daemon/typings/allocator-ref.interface.d.ts +16 -0
- package/dist/src/shared/worker-daemon/typings/daemon-config.interface.d.ts +6 -0
- package/dist/src/shared/worker-daemon/typings/fs-adapter.interface.d.ts +22 -0
- package/dist/src/shared/worker-daemon/typings/handler-context.interface.d.ts +18 -0
- package/dist/src/shared/worker-daemon/typings/memory-ref.interface.d.ts +13 -0
- package/dist/src/shared/worker-daemon/typings/wasm-fn.type.d.ts +2 -0
- package/dist/src/shared/worker-daemon/typings/write-lock.interface.d.ts +15 -0
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +22 -1
- package/dist/wasm/fs-database/kbdb_fs_database.js +28 -1
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +1 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +48 -1
- package/dist/wasm/kb-worker/kbdb_worker.js +60 -1
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +2 -0
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/worker.mjs +396 -60
- package/dist/worker.mjs.map +4 -4
- package/docs/details/cli.md +102 -15
- package/docs/details/library-api.md +55 -6
- package/docs/details/mcp-server.md +10 -4
- package/docs/details/search-and-ranking.md +63 -5
- package/docs/details/storage.md +2 -0
- package/docs/goals/auto-capture.md +378 -0
- package/docs/goals/benchmarking.md +296 -0
- package/docs/goals/cli.md +255 -14
- package/docs/goals/concurrency.md +259 -0
- package/docs/goals/database.md +244 -17
- package/docs/goals/document.md +1 -1
- package/docs/goals/hybrid-search.md +436 -0
- package/docs/goals/mcp.md +83 -14
- package/docs/goals/query-parser.md +98 -4
- package/docs/goals/query-result.md +177 -10
- package/docs/goals/semantic-dedup.md +229 -0
- package/docs/goals/skills.md +72 -0
- package/docs/goals/sync.md +217 -0
- package/docs/goals/worker-daemon.md +54 -7
- package/docs/modules/rust/fs-database/functions/integrity.md +11 -0
- package/docs/modules/rust/fs-database/functions/section.md +23 -6
- package/docs/modules/rust/fs-database/indexes/vectors.md +110 -0
- package/docs/modules/rust/fs-database/module.md +1 -0
- package/docs/modules/rust/fs-database/types/section.md +27 -1
- package/docs/modules/rust/overview.md +2 -1
- package/docs/modules/rust/query-parser/functions/module.md +2 -2
- package/docs/modules/rust/query-parser/functions/pipeline.md +44 -6
- package/docs/modules/rust/query-parser/module.md +5 -4
- package/docs/modules/rust/query-parser/types/keyphrase.md +11 -0
- package/docs/modules/rust/query-parser/types/module.md +3 -3
- package/docs/modules/typescript/shared/auto-capture/module.md +73 -0
- package/docs/modules/typescript/shared/cli/functions.md +68 -3
- package/docs/modules/typescript/shared/embedding/functions.md +94 -0
- package/docs/modules/typescript/shared/embedding/module.md +71 -0
- package/docs/modules/typescript/shared/embedding/typings.md +122 -0
- package/docs/overview.md +148 -166
- package/docs/release-notes/0.2.0.md +3 -3
- package/docs/release-notes/0.3.0.md +89 -0
- package/docs/release-notes/0.3.1.md +111 -0
- package/docs/release-notes/README.md +2 -0
- package/package.json +1 -1
- package/src/shared/auto-capture/classes/auto-capture-controller.class.ts +62 -0
- package/src/shared/auto-capture/constants/auto-capture-defaults.constant.ts +15 -0
- package/src/shared/auto-capture/functions/build-capture-prompt.function.ts +27 -0
- package/src/shared/auto-capture/functions/evaluate-trigger.function.ts +50 -0
- package/src/shared/auto-capture/index.ts +7 -0
- package/src/shared/auto-capture/typings/auto-capture-config.interface.ts +13 -0
- package/src/shared/auto-capture/typings/auto-capture-state.interface.ts +13 -0
- package/src/shared/auto-capture/typings/auto-capture-trigger.interface.ts +7 -0
- package/src/shared/cli/constants/global-help.constant.ts +73 -0
- package/src/shared/cli/constants/leaf-help.constant.ts +219 -0
- package/src/shared/cli/constants/memory-protocol-body.constant.ts +39 -0
- package/src/shared/cli/constants/query-guidance-body.constant.ts +37 -0
- package/src/shared/cli/constants/subcommand-help.constant.ts +195 -0
- package/src/shared/cli/functions/collect-files.function.ts +55 -0
- package/src/shared/cli/functions/compute-section-kbid.function.ts +49 -0
- package/src/shared/cli/functions/dispatch-command.function.ts +53 -1
- package/src/shared/cli/functions/format-mcp-output.function.ts +41 -0
- package/src/shared/cli/functions/format-output.function.ts +36 -12
- package/src/shared/cli/functions/format-text-output.function.ts +42 -0
- package/src/shared/cli/functions/generate-group-help.function.ts +41 -0
- package/src/shared/cli/functions/generate-help.function.ts +56 -1
- package/src/shared/cli/functions/handle-data-command.function.ts +67 -0
- package/src/shared/cli/functions/handle-mcp.function.ts +56 -0
- package/src/shared/cli/functions/handle-migrate.function.ts +64 -0
- package/src/shared/cli/functions/hydrate-search-previews.function.ts +29 -0
- package/src/shared/cli/functions/install-default-skills.function.ts +296 -0
- package/src/shared/cli/functions/parse-args.function.ts +16 -0
- package/src/shared/cli/functions/resolve-skill-names.function.ts +43 -0
- package/src/shared/cli/functions/run-check.function.ts +87 -6
- package/src/shared/cli/functions/run-export.function.ts +40 -0
- package/src/shared/cli/functions/run-gc.function.ts +6 -0
- package/src/shared/cli/functions/run-init.function.ts +2 -0
- package/src/shared/cli/functions/run-learn.function.ts +68 -16
- package/src/shared/cli/functions/run-recall.function.ts +66 -0
- package/src/shared/cli/functions/run-search.function.ts +60 -15
- package/src/shared/cli/functions/version-gate.function.ts +44 -0
- package/src/shared/cli/functions/wrap-command.function.ts +34 -0
- package/src/shared/cli/index.ts +4 -0
- package/src/shared/cli/typings/agent-create-client.interface.ts +47 -0
- package/src/shared/cli/typings/agent-get-client.interface.ts +39 -0
- package/src/shared/cli/typings/check-client.interface.ts +66 -0
- package/src/shared/cli/typings/cli-deps.interface.ts +54 -0
- package/src/shared/cli/typings/cli-options.interface.ts +15 -0
- package/src/shared/cli/typings/disconnectable-client.interface.ts +29 -0
- package/src/shared/cli/typings/dispatch-client.type.ts +46 -0
- package/src/shared/cli/typings/learn-client.interface.ts +53 -0
- package/src/shared/cli/typings/learn-io.interface.ts +5 -0
- package/src/shared/cli/typings/learn-result.model.ts +16 -0
- package/src/shared/cli/typings/search-client.interface.ts +73 -0
- package/src/shared/cli/typings/search-display.model.ts +18 -0
- package/src/shared/embedding/classes/null-embedding-provider.class.ts +29 -0
- package/src/shared/embedding/constants/near-duplicate-thresholds.constant.ts +17 -0
- package/src/shared/embedding/functions/build-vector-index.function.ts +79 -0
- package/src/shared/embedding/functions/cosine-similarity.function.ts +31 -0
- package/src/shared/embedding/functions/detect-near-duplicates.function.ts +69 -0
- package/src/shared/embedding/functions/jaccard-coefficient.function.ts +26 -0
- package/src/shared/embedding/functions/read-vector-index-meta.function.ts +44 -0
- package/src/shared/embedding/functions/rrf-fuse.function.ts +33 -0
- package/src/shared/embedding/functions/search-vectors.function.ts +59 -0
- package/src/shared/embedding/index.ts +20 -0
- package/src/shared/embedding/typings/embedding-config.interface.ts +23 -0
- package/src/shared/embedding/typings/embedding-provider.interface.ts +25 -0
- package/src/shared/embedding/typings/near-duplicate-candidate.model.ts +25 -0
- package/src/shared/embedding/typings/near-duplicate-result.model.ts +26 -0
- package/src/shared/embedding/typings/vector-index-entry.model.ts +13 -0
- package/src/shared/embedding/typings/vector-index-meta.model.ts +14 -0
- package/src/shared/embedding/typings/vector-search-result.model.ts +8 -0
- package/src/shared/mcp/classes/mcp-server.class.ts +36 -4
- package/src/shared/mcp/constants/tool-agent-create.constant.ts +39 -0
- package/src/shared/mcp/constants/tool-agent-delete.constant.ts +26 -0
- package/src/shared/mcp/constants/tool-agent-get.constant.ts +24 -0
- package/src/shared/mcp/constants/tool-agent-list.constant.ts +18 -0
- package/src/shared/mcp/constants/tool-auto-capture-review.constant.ts +32 -0
- package/src/shared/mcp/constants/tool-check.constant.ts +21 -0
- package/src/shared/mcp/constants/tool-content.constant.ts +29 -0
- package/src/shared/mcp/constants/tool-export.constant.ts +27 -0
- package/src/shared/mcp/constants/tool-gc.constant.ts +21 -0
- package/src/shared/mcp/constants/tool-learn.constant.ts +58 -0
- package/src/shared/mcp/constants/tool-rebuild.constant.ts +21 -0
- package/src/shared/mcp/constants/tool-recall.constant.ts +36 -0
- package/src/shared/mcp/constants/tool-retrieve.constant.ts +31 -0
- package/src/shared/mcp/constants/tool-search.constant.ts +51 -0
- package/src/shared/mcp/constants/tool-skill-delete.constant.ts +24 -0
- package/src/shared/mcp/constants/tool-skill-get.constant.ts +27 -0
- package/src/shared/mcp/constants/tool-skill-learn.constant.ts +37 -0
- package/src/shared/mcp/constants/tool-skill-list.constant.ts +18 -0
- package/src/shared/mcp/constants/tool-status.constant.ts +20 -0
- package/src/shared/mcp/constants/tool-unlearn.constant.ts +25 -0
- package/src/shared/mcp/functions/as-boolean-or-undefined.function.ts +11 -0
- package/src/shared/mcp/functions/as-string-array-or-undefined.function.ts +17 -0
- package/src/shared/mcp/functions/as-string-array.function.ts +15 -0
- package/src/shared/mcp/functions/as-string.function.ts +10 -0
- package/src/shared/mcp/functions/build-skills-text.function.ts +43 -0
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +74 -5
- package/src/shared/mcp/functions/handle-agent-create.function.ts +1 -1
- package/src/shared/mcp/functions/handle-agent-prompt.function.ts +68 -0
- package/src/shared/mcp/functions/handle-mcp-request.function.ts +202 -0
- package/src/shared/mcp/functions/handle-prompt-get.function.ts +18 -12
- package/src/shared/mcp/functions/handle-skill-prompt.function.ts +44 -0
- package/src/shared/mcp/functions/handle-tool-auto-capture-review.function.ts +24 -0
- package/src/shared/mcp/functions/handle-tool-call.function.ts +88 -2
- package/src/shared/mcp/functions/handle-tool-check.function.ts +21 -0
- package/src/shared/mcp/functions/handle-tool-content.function.ts +23 -0
- package/src/shared/mcp/functions/handle-tool-export.function.ts +25 -0
- package/src/shared/mcp/functions/handle-tool-gc.function.ts +21 -0
- package/src/shared/mcp/functions/handle-tool-learn.function.ts +69 -0
- package/src/shared/mcp/functions/handle-tool-rebuild.function.ts +21 -0
- package/src/shared/mcp/functions/handle-tool-retrieve.function.ts +40 -0
- package/src/shared/mcp/functions/handle-tool-search.function.ts +47 -0
- package/src/shared/mcp/functions/handle-tool-skill-delete.function.ts +34 -0
- package/src/shared/mcp/functions/handle-tool-skill-get.function.ts +59 -0
- package/src/shared/mcp/functions/handle-tool-skill-learn.function.ts +61 -0
- package/src/shared/mcp/functions/handle-tool-skill-list.function.ts +39 -0
- package/src/shared/mcp/functions/handle-tool-status.function.ts +21 -0
- package/src/shared/mcp/functions/handle-tool-unlearn.function.ts +24 -0
- package/src/shared/mcp/functions/parse-agent-meta.function.ts +27 -0
- package/src/shared/mcp/functions/parse-skill-arguments.function.ts +36 -0
- package/src/shared/mcp/functions/read-agent-meta.function.ts +41 -0
- package/src/shared/mcp/functions/resolve-skill-refs.function.ts +50 -0
- package/src/shared/mcp/functions/run-startup-health-check.function.ts +34 -0
- package/src/shared/mcp/typings/mcp-capabilities.interface.ts +16 -0
- package/src/shared/mcp/typings/mcp-client.interface.ts +47 -0
- package/src/shared/mcp/typings/mcp-completion.interface.ts +45 -0
- package/src/shared/mcp/typings/mcp-content-result.model.ts +9 -0
- package/src/shared/mcp/typings/mcp-export-result.model.ts +11 -0
- package/src/shared/mcp/typings/mcp-gc-result.model.ts +15 -0
- package/src/shared/mcp/typings/mcp-integrity-check-result.model.ts +17 -0
- package/src/shared/mcp/typings/mcp-integrity-error.model.ts +15 -0
- package/src/shared/mcp/typings/mcp-notification.interface.ts +9 -0
- package/src/shared/mcp/typings/mcp-rebuild-result.model.ts +9 -0
- package/src/shared/mcp/typings/mcp-request.interface.ts +11 -0
- package/src/shared/mcp/typings/mcp-resource-result.interface.ts +12 -0
- package/src/shared/mcp/typings/mcp-resource-template.interface.ts +11 -0
- package/src/shared/mcp/typings/mcp-response.interface.ts +18 -0
- package/src/shared/mcp/typings/mcp-server-info.interface.ts +7 -0
- package/src/shared/mcp/typings/mcp-server-state.interface.ts +17 -0
- package/src/shared/mcp/typings/mcp-tool-annotations.interface.ts +32 -0
- package/src/shared/mcp/typings/mcp-tool-definition.interface.ts +16 -0
- package/src/shared/mcp/typings/mcp-tool-result.interface.ts +19 -0
- package/src/shared/mcp/typings/mcp-worker-client.interface.ts +243 -0
- package/src/shared/mcp/typings/tool-call-result.model.ts +18 -0
- package/src/shared/sync/functions/build-import-report.function.ts +40 -0
- package/src/shared/sync/functions/parse-export-entry.function.ts +45 -0
- package/src/shared/sync/functions/resolve-conflict.function.ts +31 -0
- package/src/shared/sync/functions/serialize-export-entry.function.ts +18 -0
- package/src/shared/sync/index.ts +9 -0
- package/src/shared/sync/typings/conflict-resolution.type.ts +8 -0
- package/src/shared/sync/typings/export-entry.interface.ts +13 -0
- package/src/shared/sync/typings/export-options.interface.ts +9 -0
- package/src/shared/sync/typings/import-options.interface.ts +7 -0
- package/src/shared/sync/typings/import-report.interface.ts +15 -0
- package/src/shared/wasm-codec/functions/decode-add-section-result.function.ts +112 -0
- package/src/shared/wasm-codec/functions/decode-one-recall-result.function.ts +86 -0
- package/src/shared/wasm-codec/functions/decode-option-string.function.ts +24 -0
- package/src/shared/wasm-codec/functions/decode-recall-document.function.ts +59 -0
- package/src/shared/wasm-codec/functions/decode-recall-reference.function.ts +52 -0
- package/src/shared/wasm-codec/functions/decode-recall-sibling.function.ts +43 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +86 -0
- package/src/shared/wasm-codec/functions/decode-section-match.function.ts +80 -0
- package/src/shared/wasm-codec/functions/decode-section-record-trailing.function.ts +75 -0
- package/src/shared/wasm-codec/functions/decode-section-record.function.ts +85 -0
- package/src/shared/wasm-codec/functions/decode-section-records.function.ts +87 -0
- package/src/shared/wasm-codec/functions/decode-section-type.function.ts +30 -0
- package/src/shared/wasm-codec/functions/decode-wasm-list.function.ts +31 -0
- package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +68 -0
- package/src/shared/wasm-codec/index.ts +5 -0
- package/src/shared/wasm-codec/typings/add-section-input.model.ts +45 -0
- package/src/shared/wasm-codec/typings/add-section-result.model.ts +28 -0
- package/src/shared/wasm-codec/typings/document-manifest.model.ts +20 -0
- package/src/shared/wasm-codec/typings/document-section.model.ts +12 -0
- package/src/shared/wasm-codec/typings/item-decoder.type.ts +10 -0
- package/src/shared/wasm-codec/typings/near-duplicate.model.ts +16 -0
- package/src/shared/wasm-codec/typings/paged-search-result.model.ts +22 -0
- package/src/shared/wasm-codec/typings/section-match.model.ts +31 -0
- package/src/shared/wasm-codec/typings/section-record-trailing.model.ts +38 -0
- package/src/shared/wasm-codec/typings/section-record.model.ts +66 -0
- package/src/shared/wasm-codec/typings/section-type-result.model.ts +12 -0
- package/src/shared/worker-client/classes/worker-client.class.ts +19 -0
- package/src/shared/worker-client/functions/handle-ipc-data.function.ts +49 -0
- package/src/shared/worker-client/functions/send-ipc-request.function.ts +39 -0
- package/src/shared/worker-client/index.ts +4 -1
- package/src/shared/worker-client/typings/add-section-result.model.ts +32 -15
- package/src/shared/worker-client/typings/export-result.model.ts +14 -0
- package/src/shared/worker-client/typings/gc-result.model.ts +6 -0
- package/src/shared/worker-client/typings/json-rpc-response.interface.ts +17 -0
- package/src/shared/worker-client/typings/pending-call.interface.ts +7 -0
- package/src/shared/worker-client/typings/recall-document.model.ts +16 -0
- package/src/shared/worker-client/typings/recall-params.model.ts +15 -0
- package/src/shared/worker-client/typings/recall-reference.model.ts +32 -0
- package/src/shared/worker-client/typings/recall-sibling.model.ts +11 -0
- package/src/shared/worker-client/typings/recall-single-result.model.ts +41 -0
- package/src/shared/worker-client/typings/search-result.model.ts +12 -0
- package/src/shared/worker-client/typings/section.model.ts +16 -0
- package/src/shared/worker-daemon/classes/ipc-error.class.ts +22 -0
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +315 -46
- package/src/shared/worker-daemon/constants/wasm-method-map.constant.ts +69 -0
- package/src/shared/worker-daemon/functions/build-ipc-error-response.function.ts +16 -0
- package/src/shared/worker-daemon/functions/check-catalog-version.function.ts +54 -0
- package/src/shared/worker-daemon/functions/check-preconditions.function.ts +28 -0
- package/src/shared/worker-daemon/functions/create-host-imports.function.ts +19 -4
- package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +5 -1
- package/src/shared/worker-daemon/functions/detect-stale-pid.function.ts +33 -0
- package/src/shared/worker-daemon/functions/dispatch-request.function.ts +190 -0
- package/src/shared/worker-daemon/functions/handle-check-version.function.ts +74 -0
- package/src/shared/worker-daemon/functions/handle-config-method.function.ts +27 -0
- package/src/shared/worker-daemon/functions/handle-read-ops.function.ts +236 -0
- package/src/shared/worker-daemon/functions/handle-write-ops.function.ts +257 -0
- package/src/shared/worker-daemon/functions/parse-auto-capture-section.function.ts +51 -0
- package/src/shared/worker-daemon/functions/parse-catalog-version.function.ts +20 -0
- package/src/shared/worker-daemon/functions/parse-embedding-section.function.ts +38 -0
- package/src/shared/worker-daemon/functions/parse-worker-toml.function.ts +104 -0
- package/src/shared/worker-daemon/functions/run-startup-integrity-check.function.ts +55 -0
- package/src/shared/worker-daemon/functions/scan-near-duplicates.function.ts +92 -0
- package/src/shared/worker-daemon/functions/wasm-bridge.function.ts +144 -0
- package/src/shared/worker-daemon/functions/wasm-memory-helpers.function.ts +41 -0
- package/src/shared/worker-daemon/functions/write-lock.function.ts +49 -0
- package/src/shared/worker-daemon/typings/allocator-ref.interface.ts +16 -0
- package/src/shared/worker-daemon/typings/daemon-config.interface.ts +7 -0
- package/src/shared/worker-daemon/typings/fs-adapter.interface.ts +22 -0
- package/src/shared/worker-daemon/typings/handler-context.interface.ts +19 -0
- package/src/shared/worker-daemon/typings/memory-ref.interface.ts +13 -0
- package/src/shared/worker-daemon/typings/wasm-fn.type.ts +2 -0
- package/src/shared/worker-daemon/typings/write-lock.interface.ts +13 -0
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +22 -1
- package/src/wasm/fs-database/kbdb_fs_database.js +28 -1
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +1 -0
- package/src/wasm/kb-worker/kbdb_worker.d.ts +48 -1
- package/src/wasm/kb-worker/kbdb_worker.js +60 -1
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +2 -0
- package/src/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Sync -- Cross-Machine Synchronization
|
|
2
|
+
|
|
3
|
+
*Export the database as a git-friendly directory, move
|
|
4
|
+
it with any transport, import on the other side.*
|
|
5
|
+
|
|
6
|
+
## Goal
|
|
7
|
+
|
|
8
|
+
kbdb is currently single-machine -- "persists across
|
|
9
|
+
sessions" means across sessions on the same box. For
|
|
10
|
+
teams, multi-device use, or backup, the database needs
|
|
11
|
+
a sync story.
|
|
12
|
+
|
|
13
|
+
The design uses export/import as the primitive, with
|
|
14
|
+
git as the recommended transport. Sync is manual and
|
|
15
|
+
explicit. There is no background replication.
|
|
16
|
+
|
|
17
|
+
This goal addresses gap #5 from
|
|
18
|
+
[Opus 4.8 Second Brain Review](../issues/2026-06-23-opus-48-second-brain-review.md):
|
|
19
|
+
"No sync/remote story unless you build one on top,
|
|
20
|
+
which limits 'persists across sessions' to 'across
|
|
21
|
+
sessions on this box.'"
|
|
22
|
+
|
|
23
|
+
## Sync Primitives
|
|
24
|
+
|
|
25
|
+
Two operations form the sync foundation.
|
|
26
|
+
|
|
27
|
+
### Export
|
|
28
|
+
|
|
29
|
+
Serialize the database into a portable, git-friendly
|
|
30
|
+
directory:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
kbdb export --format git --db .kbdb --out ./kbdb-sync/
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The exported directory mirrors `.kbdb/` minus indexes:
|
|
37
|
+
|
|
38
|
+
- `catalog.toml` -- database table of contents
|
|
39
|
+
- `sections/**/*.section` -- all section files
|
|
40
|
+
- `documents/**/*.toml` -- all document manifests
|
|
41
|
+
|
|
42
|
+
Excluded:
|
|
43
|
+
|
|
44
|
+
- `indexes/` -- derived data, rebuildable
|
|
45
|
+
- Vector indexes (`vectors.idx`, `vectors-meta.toml`)
|
|
46
|
+
- PID files and lock files
|
|
47
|
+
|
|
48
|
+
The exported directory is a valid git subtree. It
|
|
49
|
+
contains no binary blobs except section content
|
|
50
|
+
(image sections, which are stored as base64 text).
|
|
51
|
+
Every file is human-readable and git-diffable.
|
|
52
|
+
|
|
53
|
+
### Import
|
|
54
|
+
|
|
55
|
+
Restore a database from an exported directory:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
kbdb import --from ./kbdb-sync/ --db .kbdb
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Import reads the exported directory and writes sections
|
|
62
|
+
and documents into the target database. After import,
|
|
63
|
+
run `rebuild` to regenerate all indexes (lexical and
|
|
64
|
+
vector, if configured).
|
|
65
|
+
|
|
66
|
+
Import is **additive** -- existing sections with
|
|
67
|
+
different kbids are preserved. Only the conflict
|
|
68
|
+
resolution rules below can cause existing sections to
|
|
69
|
+
be superseded.
|
|
70
|
+
|
|
71
|
+
## Conflict Resolution
|
|
72
|
+
|
|
73
|
+
When importing sections that conflict with existing
|
|
74
|
+
ones, the following rules apply in priority order:
|
|
75
|
+
|
|
76
|
+
| Condition | Action |
|
|
77
|
+
|-----------|--------|
|
|
78
|
+
| Same kbid | Skip -- identical content already exists |
|
|
79
|
+
| Same `source_key`, imported `created_at` is newer | Supersede -- imported section replaces local one |
|
|
80
|
+
| Same `source_key`, local `created_at` is newer or equal | Keep -- local version is retained |
|
|
81
|
+
| No `source_key` match | Add as new section |
|
|
82
|
+
|
|
83
|
+
This leverages the existing supersession mechanism
|
|
84
|
+
documented in [Database](database.md). The content
|
|
85
|
+
hash (kbid) remains the primary identity. The source
|
|
86
|
+
key is the logical identity used for supersession
|
|
87
|
+
matching across machines.
|
|
88
|
+
|
|
89
|
+
## Git-Based Workflow
|
|
90
|
+
|
|
91
|
+
Recommended workflow for teams:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
Machine A Git repo Machine B
|
|
95
|
+
───────── ──────── ─────────
|
|
96
|
+
kbdb export --format git ──→ git push ──→ git pull ──→ kbdb import
|
|
97
|
+
kbdb rebuild
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Steps:
|
|
101
|
+
|
|
102
|
+
1. Machine A exports to a directory within a git repo.
|
|
103
|
+
2. Machine A commits and pushes.
|
|
104
|
+
3. Machine B pulls and imports.
|
|
105
|
+
4. Machine B rebuilds indexes.
|
|
106
|
+
|
|
107
|
+
This is a manual, explicit sync -- not automatic
|
|
108
|
+
real-time replication. Any transport that moves the
|
|
109
|
+
exported directory works: git, rsync, scp, a shared
|
|
110
|
+
drive, an archive file. Git is recommended because the
|
|
111
|
+
export format is designed to be git-diffable.
|
|
112
|
+
|
|
113
|
+
## Vector Index Handling
|
|
114
|
+
|
|
115
|
+
Vector indexes (`vectors.idx`, `vectors-meta.toml`)
|
|
116
|
+
are excluded from export -- they are derived data, the
|
|
117
|
+
same as lexical indexes.
|
|
118
|
+
|
|
119
|
+
After import:
|
|
120
|
+
|
|
121
|
+
- If an embedding provider is configured, `rebuild`
|
|
122
|
+
regenerates vectors using the local model.
|
|
123
|
+
- If the importing machine uses a different embedding
|
|
124
|
+
model than the exporting machine, vectors are
|
|
125
|
+
computed fresh with the local model. No action is
|
|
126
|
+
required to handle this case -- vectors are always
|
|
127
|
+
rebuilt from content, never transferred.
|
|
128
|
+
|
|
129
|
+
## Export Formats
|
|
130
|
+
|
|
131
|
+
| Format | Description | Use Case |
|
|
132
|
+
|--------|-------------|----------|
|
|
133
|
+
| `git` | Flat directory, text-friendly | Git-based sync |
|
|
134
|
+
| `archive` | Single tarball (`.tar.gz`) | Backup, transfer |
|
|
135
|
+
|
|
136
|
+
The default format is `git` (the directory format).
|
|
137
|
+
|
|
138
|
+
## CLI Surface
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
kbdb export [--format git|archive] [--out <path>]
|
|
142
|
+
kbdb import --from <path> [--dry-run]
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
- `kbdb export` -- exports the database to the
|
|
146
|
+
specified output path. Defaults to `--format git`.
|
|
147
|
+
The `--out` path is created if it does not exist.
|
|
148
|
+
- `kbdb import` -- imports from an exported directory
|
|
149
|
+
or archive. Runs conflict resolution for each
|
|
150
|
+
incoming section and document.
|
|
151
|
+
- `--dry-run` on import -- shows what would change
|
|
152
|
+
(sections added, superseded, skipped) without
|
|
153
|
+
writing anything.
|
|
154
|
+
|
|
155
|
+
## Import Report
|
|
156
|
+
|
|
157
|
+
Import returns a structured report:
|
|
158
|
+
|
|
159
|
+
```json
|
|
160
|
+
{
|
|
161
|
+
"sections_added": 42,
|
|
162
|
+
"sections_skipped": 3,
|
|
163
|
+
"sections_superseded": 5,
|
|
164
|
+
"documents_added": 2,
|
|
165
|
+
"documents_skipped": 1,
|
|
166
|
+
"rebuild_required": true
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
`rebuild_required` is always `true` after a successful
|
|
171
|
+
import that adds or supersedes any sections, because
|
|
172
|
+
the lexical index is out of date. The caller is
|
|
173
|
+
responsible for running `rebuild` after import.
|
|
174
|
+
|
|
175
|
+
## Why Not CRDTs
|
|
176
|
+
|
|
177
|
+
CRDTs (Conflict-free Replicated Data Types) would
|
|
178
|
+
enable automatic, real-time sync without conflicts.
|
|
179
|
+
The design chooses export/import instead for three
|
|
180
|
+
reasons:
|
|
181
|
+
|
|
182
|
+
1. **Identity conflict** -- The kbid is a content
|
|
183
|
+
hash. Content changes create new identities rather
|
|
184
|
+
than updating existing ones. This conflicts with
|
|
185
|
+
CRDT merge semantics, which assume stable object
|
|
186
|
+
identity across mutations.
|
|
187
|
+
|
|
188
|
+
2. **Complexity** -- CRDT support at the current user
|
|
189
|
+
scale is speculative complexity (YAGNI). The
|
|
190
|
+
export/import model covers the primary use cases
|
|
191
|
+
(backup, team sharing, multi-device) with familiar
|
|
192
|
+
tooling and no new dependencies.
|
|
193
|
+
|
|
194
|
+
3. **Existing supersession** -- The source key
|
|
195
|
+
mechanism already provides a logical identity layer
|
|
196
|
+
above content addressing. Conflict resolution at
|
|
197
|
+
import time uses the same supersession logic that
|
|
198
|
+
`kbdb learn --replace` uses. No new primitives are
|
|
199
|
+
required.
|
|
200
|
+
|
|
201
|
+
CRDT support may be revisited in a future version if
|
|
202
|
+
demand warrants it.
|
|
203
|
+
|
|
204
|
+
## Design Constraints
|
|
205
|
+
|
|
206
|
+
- Sync is manual and explicit -- no background
|
|
207
|
+
replication.
|
|
208
|
+
- Export excludes all derived data (indexes, vectors).
|
|
209
|
+
- Import respects the existing supersession model
|
|
210
|
+
from [Database](database.md).
|
|
211
|
+
- No new dependencies -- uses existing file I/O.
|
|
212
|
+
- Git is recommended but not required -- any transport
|
|
213
|
+
that moves the exported directory works.
|
|
214
|
+
- The single-machine write lock documented in
|
|
215
|
+
[Concurrent Write Safety](concurrency.md) is not
|
|
216
|
+
relevant to sync. Import is a local write operation
|
|
217
|
+
and acquires the lock normally.
|
|
@@ -107,6 +107,34 @@ Each database directory is an independent context with
|
|
|
107
107
|
its own daemon, its own cache, and its own WASM module
|
|
108
108
|
instance. There is no shared state across contexts.
|
|
109
109
|
|
|
110
|
+
## Write Serialization
|
|
111
|
+
|
|
112
|
+
The daemon serializes write operations using an
|
|
113
|
+
exclusive file lock on `kbdb-{ctx}.lock` in the OS
|
|
114
|
+
temporary directory. The lock file uses the same
|
|
115
|
+
context ID as the PID file and IPC socket.
|
|
116
|
+
|
|
117
|
+
- **Read operations** proceed without acquiring the
|
|
118
|
+
lock. Concurrent reads are fully parallel.
|
|
119
|
+
- **Write operations** acquire the exclusive lock
|
|
120
|
+
before calling the WASM write export. If another
|
|
121
|
+
write is already in progress, the new write queues
|
|
122
|
+
behind the lock and waits.
|
|
123
|
+
- **Lock duration** -- the lock is held only for the
|
|
124
|
+
duration of the single write operation and released
|
|
125
|
+
immediately after it completes. It is not held
|
|
126
|
+
across multiple operations or across client
|
|
127
|
+
connections.
|
|
128
|
+
|
|
129
|
+
This serialization model is equivalent to SQLite's
|
|
130
|
+
default locking: readers never block, and writers
|
|
131
|
+
take turns one at a time.
|
|
132
|
+
|
|
133
|
+
Write methods subject to this lock are:
|
|
134
|
+
`addSection`, `updateSection`, `removeSection`,
|
|
135
|
+
`groupSections`, `removeGrouping`, `initDirectory`,
|
|
136
|
+
`gc`, and `rebuildIndexes`.
|
|
137
|
+
|
|
110
138
|
## Daemon Startup
|
|
111
139
|
|
|
112
140
|
When the worker client spawns a new daemon (see
|
|
@@ -127,15 +155,23 @@ daemon process performs the following startup sequence:
|
|
|
127
155
|
module (see WASM Module below).
|
|
128
156
|
5. Calls `worker_init` on the WASM module to open the
|
|
129
157
|
database context.
|
|
130
|
-
6.
|
|
158
|
+
6. Calls `db_check_integrity` on the WASM module to
|
|
159
|
+
run a startup health check. If `ok` is false, the
|
|
160
|
+
daemon logs a structured warning to stderr listing
|
|
161
|
+
the error count and error types. The daemon
|
|
162
|
+
continues operating -- health issues are not fatal
|
|
163
|
+
to startup. The health status (`integrity_ok`,
|
|
164
|
+
`integrity_errors`) is included in subsequent
|
|
165
|
+
`status` responses.
|
|
166
|
+
7. Writes its PID to `kbdb-{ctx}.pid` in the OS
|
|
131
167
|
temporary directory.
|
|
132
|
-
|
|
168
|
+
8. Creates the IPC socket (`kbdb-{ctx}.sock` on Unix,
|
|
133
169
|
named pipe on Windows).
|
|
134
|
-
|
|
170
|
+
9. Begins listening for connections.
|
|
135
171
|
|
|
136
172
|
The daemon only writes its PID file and creates the
|
|
137
173
|
IPC socket after all preconditions pass and the WASM
|
|
138
|
-
module is loaded. If the daemon exits before step
|
|
174
|
+
module is loaded. If the daemon exits before step 7,
|
|
139
175
|
the worker client's PID-file poll times out, and the
|
|
140
176
|
worker client reads the crash log (or the daemon's
|
|
141
177
|
stderr) to report the failure reason.
|
|
@@ -494,6 +530,7 @@ for each WASM operation:
|
|
|
494
530
|
| `listByType`, `list_by_type` | `worker_list_by_type` |
|
|
495
531
|
| `listDocumentsByType` | `worker_list_docs_by_type` |
|
|
496
532
|
| `recall` | `worker_recall` |
|
|
533
|
+
| `export` | `db_export` |
|
|
497
534
|
|
|
498
535
|
`migrateDatabase` is listed in the map but throws
|
|
499
536
|
`IpcError(-32601, 'migrateDatabase is not yet
|
|
@@ -520,12 +557,22 @@ Returns the daemon's current state.
|
|
|
520
557
|
// Response
|
|
521
558
|
{
|
|
522
559
|
"jsonrpc": "2.0", "id": 1,
|
|
523
|
-
"result":
|
|
560
|
+
"result": {
|
|
561
|
+
"state": "busy",
|
|
562
|
+
"integrity_ok": true,
|
|
563
|
+
"integrity_errors": []
|
|
564
|
+
}
|
|
524
565
|
}
|
|
525
566
|
```
|
|
526
567
|
|
|
527
|
-
Result:
|
|
528
|
-
|
|
568
|
+
Result fields:
|
|
569
|
+
|
|
570
|
+
| Field | Type | Description |
|
|
571
|
+
|--------------------|----------|-------------------------------------------|
|
|
572
|
+
| `state` | string | `"busy"` if connections > 0, else `"idle"` |
|
|
573
|
+
| `integrity_ok` | boolean | `true` if startup health check passed |
|
|
574
|
+
| `integrity_errors` | string[] | Error types from `db_check_integrity`; |
|
|
575
|
+
| | | empty when `integrity_ok` is `true` |
|
|
529
576
|
|
|
530
577
|
### `idle_at`
|
|
531
578
|
|
|
@@ -44,12 +44,23 @@ pub fn rebuild_indexes()
|
|
|
44
44
|
manifest must exist.
|
|
45
45
|
- Detect circular references in `$(text:)` and
|
|
46
46
|
`$(document:)` marker chains.
|
|
47
|
+
- Detect **divergent content**: sections sharing the
|
|
48
|
+
same `source_key` that have different content.
|
|
49
|
+
Indicates contradictory versions that should be
|
|
50
|
+
resolved via supersession. Reported as
|
|
51
|
+
`divergent_content` entries in `IntegrityReport`.
|
|
47
52
|
|
|
48
53
|
### `garbage_collect`
|
|
49
54
|
|
|
50
55
|
Remove section files not referenced by any document
|
|
51
56
|
manifest. Returns the number of removed files.
|
|
52
57
|
|
|
58
|
+
Also reports `stale_sources` -- an advisory count of
|
|
59
|
+
sections whose `source_path` points to a file that no
|
|
60
|
+
longer contains their heading text. Stale sections
|
|
61
|
+
are not automatically removed (they may still be
|
|
62
|
+
referenced by documents); the count is informational.
|
|
63
|
+
|
|
53
64
|
### `rebuild_indexes`
|
|
54
65
|
|
|
55
66
|
Reconstruct all index files (`terms.idx`,
|
|
@@ -30,17 +30,34 @@ pub fn remove_section(kbid: &KbId)
|
|
|
30
30
|
### `add_section`
|
|
31
31
|
|
|
32
32
|
1. Compute kb-id from content via `compute_kbid`.
|
|
33
|
-
2.
|
|
34
|
-
|
|
33
|
+
2. **Supersession check**: if `source_key` is
|
|
34
|
+
provided and a section with the same `source_key`
|
|
35
|
+
already exists, set `supersedes` to the old
|
|
36
|
+
section's kbid, set `updated_at` to the current
|
|
37
|
+
timestamp, remove the old kbid from document
|
|
38
|
+
manifests, and mark the old section for GC. The
|
|
39
|
+
new section replaces the old one as the current
|
|
40
|
+
version.
|
|
41
|
+
3. Create shard directory if needed (`host_mkdir`).
|
|
42
|
+
4. Serialize TOML header + `---` separator + body.
|
|
35
43
|
TOML header includes: kbid, docids, section_type,
|
|
36
44
|
title, description, size, created_at, checksum,
|
|
37
45
|
token_count, heading_token_count,
|
|
38
|
-
body_token_count, code_token_count
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
body_token_count, code_token_count, source_key,
|
|
47
|
+
source_path, source_mtime, updated_at, tags,
|
|
48
|
+
supersedes.
|
|
49
|
+
5. Write atomically via `atomic_write`.
|
|
50
|
+
6. **Near-duplicate detection**: compute Jaccard
|
|
51
|
+
coefficient on stemmed term sets against existing
|
|
52
|
+
sections. Sections with similarity >= 0.85 are
|
|
53
|
+
reported as `near_duplicates` in the result
|
|
54
|
+
(advisory, not a block).
|
|
55
|
+
7. Update catalog via `increment_sections(1)`.
|
|
41
56
|
|
|
42
57
|
Validation: image sections (`image/*` type) require
|
|
43
|
-
a `title` in `AddSectionParams`.
|
|
58
|
+
a `title` in `AddSectionParams`. Text sections
|
|
59
|
+
without a `title` emit a `heading_missing` warning
|
|
60
|
+
in the result.
|
|
44
61
|
|
|
45
62
|
### `update_section`
|
|
46
63
|
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# indexes::vectors -- Vector Embedding Index
|
|
2
|
+
|
|
3
|
+
*Maps kb-ids to embedding vectors for similarity search. Stored in
|
|
4
|
+
`indexes/vectors.idx` with metadata in `indexes/vectors-meta.toml`.*
|
|
5
|
+
|
|
6
|
+
## Source
|
|
7
|
+
|
|
8
|
+
`engine/crates/fs-database/src/index/vectors.rs`
|
|
9
|
+
|
|
10
|
+
## Implementation Boundary
|
|
11
|
+
|
|
12
|
+
Unlike other index files which are written by the Rust/WASM engine,
|
|
13
|
+
the vector index is written and read by TypeScript. The Rust module
|
|
14
|
+
defines the binary format specification and provides read/write
|
|
15
|
+
utilities for potential future use, but the primary producer is the
|
|
16
|
+
TypeScript embedding module. This separation exists because embedding
|
|
17
|
+
computation requires network I/O to call external API providers, and
|
|
18
|
+
the WASM target (`wasm32-unknown-unknown`) has no network access.
|
|
19
|
+
ONNX models are also too large to fit in WASM linear memory.
|
|
20
|
+
|
|
21
|
+
## Binary Format: vectors.idx
|
|
22
|
+
|
|
23
|
+
Fixed-width binary file. A 32-byte header is followed by N records,
|
|
24
|
+
one per section. Record size is fixed for a given file because all
|
|
25
|
+
embeddings share the same `dimensions` value from the header.
|
|
26
|
+
|
|
27
|
+
**Header (32 bytes):**
|
|
28
|
+
|
|
29
|
+
| Offset | Size | Type | Field |
|
|
30
|
+
|--------|------|-----------|--------------------------------|
|
|
31
|
+
| 0 | 4 | u32 LE | magic (`0x56454358` = "VECX") |
|
|
32
|
+
| 4 | 4 | u32 LE | version (1) |
|
|
33
|
+
| 8 | 4 | u32 LE | dimensions |
|
|
34
|
+
| 12 | 4 | u32 LE | record_count |
|
|
35
|
+
| 16 | 16 | [u8; 16] | reserved (zero-filled) |
|
|
36
|
+
|
|
37
|
+
**Record (variable, but fixed per file):**
|
|
38
|
+
|
|
39
|
+
| Offset | Size | Type | Field |
|
|
40
|
+
|--------|---------------|----------------|---------------------------|
|
|
41
|
+
| 0 | 64 | [u8; 64] | kbid (UTF-8, null-padded) |
|
|
42
|
+
| 64 | dims × 4 | [f32 LE; dims] | embedding vector |
|
|
43
|
+
|
|
44
|
+
Record size = 64 + (dimensions × 4). For 384-dimensional embeddings,
|
|
45
|
+
each record is 1,600 bytes.
|
|
46
|
+
|
|
47
|
+
## Metadata: vectors-meta.toml
|
|
48
|
+
|
|
49
|
+
```toml
|
|
50
|
+
model = "all-MiniLM-L6-v2"
|
|
51
|
+
dimensions = 384
|
|
52
|
+
record_count = 1042
|
|
53
|
+
version = 1
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The metadata file is read before opening `vectors.idx`. If the
|
|
57
|
+
`model` field differs from the current embedding provider's model
|
|
58
|
+
name, the vector index is considered stale and must be rebuilt before
|
|
59
|
+
it can be used for search.
|
|
60
|
+
|
|
61
|
+
## Type Definitions
|
|
62
|
+
|
|
63
|
+
```rust
|
|
64
|
+
pub struct VectorIndex {
|
|
65
|
+
dimensions: u32,
|
|
66
|
+
entries: Vec<VectorEntry>,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
pub struct VectorEntry {
|
|
70
|
+
pub kbid: KbId,
|
|
71
|
+
pub vector: Vec<f32>,
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`VectorIndex` owns all loaded entries in memory. `dimensions` is
|
|
76
|
+
stored separately from the per-entry vector length so that the header
|
|
77
|
+
value can be validated against each record during a read. Both structs
|
|
78
|
+
are not exposed at the WASM boundary -- the index is consumed
|
|
79
|
+
internally by `search` and `lookup`.
|
|
80
|
+
|
|
81
|
+
## Methods
|
|
82
|
+
|
|
83
|
+
```rust
|
|
84
|
+
impl VectorIndex {
|
|
85
|
+
pub fn read_from(path: &str) -> Result<Self, FsError>;
|
|
86
|
+
pub fn write_to(&self, path: &str) -> Result<(), FsError>;
|
|
87
|
+
pub fn lookup(&self, kbid: &KbId) -> Option<&[f32]>;
|
|
88
|
+
pub fn search(
|
|
89
|
+
&self,
|
|
90
|
+
query_vector: &[f32],
|
|
91
|
+
limit: usize,
|
|
92
|
+
) -> Vec<(KbId, f32)>;
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`read_from` parses the binary file header, validates the magic bytes
|
|
97
|
+
and version, then reads all records into memory. `write_to` serializes
|
|
98
|
+
the header followed by each entry in record order. `lookup` returns
|
|
99
|
+
the stored embedding slice for a single kb-id, or `None` if the kb-id
|
|
100
|
+
is not present. `search` computes cosine similarity between
|
|
101
|
+
`query_vector` and every stored entry, then returns the top `limit`
|
|
102
|
+
results as `(KbId, score)` pairs sorted by descending similarity.
|
|
103
|
+
|
|
104
|
+
## Rebuild Semantics
|
|
105
|
+
|
|
106
|
+
`vectors.idx` is derived data and can be regenerated from section
|
|
107
|
+
content at any time. During rebuild, the TypeScript layer iterates all
|
|
108
|
+
sections, computes embeddings via the configured `EmbeddingProvider`,
|
|
109
|
+
and writes the binary file. If no embedding provider is configured,
|
|
110
|
+
`vectors.idx` is not generated and similarity search is unavailable.
|
|
@@ -120,6 +120,7 @@ engine/crates/fs-database/
|
|
|
120
120
|
| `db_status` | Return database metadata |
|
|
121
121
|
| `db_check_integrity` | Run integrity checks |
|
|
122
122
|
| `db_garbage_collect` | Remove orphaned sections |
|
|
123
|
+
| `db_export` | Export database snapshot |
|
|
123
124
|
| `alloc` / `free` | Memory management (from `kbdb-shared`) |
|
|
124
125
|
|
|
125
126
|
## Dependencies
|
|
@@ -26,6 +26,12 @@ pub struct SectionHeader {
|
|
|
26
26
|
pub heading_token_count: u32,
|
|
27
27
|
pub body_token_count: u32,
|
|
28
28
|
pub code_token_count: u32,
|
|
29
|
+
pub source_key: Option<String>,
|
|
30
|
+
pub source_path: Option<String>,
|
|
31
|
+
pub source_mtime: Option<String>,
|
|
32
|
+
pub updated_at: Option<String>,
|
|
33
|
+
pub tags: Vec<String>,
|
|
34
|
+
pub supersedes: Option<KbId>,
|
|
29
35
|
}
|
|
30
36
|
```
|
|
31
37
|
|
|
@@ -43,6 +49,21 @@ and stored in the header for query-time retrieval.
|
|
|
43
49
|
See [FieldTokenCounts](../../shared/query/types.md)
|
|
44
50
|
for the shared struct.
|
|
45
51
|
|
|
52
|
+
`source_key` is a stable logical identity derived
|
|
53
|
+
from `sha256("${source_path}\0${heading}")`,
|
|
54
|
+
truncated to 16 hex chars. Separate from `kbid`
|
|
55
|
+
(content hash) -- identifies *what the section is
|
|
56
|
+
about* rather than *what it currently says*. `null`
|
|
57
|
+
for stdin input. `source_path` is the original file
|
|
58
|
+
path that was learned. `source_mtime` is the ISO 8601
|
|
59
|
+
modified time of the source file at learn time.
|
|
60
|
+
`updated_at` is the ISO 8601 timestamp of the last
|
|
61
|
+
supersession (`null` on first create). `tags` are
|
|
62
|
+
user-supplied strings for scoping and filtering.
|
|
63
|
+
`supersedes` is the kbid of the section this one
|
|
64
|
+
replaced (`null` on first create). See
|
|
65
|
+
[Database -- Logical Identity](../../../goals/database.md).
|
|
66
|
+
|
|
46
67
|
### `IntegrityReport`
|
|
47
68
|
|
|
48
69
|
```rust
|
|
@@ -53,6 +74,7 @@ pub struct IntegrityReport {
|
|
|
53
74
|
pub broken_refs: Vec<(KbId, String, KbId)>,
|
|
54
75
|
pub type_mismatches: Vec<(KbId, String, KbId)>,
|
|
55
76
|
pub circular_refs: Vec<(KbId, Vec<KbId>)>,
|
|
77
|
+
pub divergent_content: Vec<(String, Vec<KbId>)>,
|
|
56
78
|
}
|
|
57
79
|
```
|
|
58
80
|
|
|
@@ -64,7 +86,11 @@ covering all six marker types (`text`, `code`,
|
|
|
64
86
|
target_kbid)` where the target section type does
|
|
65
87
|
not match the marker type. `circular_refs` are
|
|
66
88
|
`(start_kbid, cycle_path)` for reference chains
|
|
67
|
-
that form loops.
|
|
89
|
+
that form loops. `divergent_content` entries are
|
|
90
|
+
`(source_key, conflicting_kbids)` -- sections
|
|
91
|
+
sharing the same `source_key` that have different
|
|
92
|
+
content, indicating contradictory versions that
|
|
93
|
+
should be resolved via supersession.
|
|
68
94
|
|
|
69
95
|
## Functions
|
|
70
96
|
|
|
@@ -266,7 +266,7 @@ engine/crates/query-parser/
|
|
|
266
266
|
├── lib.rs ← WASM exports
|
|
267
267
|
├── mem.rs ← shared-memory helpers
|
|
268
268
|
│
|
|
269
|
-
├── pipeline/ ←
|
|
269
|
+
├── pipeline/ ← 9-stage tokenizer
|
|
270
270
|
│ ├── mod.rs
|
|
271
271
|
│ ├── markers.rs
|
|
272
272
|
│ ├── unicode.rs
|
|
@@ -274,6 +274,7 @@ engine/crates/query-parser/
|
|
|
274
274
|
│ ├── identifiers.rs
|
|
275
275
|
│ ├── case.rs
|
|
276
276
|
│ ├── stopwords.rs
|
|
277
|
+
│ ├── synonyms.rs
|
|
277
278
|
│ ├── stem.rs
|
|
278
279
|
│ └── ngram.rs
|
|
279
280
|
│
|
|
@@ -5,9 +5,9 @@ extraction, and ranking.*
|
|
|
5
5
|
|
|
6
6
|
## Modules
|
|
7
7
|
|
|
8
|
-
- **[pipeline](pipeline.md)** --
|
|
8
|
+
- **[pipeline](pipeline.md)** -- 9-stage tokenization
|
|
9
9
|
pipeline. Converts raw text into normalized, stemmed
|
|
10
|
-
tokens with n-grams.
|
|
10
|
+
tokens with synonym expansion and n-grams.
|
|
11
11
|
- **[parse](parse.md)** -- Query string parsing into
|
|
12
12
|
structured `QueryPlan`.
|
|
13
13
|
- **[extract](extract.md)** -- RAKE keyphrase
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# functions::pipeline -- Tokenization Pipeline
|
|
2
2
|
|
|
3
|
-
*
|
|
4
|
-
normalized, stemmed tokens
|
|
5
|
-
and query processing.*
|
|
3
|
+
*9-stage pipeline that converts raw text into
|
|
4
|
+
normalized, stemmed tokens with synonym expansion.
|
|
5
|
+
Used for both indexing and query processing.*
|
|
6
6
|
|
|
7
7
|
## Source
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ and query processing.*
|
|
|
14
14
|
pub fn tokenize(input: &str) -> TokenStream;
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
Runs all
|
|
17
|
+
Runs all nine stages in sequence. Each stage is a
|
|
18
18
|
pure function.
|
|
19
19
|
|
|
20
20
|
## Stages
|
|
@@ -83,7 +83,32 @@ pub fn remove_stop_words(
|
|
|
83
83
|
Filters common function words. Single-character
|
|
84
84
|
tokens also removed.
|
|
85
85
|
|
|
86
|
-
### 7.
|
|
86
|
+
### 7. Synonym Expansion (`synonyms.rs`)
|
|
87
|
+
|
|
88
|
+
```rust
|
|
89
|
+
pub fn expand_synonyms(
|
|
90
|
+
word: &str,
|
|
91
|
+
map: &SynonymMap,
|
|
92
|
+
) -> Vec<String>;
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Looks up the lowercased word in the built-in synonym
|
|
96
|
+
map. Returns a vector containing the original word
|
|
97
|
+
plus any synonyms. When no synonyms exist, returns a
|
|
98
|
+
single-element vector containing only the original.
|
|
99
|
+
|
|
100
|
+
The synonym map is a bidirectional
|
|
101
|
+
`HashMap<String, Vec<String>>` built at compile time.
|
|
102
|
+
Expansion is applied after stop-word removal and
|
|
103
|
+
before stemming, so both original and synonym tokens
|
|
104
|
+
are stemmed consistently.
|
|
105
|
+
|
|
106
|
+
The map is small (~30-50 entries) and focused on
|
|
107
|
+
common IT/development vocabulary mismatches:
|
|
108
|
+
login/sign-in, auth/authentication, remove/delete,
|
|
109
|
+
config/configuration, credential/password, etc.
|
|
110
|
+
|
|
111
|
+
### 8. Stemming (`stem.rs`)
|
|
87
112
|
|
|
88
113
|
```rust
|
|
89
114
|
pub fn stem_word(word: &str) -> StemResult;
|
|
@@ -92,7 +117,7 @@ pub fn stem_word(word: &str) -> StemResult;
|
|
|
92
117
|
Snowball / Porter2. Preserves both original and
|
|
93
118
|
stemmed forms.
|
|
94
119
|
|
|
95
|
-
###
|
|
120
|
+
### 9. N-gram Extraction (`ngram.rs`)
|
|
96
121
|
|
|
97
122
|
```rust
|
|
98
123
|
pub fn extract_ngrams(
|
|
@@ -101,3 +126,16 @@ pub fn extract_ngrams(
|
|
|
101
126
|
```
|
|
102
127
|
|
|
103
128
|
Bigrams and trigrams for phrase indexing.
|
|
129
|
+
|
|
130
|
+
## Relaxed Query Mode
|
|
131
|
+
|
|
132
|
+
The tokenization pipeline is used for both the
|
|
133
|
+
primary AND-mode query plan and the relaxed OR-mode
|
|
134
|
+
fallback plan. `qp_parse_query` produces a
|
|
135
|
+
`QueryPlan` with a `match_mode` field (`All` | `Any`).
|
|
136
|
+
When the AND plan returns zero matches,
|
|
137
|
+
`kb-worker.wasm` retries with the OR plan using the
|
|
138
|
+
same tokenized terms. No additional pipeline stage or
|
|
139
|
+
WASM export is needed. See
|
|
140
|
+
[Query Parser -- Relaxed Query
|
|
141
|
+
Mode](../../../goals/query-parser.md).
|
|
@@ -49,8 +49,9 @@ engine/crates/query-parser/
|
|
|
49
49
|
│ ├── identifiers.rs # stage 4: camelCase split
|
|
50
50
|
│ ├── case.rs # stage 5: case folding
|
|
51
51
|
│ ├── stopwords.rs # stage 6: stop words
|
|
52
|
-
│ ├──
|
|
53
|
-
│
|
|
52
|
+
│ ├── synonyms.rs # stage 7: synonym expansion
|
|
53
|
+
│ ├── stem.rs # stage 8: Snowball stemmer
|
|
54
|
+
│ └── ngram.rs # stage 9: n-gram extract
|
|
54
55
|
├── parse.rs # query string → QueryPlan
|
|
55
56
|
├── extract/
|
|
56
57
|
│ ├── mod.rs # extraction facade
|
|
@@ -78,10 +79,10 @@ engine/crates/query-parser/
|
|
|
78
79
|
|
|
79
80
|
### [functions/](functions/module.md) -- Operations
|
|
80
81
|
|
|
81
|
-
- **[pipeline](functions/pipeline.md)** --
|
|
82
|
+
- **[pipeline](functions/pipeline.md)** -- 9-stage
|
|
82
83
|
tokenization pipeline. Marker stripping, NFC,
|
|
83
84
|
segmentation, identifier splitting, case folding,
|
|
84
|
-
stop words, stemming, n-grams.
|
|
85
|
+
stop words, synonym expansion, stemming, n-grams.
|
|
85
86
|
- **[parse](functions/parse.md)** -- Query string
|
|
86
87
|
parsing into `QueryPlan`.
|
|
87
88
|
- **[extract](functions/extract.md)** -- RAKE
|