@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
package/dist/db/ppr.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personalized PageRank (PPR) for adaptive link expansion.
|
|
3
|
+
*
|
|
4
|
+
* Replaces fixed-depth BFS link expansion with a principled algorithm that
|
|
5
|
+
* propagates relevance scores through the memory graph. PPR naturally handles
|
|
6
|
+
* variable-hop reasoning: densely-connected subgraphs get deeper traversal,
|
|
7
|
+
* while sparse connections receive less signal.
|
|
8
|
+
*
|
|
9
|
+
* Algorithm: Power iteration on the PPR equation:
|
|
10
|
+
* r(t+1) = damping * A_norm * r(t) + (1 - damping) * seed
|
|
11
|
+
*
|
|
12
|
+
* where:
|
|
13
|
+
* seed = initial retrieval scores (normalized to sum=1)
|
|
14
|
+
* A_norm = column-normalized adjacency matrix from memory_links
|
|
15
|
+
* damping = probability of following a link (vs teleporting back to seed)
|
|
16
|
+
*
|
|
17
|
+
* Adapted from HippoRAG (NeurIPS 2024) for AtomicMemory's pgvector + link table
|
|
18
|
+
* architecture.
|
|
19
|
+
*/
|
|
20
|
+
import pg from 'pg';
|
|
21
|
+
export interface PPRConfig {
|
|
22
|
+
/** Probability of following a link vs teleporting back to seed nodes. */
|
|
23
|
+
damping?: number;
|
|
24
|
+
/** Maximum power-iteration rounds. */
|
|
25
|
+
maxIterations?: number;
|
|
26
|
+
/** Convergence threshold (L1 norm of score delta). */
|
|
27
|
+
tolerance?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface PPRResult {
|
|
30
|
+
/** Memory ID → PPR score, sorted descending. Excludes seed nodes. */
|
|
31
|
+
scores: Map<string, number>;
|
|
32
|
+
/** Number of iterations until convergence. */
|
|
33
|
+
iterations: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Run Personalized PageRank over the memory_links graph.
|
|
37
|
+
*
|
|
38
|
+
* @param pool - Postgres connection pool
|
|
39
|
+
* @param seedScores - Map of memory ID → relevance score from initial retrieval
|
|
40
|
+
* @param config - PPR tuning parameters
|
|
41
|
+
* @returns PPR scores for all reachable memories (excluding seeds)
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* Run PPR power iteration over an in-memory adjacency list.
|
|
45
|
+
*
|
|
46
|
+
* Exported separately from the DB-loading wrapper so it can be unit-tested
|
|
47
|
+
* without a database connection.
|
|
48
|
+
*/
|
|
49
|
+
export declare function runPPR(adjacency: Map<string, Set<string>>, seedScores: Map<string, number>, pprConfig?: PPRConfig): PPRResult;
|
|
50
|
+
/**
|
|
51
|
+
* Run PPR with adjacency loaded from the database.
|
|
52
|
+
*
|
|
53
|
+
* Loads the 2-hop subgraph around seed nodes from memory_links, then
|
|
54
|
+
* delegates to the pure runPPR function.
|
|
55
|
+
*/
|
|
56
|
+
export declare function personalizedPageRank(pool: pg.Pool, seedScores: Map<string, number>, pprConfig?: PPRConfig): Promise<PPRResult>;
|
package/dist/db/ppr.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personalized PageRank (PPR) for adaptive link expansion.
|
|
3
|
+
*
|
|
4
|
+
* Replaces fixed-depth BFS link expansion with a principled algorithm that
|
|
5
|
+
* propagates relevance scores through the memory graph. PPR naturally handles
|
|
6
|
+
* variable-hop reasoning: densely-connected subgraphs get deeper traversal,
|
|
7
|
+
* while sparse connections receive less signal.
|
|
8
|
+
*
|
|
9
|
+
* Algorithm: Power iteration on the PPR equation:
|
|
10
|
+
* r(t+1) = damping * A_norm * r(t) + (1 - damping) * seed
|
|
11
|
+
*
|
|
12
|
+
* where:
|
|
13
|
+
* seed = initial retrieval scores (normalized to sum=1)
|
|
14
|
+
* A_norm = column-normalized adjacency matrix from memory_links
|
|
15
|
+
* damping = probability of following a link (vs teleporting back to seed)
|
|
16
|
+
*
|
|
17
|
+
* Adapted from HippoRAG (NeurIPS 2024) for AtomicMemory's pgvector + link table
|
|
18
|
+
* architecture.
|
|
19
|
+
*/
|
|
20
|
+
const DEFAULT_DAMPING = 0.5;
|
|
21
|
+
const DEFAULT_MAX_ITERATIONS = 20;
|
|
22
|
+
const DEFAULT_TOLERANCE = 1e-6;
|
|
23
|
+
/**
|
|
24
|
+
* Run Personalized PageRank over the memory_links graph.
|
|
25
|
+
*
|
|
26
|
+
* @param pool - Postgres connection pool
|
|
27
|
+
* @param seedScores - Map of memory ID → relevance score from initial retrieval
|
|
28
|
+
* @param config - PPR tuning parameters
|
|
29
|
+
* @returns PPR scores for all reachable memories (excluding seeds)
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Run PPR power iteration over an in-memory adjacency list.
|
|
33
|
+
*
|
|
34
|
+
* Exported separately from the DB-loading wrapper so it can be unit-tested
|
|
35
|
+
* without a database connection.
|
|
36
|
+
*/
|
|
37
|
+
export function runPPR(adjacency, seedScores, pprConfig = {}) {
|
|
38
|
+
if (seedScores.size === 0 || adjacency.size === 0) {
|
|
39
|
+
return { scores: new Map(), iterations: 0 };
|
|
40
|
+
}
|
|
41
|
+
const damping = pprConfig.damping ?? DEFAULT_DAMPING;
|
|
42
|
+
const maxIterations = pprConfig.maxIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
43
|
+
const tolerance = pprConfig.tolerance ?? DEFAULT_TOLERANCE;
|
|
44
|
+
const allNodes = collectNodes(adjacency, seedScores);
|
|
45
|
+
const seed = normalizeSeed(seedScores, allNodes);
|
|
46
|
+
const outDegree = computeOutDegree(adjacency, allNodes);
|
|
47
|
+
const { scores, iterations } = iteratePPR(allNodes, seed, adjacency, outDegree, damping, maxIterations, tolerance);
|
|
48
|
+
return { scores: extractExpansionScores(scores, seedScores), iterations };
|
|
49
|
+
}
|
|
50
|
+
/** Power iteration loop for PPR convergence. */
|
|
51
|
+
function iteratePPR(allNodes, seed, adjacency, outDegree, damping, maxIterations, tolerance) {
|
|
52
|
+
let scores = new Map(seed);
|
|
53
|
+
let iterations = 0;
|
|
54
|
+
for (let i = 0; i < maxIterations; i++) {
|
|
55
|
+
iterations = i + 1;
|
|
56
|
+
const next = computeNextScores(allNodes, seed, adjacency, outDegree, scores, damping);
|
|
57
|
+
const delta = computeDelta(allNodes, next, scores);
|
|
58
|
+
scores = next;
|
|
59
|
+
if (delta < tolerance)
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
return { scores, iterations };
|
|
63
|
+
}
|
|
64
|
+
/** Compute next-step scores from seed teleportation + link propagation. */
|
|
65
|
+
function computeNextScores(allNodes, seed, adjacency, outDegree, scores, damping) {
|
|
66
|
+
const next = new Map();
|
|
67
|
+
for (const node of allNodes) {
|
|
68
|
+
next.set(node, (1 - damping) * (seed.get(node) ?? 0));
|
|
69
|
+
}
|
|
70
|
+
for (const [src, neighbors] of adjacency) {
|
|
71
|
+
const contribution = damping * (scores.get(src) ?? 0) / (outDegree.get(src) ?? 1);
|
|
72
|
+
for (const neighbor of neighbors) {
|
|
73
|
+
next.set(neighbor, (next.get(neighbor) ?? 0) + contribution);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return next;
|
|
77
|
+
}
|
|
78
|
+
/** Compute L1 norm of score delta between iterations. */
|
|
79
|
+
function computeDelta(allNodes, next, scores) {
|
|
80
|
+
let delta = 0;
|
|
81
|
+
for (const node of allNodes) {
|
|
82
|
+
delta += Math.abs((next.get(node) ?? 0) - (scores.get(node) ?? 0));
|
|
83
|
+
}
|
|
84
|
+
return delta;
|
|
85
|
+
}
|
|
86
|
+
/** Extract non-seed scores above zero for the expansion result. */
|
|
87
|
+
function extractExpansionScores(scores, seedScores) {
|
|
88
|
+
const seedIds = new Set(seedScores.keys());
|
|
89
|
+
const expansion = new Map();
|
|
90
|
+
for (const [id, score] of scores) {
|
|
91
|
+
if (!seedIds.has(id) && score > 0) {
|
|
92
|
+
expansion.set(id, score);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return expansion;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Run PPR with adjacency loaded from the database.
|
|
99
|
+
*
|
|
100
|
+
* Loads the 2-hop subgraph around seed nodes from memory_links, then
|
|
101
|
+
* delegates to the pure runPPR function.
|
|
102
|
+
*/
|
|
103
|
+
export async function personalizedPageRank(pool, seedScores, pprConfig = {}) {
|
|
104
|
+
if (seedScores.size === 0)
|
|
105
|
+
return { scores: new Map(), iterations: 0 };
|
|
106
|
+
const adjacency = await loadAdjacency(pool, seedScores);
|
|
107
|
+
return runPPR(adjacency, seedScores, pprConfig);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Load the adjacency list for all nodes reachable within 2 hops from seeds.
|
|
111
|
+
*
|
|
112
|
+
* We limit to 2 hops from seeds to bound the graph size while still allowing
|
|
113
|
+
* PPR to propagate through intermediate nodes. The power iteration handles
|
|
114
|
+
* deeper propagation via the iterative score updates.
|
|
115
|
+
*/
|
|
116
|
+
async function loadAdjacency(pool, seedScores) {
|
|
117
|
+
const seedIds = [...seedScores.keys()];
|
|
118
|
+
if (seedIds.length === 0)
|
|
119
|
+
return new Map();
|
|
120
|
+
const result = await pool.query(`WITH seed_links AS (
|
|
121
|
+
SELECT source_id, target_id FROM memory_links
|
|
122
|
+
WHERE source_id = ANY($1) OR target_id = ANY($1)
|
|
123
|
+
),
|
|
124
|
+
hop1_nodes AS (
|
|
125
|
+
SELECT source_id AS id FROM seed_links
|
|
126
|
+
UNION
|
|
127
|
+
SELECT target_id AS id FROM seed_links
|
|
128
|
+
),
|
|
129
|
+
hop2_links AS (
|
|
130
|
+
SELECT ml.source_id, ml.target_id FROM memory_links ml
|
|
131
|
+
INNER JOIN hop1_nodes h ON ml.source_id = h.id OR ml.target_id = h.id
|
|
132
|
+
)
|
|
133
|
+
SELECT source_id, target_id FROM seed_links
|
|
134
|
+
UNION
|
|
135
|
+
SELECT source_id, target_id FROM hop2_links`, [seedIds]);
|
|
136
|
+
const adjacency = new Map();
|
|
137
|
+
for (const row of result.rows) {
|
|
138
|
+
const src = row.source_id;
|
|
139
|
+
const tgt = row.target_id;
|
|
140
|
+
if (!adjacency.has(src))
|
|
141
|
+
adjacency.set(src, new Set());
|
|
142
|
+
adjacency.get(src).add(tgt);
|
|
143
|
+
if (!adjacency.has(tgt))
|
|
144
|
+
adjacency.set(tgt, new Set());
|
|
145
|
+
adjacency.get(tgt).add(src);
|
|
146
|
+
}
|
|
147
|
+
return adjacency;
|
|
148
|
+
}
|
|
149
|
+
function collectNodes(adjacency, seedScores) {
|
|
150
|
+
const nodes = new Set();
|
|
151
|
+
for (const id of seedScores.keys())
|
|
152
|
+
nodes.add(id);
|
|
153
|
+
for (const [src, neighbors] of adjacency) {
|
|
154
|
+
nodes.add(src);
|
|
155
|
+
for (const neighbor of neighbors)
|
|
156
|
+
nodes.add(neighbor);
|
|
157
|
+
}
|
|
158
|
+
return nodes;
|
|
159
|
+
}
|
|
160
|
+
function normalizeSeed(seedScores, allNodes) {
|
|
161
|
+
let total = 0;
|
|
162
|
+
for (const score of seedScores.values())
|
|
163
|
+
total += score;
|
|
164
|
+
if (total === 0)
|
|
165
|
+
total = 1;
|
|
166
|
+
const normalized = new Map();
|
|
167
|
+
for (const node of allNodes) {
|
|
168
|
+
normalized.set(node, (seedScores.get(node) ?? 0) / total);
|
|
169
|
+
}
|
|
170
|
+
return normalized;
|
|
171
|
+
}
|
|
172
|
+
function computeOutDegree(adjacency, allNodes) {
|
|
173
|
+
const degree = new Map();
|
|
174
|
+
for (const node of allNodes) {
|
|
175
|
+
degree.set(node, adjacency.get(node)?.size ?? 0);
|
|
176
|
+
}
|
|
177
|
+
return degree;
|
|
178
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared query-building helpers for vector search and hybrid search backends.
|
|
3
|
+
*
|
|
4
|
+
* Centralizes scoring weight preparation, parameter setup, and site filtering
|
|
5
|
+
* to eliminate duplication between repository-vector-search.ts and
|
|
6
|
+
* repository-representations.ts.
|
|
7
|
+
*/
|
|
8
|
+
export declare const RRF_K = 60;
|
|
9
|
+
export interface HybridQueryParams {
|
|
10
|
+
/** Positional params array for pg.query. */
|
|
11
|
+
params: unknown[];
|
|
12
|
+
/** SQL clause fragment for optional source_site filter. Uses the alias prefix if provided. */
|
|
13
|
+
siteFilter: string;
|
|
14
|
+
/** ISO string for the reference timestamp. */
|
|
15
|
+
refTime: string;
|
|
16
|
+
/** Scoring weights from config. */
|
|
17
|
+
wSim: number;
|
|
18
|
+
wImp: number;
|
|
19
|
+
wRec: number;
|
|
20
|
+
rankingMinSimilarity: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Build shared query parameters for a hybrid (vector + FTS) search.
|
|
24
|
+
*
|
|
25
|
+
* Returns an array of positional params, the site filter clause, and
|
|
26
|
+
* scoring weights. The caller must set the first params in a known order:
|
|
27
|
+
* $1=embedding, $2=userId, $3=queryText, $4=limit, $5=wSim, $6=wImp, $7=wRec, $8=refTime, $9=rankingMinSimilarity, [$10=sourceSite]
|
|
28
|
+
*/
|
|
29
|
+
export declare function buildHybridSearchParams(queryEmbedding: number[], userId: string, queryText: string, limit: number, siteFilterColumn: string, sourceSite?: string, referenceTime?: Date): HybridQueryParams;
|
|
30
|
+
/**
|
|
31
|
+
* Build shared query parameters for a vector-only scored search.
|
|
32
|
+
*
|
|
33
|
+
* Returns params in order: $1=embedding, $2=userId, $3=limit, $4=wSim, $5=wImp, $6=wRec, $7=refTime, $8=rankingMinSimilarity, [$9=sourceSite]
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildVectorSearchParams(queryEmbedding: number[], userId: string, limit: number, sourceSite?: string, referenceTime?: Date): {
|
|
36
|
+
params: unknown[];
|
|
37
|
+
siteClause: string;
|
|
38
|
+
wSim: number;
|
|
39
|
+
wImp: number;
|
|
40
|
+
wRec: number;
|
|
41
|
+
rankingMinSimilarity: number;
|
|
42
|
+
refTime: string;
|
|
43
|
+
};
|
|
44
|
+
export declare function clampUnit(value: number): number;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared query-building helpers for vector search and hybrid search backends.
|
|
3
|
+
*
|
|
4
|
+
* Centralizes scoring weight preparation, parameter setup, and site filtering
|
|
5
|
+
* to eliminate duplication between repository-vector-search.ts and
|
|
6
|
+
* repository-representations.ts.
|
|
7
|
+
*/
|
|
8
|
+
import pgvector from 'pgvector/pg';
|
|
9
|
+
import { config } from '../config.js';
|
|
10
|
+
export const RRF_K = 60;
|
|
11
|
+
/**
|
|
12
|
+
* Build shared query parameters for a hybrid (vector + FTS) search.
|
|
13
|
+
*
|
|
14
|
+
* Returns an array of positional params, the site filter clause, and
|
|
15
|
+
* scoring weights. The caller must set the first params in a known order:
|
|
16
|
+
* $1=embedding, $2=userId, $3=queryText, $4=limit, $5=wSim, $6=wImp, $7=wRec, $8=refTime, $9=rankingMinSimilarity, [$10=sourceSite]
|
|
17
|
+
*/
|
|
18
|
+
export function buildHybridSearchParams(queryEmbedding, userId, queryText, limit, siteFilterColumn, sourceSite, referenceTime) {
|
|
19
|
+
const wSim = config.scoringWeightSimilarity;
|
|
20
|
+
const wImp = config.scoringWeightImportance;
|
|
21
|
+
const wRec = config.scoringWeightRecency;
|
|
22
|
+
const rankingMinSimilarity = clampUnit(config.retrievalProfileSettings.rankingMinSimilarity);
|
|
23
|
+
const refTime = (referenceTime ?? new Date()).toISOString();
|
|
24
|
+
const siteFilter = sourceSite ? `AND ${siteFilterColumn} = $10` : '';
|
|
25
|
+
const params = [
|
|
26
|
+
pgvector.toSql(queryEmbedding),
|
|
27
|
+
userId,
|
|
28
|
+
queryText,
|
|
29
|
+
Math.max(1, limit),
|
|
30
|
+
wSim, wImp, wRec, refTime, rankingMinSimilarity,
|
|
31
|
+
];
|
|
32
|
+
if (sourceSite)
|
|
33
|
+
params.push(sourceSite);
|
|
34
|
+
return { params, siteFilter, refTime, wSim, wImp, wRec, rankingMinSimilarity };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Build shared query parameters for a vector-only scored search.
|
|
38
|
+
*
|
|
39
|
+
* Returns params in order: $1=embedding, $2=userId, $3=limit, $4=wSim, $5=wImp, $6=wRec, $7=refTime, $8=rankingMinSimilarity, [$9=sourceSite]
|
|
40
|
+
*/
|
|
41
|
+
export function buildVectorSearchParams(queryEmbedding, userId, limit, sourceSite, referenceTime) {
|
|
42
|
+
const wSim = config.scoringWeightSimilarity;
|
|
43
|
+
const wImp = config.scoringWeightImportance;
|
|
44
|
+
const wRec = config.scoringWeightRecency;
|
|
45
|
+
const rankingMinSimilarity = clampUnit(config.retrievalProfileSettings.rankingMinSimilarity);
|
|
46
|
+
const refTime = (referenceTime ?? new Date()).toISOString();
|
|
47
|
+
const siteClause = sourceSite ? 'AND source_site = $9' : '';
|
|
48
|
+
const params = [
|
|
49
|
+
pgvector.toSql(queryEmbedding), userId, Math.max(1, Math.min(100, limit)),
|
|
50
|
+
wSim, wImp, wRec, refTime, rankingMinSimilarity,
|
|
51
|
+
];
|
|
52
|
+
if (sourceSite)
|
|
53
|
+
params.push(sourceSite);
|
|
54
|
+
return { params, siteClause, wSim, wImp, wRec, rankingMinSimilarity, refTime };
|
|
55
|
+
}
|
|
56
|
+
export function clampUnit(value) {
|
|
57
|
+
if (!Number.isFinite(value))
|
|
58
|
+
return 0;
|
|
59
|
+
return Math.max(0, Math.min(1, value));
|
|
60
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Sync hook keeping `storage_artifacts.status` in lockstep
|
|
3
|
+
* with `raw_documents.raw_storage_status`.
|
|
4
|
+
*
|
|
5
|
+
* Step 7 of the storage-sibling plan. Every existing raw-storage
|
|
6
|
+
* transition (upload finalize, reconciler success/failure, cleanup
|
|
7
|
+
* success/failure) calls this hook after mutating `raw_documents`
|
|
8
|
+
* so the paired `storage_artifacts` row tracks the same lifecycle.
|
|
9
|
+
*
|
|
10
|
+
* v1 keeps `raw_documents` as the source of truth for document-
|
|
11
|
+
* backed uploads — the artifact row is a synchronized projection.
|
|
12
|
+
* The follow-up Webapp Storage UI PR (source plan Phase 8) makes
|
|
13
|
+
* `storage_artifacts` the source of truth and switches the document
|
|
14
|
+
* formatter to a join-projection. Until then, the helper guarantees
|
|
15
|
+
* both rows agree.
|
|
16
|
+
*
|
|
17
|
+
* Status mapping (plan rev 6 §Step 7):
|
|
18
|
+
*
|
|
19
|
+
* pointer_recorded (with external_uri / pointer artifact) → 'stored'
|
|
20
|
+
* pointer_recorded (no artifact linked) → no-op
|
|
21
|
+
* blob_stored → 'stored'
|
|
22
|
+
* blob_pending → 'pending'
|
|
23
|
+
* blob_uploading → 'pending' (transient)
|
|
24
|
+
* blob_available → 'available'
|
|
25
|
+
* blob_archival_failed → 'failed'
|
|
26
|
+
* raw_storage_failed → 'failed'
|
|
27
|
+
* blob_tombstoned → 'deleted'
|
|
28
|
+
* blob_deleted → 'deleted'
|
|
29
|
+
* inline_text_stored → no-op (inline; no artifact)
|
|
30
|
+
*/
|
|
31
|
+
import type pg from 'pg';
|
|
32
|
+
import type { RawStorageStatus } from './raw-document-types.js';
|
|
33
|
+
/**
|
|
34
|
+
* Canonical raw_storage cleanup-failure envelope. Persisted to both
|
|
35
|
+
* `raw_documents.last_error` (via `markCleanupFailedAndSyncArtifact`)
|
|
36
|
+
* and the linked `storage_artifacts.last_error`. The provider's raw
|
|
37
|
+
* exception message is funneled through `buildLastError` so the
|
|
38
|
+
* central `sanitizeLastErrorMessage` cap (1 KiB) and control-char
|
|
39
|
+
* collapse apply uniformly — multi-line stack traces, sensitive
|
|
40
|
+
* URLs in error blobs, and oversized provider envelopes never reach
|
|
41
|
+
* the JSONB column unfiltered. The `storage_provider` field is
|
|
42
|
+
* appended after sanitization so the envelope shape stays
|
|
43
|
+
* additive on top of the canonical `LastError`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildRawStorageCleanupFailureEnvelope(message: string, storageProvider: string): Record<string, unknown>;
|
|
46
|
+
export interface SyncArtifactStatusInput {
|
|
47
|
+
rawDocumentId: string;
|
|
48
|
+
newRawStatus: RawStorageStatus;
|
|
49
|
+
/**
|
|
50
|
+
* Optional failure envelope to record on the artifact's
|
|
51
|
+
* `last_error` column. Pass only on failure transitions; the
|
|
52
|
+
* helper clears `last_error` on success transitions (`stored` /
|
|
53
|
+
* `pending` / `available` / `deleted`).
|
|
54
|
+
*/
|
|
55
|
+
lastError?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Map a single `raw_documents` row's new status onto its linked
|
|
59
|
+
* `storage_artifacts` row. Resolves the link inside the same query
|
|
60
|
+
* pair (no separate read) so the hook is safe to call inside the
|
|
61
|
+
* existing transactions that wrap the raw-storage transitions.
|
|
62
|
+
*
|
|
63
|
+
* No-op (silently) when:
|
|
64
|
+
* - the document is not linked to an artifact (`storage_artifact_id IS NULL`),
|
|
65
|
+
* - the new raw status maps to no artifact state (e.g. `inline_text_stored`).
|
|
66
|
+
*
|
|
67
|
+
* The function deliberately does NOT scope by `user_id` — the
|
|
68
|
+
* caller has already vouched for the row by holding the row's
|
|
69
|
+
* advisory lock or having authenticated the request that triggered
|
|
70
|
+
* the transition.
|
|
71
|
+
*/
|
|
72
|
+
export declare function syncArtifactStatusFromRawDocument(client: pg.PoolClient | pg.Pool, args: SyncArtifactStatusInput): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Reconciler paired promote: flip the document to `blob_available`
|
|
75
|
+
* AND sync the artifact in one transaction. Two-row drift is
|
|
76
|
+
* impossible — either both rows commit or both roll back.
|
|
77
|
+
*/
|
|
78
|
+
export declare function promoteAndSyncArtifact(pool: pg.Pool, args: {
|
|
79
|
+
rowId: string;
|
|
80
|
+
claimId: string;
|
|
81
|
+
provider: string;
|
|
82
|
+
providerFields: Record<string, unknown>;
|
|
83
|
+
}): Promise<number>;
|
|
84
|
+
/**
|
|
85
|
+
* Reconciler paired archival-fail: flip the document to
|
|
86
|
+
* `blob_archival_failed` AND sync the artifact (with the
|
|
87
|
+
* `last_error` envelope) in one transaction.
|
|
88
|
+
*/
|
|
89
|
+
export declare function markArchivalFailedAndSyncArtifact(pool: pg.Pool, args: {
|
|
90
|
+
rowId: string;
|
|
91
|
+
claimId: string;
|
|
92
|
+
lastError: Record<string, unknown>;
|
|
93
|
+
provider: string;
|
|
94
|
+
}): Promise<number>;
|
|
95
|
+
/**
|
|
96
|
+
* Document-keyed paired marker for the cleanup path. Each blob
|
|
97
|
+
* cleanup carries its `rawDocumentId` (see
|
|
98
|
+
* `ManagedBlobRefRow.rawDocumentId`) so the sync never needs to
|
|
99
|
+
* disambiguate by URI. The raw_documents UPDATE is owner-scoped;
|
|
100
|
+
* if zero rows match (cross-user mismatch or already-terminal),
|
|
101
|
+
* the artifact sync is skipped — preventing a mismatched caller
|
|
102
|
+
* from flipping another user's artifact.
|
|
103
|
+
*/
|
|
104
|
+
export declare function markCleanupSuccessAndSyncArtifact(pool: pg.Pool, args: {
|
|
105
|
+
userId: string;
|
|
106
|
+
rawDocumentId: string;
|
|
107
|
+
storageUri: string;
|
|
108
|
+
semantics: 'deleted' | 'unpinned' | 'tombstoned';
|
|
109
|
+
}): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Document-keyed paired failure marker. Mirrors
|
|
112
|
+
* `markCleanupSuccessAndSyncArtifact` but for the failure branch
|
|
113
|
+
* (`raw_storage_failed`). Same owner-scope gating.
|
|
114
|
+
*
|
|
115
|
+
* Retry-friendly: the UPDATE matches on `(user_id, id)` only — a row
|
|
116
|
+
* that is ALREADY `raw_storage_failed` is re-marked so a fresh
|
|
117
|
+
* provider error replaces the prior envelope on both
|
|
118
|
+
* `raw_documents.last_error` AND the linked
|
|
119
|
+
* `storage_artifacts.last_error`. Mirrors the failure-marker pattern
|
|
120
|
+
* elsewhere in the codebase, where retries land the newest, most-
|
|
121
|
+
* useful error rather than discarding it. Cross-user mismatches
|
|
122
|
+
* still roll back via the owner-scoped WHERE.
|
|
123
|
+
*/
|
|
124
|
+
export declare function markCleanupFailedAndSyncArtifact(pool: pg.Pool, args: {
|
|
125
|
+
userId: string;
|
|
126
|
+
rawDocumentId: string;
|
|
127
|
+
lastError?: Record<string, unknown>;
|
|
128
|
+
}): Promise<void>;
|