@jungjaehoon/mama-core 2.4.1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -239
- package/db/migrations/030-case-first-memory-substrate.sql +13 -98
- package/db/migrations/034-add-connector-event-scope-columns.sql +9 -13
- package/db/migrations/039-add-connector-event-operator-ingest-seq.sql +9 -95
- package/db/migrations/062-refresh-connector-event-sequences.sql +9 -113
- package/db/migrations/063-refresh-legacy-connector-event-updates.sql +9 -32
- package/db/migrations/067-add-connector-event-source-entity-id.sql +9 -13
- package/db/migrations/069-create-registry-nodes.sql +52 -0
- package/db/migrations/070-record-identity.sql +35 -0
- package/db/migrations/071-service-operation-origins.sql +187 -0
- package/db/migrations/072-observation-versions.sql +29 -0
- package/db/migrations/073-registry-corrections.sql +45 -0
- package/db/migrations/074-work-graph-ref-kinds.sql +39 -0
- package/db/migrations/075-agent-judgments.sql +58 -0
- package/db/migrations/076-scoped-checkpoint-bindings.sql +15 -0
- package/db/migrations/077-legacy-record-kind.sql +6 -0
- package/db/migrations/078-source-ingest-commands.sql +18 -0
- package/db/migrations/079-twin-edge-relations.sql +43 -0
- package/db/migrations/080-restore-duration-days.sql +7 -0
- package/db/migrations/081-mailbox.sql +61 -0
- package/db/migrations/082-commitments-row-id.sql +12 -0
- package/db/migrations/083-observation-is-the-evidence.sql +49 -0
- package/db/migrations/084-scope-kind-is-not-the-cores-to-list.sql +34 -0
- package/db/migrations/085-a-migration-has-a-source.sql +37 -0
- package/db/migrations/086-the-mailbox-is-generic.sql +110 -0
- package/db/migrations/087-mailbox-payload.sql +5 -0
- package/db/migrations/088-native-input-journal.sql +14 -0
- package/db/migrations/089-native-turn-receipt-lookup.sql +3 -0
- package/db/migrations/090-model-run-native-inputs.sql +29 -0
- package/db/migrations/091-native-turn-results.sql +11 -0
- package/db/migrations/092-restore-decision-fts.sql +34 -0
- package/db/migrations/093-native-turn-primary-kind.sql +14 -0
- package/db/migrations/094-commitment-run-provenance.sql +9 -0
- package/db/migrations/095-model-run-native-input-identity.sql +39 -0
- package/db/migrations/096-drop-connector-event-index-fts.sql +9 -0
- package/db/migrations/097-native-input-json-validity.sql +37 -0
- package/db/migrations/098-workflow-memory-kind.sql +105 -0
- package/dist/action-contracts.d.ts +212 -0
- package/dist/action-contracts.js +10 -0
- package/dist/api/catalog.d.ts +118 -0
- package/dist/api/catalog.js +1756 -0
- package/dist/api/dispatch.d.ts +76 -0
- package/dist/api/dispatch.js +372 -0
- package/dist/canonicalize.d.ts +2 -2
- package/dist/canonicalize.js +3 -3
- package/dist/client/client.d.ts +33 -0
- package/dist/client/client.js +123 -0
- package/dist/client/ipc.d.ts +81 -0
- package/dist/client/ipc.js +314 -0
- package/dist/db-adapter/base-adapter.d.ts +6 -66
- package/dist/db-adapter/base-adapter.js +6 -6
- package/dist/db-adapter/index.d.ts +5 -5
- package/dist/db-adapter/index.js +2 -5
- package/dist/db-adapter/node-sqlite-adapter.d.ts +85 -15
- package/dist/db-adapter/node-sqlite-adapter.js +1968 -570
- package/dist/db-manager.d.ts +53 -97
- package/dist/db-manager.js +121 -603
- package/dist/embedding/embedder.d.ts +132 -0
- package/dist/embedding/embedder.js +299 -0
- package/dist/identity/principal-repository.d.ts +2 -2
- package/dist/index.d.ts +43 -58
- package/dist/index.js +97 -145
- package/dist/{context-compile/channel-grant.d.ts → knowledge/access.d.ts} +12 -17
- package/dist/knowledge/access.js +663 -0
- package/dist/knowledge/case-errors.d.ts +31 -0
- package/dist/knowledge/case-errors.js +40 -0
- package/dist/{cases/search-rollup.d.ts → knowledge/case-search-rollup.d.ts} +5 -4
- package/dist/{cases/search-rollup.js → knowledge/case-search-rollup.js} +6 -8
- package/dist/{cases/store.d.ts → knowledge/case-store.d.ts} +3 -6
- package/dist/{cases/store.js → knowledge/case-store.js} +7 -42
- package/dist/{cases/timeline-range.d.ts → knowledge/case-timeline-range.d.ts} +3 -3
- package/dist/{cases/timeline-range.js → knowledge/case-timeline-range.js} +47 -25
- package/dist/{cases/types.d.ts → knowledge/case-types.d.ts} +8 -2
- package/dist/{cases/types.js → knowledge/case-types.js} +1 -1
- package/dist/knowledge/commitments.d.ts +188 -0
- package/dist/knowledge/commitments.js +370 -0
- package/dist/knowledge/decision-edges.d.ts +70 -0
- package/dist/knowledge/decision-edges.js +123 -0
- package/dist/{agent-graph/types.d.ts → knowledge/graph-query.d.ts} +80 -70
- package/dist/knowledge/graph-query.js +1585 -0
- package/dist/knowledge/identity.d.ts +16 -0
- package/dist/knowledge/identity.js +22 -0
- package/dist/knowledge/index.d.ts +47 -0
- package/dist/knowledge/index.js +90 -0
- package/dist/knowledge/judgments.d.ts +118 -0
- package/dist/knowledge/judgments.js +808 -0
- package/dist/knowledge/observations.d.ts +160 -0
- package/dist/knowledge/observations.js +449 -0
- package/dist/knowledge/question-type.d.ts +34 -0
- package/dist/knowledge/question-type.js +70 -0
- package/dist/{search → knowledge}/ranker-features.js +1 -1
- package/dist/{search → knowledge}/search-quality.d.ts +0 -1
- package/dist/knowledge/search.d.ts +38 -0
- package/dist/knowledge/search.js +91 -0
- package/dist/knowledge/source-ingest.d.ts +65 -0
- package/dist/knowledge/source-ingest.js +174 -0
- package/dist/{edges/types.d.ts → knowledge/twin-edge-types.d.ts} +31 -4
- package/dist/{edges/types.js → knowledge/twin-edge-types.js} +13 -2
- package/dist/knowledge/work-dates.d.ts +49 -0
- package/dist/knowledge/work-dates.js +120 -0
- package/dist/mama-api.d.ts +114 -778
- package/dist/mama-api.js +313 -2461
- package/dist/memory/api.d.ts +264 -24
- package/dist/memory/api.js +1633 -843
- package/dist/memory/bootstrap-builder.d.ts +2 -1
- package/dist/memory/bootstrap-builder.js +5 -5
- package/dist/memory/channel-summary-state-store.d.ts +3 -2
- package/dist/memory/channel-summary-state-store.js +53 -51
- package/dist/memory/channel-summary-store.d.ts +5 -3
- package/dist/memory/channel-summary-store.js +3 -8
- package/dist/memory/dashboard-read.d.ts +46 -0
- package/dist/memory/dashboard-read.js +94 -0
- package/dist/memory/event-store.d.ts +3 -3
- package/dist/memory/event-store.js +3 -10
- package/dist/memory/finding-store.d.ts +3 -2
- package/dist/memory/finding-store.js +2 -7
- package/dist/memory/graph-read.d.ts +52 -0
- package/dist/memory/graph-read.js +130 -0
- package/dist/memory/judgment-types.d.ts +394 -0
- package/dist/memory/judgment-types.js +16 -0
- package/dist/memory/provenance-audit.d.ts +5 -2
- package/dist/memory/provenance-audit.js +8 -14
- package/dist/memory/provenance-live.d.ts +141 -0
- package/dist/memory/provenance-live.js +409 -0
- package/dist/memory/provenance-query.d.ts +5 -4
- package/dist/memory/provenance-query.js +21 -29
- package/dist/memory/provenance-resolver.d.ts +191 -0
- package/dist/memory/provenance-resolver.js +155 -0
- package/dist/memory/provenance.d.ts +1 -11
- package/dist/memory/provenance.js +2 -33
- package/dist/memory/recall-sanitize.d.ts +55 -0
- package/dist/memory/recall-sanitize.js +144 -0
- package/dist/memory/secret-filter.d.ts +32 -0
- package/dist/memory/secret-filter.js +126 -0
- package/dist/memory/truth-store.d.ts +2 -1
- package/dist/memory/truth-store.js +1 -4
- package/dist/memory/types.d.ts +74 -24
- package/dist/memory/types.js +75 -5
- package/dist/memory/write-adapters.d.ts +98 -0
- package/dist/memory/write-adapters.js +242 -0
- package/dist/operations/owner-action-effects.d.ts +53 -0
- package/dist/operations/owner-action-effects.js +96 -0
- package/dist/provenance/source-ref.d.ts +1 -1
- package/dist/provenance/source-ref.js +0 -2
- package/dist/registry/corrections.d.ts +31 -0
- package/dist/registry/corrections.js +332 -0
- package/dist/registry/record-identity.d.ts +49 -0
- package/dist/registry/record-identity.js +133 -0
- package/dist/registry/store.d.ts +101 -0
- package/dist/registry/store.js +395 -0
- package/dist/registry/types.d.ts +28 -0
- package/dist/registry/types.js +5 -0
- package/dist/relevance-scorer.js +2 -2
- package/dist/runtime/agent-event-bus.d.ts +50 -0
- package/dist/runtime/agent-event-bus.js +101 -0
- package/dist/runtime/drivers/claude-cli-wrapper.d.ts +155 -0
- package/dist/runtime/drivers/claude-cli-wrapper.js +392 -0
- package/dist/runtime/drivers/cli-arg-redaction.d.ts +2 -0
- package/dist/runtime/drivers/cli-arg-redaction.js +18 -0
- package/dist/runtime/drivers/cli-secret-redaction.d.ts +17 -0
- package/dist/runtime/drivers/cli-secret-redaction.js +126 -0
- package/dist/runtime/drivers/codex-app-server-process.d.ts +277 -0
- package/dist/runtime/drivers/codex-app-server-process.js +2342 -0
- package/dist/runtime/drivers/codex-auxiliary-tools.d.ts +17 -0
- package/dist/runtime/drivers/codex-auxiliary-tools.js +267 -0
- package/dist/runtime/drivers/codex-home.d.ts +20 -0
- package/dist/runtime/drivers/codex-home.js +674 -0
- package/dist/runtime/drivers/codex-thread-registry.d.ts +63 -0
- package/dist/runtime/drivers/codex-thread-registry.js +433 -0
- package/dist/runtime/drivers/persistent-cli-adapter.d.ts +160 -0
- package/dist/runtime/drivers/persistent-cli-adapter.js +396 -0
- package/dist/runtime/drivers/persistent-cli-process.d.ts +424 -0
- package/dist/runtime/drivers/persistent-cli-process.js +1543 -0
- package/dist/runtime/drivers/types.d.ts +456 -0
- package/dist/runtime/drivers/types.js +110 -0
- package/dist/runtime/mailbox.d.ts +223 -0
- package/dist/runtime/mailbox.js +582 -0
- package/dist/runtime/model-run-store.d.ts +28 -0
- package/dist/{model-runs/store.js → runtime/model-run-store.js} +81 -41
- package/dist/{model-runs/types.d.ts → runtime/model-run-types.d.ts} +33 -4
- package/dist/{model-runs/types.js → runtime/model-run-types.js} +1 -1
- package/dist/runtime/native-effect-observer.d.ts +22 -0
- package/dist/runtime/native-effect-observer.js +103 -0
- package/dist/runtime/native-input-journal.d.ts +46 -0
- package/dist/runtime/native-input-journal.js +308 -0
- package/dist/runtime/native-prompt.d.ts +118 -0
- package/dist/runtime/native-prompt.js +496 -0
- package/dist/runtime/native-session.d.ts +10 -0
- package/dist/{agent-graph/index.js → runtime/native-session.js} +9 -6
- package/dist/runtime/native-tool-trace-observer.d.ts +5 -0
- package/dist/runtime/native-tool-trace-observer.js +65 -0
- package/dist/runtime/native-turn.d.ts +272 -0
- package/dist/runtime/native-turn.js +1041 -0
- package/dist/runtime/operations.d.ts +236 -0
- package/dist/runtime/operations.js +565 -0
- package/dist/runtime/post-tool-handler.d.ts +74 -0
- package/dist/runtime/post-tool-handler.js +137 -0
- package/dist/runtime/prompt-layers.d.ts +126 -0
- package/dist/runtime/prompt-layers.js +239 -0
- package/dist/runtime/runtime-process.d.ts +102 -0
- package/dist/runtime/runtime-process.js +206 -0
- package/dist/runtime/runtime.d.ts +278 -0
- package/dist/runtime/runtime.js +563 -0
- package/dist/runtime/session-pool.d.ts +176 -0
- package/dist/runtime/session-pool.js +369 -0
- package/dist/runtime/stimulus-payload.d.ts +5 -0
- package/dist/runtime/stimulus-payload.js +50 -0
- package/dist/runtime/subagent-bridge.d.ts +24 -0
- package/dist/{agent-graph/types.js → runtime/subagent-bridge.js} +1 -1
- package/dist/runtime/text-completion.d.ts +22 -0
- package/dist/{agent-situation/types.js → runtime/text-completion.js} +1 -1
- package/dist/runtime/token-estimator.d.ts +25 -0
- package/dist/runtime/token-estimator.js +75 -0
- package/dist/runtime/tool-trace-store.d.ts +22 -0
- package/dist/{model-runs → runtime}/tool-trace-store.js +46 -27
- package/dist/runtime/trace-summary.d.ts +5 -0
- package/dist/runtime/trace-summary.js +74 -0
- package/dist/runtime/turn-text.d.ts +23 -0
- package/dist/runtime/turn-text.js +41 -0
- package/dist/storage/database.d.ts +67 -0
- package/dist/storage/database.js +158 -0
- package/package.json +20 -34
- package/dist/agent-graph/alias-write.d.ts +0 -3
- package/dist/agent-graph/alias-write.js +0 -234
- package/dist/agent-graph/entity-resolve.d.ts +0 -3
- package/dist/agent-graph/entity-resolve.js +0 -271
- package/dist/agent-graph/errors.d.ts +0 -4
- package/dist/agent-graph/errors.js +0 -11
- package/dist/agent-graph/graph-query.d.ts +0 -5
- package/dist/agent-graph/graph-query.js +0 -360
- package/dist/agent-graph/index.d.ts +0 -6
- package/dist/agent-situation/builder.d.ts +0 -8
- package/dist/agent-situation/builder.js +0 -239
- package/dist/agent-situation/cache-key.d.ts +0 -4
- package/dist/agent-situation/cache-key.js +0 -64
- package/dist/agent-situation/index.d.ts +0 -7
- package/dist/agent-situation/index.js +0 -28
- package/dist/agent-situation/packet-store.d.ts +0 -27
- package/dist/agent-situation/packet-store.js +0 -228
- package/dist/agent-situation/ranking-policy.d.ts +0 -18
- package/dist/agent-situation/ranking-policy.js +0 -75
- package/dist/agent-situation/source-readers.d.ts +0 -52
- package/dist/agent-situation/source-readers.js +0 -300
- package/dist/agent-situation/types.d.ts +0 -195
- package/dist/cases/wiki-page-index.d.ts +0 -37
- package/dist/cases/wiki-page-index.js +0 -201
- package/dist/config-loader.d.ts +0 -68
- package/dist/config-loader.js +0 -239
- package/dist/connectors/event-index.d.ts +0 -24
- package/dist/connectors/event-index.js +0 -245
- package/dist/connectors/raw-query.d.ts +0 -40
- package/dist/connectors/raw-query.js +0 -412
- package/dist/connectors/types.d.ts +0 -117
- package/dist/connectors/types.js +0 -3
- package/dist/context-compile/boundary-defaults.d.ts +0 -12
- package/dist/context-compile/boundary-defaults.js +0 -105
- package/dist/context-compile/channel-grant.js +0 -66
- package/dist/context-compile/compiler-policy.d.ts +0 -39
- package/dist/context-compile/compiler-policy.js +0 -147
- package/dist/context-compile/compiler.d.ts +0 -18
- package/dist/context-compile/compiler.js +0 -404
- package/dist/context-compile/index.d.ts +0 -10
- package/dist/context-compile/index.js +0 -26
- package/dist/context-compile/packet-store.d.ts +0 -8
- package/dist/context-compile/packet-store.js +0 -239
- package/dist/context-compile/ref.d.ts +0 -7
- package/dist/context-compile/ref.js +0 -102
- package/dist/context-compile/source-readers.d.ts +0 -70
- package/dist/context-compile/source-readers.js +0 -840
- package/dist/context-compile/types.d.ts +0 -155
- package/dist/context-compile/types.js +0 -11
- package/dist/context-compile/visibility.d.ts +0 -21
- package/dist/context-compile/visibility.js +0 -224
- package/dist/decision-tracker.d.ts +0 -206
- package/dist/decision-tracker.js +0 -481
- package/dist/edges/ref-validation.d.ts +0 -7
- package/dist/edges/ref-validation.js +0 -321
- package/dist/edges/store.d.ts +0 -8
- package/dist/edges/store.js +0 -129
- package/dist/embedding-client.d.ts +0 -28
- package/dist/embedding-client.js +0 -53
- package/dist/embedding-server/index.d.ts +0 -67
- package/dist/embedding-server/index.js +0 -405
- package/dist/embedding-server/mobile/auth.d.ts +0 -44
- package/dist/embedding-server/mobile/auth.js +0 -150
- package/dist/embedding-server/mobile/daemon.d.ts +0 -129
- package/dist/embedding-server/mobile/daemon.js +0 -313
- package/dist/embedding-server/mobile/output-parser.d.ts +0 -115
- package/dist/embedding-server/mobile/output-parser.js +0 -241
- package/dist/embedding-server/mobile/session-api.d.ts +0 -57
- package/dist/embedding-server/mobile/session-api.js +0 -261
- package/dist/embedding-server/mobile/session-manager.d.ts +0 -138
- package/dist/embedding-server/mobile/session-manager.js +0 -378
- package/dist/embedding-server/mobile/websocket-handler.d.ts +0 -137
- package/dist/embedding-server/mobile/websocket-handler.js +0 -486
- package/dist/embeddings.d.ts +0 -68
- package/dist/embeddings.js +0 -244
- package/dist/entities/audit-metrics.d.ts +0 -68
- package/dist/entities/audit-metrics.js +0 -124
- package/dist/entities/candidate-generator.d.ts +0 -8
- package/dist/entities/candidate-generator.js +0 -24
- package/dist/entities/entity-linked-decision-counts.d.ts +0 -2
- package/dist/entities/entity-linked-decision-counts.js +0 -29
- package/dist/entities/entity-list.d.ts +0 -22
- package/dist/entities/entity-list.js +0 -3
- package/dist/entities/entity-orphan-list.d.ts +0 -17
- package/dist/entities/entity-orphan-list.js +0 -3
- package/dist/entities/entity-search.d.ts +0 -20
- package/dist/entities/entity-search.js +0 -3
- package/dist/entities/errors.d.ts +0 -55
- package/dist/entities/errors.js +0 -100
- package/dist/entities/lineage-store.d.ts +0 -28
- package/dist/entities/lineage-store.js +0 -204
- package/dist/entities/normalization.d.ts +0 -14
- package/dist/entities/normalization.js +0 -63
- package/dist/entities/policy-store.d.ts +0 -8
- package/dist/entities/policy-store.js +0 -75
- package/dist/entities/policy-types.d.ts +0 -72
- package/dist/entities/policy-types.js +0 -59
- package/dist/entities/projection.d.ts +0 -8
- package/dist/entities/projection.js +0 -82
- package/dist/entities/provenance-query.d.ts +0 -32
- package/dist/entities/provenance-query.js +0 -3
- package/dist/entities/read-identity.d.ts +0 -31
- package/dist/entities/read-identity.js +0 -264
- package/dist/entities/recall-bridge.d.ts +0 -5
- package/dist/entities/recall-bridge.js +0 -171
- package/dist/entities/resolution-engine.d.ts +0 -8
- package/dist/entities/resolution-engine.js +0 -3
- package/dist/entities/rollback-preview.d.ts +0 -35
- package/dist/entities/rollback-preview.js +0 -3
- package/dist/entities/source-locator.d.ts +0 -3
- package/dist/entities/source-locator.js +0 -32
- package/dist/entities/store.d.ts +0 -69
- package/dist/entities/store.js +0 -544
- package/dist/entities/types.d.ts +0 -166
- package/dist/entities/types.js +0 -30
- package/dist/memory/extraction-prompt.d.ts +0 -4
- package/dist/memory/extraction-prompt.js +0 -89
- package/dist/memory/scope-backfill.d.ts +0 -14
- package/dist/memory/scope-backfill.js +0 -3
- package/dist/memory/scope-store.d.ts +0 -4
- package/dist/memory/scope-store.js +0 -9
- package/dist/memory-store.d.ts +0 -87
- package/dist/memory-store.js +0 -78
- package/dist/model-runs/store.d.ts +0 -13
- package/dist/model-runs/tool-trace-store.d.ts +0 -8
- package/dist/notification-manager.d.ts +0 -7
- package/dist/notification-manager.js +0 -12
- package/dist/outcome-tracker.d.ts +0 -151
- package/dist/outcome-tracker.js +0 -271
- package/dist/query-intent.d.ts +0 -23
- package/dist/query-intent.js +0 -114
- package/dist/runtime/trusted-provenance.d.ts +0 -3
- package/dist/runtime/trusted-provenance.js +0 -6
- package/dist/search/question-type.d.ts +0 -5
- package/dist/search/question-type.js +0 -41
- package/dist/test-utils.d.ts +0 -80
- package/dist/test-utils.js +0 -218
- package/dist/tier-validator.d.ts +0 -43
- package/dist/tier-validator.js +0 -159
- package/dist/time-formatter.d.ts +0 -25
- package/dist/time-formatter.js +0 -93
- /package/dist/{search → knowledge}/feedback-store.d.ts +0 -0
- /package/dist/{search → knowledge}/feedback-store.js +0 -0
- /package/dist/{search → knowledge}/ranker-features.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-rescore.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-rescore.js +0 -0
- /package/dist/{search → knowledge}/ranker-trainer.d.ts +0 -0
- /package/dist/{search → knowledge}/ranker-trainer.js +0 -0
- /package/dist/{search → knowledge}/search-quality.js +0 -0
package/dist/embeddings.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* MAMA (Memory-Augmented MCP Architecture) - Embedding Generation
|
|
4
|
-
*
|
|
5
|
-
* Story M1.4: Configurable embedding model selection
|
|
6
|
-
* Generates embeddings using configurable model (default: multilingual-e5-large)
|
|
7
|
-
* Supports: Korean-English cross-lingual similarity, enhanced metadata
|
|
8
|
-
*
|
|
9
|
-
* @module embeddings
|
|
10
|
-
* @version 1.1
|
|
11
|
-
* @date 2025-11-20
|
|
12
|
-
*/
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getQuantized = exports.getEmbeddingDim = exports.getModelName = exports.loadConfig = exports.MODEL_NAME = exports.EMBEDDING_DIM = exports.embeddingCache = exports.EMBEDDING_PREFIX_SCHEME = exports.EMBEDDING_MAX_TOKENISH_SEGMENTS = exports.EMBEDDING_MODEL_MAX_LENGTH = void 0;
|
|
18
|
-
exports.prepareEmbeddingText = prepareEmbeddingText;
|
|
19
|
-
exports.generateEmbedding = generateEmbedding;
|
|
20
|
-
exports.generateEnhancedEmbedding = generateEnhancedEmbedding;
|
|
21
|
-
exports.cosineSimilarity = cosineSimilarity;
|
|
22
|
-
const os_1 = __importDefault(require("os"));
|
|
23
|
-
const path_1 = __importDefault(require("path"));
|
|
24
|
-
const debug_logger_js_1 = require("./debug-logger.js");
|
|
25
|
-
const progress_indicator_js_1 = require("./progress-indicator.js");
|
|
26
|
-
const embedding_cache_js_1 = require("./embedding-cache.js");
|
|
27
|
-
Object.defineProperty(exports, "embeddingCache", { enumerable: true, get: function () { return embedding_cache_js_1.embeddingCache; } });
|
|
28
|
-
const config_loader_js_1 = require("./config-loader.js");
|
|
29
|
-
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_loader_js_1.loadConfig; } });
|
|
30
|
-
Object.defineProperty(exports, "getModelName", { enumerable: true, get: function () { return config_loader_js_1.getModelName; } });
|
|
31
|
-
Object.defineProperty(exports, "getEmbeddingDim", { enumerable: true, get: function () { return config_loader_js_1.getEmbeddingDim; } });
|
|
32
|
-
Object.defineProperty(exports, "getQuantized", { enumerable: true, get: function () { return config_loader_js_1.getQuantized; } });
|
|
33
|
-
// Shared cache directory (not in node_modules)
|
|
34
|
-
const DEFAULT_CACHE_DIR = path_1.default.join(os_1.default.homedir(), '.cache', 'huggingface', 'transformers');
|
|
35
|
-
const TIER3_ENV_VALUES = new Set(['1', 'true', 'yes']);
|
|
36
|
-
exports.EMBEDDING_MODEL_MAX_LENGTH = 512;
|
|
37
|
-
exports.EMBEDDING_MAX_TOKENISH_SEGMENTS = 480;
|
|
38
|
-
exports.EMBEDDING_PREFIX_SCHEME = 'e5-prefixed-v1';
|
|
39
|
-
function applyRolePrefix(preparedText, role) {
|
|
40
|
-
return `${role}: ${preparedText}`;
|
|
41
|
-
}
|
|
42
|
-
const TOKENISH_SEGMENT_PATTERN = /[\p{Script=Hangul}\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]|\S+/gu;
|
|
43
|
-
// Singleton pattern for model loading
|
|
44
|
-
let embeddingPipeline = null;
|
|
45
|
-
let currentModelName = null;
|
|
46
|
-
let modelLoadFailed = false; // Cache load failures to avoid repeated slow retries
|
|
47
|
-
function isForceTier3Enabled() {
|
|
48
|
-
return TIER3_ENV_VALUES.has(String(process.env.MAMA_FORCE_TIER_3 || '').toLowerCase());
|
|
49
|
-
}
|
|
50
|
-
function assertEmbeddingsEnabled() {
|
|
51
|
-
if (isForceTier3Enabled()) {
|
|
52
|
-
throw new Error('Embedding generation disabled because MAMA_FORCE_TIER_3=true. ' +
|
|
53
|
-
'Tier 3 test mode must use lexical/no-vector fallback instead of loading the embedding model.');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function prepareEmbeddingText(text) {
|
|
57
|
-
const trimmed = text.trim();
|
|
58
|
-
let count = 0;
|
|
59
|
-
let cutIndex = trimmed.length;
|
|
60
|
-
for (const match of trimmed.matchAll(TOKENISH_SEGMENT_PATTERN)) {
|
|
61
|
-
count++;
|
|
62
|
-
if (count > exports.EMBEDDING_MAX_TOKENISH_SEGMENTS) {
|
|
63
|
-
cutIndex = match.index ?? trimmed.length;
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return cutIndex === trimmed.length ? trimmed : trimmed.slice(0, cutIndex).trimEnd();
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Load embedding model (configurable)
|
|
71
|
-
*
|
|
72
|
-
* Story M1.4 AC #2: Transformers.js singleton initialization
|
|
73
|
-
* Story M1.4 AC #3: Changing model via config triggers informative log + resets caches
|
|
74
|
-
*
|
|
75
|
-
* @returns Embedding pipeline
|
|
76
|
-
*/
|
|
77
|
-
async function loadModel() {
|
|
78
|
-
assertEmbeddingsEnabled();
|
|
79
|
-
const modelName = (0, config_loader_js_1.getModelName)();
|
|
80
|
-
// Check if model has changed (Story M1.4 AC #3)
|
|
81
|
-
if (embeddingPipeline && currentModelName && currentModelName !== modelName) {
|
|
82
|
-
(0, debug_logger_js_1.info)('[MAMA] ⚠️ Embedding model changed - resetting pipeline');
|
|
83
|
-
(0, debug_logger_js_1.info)(`[MAMA] Old model: ${currentModelName}`);
|
|
84
|
-
(0, debug_logger_js_1.info)(`[MAMA] New model: ${modelName}`);
|
|
85
|
-
// Reset pipeline and cache
|
|
86
|
-
embeddingPipeline = null;
|
|
87
|
-
currentModelName = null;
|
|
88
|
-
embedding_cache_js_1.embeddingCache.clear();
|
|
89
|
-
(0, debug_logger_js_1.info)('[MAMA] ⚡ Model cache cleared');
|
|
90
|
-
}
|
|
91
|
-
// Fail fast if a previous load attempt already failed (avoid repeated slow retries)
|
|
92
|
-
if (modelLoadFailed) {
|
|
93
|
-
throw new Error('Embedding model previously failed to load — skipping retry');
|
|
94
|
-
}
|
|
95
|
-
// Load model if not already loaded
|
|
96
|
-
if (!embeddingPipeline) {
|
|
97
|
-
(0, progress_indicator_js_1.logLoading)(`Loading embedding model: ${modelName}...`);
|
|
98
|
-
const startTime = Date.now();
|
|
99
|
-
try {
|
|
100
|
-
// Dynamic import for ES Module compatibility (Railway deployment)
|
|
101
|
-
const transformers = await import('@huggingface/transformers');
|
|
102
|
-
const { pipeline, env } = transformers;
|
|
103
|
-
// Set shared cache directory (not in node_modules)
|
|
104
|
-
// This prevents re-downloading models on every npm install
|
|
105
|
-
const cacheDir = process.env.HF_HOME || process.env.TRANSFORMERS_CACHE || DEFAULT_CACHE_DIR;
|
|
106
|
-
env.cacheDir = cacheDir;
|
|
107
|
-
(0, debug_logger_js_1.info)(`[MAMA] Model cache directory: ${cacheDir}`);
|
|
108
|
-
const quantized = (0, config_loader_js_1.getQuantized)();
|
|
109
|
-
embeddingPipeline = (await pipeline('feature-extraction', modelName, {
|
|
110
|
-
dtype: quantized ? 'q8' : 'fp32',
|
|
111
|
-
}));
|
|
112
|
-
currentModelName = modelName;
|
|
113
|
-
const loadTime = Date.now() - startTime;
|
|
114
|
-
const config = (0, config_loader_js_1.loadConfig)();
|
|
115
|
-
(0, progress_indicator_js_1.logComplete)(`Embedding model ready (${loadTime}ms, ${config.embeddingDim}-dim, ${quantized ? 'q8' : 'fp32'})`);
|
|
116
|
-
}
|
|
117
|
-
catch (loadErr) {
|
|
118
|
-
modelLoadFailed = true;
|
|
119
|
-
throw loadErr;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return embeddingPipeline;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Generate embedding vector from text
|
|
126
|
-
*
|
|
127
|
-
* Story M1.4 AC #1: Uses configurable embeddingDim from config
|
|
128
|
-
* Target: < 30ms latency
|
|
129
|
-
*
|
|
130
|
-
* @param text - Input text to embed
|
|
131
|
-
* @returns Embedding vector (dimension from config)
|
|
132
|
-
* @throws Error if text is empty or embedding fails
|
|
133
|
-
*/
|
|
134
|
-
async function generateEmbedding(text, role = 'passage') {
|
|
135
|
-
if (typeof text !== 'string' || text.trim().length === 0) {
|
|
136
|
-
throw new Error('Text cannot be empty');
|
|
137
|
-
}
|
|
138
|
-
assertEmbeddingsEnabled();
|
|
139
|
-
const preparedText = prepareEmbeddingText(text);
|
|
140
|
-
const modelInput = applyRolePrefix(preparedText, role); // e5 instruction prefix
|
|
141
|
-
// Cache key is the PREFIXED input: a passage vector can never be served for a query.
|
|
142
|
-
const cached = embedding_cache_js_1.embeddingCache.get(modelInput);
|
|
143
|
-
if (cached) {
|
|
144
|
-
return cached;
|
|
145
|
-
}
|
|
146
|
-
const startTime = Date.now();
|
|
147
|
-
try {
|
|
148
|
-
const model = await loadModel();
|
|
149
|
-
const expectedDim = (0, config_loader_js_1.getEmbeddingDim)();
|
|
150
|
-
// Generate embedding
|
|
151
|
-
const output = await model(modelInput, {
|
|
152
|
-
pooling: 'mean', // Mean pooling over tokens
|
|
153
|
-
normalize: true, // L2 normalization
|
|
154
|
-
truncation: true,
|
|
155
|
-
max_length: exports.EMBEDDING_MODEL_MAX_LENGTH,
|
|
156
|
-
});
|
|
157
|
-
// Extract Float32Array
|
|
158
|
-
const embedding = output.data;
|
|
159
|
-
// Verify dimensions match config
|
|
160
|
-
if (embedding.length !== expectedDim) {
|
|
161
|
-
throw new Error(`Expected ${expectedDim}-dim, got ${embedding.length}-dim`);
|
|
162
|
-
}
|
|
163
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
164
|
-
const _latency = Date.now() - startTime;
|
|
165
|
-
// Task 2: Store in cache (AC #3)
|
|
166
|
-
embedding_cache_js_1.embeddingCache.set(modelInput, embedding);
|
|
167
|
-
return embedding;
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
171
|
-
throw new Error(`Failed to generate embedding: ${message}`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Generate enhanced embedding with content + metadata
|
|
176
|
-
*
|
|
177
|
-
* Task 3.4: Implement enhanced embedding format
|
|
178
|
-
* Inspired by A-mem: Content + Metadata for richer semantic representation
|
|
179
|
-
*
|
|
180
|
-
* @param decision - Decision object
|
|
181
|
-
* @returns 1024-dim enhanced embedding
|
|
182
|
-
*/
|
|
183
|
-
async function generateEnhancedEmbedding(decision, role = 'passage') {
|
|
184
|
-
// Construct enriched text representation with narrative fields (Story 2.2)
|
|
185
|
-
const parts = [
|
|
186
|
-
`Topic: ${decision.topic}`,
|
|
187
|
-
`Decision: ${decision.decision}`,
|
|
188
|
-
`Reasoning: ${decision.reasoning || 'N/A'}`,
|
|
189
|
-
`Outcome: ${decision.outcome || 'ONGOING'}`,
|
|
190
|
-
`Confidence: ${decision.confidence !== undefined ? decision.confidence : 0.5}`,
|
|
191
|
-
`User Involvement: ${decision.user_involvement || 'N/A'}`,
|
|
192
|
-
];
|
|
193
|
-
// Add narrative fields if present (Story 2.2: Narrative-Based Search)
|
|
194
|
-
if (decision.evidence) {
|
|
195
|
-
const evidenceText = Array.isArray(decision.evidence)
|
|
196
|
-
? decision.evidence.join('; ')
|
|
197
|
-
: typeof decision.evidence === 'string'
|
|
198
|
-
? decision.evidence
|
|
199
|
-
: JSON.stringify(decision.evidence);
|
|
200
|
-
parts.push(`Evidence: ${evidenceText}`);
|
|
201
|
-
}
|
|
202
|
-
if (decision.alternatives) {
|
|
203
|
-
const alternativesText = Array.isArray(decision.alternatives)
|
|
204
|
-
? decision.alternatives.join('; ')
|
|
205
|
-
: typeof decision.alternatives === 'string'
|
|
206
|
-
? decision.alternatives
|
|
207
|
-
: JSON.stringify(decision.alternatives);
|
|
208
|
-
parts.push(`Alternatives: ${alternativesText}`);
|
|
209
|
-
}
|
|
210
|
-
if (decision.risks) {
|
|
211
|
-
parts.push(`Risks: ${decision.risks}`);
|
|
212
|
-
}
|
|
213
|
-
const enrichedText = parts.join('\n').trim();
|
|
214
|
-
return generateEmbedding(enrichedText, role);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Calculate cosine similarity between two embeddings
|
|
218
|
-
*
|
|
219
|
-
* Utility for testing and validation
|
|
220
|
-
*
|
|
221
|
-
* @param embA - First embedding
|
|
222
|
-
* @param embB - Second embedding
|
|
223
|
-
* @returns Cosine similarity (0-1)
|
|
224
|
-
*/
|
|
225
|
-
function cosineSimilarity(embA, embB) {
|
|
226
|
-
if (embA.length !== embB.length) {
|
|
227
|
-
throw new Error('Embeddings must have same dimension');
|
|
228
|
-
}
|
|
229
|
-
let dotProduct = 0;
|
|
230
|
-
let normA = 0;
|
|
231
|
-
let normB = 0;
|
|
232
|
-
for (let i = 0; i < embA.length; i++) {
|
|
233
|
-
dotProduct += embA[i] * embB[i];
|
|
234
|
-
normA += embA[i] * embA[i];
|
|
235
|
-
normB += embB[i] * embB[i];
|
|
236
|
-
}
|
|
237
|
-
const similarity = dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
238
|
-
return similarity;
|
|
239
|
-
}
|
|
240
|
-
// Static snapshots of config values at module load time (Story M1.4)
|
|
241
|
-
// Note: These are evaluated once at import time. Use getEmbeddingDim()/getModelName() for runtime values.
|
|
242
|
-
exports.EMBEDDING_DIM = (0, config_loader_js_1.getEmbeddingDim)();
|
|
243
|
-
exports.MODEL_NAME = (0, config_loader_js_1.getModelName)();
|
|
244
|
-
//# sourceMappingURL=embeddings.js.map
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Entity audit metric helpers.
|
|
3
|
-
*
|
|
4
|
-
* Pure functions — no DB, no embeddings. The audit queue assembles the
|
|
5
|
-
* snapshot from live tables and fixtures, then hands it to these helpers
|
|
6
|
-
* for deterministic metric calculation + baseline classification.
|
|
7
|
-
*/
|
|
8
|
-
export declare const FALSE_MERGE_HARD_CEILING = 0.02;
|
|
9
|
-
export type EntityAuditClassification = 'improved' | 'stable' | 'regressed' | 'inconclusive';
|
|
10
|
-
export interface AuditCandidateSnapshot {
|
|
11
|
-
id: string;
|
|
12
|
-
status: 'pending' | 'auto_merged' | 'approved' | 'rejected' | 'deferred';
|
|
13
|
-
score_total: number;
|
|
14
|
-
left_canonical_id: string | null;
|
|
15
|
-
right_canonical_id: string | null;
|
|
16
|
-
left_kind: string | null;
|
|
17
|
-
right_kind: string | null;
|
|
18
|
-
}
|
|
19
|
-
export interface AuditGoldPair {
|
|
20
|
-
canonical_id: string;
|
|
21
|
-
left_obs_id: string;
|
|
22
|
-
right_obs_id: string;
|
|
23
|
-
}
|
|
24
|
-
export interface AuditCandidateGoldLink {
|
|
25
|
-
candidate_id: string;
|
|
26
|
-
matched_pair_key: string;
|
|
27
|
-
score_total: number;
|
|
28
|
-
}
|
|
29
|
-
export interface AuditSnapshot {
|
|
30
|
-
candidates: AuditCandidateSnapshot[];
|
|
31
|
-
gold_pairs: AuditGoldPair[];
|
|
32
|
-
candidate_gold_matches: AuditCandidateGoldLink[];
|
|
33
|
-
gold_canonical_projection_counts: Record<string, number>;
|
|
34
|
-
}
|
|
35
|
-
export interface AuditMetricSummary {
|
|
36
|
-
false_merge_rate: number;
|
|
37
|
-
false_merge_numerator: number;
|
|
38
|
-
false_merge_denominator: number;
|
|
39
|
-
cross_language_candidate_recall_at_10: number;
|
|
40
|
-
cross_language_recall_numerator: number;
|
|
41
|
-
cross_language_recall_denominator: number;
|
|
42
|
-
ontology_violation_count: number;
|
|
43
|
-
projection_fragmentation_rate: number;
|
|
44
|
-
}
|
|
45
|
-
export interface AuditRunClassificationInput {
|
|
46
|
-
current: AuditMetricSummary;
|
|
47
|
-
baseline: AuditMetricSummary | null;
|
|
48
|
-
}
|
|
49
|
-
export declare function computeFalseMergeRate(candidates: AuditCandidateSnapshot[]): {
|
|
50
|
-
rate: number;
|
|
51
|
-
numerator: number;
|
|
52
|
-
denominator: number;
|
|
53
|
-
};
|
|
54
|
-
export declare function computeCrossLanguageRecallAtK(goldPairs: AuditGoldPair[], matches: AuditCandidateGoldLink[], k: number): {
|
|
55
|
-
recall: number;
|
|
56
|
-
numerator: number;
|
|
57
|
-
denominator: number;
|
|
58
|
-
};
|
|
59
|
-
export declare function computeCrossLanguageRecallAt10(goldPairs: AuditGoldPair[], matches: AuditCandidateGoldLink[]): {
|
|
60
|
-
recall: number;
|
|
61
|
-
numerator: number;
|
|
62
|
-
denominator: number;
|
|
63
|
-
};
|
|
64
|
-
export declare function computeOntologyViolationCount(candidates: AuditCandidateSnapshot[]): number;
|
|
65
|
-
export declare function computeProjectionFragmentationRate(counts: Record<string, number>): number;
|
|
66
|
-
export declare function computeAuditMetrics(snapshot: AuditSnapshot): AuditMetricSummary;
|
|
67
|
-
export declare function classifyAuditRun(input: AuditRunClassificationInput): EntityAuditClassification;
|
|
68
|
-
//# sourceMappingURL=audit-metrics.d.ts.map
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Entity audit metric helpers.
|
|
4
|
-
*
|
|
5
|
-
* Pure functions — no DB, no embeddings. The audit queue assembles the
|
|
6
|
-
* snapshot from live tables and fixtures, then hands it to these helpers
|
|
7
|
-
* for deterministic metric calculation + baseline classification.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.FALSE_MERGE_HARD_CEILING = void 0;
|
|
11
|
-
exports.computeFalseMergeRate = computeFalseMergeRate;
|
|
12
|
-
exports.computeCrossLanguageRecallAtK = computeCrossLanguageRecallAtK;
|
|
13
|
-
exports.computeCrossLanguageRecallAt10 = computeCrossLanguageRecallAt10;
|
|
14
|
-
exports.computeOntologyViolationCount = computeOntologyViolationCount;
|
|
15
|
-
exports.computeProjectionFragmentationRate = computeProjectionFragmentationRate;
|
|
16
|
-
exports.computeAuditMetrics = computeAuditMetrics;
|
|
17
|
-
exports.classifyAuditRun = classifyAuditRun;
|
|
18
|
-
exports.FALSE_MERGE_HARD_CEILING = 0.02;
|
|
19
|
-
const RESOLVED_MERGE_STATUSES = new Set([
|
|
20
|
-
'auto_merged',
|
|
21
|
-
'approved',
|
|
22
|
-
]);
|
|
23
|
-
function computeFalseMergeRate(candidates) {
|
|
24
|
-
let denominator = 0;
|
|
25
|
-
let numerator = 0;
|
|
26
|
-
for (const candidate of candidates) {
|
|
27
|
-
if (!RESOLVED_MERGE_STATUSES.has(candidate.status))
|
|
28
|
-
continue;
|
|
29
|
-
denominator += 1;
|
|
30
|
-
if (candidate.left_canonical_id &&
|
|
31
|
-
candidate.right_canonical_id &&
|
|
32
|
-
candidate.left_canonical_id !== candidate.right_canonical_id) {
|
|
33
|
-
numerator += 1;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const rate = denominator === 0 ? 0 : numerator / denominator;
|
|
37
|
-
return { rate, numerator, denominator };
|
|
38
|
-
}
|
|
39
|
-
function computeCrossLanguageRecallAtK(goldPairs, matches, k) {
|
|
40
|
-
const denominator = goldPairs.length;
|
|
41
|
-
if (denominator === 0) {
|
|
42
|
-
return { recall: 0, numerator: 0, denominator: 0 };
|
|
43
|
-
}
|
|
44
|
-
const topRanked = [...matches]
|
|
45
|
-
.sort((a, b) => b.score_total - a.score_total)
|
|
46
|
-
.slice(0, Math.max(0, k))
|
|
47
|
-
.map((m) => m.matched_pair_key);
|
|
48
|
-
const matched = new Set(topRanked);
|
|
49
|
-
let numerator = 0;
|
|
50
|
-
for (const pair of goldPairs) {
|
|
51
|
-
const key = `${pair.canonical_id}:${pair.left_obs_id}:${pair.right_obs_id}`;
|
|
52
|
-
if (matched.has(key)) {
|
|
53
|
-
numerator += 1;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return { recall: numerator / denominator, numerator, denominator };
|
|
57
|
-
}
|
|
58
|
-
function computeCrossLanguageRecallAt10(goldPairs, matches) {
|
|
59
|
-
return computeCrossLanguageRecallAtK(goldPairs, matches, 10);
|
|
60
|
-
}
|
|
61
|
-
function computeOntologyViolationCount(candidates) {
|
|
62
|
-
let count = 0;
|
|
63
|
-
for (const candidate of candidates) {
|
|
64
|
-
if (candidate.left_kind &&
|
|
65
|
-
candidate.right_kind &&
|
|
66
|
-
candidate.left_kind !== candidate.right_kind) {
|
|
67
|
-
count += 1;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return count;
|
|
71
|
-
}
|
|
72
|
-
function computeProjectionFragmentationRate(counts) {
|
|
73
|
-
const keys = Object.keys(counts);
|
|
74
|
-
if (keys.length === 0)
|
|
75
|
-
return 0;
|
|
76
|
-
let fragmented = 0;
|
|
77
|
-
for (const key of keys) {
|
|
78
|
-
if ((counts[key] ?? 0) > 1)
|
|
79
|
-
fragmented += 1;
|
|
80
|
-
}
|
|
81
|
-
return fragmented / keys.length;
|
|
82
|
-
}
|
|
83
|
-
function computeAuditMetrics(snapshot) {
|
|
84
|
-
const falseMerge = computeFalseMergeRate(snapshot.candidates);
|
|
85
|
-
const recall = computeCrossLanguageRecallAt10(snapshot.gold_pairs, snapshot.candidate_gold_matches);
|
|
86
|
-
const ontology = computeOntologyViolationCount(snapshot.candidates);
|
|
87
|
-
const fragmentation = computeProjectionFragmentationRate(snapshot.gold_canonical_projection_counts);
|
|
88
|
-
return {
|
|
89
|
-
false_merge_rate: falseMerge.rate,
|
|
90
|
-
false_merge_numerator: falseMerge.numerator,
|
|
91
|
-
false_merge_denominator: falseMerge.denominator,
|
|
92
|
-
cross_language_candidate_recall_at_10: recall.recall,
|
|
93
|
-
cross_language_recall_numerator: recall.numerator,
|
|
94
|
-
cross_language_recall_denominator: recall.denominator,
|
|
95
|
-
ontology_violation_count: ontology,
|
|
96
|
-
projection_fragmentation_rate: fragmentation,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function classifyAuditRun(input) {
|
|
100
|
-
const { current, baseline } = input;
|
|
101
|
-
if (current.false_merge_rate > exports.FALSE_MERGE_HARD_CEILING) {
|
|
102
|
-
return 'regressed';
|
|
103
|
-
}
|
|
104
|
-
if (!baseline) {
|
|
105
|
-
return 'inconclusive';
|
|
106
|
-
}
|
|
107
|
-
if (current.false_merge_rate > baseline.false_merge_rate) {
|
|
108
|
-
return 'regressed';
|
|
109
|
-
}
|
|
110
|
-
const recallUp = current.cross_language_candidate_recall_at_10 > baseline.cross_language_candidate_recall_at_10;
|
|
111
|
-
const fragmentationDown = current.projection_fragmentation_rate < baseline.projection_fragmentation_rate;
|
|
112
|
-
const ontologyDown = current.ontology_violation_count < baseline.ontology_violation_count;
|
|
113
|
-
if (recallUp || fragmentationDown || ontologyDown) {
|
|
114
|
-
const anyRegression = current.cross_language_candidate_recall_at_10 <
|
|
115
|
-
baseline.cross_language_candidate_recall_at_10 ||
|
|
116
|
-
current.projection_fragmentation_rate > baseline.projection_fragmentation_rate ||
|
|
117
|
-
current.ontology_violation_count > baseline.ontology_violation_count;
|
|
118
|
-
if (anyRegression)
|
|
119
|
-
return 'stable';
|
|
120
|
-
return 'improved';
|
|
121
|
-
}
|
|
122
|
-
return 'stable';
|
|
123
|
-
}
|
|
124
|
-
//# sourceMappingURL=audit-metrics.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { EntityObservation } from './types.js';
|
|
2
|
-
export declare const ENTITY_EMBEDDING_TOPN = 50;
|
|
3
|
-
export interface CandidateGeneratorOptions {
|
|
4
|
-
embeddingScorer?: (left: EntityObservation, right: EntityObservation) => Promise<number>;
|
|
5
|
-
topN?: number;
|
|
6
|
-
}
|
|
7
|
-
export declare function dedupeObservationsBySource(observations: EntityObservation[]): EntityObservation[];
|
|
8
|
-
//# sourceMappingURL=candidate-generator.d.ts.map
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ENTITY_EMBEDDING_TOPN = void 0;
|
|
4
|
-
exports.dedupeObservationsBySource = dedupeObservationsBySource;
|
|
5
|
-
exports.ENTITY_EMBEDDING_TOPN = 50;
|
|
6
|
-
function dedupeObservationsBySource(observations) {
|
|
7
|
-
const seen = new Set();
|
|
8
|
-
const deduped = [];
|
|
9
|
-
for (const observation of observations) {
|
|
10
|
-
const key = JSON.stringify([
|
|
11
|
-
observation.source_connector,
|
|
12
|
-
observation.source_locator ?? `missing-locator:${observation.id}`,
|
|
13
|
-
observation.source_raw_record_id,
|
|
14
|
-
observation.observation_type,
|
|
15
|
-
]);
|
|
16
|
-
if (seen.has(key)) {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
seen.add(key);
|
|
20
|
-
deduped.push(observation);
|
|
21
|
-
}
|
|
22
|
-
return deduped;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=candidate-generator.js.map
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadLinkedDecisionCounts = loadLinkedDecisionCounts;
|
|
4
|
-
function loadLinkedDecisionCounts(adapter, entityIds) {
|
|
5
|
-
const uniqueIds = Array.from(new Set(entityIds.filter((entityId) => typeof entityId === 'string' && entityId.length > 0)));
|
|
6
|
-
if (uniqueIds.length === 0) {
|
|
7
|
-
return new Map();
|
|
8
|
-
}
|
|
9
|
-
const placeholders = uniqueIds.map(() => '?').join(', ');
|
|
10
|
-
const rows = adapter
|
|
11
|
-
.prepare(`
|
|
12
|
-
SELECT
|
|
13
|
-
l.canonical_entity_id AS entity_id,
|
|
14
|
-
COUNT(DISTINCT des.decision_id) AS linked_decision_count
|
|
15
|
-
FROM entity_lineage_links l
|
|
16
|
-
INNER JOIN decision_entity_sources des
|
|
17
|
-
ON des.entity_observation_id = l.entity_observation_id
|
|
18
|
-
WHERE l.status = 'active'
|
|
19
|
-
AND l.canonical_entity_id IN (${placeholders})
|
|
20
|
-
GROUP BY l.canonical_entity_id
|
|
21
|
-
`)
|
|
22
|
-
.all(...uniqueIds);
|
|
23
|
-
const counts = new Map(uniqueIds.map((entityId) => [entityId, 0]));
|
|
24
|
-
for (const row of rows) {
|
|
25
|
-
counts.set(row.entity_id, Number(row.linked_decision_count) || 0);
|
|
26
|
-
}
|
|
27
|
-
return counts;
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=entity-linked-decision-counts.js.map
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { EntityNode } from './types.js';
|
|
2
|
-
export interface ListCanonicalEntitiesInput {
|
|
3
|
-
limit: number;
|
|
4
|
-
cursor?: string | null;
|
|
5
|
-
include_noisy?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export interface CanonicalEntityListRow {
|
|
8
|
-
id: string;
|
|
9
|
-
kind: EntityNode['kind'];
|
|
10
|
-
preferred_label: string;
|
|
11
|
-
scope_kind: EntityNode['scope_kind'];
|
|
12
|
-
scope_id: string | null;
|
|
13
|
-
created_at: number;
|
|
14
|
-
linked_decision_count: number;
|
|
15
|
-
}
|
|
16
|
-
export interface ListCanonicalEntitiesResult {
|
|
17
|
-
entities: CanonicalEntityListRow[];
|
|
18
|
-
next_cursor: string | null;
|
|
19
|
-
total_count: number;
|
|
20
|
-
visible_count: number;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=entity-list.d.ts.map
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { EntityNode } from './types.js';
|
|
2
|
-
export interface CanonicalEntityOrphanRow {
|
|
3
|
-
entity_id: string;
|
|
4
|
-
title: string;
|
|
5
|
-
kind: EntityNode['kind'];
|
|
6
|
-
scope_kind: EntityNode['scope_kind'];
|
|
7
|
-
scope_id: string | null;
|
|
8
|
-
scope_label: string;
|
|
9
|
-
created_at: number;
|
|
10
|
-
linked_decision_count: number;
|
|
11
|
-
evidence_summary: {
|
|
12
|
-
lineage_rows: number;
|
|
13
|
-
raw_evidence_rows: number;
|
|
14
|
-
last_seen_at: number | null;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=entity-orphan-list.d.ts.map
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { EntityNode } from './types.js';
|
|
2
|
-
export interface SearchCanonicalEntitiesInput {
|
|
3
|
-
query: string;
|
|
4
|
-
limit: number;
|
|
5
|
-
cursor?: string | null;
|
|
6
|
-
}
|
|
7
|
-
export interface EntitySearchRow {
|
|
8
|
-
id: string;
|
|
9
|
-
kind: EntityNode['kind'];
|
|
10
|
-
preferred_label: string;
|
|
11
|
-
scope_kind: EntityNode['scope_kind'];
|
|
12
|
-
scope_id: string | null;
|
|
13
|
-
score: number;
|
|
14
|
-
linked_decision_count: number;
|
|
15
|
-
}
|
|
16
|
-
export interface SearchCanonicalEntitiesResult {
|
|
17
|
-
entities: EntitySearchRow[];
|
|
18
|
-
next_cursor: string | null;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=entity-search.d.ts.map
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export interface EntityErrorEnvelope {
|
|
2
|
-
error: {
|
|
3
|
-
code: string;
|
|
4
|
-
message: string;
|
|
5
|
-
hint: string;
|
|
6
|
-
doc_url: string;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
export declare abstract class EntityError extends Error {
|
|
10
|
-
abstract readonly code: string;
|
|
11
|
-
abstract readonly doc_section: string;
|
|
12
|
-
readonly context: Record<string, unknown>;
|
|
13
|
-
readonly hint: string;
|
|
14
|
-
constructor(opts: {
|
|
15
|
-
message: string;
|
|
16
|
-
context?: Record<string, unknown>;
|
|
17
|
-
hint: string;
|
|
18
|
-
});
|
|
19
|
-
toErrorEnvelope(): EntityErrorEnvelope;
|
|
20
|
-
}
|
|
21
|
-
export declare class InvalidEntityLabelError extends EntityError {
|
|
22
|
-
readonly code = "entity.invalid_label";
|
|
23
|
-
readonly doc_section = "#invalid-label";
|
|
24
|
-
constructor(context?: Record<string, unknown>);
|
|
25
|
-
}
|
|
26
|
-
export declare class EmbeddingUnavailableError extends EntityError {
|
|
27
|
-
readonly code = "entity.embedding_unavailable";
|
|
28
|
-
readonly doc_section = "#embedding-unavailable";
|
|
29
|
-
constructor(context?: Record<string, unknown>);
|
|
30
|
-
}
|
|
31
|
-
export declare class OntologyViolationError extends EntityError {
|
|
32
|
-
readonly code = "entity.ontology_violation";
|
|
33
|
-
readonly doc_section = "#ontology-violation";
|
|
34
|
-
constructor(context?: Record<string, unknown>);
|
|
35
|
-
}
|
|
36
|
-
export declare class EntityLabelMissingError extends EntityError {
|
|
37
|
-
readonly code = "entity.label_missing";
|
|
38
|
-
readonly doc_section = "#label-missing";
|
|
39
|
-
constructor(context?: Record<string, unknown>);
|
|
40
|
-
}
|
|
41
|
-
export declare class AuditRunInProgressError extends EntityError {
|
|
42
|
-
readonly code = "entity.audit_run_in_progress";
|
|
43
|
-
readonly doc_section = "#audit-run-in-progress";
|
|
44
|
-
constructor(context?: Record<string, unknown>);
|
|
45
|
-
}
|
|
46
|
-
export declare class CaseMergeChainCycleError extends EntityError {
|
|
47
|
-
readonly code = "case.merge_chain_cycle";
|
|
48
|
-
readonly doc_section = "#case-merge-chain-cycle";
|
|
49
|
-
constructor(context: {
|
|
50
|
-
case_id: string;
|
|
51
|
-
chain: string[];
|
|
52
|
-
detected_at_depth: number;
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=errors.d.ts.map
|