dsh-data-domain-knowledge 0.1.0-alpha.9 → 0.1.1-alpha.2
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 +118 -567
- package/cordis.patch.yml +5 -418
- package/eval/README.md +19 -8
- package/eval/benchmark-extraction-format.mjs +20 -0
- package/eval/evaluate-retrieval.mjs +17 -8
- package/eval/queries.example.jsonl +1 -0
- package/lib/client.js +4181 -3239
- package/lib/contract-envelope.d.ts +91 -0
- package/lib/contract-envelope.js +106 -0
- package/lib/contract-layout.d.ts +130 -0
- package/lib/contract-layout.js +138 -0
- package/lib/contract-refs.d.ts +39 -0
- package/lib/contract-refs.js +9 -0
- package/lib/contract-version.d.ts +311 -0
- package/lib/contract-version.js +270 -0
- package/lib/contract-wire.d.ts +147 -0
- package/lib/contract-wire.js +99 -0
- package/lib/contracts.d.ts +12 -0
- package/lib/contracts.js +12 -0
- package/lib/doc-page.js +2 -2
- package/lib/pages.js +3329 -1296
- package/lib/types/agent-behavior-rules.d.ts +10 -0
- package/lib/types/agent-behavior-rules.d.ts.map +1 -0
- package/lib/types/agent-behavior-rules.js +28 -0
- package/lib/types/agent-behavior-rules.js.map +1 -0
- package/lib/types/axis-registry.d.ts +37 -5
- package/lib/types/axis-registry.d.ts.map +1 -1
- package/lib/types/axis-registry.js +234 -26
- package/lib/types/axis-registry.js.map +1 -1
- package/lib/types/card-organize.d.ts +27 -12
- package/lib/types/card-organize.d.ts.map +1 -1
- package/lib/types/card-organize.js +58 -73
- package/lib/types/card-organize.js.map +1 -1
- package/lib/types/compiler/embedding-identity.d.ts +3 -0
- package/lib/types/compiler/embedding-identity.d.ts.map +1 -0
- package/lib/types/compiler/embedding-identity.js +24 -0
- package/lib/types/compiler/embedding-identity.js.map +1 -0
- package/lib/types/compiler/snapshot.d.ts +16 -0
- package/lib/types/compiler/snapshot.d.ts.map +1 -0
- package/lib/types/compiler/snapshot.js +2 -0
- package/lib/types/compiler/snapshot.js.map +1 -0
- package/lib/types/config-schema.d.ts +6 -3
- package/lib/types/config-schema.d.ts.map +1 -1
- package/lib/types/config-schema.js +6 -2
- package/lib/types/config-schema.js.map +1 -1
- package/lib/types/convert/host.d.ts +6 -5
- package/lib/types/convert/host.d.ts.map +1 -1
- package/lib/types/convert/host.js +58 -18
- package/lib/types/convert/host.js.map +1 -1
- package/lib/types/convert/ingest.d.ts +10 -1
- package/lib/types/convert/ingest.d.ts.map +1 -1
- package/lib/types/convert/ingest.js +68 -9
- package/lib/types/convert/ingest.js.map +1 -1
- package/lib/types/derive-contract.d.ts +3 -0
- package/lib/types/derive-contract.d.ts.map +1 -0
- package/lib/types/derive-contract.js +15 -0
- package/lib/types/derive-contract.js.map +1 -0
- package/lib/types/diagnosis/cards.d.ts +7 -3
- package/lib/types/diagnosis/cards.d.ts.map +1 -1
- package/lib/types/diagnosis/cards.js +13 -8
- package/lib/types/diagnosis/cards.js.map +1 -1
- package/lib/types/diagnosis/run.d.ts +4 -13
- package/lib/types/diagnosis/run.d.ts.map +1 -1
- package/lib/types/diagnosis/run.js +26 -16
- package/lib/types/diagnosis/run.js.map +1 -1
- package/lib/types/diagnosis/schema.js +2 -2
- package/lib/types/diagnosis/schema.js.map +1 -1
- package/lib/types/diagnosis/seed-source.d.ts +1 -1
- package/lib/types/diagnosis/seed-source.d.ts.map +1 -1
- package/lib/types/diagnosis/seed-source.js +5 -4
- package/lib/types/diagnosis/seed-source.js.map +1 -1
- package/lib/types/diagnosis/seed.d.ts +4 -4
- package/lib/types/diagnosis/seed.d.ts.map +1 -1
- package/lib/types/diagnosis/seed.js +6 -8
- package/lib/types/diagnosis/seed.js.map +1 -1
- package/lib/types/diagnosis/store.d.ts +24 -18
- package/lib/types/diagnosis/store.d.ts.map +1 -1
- package/lib/types/diagnosis/store.js +130 -65
- package/lib/types/diagnosis/store.js.map +1 -1
- package/lib/types/diagnosis/types.d.ts +47 -15
- package/lib/types/diagnosis/types.d.ts.map +1 -1
- package/lib/types/diagnosis/types.js.map +1 -1
- package/lib/types/environment/dsh-python.d.ts +77 -0
- package/lib/types/environment/dsh-python.d.ts.map +1 -0
- package/lib/types/environment/dsh-python.js +139 -0
- package/lib/types/environment/dsh-python.js.map +1 -0
- package/lib/types/environment/install.d.ts +15 -0
- package/lib/types/environment/install.d.ts.map +1 -0
- package/lib/types/environment/install.js +297 -0
- package/lib/types/environment/install.js.map +1 -0
- package/lib/types/environment/manifest.d.ts +208 -0
- package/lib/types/environment/manifest.d.ts.map +1 -0
- package/lib/types/environment/manifest.js +26 -0
- package/lib/types/environment/manifest.js.map +1 -0
- package/lib/types/environment/model-catalog.d.ts +223 -0
- package/lib/types/environment/model-catalog.d.ts.map +1 -0
- package/lib/types/environment/model-catalog.js +129 -0
- package/lib/types/environment/model-catalog.js.map +1 -0
- package/lib/types/environment/process.d.ts +10 -0
- package/lib/types/environment/process.d.ts.map +1 -0
- package/lib/types/environment/process.js +54 -0
- package/lib/types/environment/process.js.map +1 -0
- package/lib/types/environment/selection.d.ts +9 -0
- package/lib/types/environment/selection.d.ts.map +1 -0
- package/lib/types/environment/selection.js +29 -0
- package/lib/types/environment/selection.js.map +1 -0
- package/lib/types/environment/service.d.ts +64 -0
- package/lib/types/environment/service.d.ts.map +1 -0
- package/lib/types/environment/service.js +424 -0
- package/lib/types/environment/service.js.map +1 -0
- package/lib/types/environment/types.d.ts +56 -0
- package/lib/types/environment/types.d.ts.map +1 -0
- package/lib/types/environment/types.js +2 -0
- package/lib/types/environment/types.js.map +1 -0
- package/lib/types/events.d.ts +76 -0
- package/lib/types/events.d.ts.map +1 -0
- package/lib/types/events.js +52 -0
- package/lib/types/events.js.map +1 -0
- package/lib/types/extract-contract.d.ts +3 -0
- package/lib/types/extract-contract.d.ts.map +1 -0
- package/lib/types/extract-contract.js +41 -0
- package/lib/types/extract-contract.js.map +1 -0
- package/lib/types/extract-model.d.ts +5 -0
- package/lib/types/extract-model.d.ts.map +1 -1
- package/lib/types/extract-model.js.map +1 -1
- package/lib/types/extract-table-contract.d.ts +3 -0
- package/lib/types/extract-table-contract.d.ts.map +1 -0
- package/lib/types/extract-table-contract.js +27 -0
- package/lib/types/extract-table-contract.js.map +1 -0
- package/lib/types/extract-table.d.ts +8 -0
- package/lib/types/extract-table.d.ts.map +1 -0
- package/lib/types/extract-table.js +158 -0
- package/lib/types/extract-table.js.map +1 -0
- package/lib/types/extraction-runs.d.ts +30 -6
- package/lib/types/extraction-runs.d.ts.map +1 -1
- package/lib/types/extraction-runs.js +69 -8
- package/lib/types/extraction-runs.js.map +1 -1
- package/lib/types/fs-atomic.d.ts +0 -7
- package/lib/types/fs-atomic.d.ts.map +1 -1
- package/lib/types/fs-atomic.js +17 -2
- package/lib/types/fs-atomic.js.map +1 -1
- package/lib/types/images.d.ts +26 -0
- package/lib/types/images.d.ts.map +1 -0
- package/lib/types/images.js +196 -0
- package/lib/types/images.js.map +1 -0
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +598 -209
- package/lib/types/index.js.map +1 -1
- package/lib/types/intent/engine.d.ts +12 -4
- package/lib/types/intent/engine.d.ts.map +1 -1
- package/lib/types/intent/engine.js +43 -5
- package/lib/types/intent/engine.js.map +1 -1
- package/lib/types/intent/host.d.ts +5 -8
- package/lib/types/intent/host.d.ts.map +1 -1
- package/lib/types/intent/host.js +56 -11
- package/lib/types/intent/host.js.map +1 -1
- package/lib/types/intent/scope.d.ts +25 -0
- package/lib/types/intent/scope.d.ts.map +1 -0
- package/lib/types/intent/scope.js +116 -0
- package/lib/types/intent/scope.js.map +1 -0
- package/lib/types/intent/tools.d.ts +24 -20
- package/lib/types/intent/tools.d.ts.map +1 -1
- package/lib/types/intent/tools.js +65 -23
- package/lib/types/intent/tools.js.map +1 -1
- package/lib/types/intent/types.d.ts +11 -4
- package/lib/types/intent/types.d.ts.map +1 -1
- package/lib/types/knowledge-bases.d.ts +11 -5
- package/lib/types/knowledge-bases.d.ts.map +1 -1
- package/lib/types/knowledge-bases.js +52 -20
- package/lib/types/knowledge-bases.js.map +1 -1
- package/lib/types/knowledge-contract.d.ts +32 -0
- package/lib/types/knowledge-contract.d.ts.map +1 -0
- package/lib/types/knowledge-contract.js +116 -0
- package/lib/types/knowledge-contract.js.map +1 -0
- package/lib/types/knowledge.d.ts +31 -9
- package/lib/types/knowledge.d.ts.map +1 -1
- package/lib/types/knowledge.js +137 -60
- package/lib/types/knowledge.js.map +1 -1
- package/lib/types/layout.d.ts +10 -29
- package/lib/types/layout.d.ts.map +1 -1
- package/lib/types/layout.js +17 -36
- package/lib/types/layout.js.map +1 -1
- package/lib/types/materialize-snapshot.d.ts +49 -0
- package/lib/types/materialize-snapshot.d.ts.map +1 -0
- package/lib/types/materialize-snapshot.js +2 -0
- package/lib/types/materialize-snapshot.js.map +1 -0
- package/lib/types/migrate.d.ts +11 -0
- package/lib/types/migrate.d.ts.map +1 -1
- package/lib/types/migrate.js +83 -2
- package/lib/types/migrate.js.map +1 -1
- package/lib/types/model-text.d.ts +58 -1
- package/lib/types/model-text.d.ts.map +1 -1
- package/lib/types/model-text.js +85 -30
- package/lib/types/model-text.js.map +1 -1
- package/lib/types/oplog.d.ts.map +1 -1
- package/lib/types/oplog.js +7 -0
- package/lib/types/oplog.js.map +1 -1
- package/lib/types/organize-contract.d.ts +18 -0
- package/lib/types/organize-contract.d.ts.map +1 -0
- package/lib/types/organize-contract.js +82 -0
- package/lib/types/organize-contract.js.map +1 -0
- package/lib/types/pipeline/engine.d.ts +66 -0
- package/lib/types/pipeline/engine.d.ts.map +1 -0
- package/lib/types/pipeline/engine.js +352 -0
- package/lib/types/pipeline/engine.js.map +1 -0
- package/lib/types/pipeline/store.d.ts +73 -0
- package/lib/types/pipeline/store.d.ts.map +1 -0
- package/lib/types/pipeline/store.js +143 -0
- package/lib/types/pipeline/store.js.map +1 -0
- package/lib/types/pipeline/types.d.ts +102 -0
- package/lib/types/pipeline/types.d.ts.map +1 -0
- package/lib/types/pipeline/types.js +5 -0
- package/lib/types/pipeline/types.js.map +1 -0
- package/lib/types/present.d.ts +2 -0
- package/lib/types/present.d.ts.map +1 -1
- package/lib/types/present.js +9 -4
- package/lib/types/present.js.map +1 -1
- package/lib/types/preset-ids.d.ts +4 -0
- package/lib/types/preset-ids.d.ts.map +1 -0
- package/lib/types/preset-ids.js +6 -0
- package/lib/types/preset-ids.js.map +1 -0
- package/lib/types/query-analysis.d.ts +13 -1
- package/lib/types/query-analysis.d.ts.map +1 -1
- package/lib/types/query-analysis.js +62 -6
- package/lib/types/query-analysis.js.map +1 -1
- package/lib/types/recall-rank.d.ts +3 -3
- package/lib/types/recall-rank.d.ts.map +1 -1
- package/lib/types/recall-rank.js +4 -4
- package/lib/types/recall-rank.js.map +1 -1
- package/lib/types/retention.d.ts +39 -0
- package/lib/types/retention.d.ts.map +1 -0
- package/lib/types/retention.js +42 -0
- package/lib/types/retention.js.map +1 -0
- package/lib/types/retrieval/vector-index.d.ts +32 -0
- package/lib/types/retrieval/vector-index.d.ts.map +1 -0
- package/lib/types/retrieval/vector-index.js +15 -0
- package/lib/types/retrieval/vector-index.js.map +1 -0
- package/lib/types/retrieval/visibility.d.ts +6 -0
- package/lib/types/retrieval/visibility.d.ts.map +1 -0
- package/lib/types/retrieval/visibility.js +11 -0
- package/lib/types/retrieval/visibility.js.map +1 -0
- package/lib/types/runtime.d.ts +272 -27
- package/lib/types/runtime.d.ts.map +1 -1
- package/lib/types/runtime.js +2751 -537
- package/lib/types/runtime.js.map +1 -1
- package/lib/types/settings-schema.d.ts +17 -15
- package/lib/types/settings-schema.d.ts.map +1 -1
- package/lib/types/settings-schema.js +50 -47
- package/lib/types/settings-schema.js.map +1 -1
- package/lib/types/settings-volatile.d.ts +4 -4
- package/lib/types/settings-volatile.js +4 -4
- package/lib/types/source-evidence.d.ts +14 -0
- package/lib/types/source-evidence.d.ts.map +1 -0
- package/lib/types/source-evidence.js +36 -0
- package/lib/types/source-evidence.js.map +1 -0
- package/lib/types/store/axis-references.d.ts +5 -0
- package/lib/types/store/axis-references.d.ts.map +1 -0
- package/lib/types/store/axis-references.js +106 -0
- package/lib/types/store/axis-references.js.map +1 -0
- package/lib/types/store/derived.d.ts +12 -1
- package/lib/types/store/derived.d.ts.map +1 -1
- package/lib/types/store/derived.js +71 -12
- package/lib/types/store/derived.js.map +1 -1
- package/lib/types/store/knowledge-db.d.ts +31 -1
- package/lib/types/store/knowledge-db.d.ts.map +1 -1
- package/lib/types/store/knowledge-db.js +252 -18
- package/lib/types/store/knowledge-db.js.map +1 -1
- package/lib/types/store/migrate.d.ts.map +1 -1
- package/lib/types/store/migrate.js +17 -6
- package/lib/types/store/migrate.js.map +1 -1
- package/lib/types/trajectory-types.d.ts +172 -0
- package/lib/types/trajectory-types.d.ts.map +1 -0
- package/lib/types/trajectory-types.js +36 -0
- package/lib/types/trajectory-types.js.map +1 -0
- package/lib/types/types.d.ts +59 -27
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/types.js +6 -15
- package/lib/types/types.js.map +1 -1
- package/lib/types/wiki-finalize.d.ts +16 -0
- package/lib/types/wiki-finalize.d.ts.map +1 -1
- package/lib/types/wiki-finalize.js +26 -0
- package/lib/types/wiki-finalize.js.map +1 -1
- package/lib/types/wiki-materialize.d.ts +4 -0
- package/lib/types/wiki-materialize.d.ts.map +1 -1
- package/lib/types/wiki-materialize.js +21 -7
- package/lib/types/wiki-materialize.js.map +1 -1
- package/lib/types/wiki-trial-types.d.ts +87 -0
- package/lib/types/wiki-trial-types.d.ts.map +1 -1
- package/lib/types/wiki-trial-types.js +0 -16
- package/lib/types/wiki-trial-types.js.map +1 -1
- package/lib/types/wiki-trial.d.ts +40 -16
- package/lib/types/wiki-trial.d.ts.map +1 -1
- package/lib/types/wiki-trial.js +337 -224
- package/lib/types/wiki-trial.js.map +1 -1
- package/package.json +29 -20
- package/python/prepare-models.py +19 -0
- package/python/requirements.txt +8 -6
- package/scripts/doctor.mjs +13 -19
- package/scripts/environment.mjs +29 -0
- package/scripts/setup-embedding.sh +15 -5
- package/src/agent-behavior-rules.ts +37 -0
- package/src/axis-registry.ts +234 -27
- package/src/card-organize.ts +69 -75
- package/src/client/AgentBehaviorRulesCard.tsx +65 -0
- package/src/client/AttributionEventGuide.tsx +41 -39
- package/src/client/AxisRegistrySection.tsx +204 -164
- package/src/client/CompileDialogs.tsx +44 -29
- package/src/client/DeleteDocumentDialog.tsx +36 -5
- package/src/client/DirectoryPicker.tsx +0 -10
- package/src/client/EnvironmentSetup.tsx +243 -0
- package/src/client/ExpansionGraph.tsx +13 -7
- package/src/client/ExtractionTasksPage.tsx +578 -0
- package/src/client/GuideArchitectureCanvas.tsx +470 -0
- package/src/client/ImportFilesDialog.tsx +2 -13
- package/src/client/IntentLogic.tsx +2 -2
- package/src/client/IntentTab.tsx +118 -47
- package/src/client/KnowledgeBaseTab.tsx +277 -197
- package/src/client/KnowledgeLayerSection.tsx +24 -6
- package/src/client/KnowledgePanel.tsx +58 -93
- package/src/client/KnowledgeSettingsDrawer.tsx +90 -0
- package/src/client/ListPager.tsx +15 -5
- package/src/client/MaterializeTrajectoryView.tsx +124 -0
- package/src/client/NodeSettings.tsx +210 -89
- package/src/client/NormalizeTrajectoryView.tsx +136 -0
- package/src/client/PipelineNotice.tsx +26 -0
- package/src/client/PreviewSections.tsx +118 -51
- package/src/client/RecallPanel.tsx +89 -85
- package/src/client/TabGuide.tsx +159 -184
- package/src/client/TrialReportView.tsx +391 -214
- package/src/client/TypeDefinitionDrawer.tsx +150 -23
- package/src/client/WikiCardPreview.tsx +62 -16
- package/src/client/WikiFlowPanel.tsx +4 -4
- package/src/client/arch/NodeLogicPanel.tsx +3 -4
- package/src/client/arch/model.ts +6 -9
- package/src/client/architecture.tsx +23 -33
- package/src/client/attribution/AttributionGraph.tsx +10 -6
- package/src/client/attribution/AttributionTab.tsx +136 -84
- package/src/client/attribution/CaseView.tsx +3 -1
- package/src/client/attribution/EventView.tsx +108 -0
- package/src/client/attribution/RunView.tsx +2 -2
- package/src/client/attribution/StageChrome.tsx +34 -3
- package/src/client/attribution/ViewSwitch.tsx +20 -5
- package/src/client/attribution/graph-options.ts +47 -39
- package/src/client/attribution/model.ts +17 -10
- package/src/client/config-scope.ts +3 -3
- package/src/client/graph/palette.ts +165 -0
- package/src/client/index.ts +49 -42
- package/src/client/pages.css +459 -135
- package/src/client/pages.tsx +37 -9
- package/src/client/problem-domains.ts +1 -1
- package/src/client/session-remote.ts +9 -0
- package/src/client/styles.css +205 -62
- package/src/client/wiki-trial.ts +44 -3
- package/src/compiler/embedding-identity.ts +21 -0
- package/src/compiler/snapshot.ts +17 -0
- package/src/config-schema.ts +8 -3
- package/src/convert/host.ts +56 -21
- package/src/convert/ingest.ts +74 -10
- package/src/derive-contract.ts +14 -0
- package/src/diagnosis/cards.ts +13 -8
- package/src/diagnosis/run.ts +27 -17
- package/src/diagnosis/schema.ts +2 -2
- package/src/diagnosis/seed-source.ts +5 -4
- package/src/diagnosis/seed.ts +6 -8
- package/src/diagnosis/store.ts +138 -69
- package/src/diagnosis/types.ts +34 -15
- package/src/environment/dsh-python.ts +156 -0
- package/src/environment/install.ts +244 -0
- package/src/environment/manifest.ts +28 -0
- package/src/environment/model-catalog.ts +147 -0
- package/src/environment/process.ts +54 -0
- package/src/environment/selection.ts +29 -0
- package/src/environment/service.ts +348 -0
- package/src/environment/types.ts +45 -0
- package/src/events.ts +108 -0
- package/src/extract-contract.ts +42 -0
- package/src/extract-model.ts +10 -1
- package/src/extract-table-contract.ts +26 -0
- package/src/extract-table.ts +132 -0
- package/src/extraction-runs.ts +70 -11
- package/src/fs-atomic.ts +19 -2
- package/src/images.ts +203 -0
- package/src/index.ts +553 -205
- package/src/intent/README.md +8 -6
- package/src/intent/engine.ts +44 -6
- package/src/intent/host.ts +59 -18
- package/src/intent/scope.ts +125 -0
- package/src/intent/tools.ts +70 -28
- package/src/intent/types.ts +11 -4
- package/src/knowledge-bases.ts +56 -20
- package/src/knowledge-contract.ts +114 -0
- package/src/knowledge.ts +138 -69
- package/src/layout.ts +17 -37
- package/src/materialize-snapshot.ts +46 -0
- package/src/migrate.ts +75 -2
- package/src/model-text.ts +109 -4
- package/src/oplog.ts +7 -0
- package/src/organize-contract.ts +83 -0
- package/src/pipeline/engine.ts +323 -0
- package/src/pipeline/store.ts +147 -0
- package/src/pipeline/types.ts +93 -0
- package/src/present.ts +10 -4
- package/src/preset-ids.ts +6 -0
- package/src/python/embedding_worker.py +66 -2
- package/src/query-analysis.ts +68 -8
- package/src/recall-rank.ts +5 -5
- package/src/retention.ts +76 -0
- package/src/retrieval/vector-index.ts +45 -0
- package/src/retrieval/visibility.ts +14 -0
- package/src/runtime.ts +2708 -567
- package/src/settings-schema.ts +11 -8
- package/src/settings-volatile.ts +4 -4
- package/src/source-evidence.ts +37 -0
- package/src/store/axis-references.ts +96 -0
- package/src/store/derived.ts +70 -12
- package/src/store/knowledge-db.ts +248 -17
- package/src/store/migrate.ts +16 -6
- package/src/trajectory-types.ts +142 -0
- package/src/types.ts +61 -35
- package/src/wiki-finalize.ts +28 -0
- package/src/wiki-materialize.ts +25 -6
- package/src/wiki-trial-types.ts +83 -1
- package/src/wiki-trial.ts +357 -185
- package/lib/types/intent/preset-tools.d.ts +0 -37
- package/lib/types/intent/preset-tools.d.ts.map +0 -1
- package/lib/types/intent/preset-tools.js +0 -45
- package/lib/types/intent/preset-tools.js.map +0 -1
- package/preset/tita-data-agent/agent.cordis.yml +0 -394
- package/preset/tita-data-agent/preset.yml +0 -3
- package/scripts/install-agent-preset.mjs +0 -92
- package/scripts/sync-agent-preset.mjs +0 -188
- package/src/client/AgentPresetCard.tsx +0 -247
- package/src/client/agent-preset.ts +0 -121
- package/src/client/convert/ConvertPanel.tsx +0 -583
- package/src/client/convert/styles.css +0 -138
- package/src/client/convert/styles.ts +0 -49
- package/src/intent/preset-tools.ts +0 -48
|
@@ -283,6 +283,45 @@ def encode_multimodal(model_wrapper: Any, items: list[dict[str, Any]], device: s
|
|
|
283
283
|
return outputs
|
|
284
284
|
|
|
285
285
|
|
|
286
|
+
def text_windows(tokenizer, text: str, budget: int, overlap: int = 48) -> list[str]:
|
|
287
|
+
"""Physical windows only. The host retains the complete logical H2 section."""
|
|
288
|
+
ids = tokenizer.encode(text, add_special_tokens=False)
|
|
289
|
+
if len(ids) <= budget:
|
|
290
|
+
return [text]
|
|
291
|
+
step = max(1, budget - min(overlap, budget // 4))
|
|
292
|
+
windows = []
|
|
293
|
+
for start in range(0, len(ids), step):
|
|
294
|
+
windows.append(tokenizer.decode(ids[start:start + budget], skip_special_tokens=True))
|
|
295
|
+
if start + budget >= len(ids):
|
|
296
|
+
break
|
|
297
|
+
return windows
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def embedding_tokenizer(model):
|
|
301
|
+
if has_official_path(model):
|
|
302
|
+
tokenizer = getattr(model[0].processor, "tokenizer", None)
|
|
303
|
+
else:
|
|
304
|
+
tokenizer = getattr(model, "tokenizer", None)
|
|
305
|
+
if tokenizer is None:
|
|
306
|
+
raise RuntimeError("EMBEDDING_TOKENIZER_UNAVAILABLE")
|
|
307
|
+
return tokenizer
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def split_inputs(request: dict[str, Any]) -> dict[str, Any]:
|
|
311
|
+
model, _ = cached_model(str(request["model"]), str(request.get("device") or "auto"))
|
|
312
|
+
tokenizer = embedding_tokenizer(model)
|
|
313
|
+
limit = min(int(getattr(model, "max_seq_length", 512) or 512), 512)
|
|
314
|
+
windows = []
|
|
315
|
+
for item in request.get("inputs", []):
|
|
316
|
+
prefix = str(item.get("prefix") or "")
|
|
317
|
+
prefix_size = len(tokenizer.encode(prefix, add_special_tokens=False))
|
|
318
|
+
budget = limit - prefix_size - 16
|
|
319
|
+
if budget < 64:
|
|
320
|
+
raise ValueError("EMBEDDING_SECTION_TITLE_TOO_LONG")
|
|
321
|
+
windows.append([prefix + "\n\n" + part for part in text_windows(tokenizer, str(item.get("text") or ""), budget)])
|
|
322
|
+
return {"ok": True, "windows": windows, "tokenLimit": limit}
|
|
323
|
+
|
|
324
|
+
|
|
286
325
|
def encode(request: dict[str, Any]) -> dict[str, Any]:
|
|
287
326
|
model_name = str(request.get("model") or "ewin-reg/WeMM-Embedding-2B-Quantized")
|
|
288
327
|
requested_device = str(request.get("device") or "auto")
|
|
@@ -334,6 +373,9 @@ def encode(request: dict[str, Any]) -> dict[str, Any]:
|
|
|
334
373
|
str(item.get("text") or "") if isinstance(item, dict) else str(item)
|
|
335
374
|
for item in batch
|
|
336
375
|
]
|
|
376
|
+
limit = int(getattr(model, "max_seq_length", 512) or 512)
|
|
377
|
+
if any(len(model.tokenizer.encode(text, add_special_tokens=True)) > limit for text in generic_batch):
|
|
378
|
+
raise ValueError("EMBEDDING_INPUT_TOO_LONG: split H2 text or shorten the current subquestion")
|
|
337
379
|
encoded = model.encode(
|
|
338
380
|
generic_batch,
|
|
339
381
|
batch_size=batch_size,
|
|
@@ -454,9 +496,29 @@ def rerank(request: dict[str, Any]) -> dict[str, Any]:
|
|
|
454
496
|
if not isinstance(documents, list) or not documents:
|
|
455
497
|
raise ValueError("rerank requires a non-empty documents array")
|
|
456
498
|
model, device, health = cached_reranker(model_name, requested_device)
|
|
457
|
-
|
|
499
|
+
tokenizer = model.tokenizer
|
|
500
|
+
limit = min(int(getattr(model, "max_length", 512) or 512), 512)
|
|
501
|
+
query_size = len(tokenizer.encode(query, add_special_tokens=False))
|
|
502
|
+
budget = limit - query_size - 16
|
|
503
|
+
if budget < 64:
|
|
504
|
+
raise ValueError("RERANK_QUERY_TOO_LONG: shorten the current subquestion")
|
|
505
|
+
pairs = []
|
|
506
|
+
owners = []
|
|
507
|
+
for owner, document in enumerate(documents):
|
|
508
|
+
title, separator, body = str(document).partition("\n\n")
|
|
509
|
+
prefix = title + "\n\n" if separator else ""
|
|
510
|
+
content = body if separator else title
|
|
511
|
+
document_budget = budget - len(tokenizer.encode(prefix, add_special_tokens=False))
|
|
512
|
+
if document_budget < 32:
|
|
513
|
+
raise ValueError("RERANK_SECTION_TITLE_TOO_LONG")
|
|
514
|
+
for window in text_windows(tokenizer, content, document_budget):
|
|
515
|
+
pairs.append((query, prefix + window))
|
|
516
|
+
owners.append(owner)
|
|
458
517
|
with redirect_stdout(sys.stderr):
|
|
459
|
-
|
|
518
|
+
raw_scores = predict_raw(model, pairs)
|
|
519
|
+
scores = [float("-inf")] * len(documents)
|
|
520
|
+
for owner, score in zip(owners, raw_scores):
|
|
521
|
+
scores[owner] = max(scores[owner], float(score))
|
|
460
522
|
return {
|
|
461
523
|
"ok": True,
|
|
462
524
|
"device": device,
|
|
@@ -476,6 +538,8 @@ def main() -> None:
|
|
|
476
538
|
# selects the path and both models are cached per process.
|
|
477
539
|
if str(request.get("task") or "") == "rerank":
|
|
478
540
|
emit(rerank(request))
|
|
541
|
+
elif str(request.get("task") or "") == "split":
|
|
542
|
+
emit(split_inputs(request))
|
|
479
543
|
else:
|
|
480
544
|
emit(encode(request))
|
|
481
545
|
except Exception as exc: # return machine-readable errors to the Host
|
package/src/query-analysis.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AxisEntity, AxisKind } from './axis-registry.js'
|
|
1
|
+
import type { AxisEntity, AxisKind, AxisRelation } from './axis-registry.js'
|
|
2
2
|
import { normalizeAxisName } from './axis-registry.js'
|
|
3
3
|
import type { CardCoordinate } from './types.js'
|
|
4
4
|
|
|
@@ -20,6 +20,14 @@ export interface QueryCoordinateCandidate {
|
|
|
20
20
|
matchedAxes: AxisKind[]
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
export interface QueryRelationCandidate extends QueryCoordinateCandidate {
|
|
24
|
+
relationId: string
|
|
25
|
+
relationType: 'related_to'
|
|
26
|
+
matchedObjectId: string
|
|
27
|
+
relatedObjectId: string
|
|
28
|
+
evidence: string
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
export interface QueryAnalysis {
|
|
24
32
|
query: string
|
|
25
33
|
intent: { id: QueryIntent; confidence: number }
|
|
@@ -92,10 +100,11 @@ function coordinateCandidates(
|
|
|
92
100
|
axes: Record<AxisKind, QueryAxisMatch[]>,
|
|
93
101
|
cards: CoordinateCard[],
|
|
94
102
|
): QueryCoordinateCandidate[] {
|
|
95
|
-
const byKind: Record<AxisKind, Map<string,
|
|
96
|
-
object: new Map(
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
const byKind: Record<AxisKind, Map<string, number>> = {
|
|
104
|
+
object: new Map(), action: new Map(), scene: new Map(),
|
|
105
|
+
}
|
|
106
|
+
for (const kind of ['object', 'action', 'scene'] as const) {
|
|
107
|
+
for (const match of axes[kind]) byKind[kind].set(match.id, match.confidence)
|
|
99
108
|
}
|
|
100
109
|
const fields: Array<[AxisKind, keyof CardCoordinate]> = [
|
|
101
110
|
['object', 'objectId'], ['action', 'actionId'], ['scene', 'sceneId'],
|
|
@@ -105,10 +114,10 @@ function coordinateCandidates(
|
|
|
105
114
|
const matchedAxes: AxisKind[] = []
|
|
106
115
|
let score = 0
|
|
107
116
|
for (const [kind, field] of fields) {
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
117
|
+
const confidence = byKind[kind].get(card.coordinate[field])
|
|
118
|
+
if (confidence === undefined) continue
|
|
110
119
|
matchedAxes.push(kind)
|
|
111
|
-
score +=
|
|
120
|
+
score += confidence
|
|
112
121
|
}
|
|
113
122
|
if (matchedAxes.length === 0) return []
|
|
114
123
|
// 匹配多个轴的卡片优先,但只匹配一个轴也要可召回,不能硬过滤。
|
|
@@ -117,6 +126,57 @@ function coordinateCandidates(
|
|
|
117
126
|
}).sort((left, right) => right.score - left.score || left.cardKey.localeCompare(right.cardKey))
|
|
118
127
|
}
|
|
119
128
|
|
|
129
|
+
/**
|
|
130
|
+
* 一跳 related_to 关系候选。关系只拓展对象轴,不把 scopeId 当层级;
|
|
131
|
+
* 关联候选进入独立召回路,后续仍由多路融合与重排判断相关性。
|
|
132
|
+
*/
|
|
133
|
+
export function relationCandidates(
|
|
134
|
+
analysis: QueryAnalysis,
|
|
135
|
+
relations: AxisRelation[],
|
|
136
|
+
cards: CoordinateCard[],
|
|
137
|
+
): QueryRelationCandidate[] {
|
|
138
|
+
const matchedObjects = analysis.axes.object
|
|
139
|
+
if (matchedObjects.length === 0 || relations.length === 0) return []
|
|
140
|
+
const matchedById = new Map(matchedObjects.map(item => [item.id, item]))
|
|
141
|
+
const related = new Map<string, { matchedObjectId: string; score: number; relation: AxisRelation }>()
|
|
142
|
+
for (const relation of relations) {
|
|
143
|
+
if (relation.relationType !== 'related_to') continue
|
|
144
|
+
const left = matchedById.get(relation.fromId)
|
|
145
|
+
const right = matchedById.get(relation.toId)
|
|
146
|
+
if (left !== undefined && right !== undefined) continue
|
|
147
|
+
const matched = left ?? right
|
|
148
|
+
if (matched === undefined) continue
|
|
149
|
+
const relatedObjectId = left ? relation.toId : relation.fromId
|
|
150
|
+
if (matched.id === relatedObjectId) continue
|
|
151
|
+
const score = matched.confidence * 0.65
|
|
152
|
+
const previous = related.get(relatedObjectId)
|
|
153
|
+
if (previous === undefined || score > previous.score) {
|
|
154
|
+
related.set(relatedObjectId, { matchedObjectId: matched.id, score, relation })
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const byCard = new Map<string, QueryRelationCandidate>()
|
|
158
|
+
for (const card of cards) {
|
|
159
|
+
const relatedObjectId = card.coordinate?.objectId
|
|
160
|
+
if (!relatedObjectId) continue
|
|
161
|
+
const match = related.get(relatedObjectId)
|
|
162
|
+
if (match === undefined) continue
|
|
163
|
+
const candidate: QueryRelationCandidate = {
|
|
164
|
+
cardKey: card.cardKey,
|
|
165
|
+
coordinate: card.coordinate!,
|
|
166
|
+
score: match.score,
|
|
167
|
+
matchedAxes: ['object'],
|
|
168
|
+
relationId: match.relation.id,
|
|
169
|
+
relationType: match.relation.relationType,
|
|
170
|
+
matchedObjectId: match.matchedObjectId,
|
|
171
|
+
relatedObjectId,
|
|
172
|
+
evidence: match.relation.evidence,
|
|
173
|
+
}
|
|
174
|
+
const previous = byCard.get(card.cardKey)
|
|
175
|
+
if (previous === undefined || candidate.score > previous.score) byCard.set(card.cardKey, candidate)
|
|
176
|
+
}
|
|
177
|
+
return [...byCard.values()].sort((left, right) => right.score - left.score || left.cardKey.localeCompare(right.cardKey))
|
|
178
|
+
}
|
|
179
|
+
|
|
120
180
|
export function analyzeQuery(query: string, entities: RegistryEntity[], cards: CoordinateCard[]): QueryAnalysis {
|
|
121
181
|
const axes: Record<AxisKind, QueryAxisMatch[]> = {
|
|
122
182
|
object: matchEntities(query, 'object', entities),
|
package/src/recall-rank.ts
CHANGED
|
@@ -34,8 +34,8 @@ export interface RrfOptions {
|
|
|
34
34
|
/**
|
|
35
35
|
* 名次级融合(Reciprocal Rank Fusion)。
|
|
36
36
|
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
37
|
+
* **为什么不用分数加权和**:四路的分数来自不同刻度 —— 关键词是归一化 BM25、
|
|
38
|
+
* 向量是余弦、坐标与关系路是解析置信分。把它们乘权重相加,等于假设「0.5 的关键词分」
|
|
39
39
|
* 与「0.5 的余弦」一样好,而这个假设没有任何依据。0030 的实际后果就是:向量路输出
|
|
40
40
|
* 常数时,hybrid 的 55% 权重全是噪声,排序退化成 `unitId` 字典序(实测 4 条命中
|
|
41
41
|
* 分数完全相同:`0.2753 = 0.5 × 0.55`)。
|
|
@@ -47,7 +47,7 @@ export function rrfFuse(rankings: Partial<Record<RecallRoute, RouteRanking[]>>,
|
|
|
47
47
|
const { k, weights } = options
|
|
48
48
|
const ranks = new Map<string, Partial<Record<RecallRoute, number>>>()
|
|
49
49
|
const scores = new Map<string, number>()
|
|
50
|
-
const order: RecallRoute[] = ['coordinate', 'fts', 'vector', 'graph']
|
|
50
|
+
const order: RecallRoute[] = ['coordinate', 'relation', 'fts', 'vector', 'graph']
|
|
51
51
|
for (const route of order) {
|
|
52
52
|
const list = rankings[route]
|
|
53
53
|
if (!list || list.length === 0) continue
|
|
@@ -260,8 +260,8 @@ export function selectContext<T>(items: T[], options: MmrOptions<T>): T[] {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
/** `match` 字段由名次推导:多个候选路命中 = hybrid。 */
|
|
263
|
-
export function matchOf(ranks: Partial<Record<RecallRoute, number>>): 'fts' | 'vector' | 'coordinate' | 'graph' | 'hybrid' {
|
|
264
|
-
const used = (['coordinate', 'fts', 'vector', 'graph'] as RecallRoute[]).filter(route => ranks[route] !== undefined)
|
|
263
|
+
export function matchOf(ranks: Partial<Record<RecallRoute, number>>): 'fts' | 'vector' | 'coordinate' | 'relation' | 'graph' | 'hybrid' {
|
|
264
|
+
const used = (['coordinate', 'relation', 'fts', 'vector', 'graph'] as RecallRoute[]).filter(route => ranks[route] !== undefined)
|
|
265
265
|
if (used.length >= 2) return 'hybrid'
|
|
266
266
|
return used[0] ?? 'fts'
|
|
267
267
|
}
|
package/src/retention.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 保留上限(0070)。
|
|
3
|
+
*
|
|
4
|
+
* 文档里写着保留策略(「命名永久 + 最近 100 + 每日末版;机器版本只活到硬上限」),
|
|
5
|
+
* 而代码里对这几张表一条 `DELETE` 都没有:`revision` / `blob` / `tree` / `operations` /
|
|
6
|
+
* `pipeline_extractions` / `pipeline_events` 只增不减。这个模块把**新数据**的上限补上。
|
|
7
|
+
*
|
|
8
|
+
* ## 为什么是「水位 + 上限」,而不是直接按条数删
|
|
9
|
+
*
|
|
10
|
+
* 上限一旦生效,第一次裁剪就会把库里**已有的**历史删掉 —— 那是不可逆的,而用户的决定是
|
|
11
|
+
* 「只对新数据加上限,不动存量」。所以每张表第一次裁剪时先把当前最大键记成**水位**:
|
|
12
|
+
* 水位以下的既有行永不删除;水位以上的新行按上限保留。代价是总量变成
|
|
13
|
+
* 「升级那一刻的存量 + 上限」,而不是「上限」—— 这是「不动存量」能给出的最强的界。
|
|
14
|
+
*
|
|
15
|
+
* ## 键列的要求
|
|
16
|
+
*
|
|
17
|
+
* `key` 必须是单调递增的整数列(`rowid` 或自增 `seq`)。用时间戳当键不行:同一毫秒里
|
|
18
|
+
* 两行的顺序不确定,裁剪会随机丢一行。
|
|
19
|
+
*/
|
|
20
|
+
import type { SqliteDatabase } from './fts.js'
|
|
21
|
+
|
|
22
|
+
export interface RetentionSpec {
|
|
23
|
+
/** 表名。内插进 SQL,所以调用方只能传常量。 */
|
|
24
|
+
table: string
|
|
25
|
+
/** 单调递增的整数键列,例如 `rowid` 或 `seq`。 */
|
|
26
|
+
key: string
|
|
27
|
+
/** 水位以上保留多少行;`0` 表示水位以上的匹配行全部删掉(用于回收无引用的 blob)。 */
|
|
28
|
+
keep: number
|
|
29
|
+
/** 额外的行条件(可含子查询)。同样只允许常量 SQL。 */
|
|
30
|
+
where?: string
|
|
31
|
+
/** 分组表达式:给了就是「每组保留 keep 行」,而不是全表保留。 */
|
|
32
|
+
groupBy?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 水位表的表名。它跟着所在的那个库走(审计库与 knowledge.db 各有一份)。 */
|
|
36
|
+
const FLOOR_TABLE = 'retention_floor'
|
|
37
|
+
|
|
38
|
+
function ensureFloors(db: SqliteDatabase): void {
|
|
39
|
+
db.exec(`CREATE TABLE IF NOT EXISTS ${FLOOR_TABLE} (name TEXT PRIMARY KEY, floor INTEGER NOT NULL, at TEXT NOT NULL)`)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function floorOf(db: SqliteDatabase, name: string, table: string, key: string): number {
|
|
43
|
+
const row = db.prepare(`SELECT floor FROM ${FLOOR_TABLE} WHERE name = ?`).get(name) as { floor?: unknown } | undefined
|
|
44
|
+
if (row !== undefined) return Number(row.floor ?? 0)
|
|
45
|
+
const max = Number((db.prepare(`SELECT COALESCE(MAX(${key}), 0) AS m FROM ${table}`).get() as { m?: unknown } | undefined)?.m ?? 0)
|
|
46
|
+
db.prepare(`INSERT OR IGNORE INTO ${FLOOR_TABLE}(name, floor, at) VALUES (?, ?, ?)`).run(name, max, new Date().toISOString())
|
|
47
|
+
return max
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 裁掉水位以上的超限行,返回删掉的行数。
|
|
52
|
+
*
|
|
53
|
+
* 幂等且可反复调用:没有超限时最多花一次索引区间计数。
|
|
54
|
+
*/
|
|
55
|
+
export function applyRetention(db: SqliteDatabase, name: string, spec: RetentionSpec): number {
|
|
56
|
+
ensureFloors(db)
|
|
57
|
+
const floor = floorOf(db, name, spec.table, spec.key)
|
|
58
|
+
const filter = spec.where === undefined ? '' : ` AND (${spec.where})`
|
|
59
|
+
const above = Number((db.prepare(`SELECT COUNT(*) AS n FROM ${spec.table} WHERE ${spec.key} > ?${filter}`).get(floor) as { n?: unknown } | undefined)?.n ?? 0)
|
|
60
|
+
if (above <= spec.keep) return 0
|
|
61
|
+
if (spec.groupBy === undefined) {
|
|
62
|
+
const changes = spec.keep <= 0
|
|
63
|
+
? db.prepare(`DELETE FROM ${spec.table} WHERE ${spec.key} > ?${filter}`).run(floor)
|
|
64
|
+
: db.prepare(`DELETE FROM ${spec.table} WHERE ${spec.key} > ? AND ${spec.key} < (
|
|
65
|
+
SELECT ${spec.key} FROM ${spec.table} WHERE ${spec.key} > ?${filter} ORDER BY ${spec.key} DESC LIMIT 1 OFFSET ?
|
|
66
|
+
)${filter}`).run(floor, floor, spec.keep - 1)
|
|
67
|
+
return Number((changes as { changes?: unknown })?.changes ?? 0)
|
|
68
|
+
}
|
|
69
|
+
const changes = db.prepare(`DELETE FROM ${spec.table} WHERE ${spec.key} IN (
|
|
70
|
+
SELECT ${spec.key} FROM (
|
|
71
|
+
SELECT ${spec.key}, ROW_NUMBER() OVER (PARTITION BY ${spec.groupBy} ORDER BY ${spec.key} DESC) AS rn
|
|
72
|
+
FROM ${spec.table} WHERE ${spec.key} > ?${filter}
|
|
73
|
+
) WHERE rn > ?
|
|
74
|
+
)`).run(floor, spec.keep)
|
|
75
|
+
return Number((changes as { changes?: unknown })?.changes ?? 0)
|
|
76
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { KnowledgeConfig } from '../types.js'
|
|
2
|
+
import type { DerivedDb } from '../store/derived.js'
|
|
3
|
+
|
|
4
|
+
export interface VectorItem {
|
|
5
|
+
unitId: string
|
|
6
|
+
parentUnitId?: string
|
|
7
|
+
contentHash: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface VectorManifest {
|
|
11
|
+
version: number
|
|
12
|
+
createdAt: string
|
|
13
|
+
provider: KnowledgeConfig['embeddingProvider']
|
|
14
|
+
model: string
|
|
15
|
+
modelFingerprint?: string
|
|
16
|
+
/**
|
|
17
|
+
* 编码实现的指纹(0031)。旧清单没有这个字段 → 视为不兼容,于是修复编码器之后
|
|
18
|
+
* 一定触发一次真正的重编码,而不是把旧向量按 contentHash 复用回来。
|
|
19
|
+
*/
|
|
20
|
+
encoder?: string
|
|
21
|
+
device: string
|
|
22
|
+
dimension: number
|
|
23
|
+
quantization: 'binary+hamming+int8'
|
|
24
|
+
itemCount: number
|
|
25
|
+
items: VectorItem[]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface LoadedVectorIndex {
|
|
29
|
+
manifest: VectorManifest
|
|
30
|
+
binary: Buffer
|
|
31
|
+
int8: Buffer
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Validate a generation's BLOBs before either reuse or query. */
|
|
35
|
+
export function decodeVectorIndex(loaded: ReturnType<DerivedDb['vectorIndex']>, encoder: string): LoadedVectorIndex | null {
|
|
36
|
+
if (!loaded) return null
|
|
37
|
+
const manifest = loaded.manifest as VectorManifest
|
|
38
|
+
if (!manifest || manifest.quantization !== 'binary+hamming+int8' || manifest.encoder !== encoder
|
|
39
|
+
|| !Number.isInteger(manifest.dimension) || manifest.dimension < 8 || manifest.dimension % 8 !== 0
|
|
40
|
+
|| !Number.isInteger(manifest.itemCount) || !Array.isArray(manifest.items)
|
|
41
|
+
|| manifest.itemCount !== manifest.items.length
|
|
42
|
+
|| loaded.binary.length !== manifest.itemCount * Math.ceil(manifest.dimension / 8)
|
|
43
|
+
|| loaded.int8.length !== manifest.itemCount * manifest.dimension) return null
|
|
44
|
+
return { ...loaded, manifest }
|
|
45
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ContextGraph } from '../types.js'
|
|
2
|
+
import type { KnowledgeDb } from '../store/knowledge-db.js'
|
|
3
|
+
|
|
4
|
+
export function liveGraphKeys(db: KnowledgeDb): Set<string> {
|
|
5
|
+
const rows = db.raw("SELECT entity_type AS type, entity_id AS id FROM card UNION SELECT 'source' AS type, entity_id AS id FROM source").all() as Array<{ type: string; id: string }>
|
|
6
|
+
return new Set(rows.map(row => `${row.type}:${row.id}`))
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** A retained generation must not restore entities that the user deleted. */
|
|
10
|
+
export function visibleGraph(graph: ContextGraph, live: Set<string>): ContextGraph {
|
|
11
|
+
const nodes = graph.nodes.filter(node => live.has(`${node.type}:${node.id}`))
|
|
12
|
+
const keys = new Set(nodes.map(node => `${node.type}:${node.id}`))
|
|
13
|
+
return { nodes, edges: graph.edges.filter(edge => keys.has(String(edge.from)) && keys.has(String(edge.to))) }
|
|
14
|
+
}
|