@atomicmemory/core 1.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/CHANGELOG.md +27 -0
- package/LICENSE +201 -0
- package/README.md +314 -0
- package/dist/app/bind-ephemeral.d.ts +18 -0
- package/dist/app/bind-ephemeral.js +22 -0
- package/dist/app/cors-headers.d.ts +12 -0
- package/dist/app/cors-headers.js +18 -0
- package/dist/app/create-app.d.ts +25 -0
- package/dist/app/create-app.js +156 -0
- package/dist/app/runtime-config-route-snapshot.d.ts +27 -0
- package/dist/app/runtime-config-route-snapshot.js +27 -0
- package/dist/app/runtime-container.d.ts +281 -0
- package/dist/app/runtime-container.js +297 -0
- package/dist/app/startup-checks.d.ts +28 -0
- package/dist/app/startup-checks.js +45 -0
- package/dist/bin.d.ts +17 -0
- package/dist/bin.js +128 -0
- package/dist/config.d.ts +680 -0
- package/dist/config.js +808 -0
- package/dist/db/agent-trust-repository.d.ts +49 -0
- package/dist/db/agent-trust-repository.js +66 -0
- package/dist/db/belief-edges-repository.d.ts +68 -0
- package/dist/db/belief-edges-repository.js +124 -0
- package/dist/db/claim-repository.d.ts +6 -0
- package/dist/db/claim-repository.js +4 -0
- package/dist/db/contradictions-repository.d.ts +56 -0
- package/dist/db/contradictions-repository.js +88 -0
- package/dist/db/document-chunk-repository.d.ts +48 -0
- package/dist/db/document-chunk-repository.js +145 -0
- package/dist/db/document-chunk-types.d.ts +35 -0
- package/dist/db/document-chunk-types.js +9 -0
- package/dist/db/document-list-cursor.d.ts +45 -0
- package/dist/db/document-list-cursor.js +111 -0
- package/dist/db/document-list-repository.d.ts +103 -0
- package/dist/db/document-list-repository.js +204 -0
- package/dist/db/entity-cards-repository.d.ts +37 -0
- package/dist/db/entity-cards-repository.js +46 -0
- package/dist/db/entity-values-repository.d.ts +26 -0
- package/dist/db/entity-values-repository.js +57 -0
- package/dist/db/link-repository.d.ts +30 -0
- package/dist/db/link-repository.js +54 -0
- package/dist/db/memory-repository.d.ts +163 -0
- package/dist/db/memory-repository.js +232 -0
- package/dist/db/migrate.d.ts +6 -0
- package/dist/db/migrate.js +36 -0
- package/dist/db/mmr.d.ts +14 -0
- package/dist/db/mmr.js +57 -0
- package/dist/db/passport-feed-repository.d.ts +91 -0
- package/dist/db/passport-feed-repository.js +198 -0
- package/dist/db/pg-episode-store.d.ts +19 -0
- package/dist/db/pg-episode-store.js +17 -0
- package/dist/db/pg-link-store.d.ts +17 -0
- package/dist/db/pg-link-store.js +14 -0
- package/dist/db/pg-memory-store.d.ts +68 -0
- package/dist/db/pg-memory-store.js +53 -0
- package/dist/db/pg-recap-store.d.ts +13 -0
- package/dist/db/pg-recap-store.js +19 -0
- package/dist/db/pg-representation-store.d.ts +17 -0
- package/dist/db/pg-representation-store.js +17 -0
- package/dist/db/pg-search-store.d.ts +29 -0
- package/dist/db/pg-search-store.js +47 -0
- package/dist/db/pool.d.ts +5 -0
- package/dist/db/pool.js +21 -0
- package/dist/db/ppr.d.ts +56 -0
- package/dist/db/ppr.js +178 -0
- package/dist/db/query-helpers.d.ts +44 -0
- package/dist/db/query-helpers.js +60 -0
- package/dist/db/raw-doc-artifact-sync.d.ts +128 -0
- package/dist/db/raw-doc-artifact-sync.js +259 -0
- package/dist/db/raw-document-blob-repository.d.ts +148 -0
- package/dist/db/raw-document-blob-repository.js +300 -0
- package/dist/db/raw-document-repository.d.ts +104 -0
- package/dist/db/raw-document-repository.js +410 -0
- package/dist/db/raw-document-status-repository.d.ts +122 -0
- package/dist/db/raw-document-status-repository.js +183 -0
- package/dist/db/raw-document-types.d.ts +236 -0
- package/dist/db/raw-document-types.js +10 -0
- package/dist/db/raw-storage-reconciliation-repository.d.ts +110 -0
- package/dist/db/raw-storage-reconciliation-repository.js +200 -0
- package/dist/db/reflection-jobs-repository.d.ts +33 -0
- package/dist/db/reflection-jobs-repository.js +48 -0
- package/dist/db/reflections-repository.d.ts +41 -0
- package/dist/db/reflections-repository.js +83 -0
- package/dist/db/repository-claims.d.ts +141 -0
- package/dist/db/repository-claims.js +376 -0
- package/dist/db/repository-deferred-audn.d.ts +33 -0
- package/dist/db/repository-deferred-audn.js +69 -0
- package/dist/db/repository-document-delete.d.ts +53 -0
- package/dist/db/repository-document-delete.js +156 -0
- package/dist/db/repository-entities.d.ts +114 -0
- package/dist/db/repository-entities.js +317 -0
- package/dist/db/repository-entity-attributes.d.ts +41 -0
- package/dist/db/repository-entity-attributes.js +65 -0
- package/dist/db/repository-entity-graph.d.ts +32 -0
- package/dist/db/repository-entity-graph.js +87 -0
- package/dist/db/repository-first-mentions.d.ts +41 -0
- package/dist/db/repository-first-mentions.js +79 -0
- package/dist/db/repository-lessons.d.ts +51 -0
- package/dist/db/repository-lessons.js +90 -0
- package/dist/db/repository-links.d.ts +26 -0
- package/dist/db/repository-links.js +105 -0
- package/dist/db/repository-observation.d.ts +26 -0
- package/dist/db/repository-observation.js +51 -0
- package/dist/db/repository-read.d.ts +56 -0
- package/dist/db/repository-read.js +271 -0
- package/dist/db/repository-recaps.d.ts +59 -0
- package/dist/db/repository-recaps.js +158 -0
- package/dist/db/repository-representations.d.ts +48 -0
- package/dist/db/repository-representations.js +162 -0
- package/dist/db/repository-temporal-state.d.ts +35 -0
- package/dist/db/repository-temporal-state.js +46 -0
- package/dist/db/repository-tll.d.ts +88 -0
- package/dist/db/repository-tll.js +179 -0
- package/dist/db/repository-types.d.ts +313 -0
- package/dist/db/repository-types.js +142 -0
- package/dist/db/repository-user-profiles.d.ts +17 -0
- package/dist/db/repository-user-profiles.js +28 -0
- package/dist/db/repository-vector-search.d.ts +33 -0
- package/dist/db/repository-vector-search.js +373 -0
- package/dist/db/repository-wipe.d.ts +34 -0
- package/dist/db/repository-wipe.js +94 -0
- package/dist/db/repository-write.d.ts +61 -0
- package/dist/db/repository-write.js +279 -0
- package/dist/db/schema.sql +1355 -0
- package/dist/db/storage-artifact-delete-tx.d.ts +56 -0
- package/dist/db/storage-artifact-delete-tx.js +123 -0
- package/dist/db/storage-artifact-providers.d.ts +21 -0
- package/dist/db/storage-artifact-providers.js +21 -0
- package/dist/db/storage-artifact-recovery-repository.d.ts +66 -0
- package/dist/db/storage-artifact-recovery-repository.js +58 -0
- package/dist/db/storage-artifact-repository.d.ts +329 -0
- package/dist/db/storage-artifact-repository.js +497 -0
- package/dist/db/stores.d.ts +220 -0
- package/dist/db/stores.js +12 -0
- package/dist/db/summaries-repository.d.ts +74 -0
- package/dist/db/summaries-repository.js +125 -0
- package/dist/eval/beam-10m-loader.d.ts +98 -0
- package/dist/eval/beam-10m-loader.js +128 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +17 -0
- package/dist/middleware/require-bearer.d.ts +27 -0
- package/dist/middleware/require-bearer.js +60 -0
- package/dist/middleware/validate-response.d.ts +33 -0
- package/dist/middleware/validate-response.js +55 -0
- package/dist/middleware/validate.d.ts +43 -0
- package/dist/middleware/validate.js +85 -0
- package/dist/routes/agents.d.ts +13 -0
- package/dist/routes/agents.js +89 -0
- package/dist/routes/document-response-formatters.d.ts +98 -0
- package/dist/routes/document-response-formatters.js +243 -0
- package/dist/routes/documents.d.ts +74 -0
- package/dist/routes/documents.js +425 -0
- package/dist/routes/memories.d.ts +29 -0
- package/dist/routes/memories.js +725 -0
- package/dist/routes/memory-response-formatters.d.ts +179 -0
- package/dist/routes/memory-response-formatters.js +210 -0
- package/dist/routes/public-raw-storage-metadata.d.ts +54 -0
- package/dist/routes/public-raw-storage-metadata.js +56 -0
- package/dist/routes/reflect.d.ts +14 -0
- package/dist/routes/reflect.js +19 -0
- package/dist/routes/response-schema-map.d.ts +14 -0
- package/dist/routes/response-schema-map.js +69 -0
- package/dist/routes/route-errors.d.ts +12 -0
- package/dist/routes/route-errors.js +30 -0
- package/dist/routes/storage-error-handlers.d.ts +34 -0
- package/dist/routes/storage-error-handlers.js +185 -0
- package/dist/routes/storage-response-formatters.d.ts +44 -0
- package/dist/routes/storage-response-formatters.js +155 -0
- package/dist/routes/storage.d.ts +38 -0
- package/dist/routes/storage.js +369 -0
- package/dist/routes/upstream-provider-errors.d.ts +19 -0
- package/dist/routes/upstream-provider-errors.js +95 -0
- package/dist/schemas/agents.d.ts +79 -0
- package/dist/schemas/agents.js +126 -0
- package/dist/schemas/common.d.ts +110 -0
- package/dist/schemas/common.js +190 -0
- package/dist/schemas/document-list-responses.d.ts +102 -0
- package/dist/schemas/document-list-responses.js +87 -0
- package/dist/schemas/document-list-schemas.d.ts +123 -0
- package/dist/schemas/document-list-schemas.js +174 -0
- package/dist/schemas/document-response-schemas.d.ts +610 -0
- package/dist/schemas/document-response-schemas.js +264 -0
- package/dist/schemas/document-status-envelope.d.ts +48 -0
- package/dist/schemas/document-status-envelope.js +54 -0
- package/dist/schemas/documents.d.ts +292 -0
- package/dist/schemas/documents.js +449 -0
- package/dist/schemas/errors.d.ts +75 -0
- package/dist/schemas/errors.js +105 -0
- package/dist/schemas/memories.d.ts +378 -0
- package/dist/schemas/memories.js +542 -0
- package/dist/schemas/openapi.d.ts +24 -0
- package/dist/schemas/openapi.js +1038 -0
- package/dist/schemas/response-scalars.d.ts +10 -0
- package/dist/schemas/response-scalars.js +10 -0
- package/dist/schemas/responses.d.ts +536 -0
- package/dist/schemas/responses.js +350 -0
- package/dist/schemas/search-response-parts.d.ts +97 -0
- package/dist/schemas/search-response-parts.js +103 -0
- package/dist/schemas/storage-schemas.d.ts +175 -0
- package/dist/schemas/storage-schemas.js +277 -0
- package/dist/schemas/zod-setup.d.ts +15 -0
- package/dist/schemas/zod-setup.js +17 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.js +57 -0
- package/dist/services/abstract-query-policy.d.ts +13 -0
- package/dist/services/abstract-query-policy.js +50 -0
- package/dist/services/affinity-clustering.d.ts +66 -0
- package/dist/services/affinity-clustering.js +125 -0
- package/dist/services/agentic-retrieval.d.ts +38 -0
- package/dist/services/agentic-retrieval.js +126 -0
- package/dist/services/answer-format.d.ts +56 -0
- package/dist/services/answer-format.js +118 -0
- package/dist/services/answer-rescue.d.ts +72 -0
- package/dist/services/answer-rescue.js +177 -0
- package/dist/services/answer-verifier.d.ts +24 -0
- package/dist/services/answer-verifier.js +73 -0
- package/dist/services/api-retry.d.ts +6 -0
- package/dist/services/api-retry.js +41 -0
- package/dist/services/assistant-turn-filter.d.ts +20 -0
- package/dist/services/assistant-turn-filter.js +69 -0
- package/dist/services/atomicmem-uri.d.ts +33 -0
- package/dist/services/atomicmem-uri.js +86 -0
- package/dist/services/audit-events.d.ts +54 -0
- package/dist/services/audit-events.js +56 -0
- package/dist/services/chunked-extraction.d.ts +21 -0
- package/dist/services/chunked-extraction.js +108 -0
- package/dist/services/claim-slotting.d.ts +27 -0
- package/dist/services/claim-slotting.js +38 -0
- package/dist/services/claude-code-llm.d.ts +19 -0
- package/dist/services/claude-code-llm.js +96 -0
- package/dist/services/composite-dedup.d.ts +50 -0
- package/dist/services/composite-dedup.js +153 -0
- package/dist/services/composite-grouping.d.ts +41 -0
- package/dist/services/composite-grouping.js +111 -0
- package/dist/services/composite-staleness.d.ts +20 -0
- package/dist/services/composite-staleness.js +50 -0
- package/dist/services/conciseness-preference.d.ts +14 -0
- package/dist/services/conciseness-preference.js +42 -0
- package/dist/services/conflict-policy.d.ts +20 -0
- package/dist/services/conflict-policy.js +335 -0
- package/dist/services/consensus-extraction.d.ts +39 -0
- package/dist/services/consensus-extraction.js +147 -0
- package/dist/services/consensus-validation.d.ts +52 -0
- package/dist/services/consensus-validation.js +206 -0
- package/dist/services/consolidation-service.d.ts +60 -0
- package/dist/services/consolidation-service.js +171 -0
- package/dist/services/content-detection.d.ts +18 -0
- package/dist/services/content-detection.js +25 -0
- package/dist/services/contradiction-surfacing.d.ts +62 -0
- package/dist/services/contradiction-surfacing.js +111 -0
- package/dist/services/cost-telemetry.d.ts +39 -0
- package/dist/services/cost-telemetry.js +58 -0
- package/dist/services/counter-evidence.d.ts +34 -0
- package/dist/services/counter-evidence.js +92 -0
- package/dist/services/current-state-ranking.d.ts +21 -0
- package/dist/services/current-state-ranking.js +152 -0
- package/dist/services/deferred-audn.d.ts +47 -0
- package/dist/services/deferred-audn.js +162 -0
- package/dist/services/document-chunker.d.ts +50 -0
- package/dist/services/document-chunker.js +153 -0
- package/dist/services/document-failure-markers.d.ts +91 -0
- package/dist/services/document-failure-markers.js +305 -0
- package/dist/services/document-indexer.d.ts +122 -0
- package/dist/services/document-indexer.js +405 -0
- package/dist/services/document-service.d.ts +245 -0
- package/dist/services/document-service.js +325 -0
- package/dist/services/document-upload-artifact-sync.d.ts +80 -0
- package/dist/services/document-upload-artifact-sync.js +162 -0
- package/dist/services/document-upload-beta2-recovery.d.ts +72 -0
- package/dist/services/document-upload-beta2-recovery.js +94 -0
- package/dist/services/document-upload.d.ts +44 -0
- package/dist/services/document-upload.js +353 -0
- package/dist/services/embedding.d.ts +57 -0
- package/dist/services/embedding.js +416 -0
- package/dist/services/entity-attribute-extractor.d.ts +34 -0
- package/dist/services/entity-attribute-extractor.js +117 -0
- package/dist/services/entity-card-synthesis.d.ts +54 -0
- package/dist/services/entity-card-synthesis.js +92 -0
- package/dist/services/entity-dedup.d.ts +9 -0
- package/dist/services/entity-dedup.js +14 -0
- package/dist/services/entity-graph.d.ts +17 -0
- package/dist/services/entity-graph.js +135 -0
- package/dist/services/entropy-gate.d.ts +52 -0
- package/dist/services/entropy-gate.js +56 -0
- package/dist/services/episode-fetcher.d.ts +47 -0
- package/dist/services/episode-fetcher.js +128 -0
- package/dist/services/event-anchor-facts.d.ts +8 -0
- package/dist/services/event-anchor-facts.js +205 -0
- package/dist/services/event-chain-detector.d.ts +52 -0
- package/dist/services/event-chain-detector.js +83 -0
- package/dist/services/extraction-cache.d.ts +9 -0
- package/dist/services/extraction-cache.js +54 -0
- package/dist/services/extraction-enrichment.d.ts +9 -0
- package/dist/services/extraction-enrichment.js +223 -0
- package/dist/services/extraction.d.ts +69 -0
- package/dist/services/extraction.js +596 -0
- package/dist/services/fact-normalization.d.ts +12 -0
- package/dist/services/fact-normalization.js +248 -0
- package/dist/services/filecoin-observability.d.ts +127 -0
- package/dist/services/filecoin-observability.js +200 -0
- package/dist/services/first-mention-service.d.ts +76 -0
- package/dist/services/first-mention-service.js +186 -0
- package/dist/services/hierarchical-retrieval.d.ts +49 -0
- package/dist/services/hierarchical-retrieval.js +50 -0
- package/dist/services/ingest-fact-pipeline.d.ts +32 -0
- package/dist/services/ingest-fact-pipeline.js +212 -0
- package/dist/services/ingest-post-write.d.ts +50 -0
- package/dist/services/ingest-post-write.js +117 -0
- package/dist/services/ingest-trace.d.ts +32 -0
- package/dist/services/ingest-trace.js +60 -0
- package/dist/services/input-sanitizer.d.ts +41 -0
- package/dist/services/input-sanitizer.js +135 -0
- package/dist/services/iterative-retrieval.d.ts +26 -0
- package/dist/services/iterative-retrieval.js +139 -0
- package/dist/services/keyword-expansion.d.ts +10 -0
- package/dist/services/keyword-expansion.js +26 -0
- package/dist/services/lesson-service.d.ts +68 -0
- package/dist/services/lesson-service.js +178 -0
- package/dist/services/literal-extractor.d.ts +16 -0
- package/dist/services/literal-extractor.js +74 -0
- package/dist/services/literal-list-protection.d.ts +17 -0
- package/dist/services/literal-list-protection.js +134 -0
- package/dist/services/literal-query-expansion.d.ts +20 -0
- package/dist/services/literal-query-expansion.js +181 -0
- package/dist/services/llm.d.ts +61 -0
- package/dist/services/llm.js +265 -0
- package/dist/services/memcell-projection.d.ts +17 -0
- package/dist/services/memcell-projection.js +41 -0
- package/dist/services/memory-audn.d.ts +43 -0
- package/dist/services/memory-audn.js +419 -0
- package/dist/services/memory-crud.d.ts +93 -0
- package/dist/services/memory-crud.js +255 -0
- package/dist/services/memory-ingest.d.ts +21 -0
- package/dist/services/memory-ingest.js +249 -0
- package/dist/services/memory-lifecycle.d.ts +75 -0
- package/dist/services/memory-lifecycle.js +108 -0
- package/dist/services/memory-lineage.d.ts +181 -0
- package/dist/services/memory-lineage.js +232 -0
- package/dist/services/memory-network.d.ts +40 -0
- package/dist/services/memory-network.js +75 -0
- package/dist/services/memory-search-types.d.ts +25 -0
- package/dist/services/memory-search-types.js +10 -0
- package/dist/services/memory-search.d.ts +48 -0
- package/dist/services/memory-search.js +505 -0
- package/dist/services/memory-service-types.d.ts +371 -0
- package/dist/services/memory-service-types.js +8 -0
- package/dist/services/memory-service.d.ts +152 -0
- package/dist/services/memory-service.js +225 -0
- package/dist/services/memory-storage.d.ts +33 -0
- package/dist/services/memory-storage.js +328 -0
- package/dist/services/msr-aggregator.d.ts +38 -0
- package/dist/services/msr-aggregator.js +97 -0
- package/dist/services/msr-detector.d.ts +35 -0
- package/dist/services/msr-detector.js +65 -0
- package/dist/services/namespace-retrieval.d.ts +60 -0
- package/dist/services/namespace-retrieval.js +180 -0
- package/dist/services/observation-date-extraction.d.ts +12 -0
- package/dist/services/observation-date-extraction.js +50 -0
- package/dist/services/observation-service.d.ts +27 -0
- package/dist/services/observation-service.js +84 -0
- package/dist/services/packaging-observability.d.ts +29 -0
- package/dist/services/packaging-observability.js +146 -0
- package/dist/services/query-expansion.d.ts +83 -0
- package/dist/services/query-expansion.js +242 -0
- package/dist/services/query-keyword-matches.d.ts +6 -0
- package/dist/services/query-keyword-matches.js +56 -0
- package/dist/services/query-term-visibility.d.ts +28 -0
- package/dist/services/query-term-visibility.js +100 -0
- package/dist/services/quick-extraction.d.ts +25 -0
- package/dist/services/quick-extraction.js +431 -0
- package/dist/services/quoted-entity-extraction.d.ts +10 -0
- package/dist/services/quoted-entity-extraction.js +161 -0
- package/dist/services/raw-storage-reconciler-backoff.d.ts +8 -0
- package/dist/services/raw-storage-reconciler-backoff.js +14 -0
- package/dist/services/raw-storage-reconciler-scheduler.d.ts +29 -0
- package/dist/services/raw-storage-reconciler-scheduler.js +43 -0
- package/dist/services/raw-storage-reconciler.d.ts +71 -0
- package/dist/services/raw-storage-reconciler.js +278 -0
- package/dist/services/recap-builder.d.ts +49 -0
- package/dist/services/recap-builder.js +157 -0
- package/dist/services/reflect-jobs.d.ts +23 -0
- package/dist/services/reflect-jobs.js +36 -0
- package/dist/services/reflect-prompts.d.ts +71 -0
- package/dist/services/reflect-prompts.js +99 -0
- package/dist/services/reflect-retrieval.d.ts +33 -0
- package/dist/services/reflect-retrieval.js +30 -0
- package/dist/services/reflect.d.ts +49 -0
- package/dist/services/reflect.js +84 -0
- package/dist/services/relative-temporal.d.ts +14 -0
- package/dist/services/relative-temporal.js +163 -0
- package/dist/services/relevance-policy.d.ts +37 -0
- package/dist/services/relevance-policy.js +109 -0
- package/dist/services/rerank.d.ts +32 -0
- package/dist/services/rerank.js +118 -0
- package/dist/services/reranker.d.ts +20 -0
- package/dist/services/reranker.js +99 -0
- package/dist/services/retrieval-channel-rules.d.ts +34 -0
- package/dist/services/retrieval-channel-rules.js +41 -0
- package/dist/services/retrieval-config-overlay.d.ts +36 -0
- package/dist/services/retrieval-config-overlay.js +44 -0
- package/dist/services/retrieval-format.d.ts +119 -0
- package/dist/services/retrieval-format.js +559 -0
- package/dist/services/retrieval-policy.d.ts +69 -0
- package/dist/services/retrieval-policy.js +275 -0
- package/dist/services/retrieval-profiles.d.ts +37 -0
- package/dist/services/retrieval-profiles.js +90 -0
- package/dist/services/retrieval-side-effects.d.ts +14 -0
- package/dist/services/retrieval-side-effects.js +26 -0
- package/dist/services/retrieval-trace.d.ts +108 -0
- package/dist/services/retrieval-trace.js +147 -0
- package/dist/services/rrf-fusion.d.ts +18 -0
- package/dist/services/rrf-fusion.js +34 -0
- package/dist/services/search-pipeline.d.ts +71 -0
- package/dist/services/search-pipeline.js +788 -0
- package/dist/services/session-date.d.ts +20 -0
- package/dist/services/session-date.js +61 -0
- package/dist/services/session-packaging.d.ts +53 -0
- package/dist/services/session-packaging.js +182 -0
- package/dist/services/session-summary-generator.d.ts +53 -0
- package/dist/services/session-summary-generator.js +134 -0
- package/dist/services/specialists/cr-specialist.d.ts +52 -0
- package/dist/services/specialists/cr-specialist.js +121 -0
- package/dist/services/specialists/dispatch.d.ts +53 -0
- package/dist/services/specialists/dispatch.js +102 -0
- package/dist/services/specialists/ie-ku-specialist.d.ts +37 -0
- package/dist/services/specialists/ie-ku-specialist.js +63 -0
- package/dist/services/specialists/msr-specialist.d.ts +61 -0
- package/dist/services/specialists/msr-specialist.js +162 -0
- package/dist/services/specialists/tr-specialist.d.ts +37 -0
- package/dist/services/specialists/tr-specialist.js +146 -0
- package/dist/services/storage-key-prefix.d.ts +42 -0
- package/dist/services/storage-key-prefix.js +45 -0
- package/dist/services/storage-put-recovery.d.ts +71 -0
- package/dist/services/storage-put-recovery.js +269 -0
- package/dist/services/storage-service-errors.d.ts +124 -0
- package/dist/services/storage-service-errors.js +189 -0
- package/dist/services/storage-service.d.ts +176 -0
- package/dist/services/storage-service.js +423 -0
- package/dist/services/subject-aware-ranking.d.ts +19 -0
- package/dist/services/subject-aware-ranking.js +161 -0
- package/dist/services/supplemental-extraction.d.ts +7 -0
- package/dist/services/supplemental-extraction.js +116 -0
- package/dist/services/tbc-execution.d.ts +49 -0
- package/dist/services/tbc-execution.js +284 -0
- package/dist/services/temporal-classifier.d.ts +56 -0
- package/dist/services/temporal-classifier.js +94 -0
- package/dist/services/temporal-endpoint-evidence.d.ts +12 -0
- package/dist/services/temporal-endpoint-evidence.js +313 -0
- package/dist/services/temporal-fingerprint.d.ts +6 -0
- package/dist/services/temporal-fingerprint.js +12 -0
- package/dist/services/temporal-format.d.ts +9 -0
- package/dist/services/temporal-format.js +21 -0
- package/dist/services/temporal-intent.d.ts +39 -0
- package/dist/services/temporal-intent.js +78 -0
- package/dist/services/temporal-query-constraints.d.ts +16 -0
- package/dist/services/temporal-query-constraints.js +107 -0
- package/dist/services/temporal-query-expansion.d.ts +14 -0
- package/dist/services/temporal-query-expansion.js +131 -0
- package/dist/services/temporal-rerank.d.ts +22 -0
- package/dist/services/temporal-rerank.js +47 -0
- package/dist/services/temporal-result-protection.d.ts +7 -0
- package/dist/services/temporal-result-protection.js +60 -0
- package/dist/services/temporal-state-write.d.ts +57 -0
- package/dist/services/temporal-state-write.js +45 -0
- package/dist/services/tiered-context.d.ts +87 -0
- package/dist/services/tiered-context.js +214 -0
- package/dist/services/tiered-loading.d.ts +88 -0
- package/dist/services/tiered-loading.js +263 -0
- package/dist/services/timeline-pack.d.ts +36 -0
- package/dist/services/timeline-pack.js +50 -0
- package/dist/services/timing.d.ts +13 -0
- package/dist/services/timing.js +72 -0
- package/dist/services/tll-augmentation.d.ts +20 -0
- package/dist/services/tll-augmentation.js +125 -0
- package/dist/services/tll-retrieval.d.ts +55 -0
- package/dist/services/tll-retrieval.js +101 -0
- package/dist/services/topic-abstraction.d.ts +36 -0
- package/dist/services/topic-abstraction.js +105 -0
- package/dist/services/trust-scoring.d.ts +43 -0
- package/dist/services/trust-scoring.js +89 -0
- package/dist/services/typed-belief-calculus.d.ts +126 -0
- package/dist/services/typed-belief-calculus.js +204 -0
- package/dist/services/upload-config.d.ts +34 -0
- package/dist/services/upload-config.js +23 -0
- package/dist/services/upload-decision.d.ts +65 -0
- package/dist/services/upload-decision.js +98 -0
- package/dist/services/upload-helpers.d.ts +107 -0
- package/dist/services/upload-helpers.js +148 -0
- package/dist/services/user-profile-builder.d.ts +22 -0
- package/dist/services/user-profile-builder.js +109 -0
- package/dist/services/voyage-embedding.d.ts +22 -0
- package/dist/services/voyage-embedding.js +77 -0
- package/dist/services/write-security.d.ts +31 -0
- package/dist/services/write-security.js +64 -0
- package/dist/storage/artifact-public-redaction.d.ts +34 -0
- package/dist/storage/artifact-public-redaction.js +83 -0
- package/dist/storage/cleanup.d.ts +103 -0
- package/dist/storage/cleanup.js +138 -0
- package/dist/storage/codec-factory.d.ts +17 -0
- package/dist/storage/codec-factory.js +33 -0
- package/dist/storage/codecs/aes-gcm-codec.d.ts +44 -0
- package/dist/storage/codecs/aes-gcm-codec.js +108 -0
- package/dist/storage/codecs/noop-codec.d.ts +16 -0
- package/dist/storage/codecs/noop-codec.js +23 -0
- package/dist/storage/factory.d.ts +44 -0
- package/dist/storage/factory.js +99 -0
- package/dist/storage/filecoin-cid-validation.d.ts +82 -0
- package/dist/storage/filecoin-cid-validation.js +122 -0
- package/dist/storage/filecoin-public-metadata.d.ts +73 -0
- package/dist/storage/filecoin-public-metadata.js +110 -0
- package/dist/storage/local-fs-store.d.ts +39 -0
- package/dist/storage/local-fs-store.js +145 -0
- package/dist/storage/pointer-uri-allowlist.d.ts +38 -0
- package/dist/storage/pointer-uri-allowlist.js +70 -0
- package/dist/storage/provider-metadata-projection.d.ts +27 -0
- package/dist/storage/provider-metadata-projection.js +68 -0
- package/dist/storage/providers/filecoin/backend.d.ts +42 -0
- package/dist/storage/providers/filecoin/backend.js +250 -0
- package/dist/storage/providers/filecoin/config.d.ts +70 -0
- package/dist/storage/providers/filecoin/config.js +275 -0
- package/dist/storage/providers/filecoin/errors.d.ts +45 -0
- package/dist/storage/providers/filecoin/errors.js +56 -0
- package/dist/storage/providers/filecoin/filecoin-pin-car.d.ts +78 -0
- package/dist/storage/providers/filecoin/filecoin-pin-car.js +155 -0
- package/dist/storage/providers/filecoin/filecoin-pin-client.d.ts +92 -0
- package/dist/storage/providers/filecoin/filecoin-pin-client.js +199 -0
- package/dist/storage/providers/filecoin/filecoin-pin-mapping.d.ts +58 -0
- package/dist/storage/providers/filecoin/filecoin-pin-mapping.js +103 -0
- package/dist/storage/providers/filecoin/filecoin-pin-timeout.d.ts +30 -0
- package/dist/storage/providers/filecoin/filecoin-pin-timeout.js +53 -0
- package/dist/storage/providers/filecoin/filecoin-pin-vendor.d.ts +111 -0
- package/dist/storage/providers/filecoin/filecoin-pin-vendor.js +87 -0
- package/dist/storage/providers/filecoin/hints.d.ts +71 -0
- package/dist/storage/providers/filecoin/hints.js +123 -0
- package/dist/storage/providers/filecoin/index.d.ts +51 -0
- package/dist/storage/providers/filecoin/index.js +103 -0
- package/dist/storage/providers/filecoin/ipfs-cid.d.ts +50 -0
- package/dist/storage/providers/filecoin/ipfs-cid.js +64 -0
- package/dist/storage/providers/filecoin/metadata.d.ts +72 -0
- package/dist/storage/providers/filecoin/metadata.js +137 -0
- package/dist/storage/providers/filecoin/piece-cid.d.ts +48 -0
- package/dist/storage/providers/filecoin/piece-cid.js +57 -0
- package/dist/storage/providers/filecoin/provider-client.d.ts +234 -0
- package/dist/storage/providers/filecoin/provider-client.js +27 -0
- package/dist/storage/providers/filecoin/readiness.d.ts +62 -0
- package/dist/storage/providers/filecoin/readiness.js +85 -0
- package/dist/storage/providers/filecoin/retriever.d.ts +82 -0
- package/dist/storage/providers/filecoin/retriever.js +63 -0
- package/dist/storage/providers/filecoin/skeleton-client.d.ts +36 -0
- package/dist/storage/providers/filecoin/skeleton-client.js +55 -0
- package/dist/storage/providers/filecoin/synapse-client.d.ts +169 -0
- package/dist/storage/providers/filecoin/synapse-client.js +343 -0
- package/dist/storage/providers/filecoin/synapse-construction.d.ts +26 -0
- package/dist/storage/providers/filecoin/synapse-construction.js +47 -0
- package/dist/storage/providers/filecoin/synapse-error-mapping.d.ts +23 -0
- package/dist/storage/providers/filecoin/synapse-error-mapping.js +49 -0
- package/dist/storage/providers/filecoin/synapse-readiness.d.ts +37 -0
- package/dist/storage/providers/filecoin/synapse-readiness.js +231 -0
- package/dist/storage/providers/filecoin/uri.d.ts +49 -0
- package/dist/storage/providers/filecoin/uri.js +84 -0
- package/dist/storage/providers/filecoin/verified-fetch-lifecycle.d.ts +77 -0
- package/dist/storage/providers/filecoin/verified-fetch-lifecycle.js +196 -0
- package/dist/storage/providers/filecoin/verified-fetch-retriever.d.ts +54 -0
- package/dist/storage/providers/filecoin/verified-fetch-retriever.js +81 -0
- package/dist/storage/providers/filecoin/verified-fetch-vendor.d.ts +71 -0
- package/dist/storage/providers/filecoin/verified-fetch-vendor.js +94 -0
- package/dist/storage/raw-content-codec.d.ts +89 -0
- package/dist/storage/raw-content-codec.js +47 -0
- package/dist/storage/raw-content-store-backend-adapter.d.ts +28 -0
- package/dist/storage/raw-content-store-backend-adapter.js +67 -0
- package/dist/storage/raw-content-store.d.ts +228 -0
- package/dist/storage/raw-content-store.js +27 -0
- package/dist/storage/s3-store.d.ts +42 -0
- package/dist/storage/s3-store.js +181 -0
- package/dist/storage/storage-backend-registry.d.ts +58 -0
- package/dist/storage/storage-backend-registry.js +56 -0
- package/dist/storage/storage-backend.d.ts +82 -0
- package/dist/storage/storage-backend.js +14 -0
- package/dist/storage/storage-capabilities.d.ts +56 -0
- package/dist/storage/storage-capabilities.js +170 -0
- package/dist/storage/store-registry.d.ts +67 -0
- package/dist/storage/store-registry.js +77 -0
- package/dist/vector-math.d.ts +15 -0
- package/dist/vector-math.js +31 -0
- package/dist/xml-escape.d.ts +5 -0
- package/dist/xml-escape.js +7 -0
- package/openapi.json +15395 -0
- package/openapi.yaml +10794 -0
- package/package.json +119 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity-card synthesis (BEAM-0.85 — always-on ENTITY_CARD channel).
|
|
3
|
+
*
|
|
4
|
+
* Pure dependency-injected: callers provide `llmCallTool` (typically Sonnet 4.5)
|
|
5
|
+
* and the prior card lookup. For each entity with at least
|
|
6
|
+
* `minObservations` new observations in the current Reflect run, the
|
|
7
|
+
* synthesizer assembles a `buildEntityCardMessages` prompt and calls the
|
|
8
|
+
* model to produce an updated card. The output for one entity has no
|
|
9
|
+
* dependency on the output for any other entity — callers parallelize via
|
|
10
|
+
* Promise.allSettled to fail-soft on individual synthesis errors.
|
|
11
|
+
*
|
|
12
|
+
* No silent error catching: errors from `llmCallTool` propagate to the
|
|
13
|
+
* Promise.allSettled boundary in the caller, which logs each rejection.
|
|
14
|
+
*/
|
|
15
|
+
import { buildEntityCardMessages, } from './reflect-prompts.js';
|
|
16
|
+
/** Schema for the tool-use call that returns the updated card text. */
|
|
17
|
+
const ENTITY_CARD_TOOL_SCHEMA = {
|
|
18
|
+
name: 'record_entity_card',
|
|
19
|
+
description: 'Persist the updated entity card text.',
|
|
20
|
+
input_schema: {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: { card_text: { type: 'string' } },
|
|
23
|
+
required: ['card_text'],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Group observations by entity_name. The entity is extracted from
|
|
28
|
+
* entity_state observations whose text begins with "<EntityName>:" or
|
|
29
|
+
* a leading capitalized noun before the first colon/verb.
|
|
30
|
+
*
|
|
31
|
+
* Heuristic (simplified — see compromises in report): the first capitalized
|
|
32
|
+
* token sequence at the start of the observation text. The literal token
|
|
33
|
+
* "User" / "user" maps to the canonical entity "user".
|
|
34
|
+
*/
|
|
35
|
+
export function groupObservationsByEntity(observations) {
|
|
36
|
+
const grouped = new Map();
|
|
37
|
+
for (const obs of observations) {
|
|
38
|
+
const entity = extractEntityName(obs);
|
|
39
|
+
if (!entity)
|
|
40
|
+
continue;
|
|
41
|
+
const list = grouped.get(entity) ?? [];
|
|
42
|
+
list.push(obs);
|
|
43
|
+
grouped.set(entity, list);
|
|
44
|
+
}
|
|
45
|
+
return grouped;
|
|
46
|
+
}
|
|
47
|
+
const USER_PREFIX = /^\s*(user|the user|you)\b/i;
|
|
48
|
+
const CAPITALIZED_PHRASE = /^([A-Z][A-Za-z0-9_-]*(?:\s+[A-Z][A-Za-z0-9_-]*){0,2})\b/;
|
|
49
|
+
function extractEntityName(obs) {
|
|
50
|
+
// entity_state observations are the strongest signal — but any observation
|
|
51
|
+
// that starts with a capitalized noun phrase or the literal "user"
|
|
52
|
+
// contributes to that entity's card.
|
|
53
|
+
const text = obs.text.trim();
|
|
54
|
+
if (USER_PREFIX.test(text))
|
|
55
|
+
return 'user';
|
|
56
|
+
const m = CAPITALIZED_PHRASE.exec(text);
|
|
57
|
+
if (m)
|
|
58
|
+
return m[1].trim();
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Synthesize ENTITY_CARDs for every entity with >= minObservations
|
|
63
|
+
* observations in the current Reflect run. Prior cards are looked up
|
|
64
|
+
* by entity_name; absent entities use the empty prior. Returns one
|
|
65
|
+
* EntityCardSynth per synthesized entity.
|
|
66
|
+
*/
|
|
67
|
+
export async function synthesizeCards(observations, priorCards, deps) {
|
|
68
|
+
const grouped = groupObservationsByEntity(observations);
|
|
69
|
+
const eligible = Array.from(grouped.entries())
|
|
70
|
+
.filter(([, list]) => list.length >= deps.minObservations)
|
|
71
|
+
.slice(0, deps.maxEntities);
|
|
72
|
+
const results = [];
|
|
73
|
+
for (const [entityName, list] of eligible) {
|
|
74
|
+
const obsInputs = list.map(o => ({
|
|
75
|
+
id: o.id,
|
|
76
|
+
text: o.text,
|
|
77
|
+
observedAt: o.observedAt,
|
|
78
|
+
}));
|
|
79
|
+
const priorText = priorCards.get(entityName) ?? null;
|
|
80
|
+
const { system, user } = buildEntityCardMessages(entityName, priorText, obsInputs);
|
|
81
|
+
const out = await deps.llmCallTool(system, user, ENTITY_CARD_TOOL_SCHEMA);
|
|
82
|
+
const cardText = (out.card_text ?? '').trim();
|
|
83
|
+
if (!cardText)
|
|
84
|
+
continue;
|
|
85
|
+
results.push({
|
|
86
|
+
entityName,
|
|
87
|
+
cardText,
|
|
88
|
+
sourceObservationIds: list.map(o => o.id),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
return results;
|
|
92
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared entity deduplication utility.
|
|
3
|
+
*
|
|
4
|
+
* Placed in its own module to avoid extending the circular dependency between
|
|
5
|
+
* extraction.ts, extraction-enrichment.ts, and event-anchor-facts.ts.
|
|
6
|
+
*/
|
|
7
|
+
import type { ExtractedEntity } from './extraction.js';
|
|
8
|
+
/** Deduplicate entities by type+lowered-name key. */
|
|
9
|
+
export declare function dedupeEntities(entities: ExtractedEntity[]): ExtractedEntity[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared entity deduplication utility.
|
|
3
|
+
*
|
|
4
|
+
* Placed in its own module to avoid extending the circular dependency between
|
|
5
|
+
* extraction.ts, extraction-enrichment.ts, and event-anchor-facts.ts.
|
|
6
|
+
*/
|
|
7
|
+
/** Deduplicate entities by type+lowered-name key. */
|
|
8
|
+
export function dedupeEntities(entities) {
|
|
9
|
+
const unique = new Map();
|
|
10
|
+
for (const entity of entities) {
|
|
11
|
+
unique.set(`${entity.type}:${entity.name.toLowerCase()}`, entity);
|
|
12
|
+
}
|
|
13
|
+
return [...unique.values()];
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity co-occurrence graph for spreading activation retrieval.
|
|
3
|
+
*
|
|
4
|
+
* At ingest time: extract entities from fact text, store pairwise co-occurrence edges.
|
|
5
|
+
* At query time: extract query entities, run 3-hop spreading activation, score memories
|
|
6
|
+
* by accumulated activation. Returns ranked memory IDs for RRF fusion with vector search.
|
|
7
|
+
*/
|
|
8
|
+
export interface EntityGraphResult {
|
|
9
|
+
memoryId: string;
|
|
10
|
+
activationScore: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Extract entities from text for graph construction.
|
|
14
|
+
* Captures: proper nouns (capitalized words), technology names, multi-word terms.
|
|
15
|
+
* Returns normalized lowercase entities.
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractEntities(text: string): string[];
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity co-occurrence graph for spreading activation retrieval.
|
|
3
|
+
*
|
|
4
|
+
* At ingest time: extract entities from fact text, store pairwise co-occurrence edges.
|
|
5
|
+
* At query time: extract query entities, run 3-hop spreading activation, score memories
|
|
6
|
+
* by accumulated activation. Returns ranked memory IDs for RRF fusion with vector search.
|
|
7
|
+
*/
|
|
8
|
+
import { storeEntityEdges, findNeighbors, findMemoriesForEntities, removeEntityEdges as removeEdges, } from '../db/repository-entity-graph.js';
|
|
9
|
+
/** Spreading activation parameters (SLM-V3: γ=0.7, maxHops=3). */
|
|
10
|
+
const ACTIVATION_DECAY = 0.7;
|
|
11
|
+
const MAX_HOPS = 3;
|
|
12
|
+
const ACTIVATION_THRESHOLD = 0.01;
|
|
13
|
+
/** Minimum entity length for graph inclusion. */
|
|
14
|
+
const MIN_ENTITY_LENGTH = 3;
|
|
15
|
+
/**
|
|
16
|
+
* Stopwords excluded from entity extraction.
|
|
17
|
+
* Broader than AUDN conflict keywords — filters common verbs, prepositions, articles.
|
|
18
|
+
*/
|
|
19
|
+
const STOPWORDS = new Set([
|
|
20
|
+
'the', 'and', 'for', 'that', 'this', 'with', 'from', 'have', 'has', 'had',
|
|
21
|
+
'was', 'were', 'been', 'being', 'will', 'would', 'could', 'should', 'might',
|
|
22
|
+
'also', 'just', 'about', 'into', 'over', 'after', 'before', 'between',
|
|
23
|
+
'through', 'during', 'each', 'other', 'some', 'such', 'than', 'then',
|
|
24
|
+
'these', 'those', 'when', 'where', 'which', 'while', 'their', 'there',
|
|
25
|
+
'they', 'them', 'what', 'who', 'how', 'very', 'more', 'most', 'only',
|
|
26
|
+
'same', 'does', 'doing', 'done', 'using', 'used', 'uses', 'user',
|
|
27
|
+
'like', 'want', 'wants', 'make', 'made', 'making', 'work', 'working',
|
|
28
|
+
'plan', 'plans', 'planning', 'currently', 'recently', 'project',
|
|
29
|
+
'maybe', 'might', 'perhaps', 'check', 'tomorrow', 'sure', 'think',
|
|
30
|
+
'not',
|
|
31
|
+
]);
|
|
32
|
+
/**
|
|
33
|
+
* Extract entities from text for graph construction.
|
|
34
|
+
* Captures: proper nouns (capitalized words), technology names, multi-word terms.
|
|
35
|
+
* Returns normalized lowercase entities.
|
|
36
|
+
*/
|
|
37
|
+
export function extractEntities(text) {
|
|
38
|
+
const entities = new Set();
|
|
39
|
+
const words = text.match(/[A-Za-z][A-Za-z0-9._-]*/g) ?? [];
|
|
40
|
+
for (const word of words) {
|
|
41
|
+
const lower = word.toLowerCase();
|
|
42
|
+
if (lower.length < MIN_ENTITY_LENGTH)
|
|
43
|
+
continue;
|
|
44
|
+
if (STOPWORDS.has(lower))
|
|
45
|
+
continue;
|
|
46
|
+
entities.add(lower);
|
|
47
|
+
}
|
|
48
|
+
const compoundPatterns = [
|
|
49
|
+
/[A-Z][a-z]+(?:\s+[A-Z][a-z]+)+/g,
|
|
50
|
+
/[A-Za-z]+[._-][A-Za-z]+/g,
|
|
51
|
+
];
|
|
52
|
+
for (const pattern of compoundPatterns) {
|
|
53
|
+
const matches = text.match(pattern) ?? [];
|
|
54
|
+
for (const match of matches) {
|
|
55
|
+
const normalized = match.toLowerCase().replace(/\s+/g, '_');
|
|
56
|
+
if (normalized.length >= MIN_ENTITY_LENGTH) {
|
|
57
|
+
entities.add(normalized);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return [...entities];
|
|
62
|
+
}
|
|
63
|
+
/** Update entity graph after storing a new memory. */
|
|
64
|
+
async function updateEntityGraph(pool, userId, memoryId, factText) {
|
|
65
|
+
const entities = extractEntities(factText);
|
|
66
|
+
return storeEntityEdges(pool, userId, memoryId, entities);
|
|
67
|
+
}
|
|
68
|
+
/** Replace entity graph edges for a memory (used on UPDATE/SUPERSEDE). */
|
|
69
|
+
async function replaceEntityEdges(pool, userId, memoryId, factText) {
|
|
70
|
+
await removeEdges(pool, memoryId);
|
|
71
|
+
return updateEntityGraph(pool, userId, memoryId, factText);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 3-hop spreading activation from query entities.
|
|
75
|
+
* Returns memories scored by accumulated activation, sorted descending.
|
|
76
|
+
*
|
|
77
|
+
* Algorithm:
|
|
78
|
+
* 1. Seed activation map with query entities (activation=1.0)
|
|
79
|
+
* 2. For each hop: find neighbors, propagate activation * γ
|
|
80
|
+
* 3. Collect all activated entities, find linked memories
|
|
81
|
+
* 4. Score each memory by sum of activations from its linked entities
|
|
82
|
+
*/
|
|
83
|
+
async function spreadingActivation(pool, userId, queryText, limit) {
|
|
84
|
+
const queryEntities = extractEntities(queryText);
|
|
85
|
+
if (queryEntities.length === 0)
|
|
86
|
+
return [];
|
|
87
|
+
const activation = seedActivationMap(queryEntities);
|
|
88
|
+
await propagateActivation(pool, userId, activation);
|
|
89
|
+
return scoreMemoriesByActivation(pool, userId, activation, limit);
|
|
90
|
+
}
|
|
91
|
+
/** Initialize activation map with query entities at full activation. */
|
|
92
|
+
function seedActivationMap(entities) {
|
|
93
|
+
const activation = new Map();
|
|
94
|
+
for (const entity of entities) {
|
|
95
|
+
activation.set(entity, 1.0);
|
|
96
|
+
}
|
|
97
|
+
return activation;
|
|
98
|
+
}
|
|
99
|
+
/** Propagate activation through the entity graph for MAX_HOPS iterations. */
|
|
100
|
+
async function propagateActivation(pool, userId, activation) {
|
|
101
|
+
for (let hop = 0; hop < MAX_HOPS; hop++) {
|
|
102
|
+
const activeEntities = [...activation.entries()]
|
|
103
|
+
.filter(([, score]) => score >= ACTIVATION_THRESHOLD)
|
|
104
|
+
.map(([entity]) => entity);
|
|
105
|
+
if (activeEntities.length === 0)
|
|
106
|
+
break;
|
|
107
|
+
const neighbors = await findNeighbors(pool, userId, activeEntities);
|
|
108
|
+
for (const neighbor of neighbors) {
|
|
109
|
+
const sourceActivation = activation.get(neighbor.entity) ?? 0;
|
|
110
|
+
if (sourceActivation < ACTIVATION_THRESHOLD)
|
|
111
|
+
continue;
|
|
112
|
+
const propagated = sourceActivation * ACTIVATION_DECAY;
|
|
113
|
+
const existing = activation.get(neighbor.entity) ?? 0;
|
|
114
|
+
activation.set(neighbor.entity, Math.max(existing, propagated));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Score memories by summing activation from their linked entities. */
|
|
119
|
+
async function scoreMemoriesByActivation(pool, userId, activation, limit) {
|
|
120
|
+
const allActivatedEntities = [...activation.entries()]
|
|
121
|
+
.filter(([, score]) => score >= ACTIVATION_THRESHOLD)
|
|
122
|
+
.map(([entity]) => entity);
|
|
123
|
+
if (allActivatedEntities.length === 0)
|
|
124
|
+
return [];
|
|
125
|
+
const memoryEntities = await findMemoriesForEntities(pool, userId, allActivatedEntities);
|
|
126
|
+
const memoryScores = new Map();
|
|
127
|
+
for (const { memoryId, entity } of memoryEntities) {
|
|
128
|
+
const current = memoryScores.get(memoryId) ?? 0;
|
|
129
|
+
memoryScores.set(memoryId, current + (activation.get(entity) ?? 0));
|
|
130
|
+
}
|
|
131
|
+
return [...memoryScores.entries()]
|
|
132
|
+
.sort((a, b) => b[1] - a[1])
|
|
133
|
+
.slice(0, limit)
|
|
134
|
+
.map(([memoryId, activationScore]) => ({ memoryId, activationScore }));
|
|
135
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entropy-Aware Write Gating.
|
|
3
|
+
*
|
|
4
|
+
* Filters low-information writes before they reach the memory store.
|
|
5
|
+
* A candidate memory is discarded if its entropy score falls below
|
|
6
|
+
* ENTROPY_THRESHOLD (default 0.35), meaning it adds little novel
|
|
7
|
+
* information relative to what's already stored.
|
|
8
|
+
*
|
|
9
|
+
* Entropy score combines two signals:
|
|
10
|
+
* - Entity novelty: ratio of new entities to total entities in the text
|
|
11
|
+
* - Semantic novelty: cosine distance from the previous context embedding
|
|
12
|
+
*
|
|
13
|
+
* Source: SimpleMem pattern (entropy-aware gating at threshold 0.35).
|
|
14
|
+
*/
|
|
15
|
+
import { cosineSimilarity } from '../vector-math.js';
|
|
16
|
+
export interface EntropyGateConfig {
|
|
17
|
+
threshold: number;
|
|
18
|
+
alpha: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const DEFAULT_ENTROPY_CONFIG: EntropyGateConfig;
|
|
21
|
+
export interface EntropyInput {
|
|
22
|
+
/** Entities extracted from the candidate text. */
|
|
23
|
+
windowEntities: string[];
|
|
24
|
+
/** Entities already known from existing memories. */
|
|
25
|
+
existingEntities: Set<string>;
|
|
26
|
+
/** Embedding of the candidate text. */
|
|
27
|
+
windowEmbedding: number[];
|
|
28
|
+
/** Embedding of the previous context window (null if first). */
|
|
29
|
+
previousEmbedding: number[] | null;
|
|
30
|
+
}
|
|
31
|
+
export interface EntropyResult {
|
|
32
|
+
score: number;
|
|
33
|
+
entityNovelty: number;
|
|
34
|
+
semanticNovelty: number;
|
|
35
|
+
accepted: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Compute the entropy score for a candidate memory.
|
|
39
|
+
* Score = α × entityNovelty + (1-α) × semanticNovelty.
|
|
40
|
+
*/
|
|
41
|
+
export declare function computeEntropyScore(input: EntropyInput, config?: EntropyGateConfig): EntropyResult;
|
|
42
|
+
/**
|
|
43
|
+
* Ratio of new (unseen) entities to total entities in the window.
|
|
44
|
+
* Returns 1.0 if no entities are present (assume novel).
|
|
45
|
+
*/
|
|
46
|
+
export declare function computeEntityNovelty(windowEntities: string[], existingEntities: Set<string>): number;
|
|
47
|
+
/**
|
|
48
|
+
* Semantic distance from previous context embedding.
|
|
49
|
+
* Returns 1.0 if no previous embedding exists (assume fully novel).
|
|
50
|
+
*/
|
|
51
|
+
export declare function computeSemanticNovelty(current: number[], previous: number[] | null): number;
|
|
52
|
+
export { cosineSimilarity };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entropy-Aware Write Gating.
|
|
3
|
+
*
|
|
4
|
+
* Filters low-information writes before they reach the memory store.
|
|
5
|
+
* A candidate memory is discarded if its entropy score falls below
|
|
6
|
+
* ENTROPY_THRESHOLD (default 0.35), meaning it adds little novel
|
|
7
|
+
* information relative to what's already stored.
|
|
8
|
+
*
|
|
9
|
+
* Entropy score combines two signals:
|
|
10
|
+
* - Entity novelty: ratio of new entities to total entities in the text
|
|
11
|
+
* - Semantic novelty: cosine distance from the previous context embedding
|
|
12
|
+
*
|
|
13
|
+
* Source: SimpleMem pattern (entropy-aware gating at threshold 0.35).
|
|
14
|
+
*/
|
|
15
|
+
import { cosineSimilarity } from '../vector-math.js';
|
|
16
|
+
const DEFAULT_ENTROPY_THRESHOLD = 0.35;
|
|
17
|
+
const DEFAULT_ALPHA = 0.5;
|
|
18
|
+
export const DEFAULT_ENTROPY_CONFIG = {
|
|
19
|
+
threshold: DEFAULT_ENTROPY_THRESHOLD,
|
|
20
|
+
alpha: DEFAULT_ALPHA,
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Compute the entropy score for a candidate memory.
|
|
24
|
+
* Score = α × entityNovelty + (1-α) × semanticNovelty.
|
|
25
|
+
*/
|
|
26
|
+
export function computeEntropyScore(input, config = DEFAULT_ENTROPY_CONFIG) {
|
|
27
|
+
const entityNovelty = computeEntityNovelty(input.windowEntities, input.existingEntities);
|
|
28
|
+
const semanticNovelty = computeSemanticNovelty(input.windowEmbedding, input.previousEmbedding);
|
|
29
|
+
const score = config.alpha * entityNovelty + (1 - config.alpha) * semanticNovelty;
|
|
30
|
+
return {
|
|
31
|
+
score,
|
|
32
|
+
entityNovelty,
|
|
33
|
+
semanticNovelty,
|
|
34
|
+
accepted: score >= config.threshold,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Ratio of new (unseen) entities to total entities in the window.
|
|
39
|
+
* Returns 1.0 if no entities are present (assume novel).
|
|
40
|
+
*/
|
|
41
|
+
export function computeEntityNovelty(windowEntities, existingEntities) {
|
|
42
|
+
if (windowEntities.length === 0)
|
|
43
|
+
return 1.0;
|
|
44
|
+
const newCount = windowEntities.filter((e) => !existingEntities.has(e)).length;
|
|
45
|
+
return newCount / windowEntities.length;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Semantic distance from previous context embedding.
|
|
49
|
+
* Returns 1.0 if no previous embedding exists (assume fully novel).
|
|
50
|
+
*/
|
|
51
|
+
export function computeSemanticNovelty(current, previous) {
|
|
52
|
+
if (!previous || previous.length === 0)
|
|
53
|
+
return 1.0;
|
|
54
|
+
return 1 - cosineSimilarity(current, previous);
|
|
55
|
+
}
|
|
56
|
+
export { cosineSimilarity };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injection-channel fetchers (Sprint 3 v1.5 H2 + v1.6 H4 from haiku-080).
|
|
3
|
+
*
|
|
4
|
+
* Extracted from memory-search.ts to keep that orchestrator under the
|
|
5
|
+
* 400-line cap. Owns the side-channel reads (user-profile + recap top-K)
|
|
6
|
+
* that surface as dedicated prompt sections (`## USER PROFILE`,
|
|
7
|
+
* `## EPISODES`) above the standard `<atomicmem_context>` body.
|
|
8
|
+
*
|
|
9
|
+
* The episodes channel is the alternative to routing recaps through the
|
|
10
|
+
* RRF fan-in — recap rows surface to the answer LLM in their own prompt
|
|
11
|
+
* section instead of displacing atomic facts in top-K.
|
|
12
|
+
*/
|
|
13
|
+
import type { MemoryServiceDeps } from './memory-service-types.js';
|
|
14
|
+
import type { EpisodeForInjection } from './retrieval-format.js';
|
|
15
|
+
/**
|
|
16
|
+
* Fetch the recap-store top-K rows for the given query embedding when the
|
|
17
|
+
* episodes channel flag is on. Returns `[]` whenever the flag is off, the
|
|
18
|
+
* recap store is absent, or no candidates are found.
|
|
19
|
+
*/
|
|
20
|
+
export declare function fetchEpisodesForInjection(deps: MemoryServiceDeps, userId: string, queryEmbedding: number[]): Promise<EpisodeForInjection[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Fetch the pinned user-profile document (Sprint 3 v1.5 — H2). Returns
|
|
23
|
+
* `undefined` when the channel flag is off, the store is null, or no profile
|
|
24
|
+
* row exists for the user. Fail-soft: log + treat as absent on read errors,
|
|
25
|
+
* never block the search path.
|
|
26
|
+
*/
|
|
27
|
+
export declare function fetchUserProfileText(deps: MemoryServiceDeps, userId: string): Promise<string | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Entity-attribute triple promoted into the injection's `## FACTS` channel
|
|
30
|
+
* (Sprint 4 EAI — Task C). Reaches the answer LLM as a pinned line above
|
|
31
|
+
* the standard memories body so atomic facts survive the top-K cutoff.
|
|
32
|
+
*/
|
|
33
|
+
export interface EntityFactForInjection {
|
|
34
|
+
entity: string;
|
|
35
|
+
attribute: string;
|
|
36
|
+
value: string;
|
|
37
|
+
observedAt: Date;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Fetch entity-attribute triples likely relevant to the query. Heuristic:
|
|
41
|
+
* extract nouns + numerics + attribute-like tokens from the query, look them
|
|
42
|
+
* up in the EAI by entity_name OR attribute_key match. Returns most-recent
|
|
43
|
+
* first. Fail-soft: returns [] on any error so the search path never breaks.
|
|
44
|
+
*/
|
|
45
|
+
export declare function fetchEntityFactsForInjection(deps: MemoryServiceDeps, userId: string, query: string): Promise<EntityFactForInjection[]>;
|
|
46
|
+
/** Tokenize the query into lookup-worthy strings. */
|
|
47
|
+
export declare function extractLookupTokens(query: string): string[];
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injection-channel fetchers (Sprint 3 v1.5 H2 + v1.6 H4 from haiku-080).
|
|
3
|
+
*
|
|
4
|
+
* Extracted from memory-search.ts to keep that orchestrator under the
|
|
5
|
+
* 400-line cap. Owns the side-channel reads (user-profile + recap top-K)
|
|
6
|
+
* that surface as dedicated prompt sections (`## USER PROFILE`,
|
|
7
|
+
* `## EPISODES`) above the standard `<atomicmem_context>` body.
|
|
8
|
+
*
|
|
9
|
+
* The episodes channel is the alternative to routing recaps through the
|
|
10
|
+
* RRF fan-in — recap rows surface to the answer LLM in their own prompt
|
|
11
|
+
* section instead of displacing atomic facts in top-K.
|
|
12
|
+
*/
|
|
13
|
+
/** Lower/upper bounds on the recap top-K, to keep the channel signal tight. */
|
|
14
|
+
const EPISODES_TOP_K_MIN = 1;
|
|
15
|
+
const EPISODES_TOP_K_MAX = 5;
|
|
16
|
+
/**
|
|
17
|
+
* Fetch the recap-store top-K rows for the given query embedding when the
|
|
18
|
+
* episodes channel flag is on. Returns `[]` whenever the flag is off, the
|
|
19
|
+
* recap store is absent, or no candidates are found.
|
|
20
|
+
*/
|
|
21
|
+
export async function fetchEpisodesForInjection(deps, userId, queryEmbedding) {
|
|
22
|
+
if (!deps.config.episodesChannelEnabled)
|
|
23
|
+
return [];
|
|
24
|
+
const recapStore = deps.stores.recap;
|
|
25
|
+
if (!recapStore)
|
|
26
|
+
return [];
|
|
27
|
+
const k = clampTopK(deps.config.episodesChannelTopK);
|
|
28
|
+
try {
|
|
29
|
+
const candidates = await recapStore.findRecapCandidates(userId, queryEmbedding, k);
|
|
30
|
+
return candidates.map((row) => ({
|
|
31
|
+
topic: row.topic,
|
|
32
|
+
narrative: row.recap_text,
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
console.warn(`[episodes] fetch failed for user=${userId}: ${err.message}`);
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Fetch the pinned user-profile document (Sprint 3 v1.5 — H2). Returns
|
|
42
|
+
* `undefined` when the channel flag is off, the store is null, or no profile
|
|
43
|
+
* row exists for the user. Fail-soft: log + treat as absent on read errors,
|
|
44
|
+
* never block the search path.
|
|
45
|
+
*/
|
|
46
|
+
export async function fetchUserProfileText(deps, userId) {
|
|
47
|
+
if (!deps.config.userProfileChannelEnabled)
|
|
48
|
+
return undefined;
|
|
49
|
+
const profileStore = deps.stores.userProfile;
|
|
50
|
+
if (!profileStore)
|
|
51
|
+
return undefined;
|
|
52
|
+
try {
|
|
53
|
+
const row = await profileStore.getProfile(userId);
|
|
54
|
+
if (row?.profile_text)
|
|
55
|
+
return row.profile_text;
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
console.warn(`[profile] fetch failed for user=${userId}: ${err.message}`);
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function clampTopK(requested) {
|
|
64
|
+
if (!Number.isFinite(requested))
|
|
65
|
+
return EPISODES_TOP_K_MIN;
|
|
66
|
+
return Math.max(EPISODES_TOP_K_MIN, Math.min(EPISODES_TOP_K_MAX, Math.floor(requested)));
|
|
67
|
+
}
|
|
68
|
+
/** Lower/upper bounds on EAI lookup top-K; mirrors the channel-pattern. */
|
|
69
|
+
const EAI_TOP_K_MIN = 5;
|
|
70
|
+
const EAI_TOP_K_MAX = 40;
|
|
71
|
+
/**
|
|
72
|
+
* Fetch entity-attribute triples likely relevant to the query. Heuristic:
|
|
73
|
+
* extract nouns + numerics + attribute-like tokens from the query, look them
|
|
74
|
+
* up in the EAI by entity_name OR attribute_key match. Returns most-recent
|
|
75
|
+
* first. Fail-soft: returns [] on any error so the search path never breaks.
|
|
76
|
+
*/
|
|
77
|
+
export async function fetchEntityFactsForInjection(deps, userId, query) {
|
|
78
|
+
if (!deps.config.entityAttributesEnabled)
|
|
79
|
+
return [];
|
|
80
|
+
const repo = deps.stores.entityAttributes;
|
|
81
|
+
if (!repo)
|
|
82
|
+
return [];
|
|
83
|
+
const tokens = extractLookupTokens(query);
|
|
84
|
+
if (tokens.length === 0)
|
|
85
|
+
return [];
|
|
86
|
+
try {
|
|
87
|
+
const limit = clampEaiTopK(deps.config.entityAttributesTopK);
|
|
88
|
+
const rows = await repo.findByEntityOrAttribute(userId, tokens, limit);
|
|
89
|
+
return rows.map((r) => ({
|
|
90
|
+
entity: r.entity_name,
|
|
91
|
+
attribute: r.attribute_key,
|
|
92
|
+
value: r.attribute_value,
|
|
93
|
+
observedAt: r.observed_at,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
console.warn(`[eai] fetch failed user=${userId}: ${err.message}`);
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function clampEaiTopK(requested) {
|
|
102
|
+
const value = requested ?? 20;
|
|
103
|
+
if (!Number.isFinite(value))
|
|
104
|
+
return EAI_TOP_K_MIN;
|
|
105
|
+
return Math.max(EAI_TOP_K_MIN, Math.min(EAI_TOP_K_MAX, Math.floor(value)));
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Tokenizer-stopwords for the EAI query→lookup heuristic. Conservative list —
|
|
109
|
+
* drops question-frame words and tiny connectives but keeps domain nouns
|
|
110
|
+
* (e.g. "problems", "features", "columns") so they can match `entity_name`
|
|
111
|
+
* or `attribute_key` rows in the EAI.
|
|
112
|
+
*/
|
|
113
|
+
const STOP_TOKENS = new Set([
|
|
114
|
+
'the', 'a', 'an', 'of', 'in', 'on', 'at', 'to', 'for', 'and', 'or', 'is', 'are', 'was', 'were', 'my', 'your',
|
|
115
|
+
'i', 'you', 'we', 'they', 'what', 'which', 'when', 'where', 'how', 'many', 'much', 'do', 'did', 'have', 'has',
|
|
116
|
+
'had', 'this', 'that', 'these', 'those', 'it', 'its', 'about', 'any', 'some', 'all', 'can', 'could', 'would',
|
|
117
|
+
'should', 'will', 'please', 'tell', 'me', 'show', 'across', 'between', 'from', 'with', 'if',
|
|
118
|
+
'over', 'under', 'same', 'different', 'specific', 'only', 'just', 'simply', 'really', 'very', 'also', 'too',
|
|
119
|
+
]);
|
|
120
|
+
const EAI_TOKEN_MAX = 8;
|
|
121
|
+
const EAI_TOKEN_MIN_LENGTH = 3;
|
|
122
|
+
/** Tokenize the query into lookup-worthy strings. */
|
|
123
|
+
export function extractLookupTokens(query) {
|
|
124
|
+
const words = (query.toLowerCase().match(/[a-z][a-z0-9_-]+/g) ?? []).filter((w) => w.length >= EAI_TOKEN_MIN_LENGTH && !STOP_TOKENS.has(w));
|
|
125
|
+
const numbers = query.match(/\b\d+\b/g) ?? [];
|
|
126
|
+
// Deduplicate, cap at EAI_TOKEN_MAX to keep SQL parameter list small.
|
|
127
|
+
return Array.from(new Set([...words, ...numbers])).slice(0, EAI_TOKEN_MAX);
|
|
128
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic event-anchor fact generation for Cat2-style disambiguation.
|
|
3
|
+
* Converts high-signal extracted facts into explicit event memories such as
|
|
4
|
+
* "event anchor mentorship.received for Jon occurred on June 15 2023" so
|
|
5
|
+
* retrieval and answer-time prompting can rely on structured event labels.
|
|
6
|
+
*/
|
|
7
|
+
import type { ExtractedFact } from './extraction.js';
|
|
8
|
+
export declare function inferEventAnchorFacts(fact: ExtractedFact): ExtractedFact[];
|