nox-mem 3.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/LICENSE +21 -0
- package/README.md +179 -0
- package/dist/api/answer.d.ts +116 -0
- package/dist/api/answer.js +274 -0
- package/dist/api/answer.validate-patch.d.ts +72 -0
- package/dist/api/answer.validate-patch.js +52 -0
- package/dist/api/brief-diversity.d.ts +64 -0
- package/dist/api/brief-diversity.js +91 -0
- package/dist/api/brief.d.ts +114 -0
- package/dist/api/brief.js +524 -0
- package/dist/api/conflict.d.ts +33 -0
- package/dist/api/conflict.js +143 -0
- package/dist/api/cors.d.ts +73 -0
- package/dist/api/cors.js +124 -0
- package/dist/api/events-stream-limited.d.ts +133 -0
- package/dist/api/events-stream-limited.js +217 -0
- package/dist/api/events-stream.d.ts +53 -0
- package/dist/api/events-stream.js +125 -0
- package/dist/api/export.d.ts +42 -0
- package/dist/api/export.js +85 -0
- package/dist/api/health-confidence-adapter.d.ts +29 -0
- package/dist/api/health-confidence-adapter.js +73 -0
- package/dist/api/health-confidence.d.ts +36 -0
- package/dist/api/health-confidence.js +141 -0
- package/dist/api/hooks.d.ts +50 -0
- package/dist/api/hooks.js +115 -0
- package/dist/api/import.d.ts +38 -0
- package/dist/api/import.js +87 -0
- package/dist/api/ingest-event.d.ts +65 -0
- package/dist/api/ingest-event.js +153 -0
- package/dist/api/mark.d.ts +42 -0
- package/dist/api/mark.js +127 -0
- package/dist/api/server-deps-a2.d.ts +55 -0
- package/dist/api/server-deps-a2.js +138 -0
- package/dist/api/server-deps-l2-l3.d.ts +68 -0
- package/dist/api/server-deps-l2-l3.js +123 -0
- package/dist/api/server-deps-p1.d.ts +84 -0
- package/dist/api/server-deps-p1.js +156 -0
- package/dist/api/server-deps-p2.d.ts +32 -0
- package/dist/api/server-deps-p2.js +84 -0
- package/dist/api/server-deps-p5.d.ts +66 -0
- package/dist/api/server-deps-p5.js +139 -0
- package/dist/api/viewer-static.d.ts +30 -0
- package/dist/api/viewer-static.js +102 -0
- package/dist/api/wire-up.d.ts +54 -0
- package/dist/api/wire-up.js +521 -0
- package/dist/api-impact.d.ts +30 -0
- package/dist/api-impact.js +196 -0
- package/dist/api-server.d.ts +2 -0
- package/dist/api-server.js +614 -0
- package/dist/backfill-fts-anchor.d.ts +15 -0
- package/dist/backfill-fts-anchor.js +97 -0
- package/dist/backfill-source-type.d.ts +20 -0
- package/dist/backfill-source-type.js +182 -0
- package/dist/churn.d.ts +31 -0
- package/dist/churn.js +98 -0
- package/dist/cli/answer.d.ts +66 -0
- package/dist/cli/answer.js +287 -0
- package/dist/cli/conflict.d.ts +38 -0
- package/dist/cli/conflict.js +282 -0
- package/dist/cli/export.d.ts +51 -0
- package/dist/cli/export.js +280 -0
- package/dist/cli/hooks.d.ts +54 -0
- package/dist/cli/hooks.js +133 -0
- package/dist/cli/import.d.ts +52 -0
- package/dist/cli/import.js +274 -0
- package/dist/cli/mark.d.ts +33 -0
- package/dist/cli/mark.js +130 -0
- package/dist/cli/ocr-batch.d.ts +12 -0
- package/dist/cli/ocr-batch.js +411 -0
- package/dist/cli/snapshot-main.d.ts +30 -0
- package/dist/cli/snapshot-main.js +47 -0
- package/dist/cli/viewer.d.ts +35 -0
- package/dist/cli/viewer.js +71 -0
- package/dist/cli-telemetry.d.ts +36 -0
- package/dist/cli-telemetry.js +150 -0
- package/dist/compact.d.ts +7 -0
- package/dist/compact.js +147 -0
- package/dist/consolidate.d.ts +18 -0
- package/dist/consolidate.js +475 -0
- package/dist/consolidation.d.ts +32 -0
- package/dist/consolidation.js +212 -0
- package/dist/cross-agent-v2.d.ts +45 -0
- package/dist/cross-agent-v2.js +271 -0
- package/dist/cross-search.d.ts +11 -0
- package/dist/cross-search.js +119 -0
- package/dist/crystallize.d.ts +43 -0
- package/dist/crystallize.js +111 -0
- package/dist/db.d.ts +11 -0
- package/dist/db.js +388 -0
- package/dist/dedup.d.ts +1 -0
- package/dist/dedup.js +106 -0
- package/dist/detect-changes.d.ts +29 -0
- package/dist/detect-changes.js +236 -0
- package/dist/digest.d.ts +1 -0
- package/dist/digest.js +205 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +71 -0
- package/dist/embed.d.ts +45 -0
- package/dist/embed.js +257 -0
- package/dist/evals.d.ts +176 -0
- package/dist/evals.js +351 -0
- package/dist/generate-user-profile.d.ts +18 -0
- package/dist/generate-user-profile.js +163 -0
- package/dist/graphify-ingest.d.ts +18 -0
- package/dist/graphify-ingest.js +158 -0
- package/dist/impact.d.ts +39 -0
- package/dist/impact.js +143 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +689 -0
- package/dist/ingest-entity.d.ts +44 -0
- package/dist/ingest-entity.js +197 -0
- package/dist/ingest.d.ts +13 -0
- package/dist/ingest.js +210 -0
- package/dist/kg-llm.d.ts +39 -0
- package/dist/kg-llm.js +295 -0
- package/dist/knowledge-graph.d.ts +72 -0
- package/dist/knowledge-graph.js +507 -0
- package/dist/lib/answer/config.d.ts +41 -0
- package/dist/lib/answer/config.js +70 -0
- package/dist/lib/answer/index.d.ts +47 -0
- package/dist/lib/answer/index.js +221 -0
- package/dist/lib/answer/prompt.d.ts +37 -0
- package/dist/lib/answer/prompt.js +88 -0
- package/dist/lib/answer/provider.d.ts +47 -0
- package/dist/lib/answer/provider.js +101 -0
- package/dist/lib/answer/retrieval.d.ts +36 -0
- package/dist/lib/answer/retrieval.js +92 -0
- package/dist/lib/answer/telemetry.d.ts +99 -0
- package/dist/lib/answer/telemetry.js +154 -0
- package/dist/lib/answer/types.d.ts +108 -0
- package/dist/lib/answer/types.js +1 -0
- package/dist/lib/api/error-leak-fix.d.ts +54 -0
- package/dist/lib/api/error-leak-fix.js +55 -0
- package/dist/lib/api/safe-error-message.d.ts +70 -0
- package/dist/lib/api/safe-error-message.js +122 -0
- package/dist/lib/archive/common-passwords.d.ts +37 -0
- package/dist/lib/archive/common-passwords.js +753 -0
- package/dist/lib/archive/encryption.d.ts +81 -0
- package/dist/lib/archive/encryption.js +236 -0
- package/dist/lib/archive/enforce-strength.d.ts +54 -0
- package/dist/lib/archive/enforce-strength.js +70 -0
- package/dist/lib/archive/entropy.d.ts +34 -0
- package/dist/lib/archive/entropy.js +180 -0
- package/dist/lib/archive/export-locking.d.ts +102 -0
- package/dist/lib/archive/export-locking.js +202 -0
- package/dist/lib/archive/format.d.ts +20 -0
- package/dist/lib/archive/format.js +174 -0
- package/dist/lib/archive/index.d.ts +23 -0
- package/dist/lib/archive/index.js +17 -0
- package/dist/lib/archive/manifest.d.ts +53 -0
- package/dist/lib/archive/manifest.js +183 -0
- package/dist/lib/archive/migration.d.ts +36 -0
- package/dist/lib/archive/migration.js +100 -0
- package/dist/lib/archive/migrations/v18_to_v19.d.ts +16 -0
- package/dist/lib/archive/migrations/v18_to_v19.js +18 -0
- package/dist/lib/archive/orchestrator.d.ts +166 -0
- package/dist/lib/archive/orchestrator.js +428 -0
- package/dist/lib/archive/serializers/chunks.d.ts +30 -0
- package/dist/lib/archive/serializers/chunks.js +113 -0
- package/dist/lib/archive/serializers/embeddings.d.ts +36 -0
- package/dist/lib/archive/serializers/embeddings.js +115 -0
- package/dist/lib/archive/serializers/kg.d.ts +28 -0
- package/dist/lib/archive/serializers/kg.js +184 -0
- package/dist/lib/archive/serializers/ops_audit.d.ts +21 -0
- package/dist/lib/archive/serializers/ops_audit.js +97 -0
- package/dist/lib/archive/server-deps.d.ts +131 -0
- package/dist/lib/archive/server-deps.js +232 -0
- package/dist/lib/archive/strength.d.ts +50 -0
- package/dist/lib/archive/strength.js +77 -0
- package/dist/lib/archive/types.d.ts +159 -0
- package/dist/lib/archive/types.js +45 -0
- package/dist/lib/archive/unpack-streaming.d.ts +70 -0
- package/dist/lib/archive/unpack-streaming.js +255 -0
- package/dist/lib/auth/localhost-guard.d.ts +106 -0
- package/dist/lib/auth/localhost-guard.js +164 -0
- package/dist/lib/confidence/config.d.ts +37 -0
- package/dist/lib/confidence/config.js +107 -0
- package/dist/lib/confidence/db-shim-singleton.d.ts +20 -0
- package/dist/lib/confidence/db-shim-singleton.js +41 -0
- package/dist/lib/confidence/db-shim.d.ts +47 -0
- package/dist/lib/confidence/db-shim.js +141 -0
- package/dist/lib/confidence/mark.d.ts +58 -0
- package/dist/lib/confidence/mark.js +168 -0
- package/dist/lib/confidence/ranking.d.ts +69 -0
- package/dist/lib/confidence/ranking.js +101 -0
- package/dist/lib/confidence/search-filter.d.ts +44 -0
- package/dist/lib/confidence/search-filter.js +103 -0
- package/dist/lib/confidence/types.d.ts +146 -0
- package/dist/lib/confidence/types.js +20 -0
- package/dist/lib/confidence/write-hooks.d.ts +50 -0
- package/dist/lib/confidence/write-hooks.js +159 -0
- package/dist/lib/conflict/audit-fk-check.d.ts +72 -0
- package/dist/lib/conflict/audit-fk-check.js +131 -0
- package/dist/lib/conflict/audit-writer.d.ts +39 -0
- package/dist/lib/conflict/audit-writer.js +133 -0
- package/dist/lib/conflict/db-singleton.d.ts +28 -0
- package/dist/lib/conflict/db-singleton.js +61 -0
- package/dist/lib/conflict/db.d.ts +27 -0
- package/dist/lib/conflict/db.js +20 -0
- package/dist/lib/conflict/detector-direct.d.ts +21 -0
- package/dist/lib/conflict/detector-direct.js +105 -0
- package/dist/lib/conflict/evidence.d.ts +24 -0
- package/dist/lib/conflict/evidence.js +76 -0
- package/dist/lib/conflict/index.d.ts +14 -0
- package/dist/lib/conflict/index.js +12 -0
- package/dist/lib/conflict/scheduler.d.ts +78 -0
- package/dist/lib/conflict/scheduler.js +111 -0
- package/dist/lib/conflict/shadow.d.ts +75 -0
- package/dist/lib/conflict/shadow.js +161 -0
- package/dist/lib/conflict/types.d.ts +133 -0
- package/dist/lib/conflict/types.js +19 -0
- package/dist/lib/cost-cap.d.ts +94 -0
- package/dist/lib/cost-cap.js +129 -0
- package/dist/lib/deps/deps-registry.d.ts +111 -0
- package/dist/lib/deps/deps-registry.js +209 -0
- package/dist/lib/error-sanitizer/middleware.d.ts +43 -0
- package/dist/lib/error-sanitizer/middleware.js +100 -0
- package/dist/lib/error-sanitizer/sanitize.d.ts +78 -0
- package/dist/lib/error-sanitizer/sanitize.js +202 -0
- package/dist/lib/eval-batch.d.ts +34 -0
- package/dist/lib/eval-batch.js +103 -0
- package/dist/lib/eval-metrics.d.ts +36 -0
- package/dist/lib/eval-metrics.js +95 -0
- package/dist/lib/eval.d.ts +106 -0
- package/dist/lib/eval.js +343 -0
- package/dist/lib/events/bus.d.ts +135 -0
- package/dist/lib/events/bus.js +95 -0
- package/dist/lib/fts-anchor.d.ts +1 -0
- package/dist/lib/fts-anchor.js +131 -0
- package/dist/lib/hooks/classifier.d.ts +47 -0
- package/dist/lib/hooks/classifier.js +129 -0
- package/dist/lib/hooks/config.d.ts +49 -0
- package/dist/lib/hooks/config.js +106 -0
- package/dist/lib/hooks/decorators.d.ts +35 -0
- package/dist/lib/hooks/decorators.js +59 -0
- package/dist/lib/hooks/pipeline.d.ts +76 -0
- package/dist/lib/hooks/pipeline.js +213 -0
- package/dist/lib/hooks/privacy-filter-adapter.d.ts +55 -0
- package/dist/lib/hooks/privacy-filter-adapter.js +84 -0
- package/dist/lib/hooks/rate-limit-constant-time.d.ts +57 -0
- package/dist/lib/hooks/rate-limit-constant-time.js +69 -0
- package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +71 -0
- package/dist/lib/hooks/rate-limit-dryrun-fix.js +110 -0
- package/dist/lib/hooks/rate-limit.d.ts +54 -0
- package/dist/lib/hooks/rate-limit.js +122 -0
- package/dist/lib/hooks/server-deps.d.ts +61 -0
- package/dist/lib/hooks/server-deps.js +92 -0
- package/dist/lib/hooks/source-allowlist.d.ts +26 -0
- package/dist/lib/hooks/source-allowlist.js +53 -0
- package/dist/lib/hooks/types.d.ts +129 -0
- package/dist/lib/hooks/types.js +24 -0
- package/dist/lib/hooks/worker.d.ts +56 -0
- package/dist/lib/hooks/worker.js +150 -0
- package/dist/lib/ingest-router.d.ts +25 -0
- package/dist/lib/ingest-router.js +103 -0
- package/dist/lib/ocr-detector.d.ts +61 -0
- package/dist/lib/ocr-detector.js +138 -0
- package/dist/lib/ocr-engine-stub.d.ts +48 -0
- package/dist/lib/ocr-engine-stub.js +190 -0
- package/dist/lib/ocr-engines/google-doc-ai.d.ts +36 -0
- package/dist/lib/ocr-engines/google-doc-ai.js +164 -0
- package/dist/lib/ocr-jobs.d.ts +67 -0
- package/dist/lib/ocr-jobs.js +129 -0
- package/dist/lib/op-audit-extension/ran-at-guard.d.ts +86 -0
- package/dist/lib/op-audit-extension/ran-at-guard.js +110 -0
- package/dist/lib/op-audit.d.ts +71 -0
- package/dist/lib/op-audit.js +777 -0
- package/dist/lib/privacy-br/detector.d.ts +42 -0
- package/dist/lib/privacy-br/detector.js +130 -0
- package/dist/lib/privacy-br/index.d.ts +20 -0
- package/dist/lib/privacy-br/index.js +20 -0
- package/dist/lib/privacy-br/integration.d.ts +71 -0
- package/dist/lib/privacy-br/integration.js +74 -0
- package/dist/lib/privacy-br/patterns.d.ts +117 -0
- package/dist/lib/privacy-br/patterns.js +434 -0
- package/dist/lib/privacy-br/redact.d.ts +42 -0
- package/dist/lib/privacy-br/redact.js +103 -0
- package/dist/lib/privacy-br/types.d.ts +55 -0
- package/dist/lib/privacy-br/types.js +25 -0
- package/dist/lib/regex-extract/extractor.d.ts +30 -0
- package/dist/lib/regex-extract/extractor.js +91 -0
- package/dist/lib/regex-extract/frontmatter.d.ts +44 -0
- package/dist/lib/regex-extract/frontmatter.js +169 -0
- package/dist/lib/regex-extract/index.d.ts +14 -0
- package/dist/lib/regex-extract/index.js +14 -0
- package/dist/lib/regex-extract/ingest-router-l4.d.ts +76 -0
- package/dist/lib/regex-extract/ingest-router-l4.js +102 -0
- package/dist/lib/regex-extract/patterns.d.ts +61 -0
- package/dist/lib/regex-extract/patterns.js +91 -0
- package/dist/lib/regex-extract/production-wire.d.ts +128 -0
- package/dist/lib/regex-extract/production-wire.js +202 -0
- package/dist/lib/regex-extract/reconcile.d.ts +162 -0
- package/dist/lib/regex-extract/reconcile.js +210 -0
- package/dist/lib/regex-extract/strip-code.d.ts +24 -0
- package/dist/lib/regex-extract/strip-code.js +52 -0
- package/dist/lib/regex-extract/types.d.ts +48 -0
- package/dist/lib/regex-extract/types.js +25 -0
- package/dist/lib/reranker.d.ts +80 -0
- package/dist/lib/reranker.js +324 -0
- package/dist/lib/shadow-tracker.d.ts +191 -0
- package/dist/lib/shadow-tracker.js +384 -0
- package/dist/lib/spo-injection.d.ts +52 -0
- package/dist/lib/spo-injection.js +166 -0
- package/dist/lib/telemetry-collector.d.ts +158 -0
- package/dist/lib/telemetry-collector.js +249 -0
- package/dist/lib/temporal-detector.d.ts +27 -0
- package/dist/lib/temporal-detector.js +81 -0
- package/dist/lib/viewer/auth.d.ts +37 -0
- package/dist/lib/viewer/auth.js +70 -0
- package/dist/lib/viewer/backpressure.d.ts +59 -0
- package/dist/lib/viewer/backpressure.js +100 -0
- package/dist/lib/viewer/broadcast-singleton.d.ts +34 -0
- package/dist/lib/viewer/broadcast-singleton.js +49 -0
- package/dist/lib/viewer/broadcast.d.ts +66 -0
- package/dist/lib/viewer/broadcast.js +96 -0
- package/dist/lib/viewer/event-types.d.ts +132 -0
- package/dist/lib/viewer/event-types.js +74 -0
- package/dist/lib/viewer/instrumentation.d.ts +106 -0
- package/dist/lib/viewer/instrumentation.js +224 -0
- package/dist/lib/viewer/migration.d.ts +23 -0
- package/dist/lib/viewer/migration.js +56 -0
- package/dist/lib/viewer/redaction.d.ts +44 -0
- package/dist/lib/viewer/redaction.js +139 -0
- package/dist/lib/viewer/session.d.ts +51 -0
- package/dist/lib/viewer/session.js +87 -0
- package/dist/mcp/tools/answer.d.ts +94 -0
- package/dist/mcp/tools/answer.js +213 -0
- package/dist/mcp/tools/archive.d.ts +152 -0
- package/dist/mcp/tools/archive.js +170 -0
- package/dist/mcp/tools/conflict.d.ts +44 -0
- package/dist/mcp/tools/conflict.js +130 -0
- package/dist/mcp/tools/hooks.d.ts +29 -0
- package/dist/mcp/tools/hooks.js +78 -0
- package/dist/mcp/tools/mark.d.ts +38 -0
- package/dist/mcp/tools/mark.js +82 -0
- package/dist/mcp/tools/viewer.d.ts +58 -0
- package/dist/mcp/tools/viewer.js +64 -0
- package/dist/mcp-server.d.ts +2 -0
- package/dist/mcp-server.js +395 -0
- package/dist/metrics.d.ts +3 -0
- package/dist/metrics.js +59 -0
- package/dist/noise-filter.d.ts +18 -0
- package/dist/noise-filter.js +142 -0
- package/dist/notion-sync.d.ts +7 -0
- package/dist/notion-sync.js +97 -0
- package/dist/observability/adapters/a3-adapter.d.ts +63 -0
- package/dist/observability/adapters/a3-adapter.js +83 -0
- package/dist/observability/adapters/p1-adapter.d.ts +49 -0
- package/dist/observability/adapters/p1-adapter.js +63 -0
- package/dist/observability/adapters/p5-adapter.d.ts +36 -0
- package/dist/observability/adapters/p5-adapter.js +71 -0
- package/dist/observability/cardinality.d.ts +61 -0
- package/dist/observability/cardinality.js +300 -0
- package/dist/observability/collectors/db-stats.collector.d.ts +9 -0
- package/dist/observability/collectors/db-stats.collector.js +88 -0
- package/dist/observability/collectors/eventbus.collector.d.ts +6 -0
- package/dist/observability/collectors/eventbus.collector.js +50 -0
- package/dist/observability/collectors/process.collector.d.ts +7 -0
- package/dist/observability/collectors/process.collector.js +93 -0
- package/dist/observability/collectors/provider-telemetry.collector.d.ts +11 -0
- package/dist/observability/collectors/provider-telemetry.collector.js +112 -0
- package/dist/observability/collectors/search-telemetry.collector.d.ts +12 -0
- package/dist/observability/collectors/search-telemetry.collector.js +76 -0
- package/dist/observability/exporter.d.ts +30 -0
- package/dist/observability/exporter.js +182 -0
- package/dist/observability/index.d.ts +22 -0
- package/dist/observability/index.js +21 -0
- package/dist/observability/metrics.d.ts +53 -0
- package/dist/observability/metrics.js +213 -0
- package/dist/observability/privacy-guard.d.ts +32 -0
- package/dist/observability/privacy-guard.js +116 -0
- package/dist/observability/record.d.ts +83 -0
- package/dist/observability/record.js +217 -0
- package/dist/observability/registry.d.ts +60 -0
- package/dist/observability/registry.js +93 -0
- package/dist/observability/types.d.ts +115 -0
- package/dist/observability/types.js +235 -0
- package/dist/observability.d.ts +131 -0
- package/dist/observability.js +234 -0
- package/dist/plugins/nox-hooks/index.d.ts +61 -0
- package/dist/plugins/nox-hooks/index.js +99 -0
- package/dist/primer.d.ts +1 -0
- package/dist/primer.js +100 -0
- package/dist/privacy/filter.d.ts +27 -0
- package/dist/privacy/filter.js +74 -0
- package/dist/privacy/patterns.d.ts +29 -0
- package/dist/privacy/patterns.js +178 -0
- package/dist/privacy/tag-parser.d.ts +24 -0
- package/dist/privacy/tag-parser.js +29 -0
- package/dist/project-context-gen.d.ts +10 -0
- package/dist/project-context-gen.js +106 -0
- package/dist/providers/embedding/gemini.d.ts +73 -0
- package/dist/providers/embedding/gemini.js +118 -0
- package/dist/providers/embedding/openai.d.ts +76 -0
- package/dist/providers/embedding/openai.js +123 -0
- package/dist/providers/embedding/types.d.ts +39 -0
- package/dist/providers/embedding/types.js +1 -0
- package/dist/providers/embedding/voyage.d.ts +36 -0
- package/dist/providers/embedding/voyage.js +29 -0
- package/dist/providers/index.d.ts +116 -0
- package/dist/providers/index.js +158 -0
- package/dist/providers/llm/anthropic.d.ts +29 -0
- package/dist/providers/llm/anthropic.js +28 -0
- package/dist/providers/llm/chain.d.ts +99 -0
- package/dist/providers/llm/chain.js +213 -0
- package/dist/providers/llm/gemini.d.ts +48 -0
- package/dist/providers/llm/gemini.js +96 -0
- package/dist/providers/llm/openai.d.ts +64 -0
- package/dist/providers/llm/openai.js +109 -0
- package/dist/providers/llm/types.d.ts +47 -0
- package/dist/providers/llm/types.js +1 -0
- package/dist/providers/telemetry.d.ts +87 -0
- package/dist/providers/telemetry.js +156 -0
- package/dist/providers/types.d.ts +42 -0
- package/dist/providers/types.js +59 -0
- package/dist/query-entity-count.d.ts +54 -0
- package/dist/query-entity-count.js +171 -0
- package/dist/reflect.d.ts +26 -0
- package/dist/reflect.js +290 -0
- package/dist/reindex-errors.d.ts +7 -0
- package/dist/reindex-errors.js +21 -0
- package/dist/reindex.d.ts +16 -0
- package/dist/reindex.js +293 -0
- package/dist/retention.d.ts +40 -0
- package/dist/retention.js +86 -0
- package/dist/salience.d.ts +85 -0
- package/dist/salience.js +245 -0
- package/dist/scripts/migrate-v17-ops-audit.d.ts +17 -0
- package/dist/scripts/migrate-v17-ops-audit.js +70 -0
- package/dist/search-dedup.d.ts +44 -0
- package/dist/search-dedup.js +137 -0
- package/dist/search-expansion.d.ts +20 -0
- package/dist/search-expansion.js +99 -0
- package/dist/search.d.ts +62 -0
- package/dist/search.js +582 -0
- package/dist/seh-detector.d.ts +31 -0
- package/dist/seh-detector.js +201 -0
- package/dist/self-improve.d.ts +1 -0
- package/dist/self-improve.js +189 -0
- package/dist/session-distill.d.ts +29 -0
- package/dist/session-distill.js +325 -0
- package/dist/session-update.d.ts +1 -0
- package/dist/session-update.js +54 -0
- package/dist/shared-memory.d.ts +24 -0
- package/dist/shared-memory.js +104 -0
- package/dist/stats.d.ts +1 -0
- package/dist/stats.js +44 -0
- package/dist/temporal-retrieval.d.ts +132 -0
- package/dist/temporal-retrieval.js +495 -0
- package/dist/tier-manager.d.ts +69 -0
- package/dist/tier-manager.js +225 -0
- package/dist/vectorize.d.ts +16 -0
- package/dist/vectorize.js +91 -0
- package/dist/watch.d.ts +8 -0
- package/dist/watch.js +124 -0
- package/package.json +74 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T7 — Stale-link reconciliation on entity file update.
|
|
3
|
+
*
|
|
4
|
+
* When an entity file is renamed or edited, links pointing to the old slug may
|
|
5
|
+
* become stale. This module handles two modes:
|
|
6
|
+
*
|
|
7
|
+
* - stale-mark (default): sets `confidence` to STALE_CONFIDENCE + adds a
|
|
8
|
+
* `superseded_by` pointer to the new slug in each affected relation.
|
|
9
|
+
* - auto-rename (env `NOX_L4_AUTO_RENAME=1`): rewrites old slug → new slug
|
|
10
|
+
* across all affected kg_relations records.
|
|
11
|
+
*
|
|
12
|
+
* CRITICAL: auto-rename is DESTRUCTIVE — must require explicit env opt-in.
|
|
13
|
+
* Default is stale-mark (append-only philosophy per CLAUDE.md regra 6).
|
|
14
|
+
*
|
|
15
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §8.
|
|
16
|
+
*/
|
|
17
|
+
import { extractEntityRefsRegex } from "./extractor.js";
|
|
18
|
+
import { extractFrontmatterRelations } from "./frontmatter.js";
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Constants
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
/** Confidence assigned to stale relations (low — known stale). */
|
|
23
|
+
export const STALE_CONFIDENCE = 0.3;
|
|
24
|
+
/**
|
|
25
|
+
* Reason string written to superseded_reason when stale-marking a relation.
|
|
26
|
+
* Matches the reason used in the stale-link reconciliation flow (spec §8).
|
|
27
|
+
*/
|
|
28
|
+
export const STALE_REASON = "stale_link_reconciliation";
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Content → slug set extraction
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
/**
|
|
33
|
+
* Derive the full set of target slugs found in `content` via regex extraction
|
|
34
|
+
* (entity refs + frontmatter relations combined). Code refs are excluded from
|
|
35
|
+
* reconciliation — they're not direct KG entity slugs.
|
|
36
|
+
*/
|
|
37
|
+
export function extractTargetSlugsFromContent(content) {
|
|
38
|
+
const slugs = new Set();
|
|
39
|
+
for (const ref of extractEntityRefsRegex(content)) {
|
|
40
|
+
slugs.add(ref.key); // already `<entityType>/<slug>`
|
|
41
|
+
}
|
|
42
|
+
for (const rel of extractFrontmatterRelations(content)) {
|
|
43
|
+
const tgt = rel.target.trim();
|
|
44
|
+
if (tgt)
|
|
45
|
+
slugs.add(tgt);
|
|
46
|
+
}
|
|
47
|
+
return slugs;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Reconcile kg_relations for a given entity when its content changes.
|
|
51
|
+
*
|
|
52
|
+
* Algorithm (spec §8):
|
|
53
|
+
* 1. Extract new target slugs from `newContent` via regex.
|
|
54
|
+
* 2. Diff `existingRelations` vs new slug set:
|
|
55
|
+
* - Added: in new set, not in existing → emit `add` action.
|
|
56
|
+
* - Removed: in existing (regex_extracted only), not in new set → emit
|
|
57
|
+
* `mark_stale` or `auto_rename` action.
|
|
58
|
+
* - Unchanged: present in both → emit `noop`.
|
|
59
|
+
* 3. Gemini relations (extraction_method='gemini') are NEVER touched —
|
|
60
|
+
* deferred to next Gemini run.
|
|
61
|
+
* 4. Already-superseded relations are skipped.
|
|
62
|
+
*
|
|
63
|
+
* @param sourceSlug The entity being reconciled (e.g. `feedback/no_secrets`).
|
|
64
|
+
* @param newContent New markdown content of the entity file.
|
|
65
|
+
* @param existingRelations Current `kg_relations` rows for this entity.
|
|
66
|
+
* @param opts Reconcile options.
|
|
67
|
+
*/
|
|
68
|
+
export function reconcileEntityLinks(sourceSlug, newContent, existingRelations, opts = {}) {
|
|
69
|
+
const autoRename = opts.autoRename === true;
|
|
70
|
+
const newSlug = opts.newSlug?.trim() ?? "";
|
|
71
|
+
const mode = autoRename && newSlug
|
|
72
|
+
? "auto_rename"
|
|
73
|
+
: "stale_mark";
|
|
74
|
+
// Derive new target slug set from updated content.
|
|
75
|
+
const newTargetSlugs = extractTargetSlugsFromContent(newContent);
|
|
76
|
+
// Build lookup of existing REGEX-extracted (active) relations by target slug.
|
|
77
|
+
const existingByTarget = new Map();
|
|
78
|
+
for (const rel of existingRelations) {
|
|
79
|
+
if (rel.extraction_method !== "regex")
|
|
80
|
+
continue; // only manage regex rels
|
|
81
|
+
if (rel.superseded)
|
|
82
|
+
continue; // skip already-superseded
|
|
83
|
+
existingByTarget.set(rel.targetSlug, rel);
|
|
84
|
+
}
|
|
85
|
+
const actions = [];
|
|
86
|
+
const added = [];
|
|
87
|
+
const removed = [];
|
|
88
|
+
const unchanged = [];
|
|
89
|
+
// Check new slugs: adds vs noops.
|
|
90
|
+
for (const tgtSlug of newTargetSlugs) {
|
|
91
|
+
if (existingByTarget.has(tgtSlug)) {
|
|
92
|
+
actions.push({ type: "noop", targetSlug: tgtSlug });
|
|
93
|
+
unchanged.push(tgtSlug);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
actions.push({
|
|
97
|
+
type: "add",
|
|
98
|
+
targetSlug: tgtSlug,
|
|
99
|
+
relationType: "regex_extracted",
|
|
100
|
+
});
|
|
101
|
+
added.push(tgtSlug);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Check removed: existing regex rels not in new set.
|
|
105
|
+
for (const [tgtSlug, rel] of existingByTarget) {
|
|
106
|
+
if (newTargetSlugs.has(tgtSlug))
|
|
107
|
+
continue; // handled above
|
|
108
|
+
if (mode === "auto_rename" && newSlug) {
|
|
109
|
+
actions.push({
|
|
110
|
+
type: "auto_rename",
|
|
111
|
+
relation: rel,
|
|
112
|
+
oldTargetSlug: tgtSlug,
|
|
113
|
+
newTargetSlug: newSlug,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
actions.push({
|
|
118
|
+
type: "mark_stale",
|
|
119
|
+
relation: rel,
|
|
120
|
+
newConfidence: STALE_CONFIDENCE,
|
|
121
|
+
supersededReason: STALE_REASON,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
removed.push(tgtSlug);
|
|
125
|
+
}
|
|
126
|
+
return { actions, added, removed, unchanged, mode };
|
|
127
|
+
}
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
// Rename detection helper
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
/**
|
|
132
|
+
* Detect whether an entity slug has changed between two content snapshots by
|
|
133
|
+
* comparing the `slug` frontmatter field (or the first heading). Returns the
|
|
134
|
+
* detected new slug if different, null if no change detected.
|
|
135
|
+
*
|
|
136
|
+
* This is a lightweight heuristic — the definitive source is the filesystem
|
|
137
|
+
* rename event from the watcher. Use this as a sanity check.
|
|
138
|
+
*/
|
|
139
|
+
export function detectSlugChange(oldContent, newContent) {
|
|
140
|
+
const extractSlugHint = (content) => {
|
|
141
|
+
// Try frontmatter `slug:` field first.
|
|
142
|
+
const fm = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
143
|
+
if (fm) {
|
|
144
|
+
const slugMatch = fm[1]?.match(/^slug:\s*([^\r\n]+)/m);
|
|
145
|
+
if (slugMatch)
|
|
146
|
+
return slugMatch[1]?.trim() ?? null;
|
|
147
|
+
}
|
|
148
|
+
// Fallback: first H1.
|
|
149
|
+
const h1 = content.match(/^#\s+(.+)$/m);
|
|
150
|
+
if (h1)
|
|
151
|
+
return h1[1]?.trim() ?? null;
|
|
152
|
+
return null;
|
|
153
|
+
};
|
|
154
|
+
const oldSlug = extractSlugHint(oldContent);
|
|
155
|
+
const newSlug = extractSlugHint(newContent);
|
|
156
|
+
const changed = oldSlug !== null && newSlug !== null && oldSlug !== newSlug;
|
|
157
|
+
return { changed, oldSlug, newSlug };
|
|
158
|
+
}
|
|
159
|
+
export function rewriteChunksForRename(chunks, oldSlug, newSlug) {
|
|
160
|
+
if (!oldSlug || !newSlug || oldSlug === newSlug) {
|
|
161
|
+
return chunks.map((c) => ({
|
|
162
|
+
chunkId: c.chunkId,
|
|
163
|
+
original: c.content,
|
|
164
|
+
rewritten: c.content,
|
|
165
|
+
changed: false,
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
const escaped = oldSlug.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
169
|
+
// Rewrite markdown links: [label](path/to/oldSlug) → [label](path/to/newSlug)
|
|
170
|
+
const mdLinkRe = new RegExp(`(\\[[^\\]]*\\]\\()([^)]*?)\\b${escaped}\\b([^)]*)\\)`, "g");
|
|
171
|
+
// Rewrite wikilinks: [[oldSlug]] → [[newSlug]] (including anchors and pipes)
|
|
172
|
+
const wikilinkRe = new RegExp(`(\\[\\[)${escaped}((?:#[^|\\]\\n]*)?(?:\\|[^\\]\\n]*)?)(\\]\\])`, "g");
|
|
173
|
+
// Rewrite bare refs: anchored to word-like boundaries (avoid URLs)
|
|
174
|
+
const bareRefRe = new RegExp(`(?<=^|[\\s(,;])${escaped}(?=$|[\\s).,?!;:])`, "gm");
|
|
175
|
+
return chunks.map((c) => {
|
|
176
|
+
let rewritten = c.content;
|
|
177
|
+
rewritten = rewritten.replace(mdLinkRe, `$1$2${newSlug}$3)`);
|
|
178
|
+
rewritten = rewritten.replace(wikilinkRe, `$1${newSlug}$2$3`);
|
|
179
|
+
rewritten = rewritten.replace(bareRefRe, newSlug);
|
|
180
|
+
const changed = rewritten !== c.content;
|
|
181
|
+
return { chunkId: c.chunkId, original: c.content, rewritten, changed };
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
// ---------------------------------------------------------------------------
|
|
185
|
+
// Circular rename guard
|
|
186
|
+
// ---------------------------------------------------------------------------
|
|
187
|
+
/**
|
|
188
|
+
* Validate a sequence of renames for circular dependencies.
|
|
189
|
+
* Returns an error string if a cycle is detected, null otherwise.
|
|
190
|
+
*
|
|
191
|
+
* A cycle exists when following rename chain A→B→C→A.
|
|
192
|
+
*/
|
|
193
|
+
export function detectCircularRename(renames) {
|
|
194
|
+
const edges = new Map();
|
|
195
|
+
for (const r of renames) {
|
|
196
|
+
edges.set(r.from, r.to);
|
|
197
|
+
}
|
|
198
|
+
for (const start of edges.keys()) {
|
|
199
|
+
const visited = new Set();
|
|
200
|
+
let cur = start;
|
|
201
|
+
while (cur !== undefined) {
|
|
202
|
+
if (visited.has(cur)) {
|
|
203
|
+
return `Circular rename detected: ${Array.from(visited).join(" → ")} → ${cur}`;
|
|
204
|
+
}
|
|
205
|
+
visited.add(cur);
|
|
206
|
+
cur = edges.get(cur);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T1 — stripCodeBlocks helper.
|
|
3
|
+
*
|
|
4
|
+
* Adapted from gbrain/src/core/link-extraction.ts (MIT, Garry Tan, https://github.com/garry-tan/gbrain).
|
|
5
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §6.1.
|
|
6
|
+
*
|
|
7
|
+
* Replaces fenced ``` blocks (with optional language tag) AND inline `code`
|
|
8
|
+
* with whitespace of equivalent length. Preserving length keeps any downstream
|
|
9
|
+
* offset/line maths stable across the strip — callers can run regexes over the
|
|
10
|
+
* stripped buffer and report locations against the original text.
|
|
11
|
+
*/
|
|
12
|
+
/** Stable result of stripping. */
|
|
13
|
+
export interface StripResult {
|
|
14
|
+
stripped: string;
|
|
15
|
+
hadFences: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Strip fenced + inline + indented-4 code spans from markdown, returning a
|
|
19
|
+
* length-preserved string safe for further regex matching.
|
|
20
|
+
*
|
|
21
|
+
* Order matters: fences first (so triple-backtick inline doesn't get clipped),
|
|
22
|
+
* then inline backticks.
|
|
23
|
+
*/
|
|
24
|
+
export declare function stripCodeBlocks(text: string): StripResult;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T1 — stripCodeBlocks helper.
|
|
3
|
+
*
|
|
4
|
+
* Adapted from gbrain/src/core/link-extraction.ts (MIT, Garry Tan, https://github.com/garry-tan/gbrain).
|
|
5
|
+
* Spec: specs/2026-05-18-L4-regex-first-extraction.md §6.1.
|
|
6
|
+
*
|
|
7
|
+
* Replaces fenced ``` blocks (with optional language tag) AND inline `code`
|
|
8
|
+
* with whitespace of equivalent length. Preserving length keeps any downstream
|
|
9
|
+
* offset/line maths stable across the strip — callers can run regexes over the
|
|
10
|
+
* stripped buffer and report locations against the original text.
|
|
11
|
+
*/
|
|
12
|
+
/** Match fenced code blocks (```...``` with optional info-string). DOTALL via [\s\S]. */
|
|
13
|
+
const FENCE_RE = /```[^\n]*\n[\s\S]*?```/g;
|
|
14
|
+
/** Match indented (4-space) code blocks at line start. Multi-line block. */
|
|
15
|
+
const INDENTED_BLOCK_RE = /(^|\n)((?: [^\n]*(?:\n|$))+)/g;
|
|
16
|
+
/** Match inline code: balanced single/double/triple backticks on one line. */
|
|
17
|
+
const INLINE_CODE_RE = /(`{1,3})([^\n`]|`(?!`))+?\1/g;
|
|
18
|
+
/**
|
|
19
|
+
* Replace each match with same-length whitespace (newlines preserved verbatim
|
|
20
|
+
* so line numbers don't shift).
|
|
21
|
+
*/
|
|
22
|
+
function blankPreserveNewlines(input) {
|
|
23
|
+
let out = "";
|
|
24
|
+
for (let i = 0; i < input.length; i++) {
|
|
25
|
+
const ch = input[i];
|
|
26
|
+
out += ch === "\n" || ch === "\r" ? ch : " ";
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Strip fenced + inline + indented-4 code spans from markdown, returning a
|
|
32
|
+
* length-preserved string safe for further regex matching.
|
|
33
|
+
*
|
|
34
|
+
* Order matters: fences first (so triple-backtick inline doesn't get clipped),
|
|
35
|
+
* then inline backticks.
|
|
36
|
+
*/
|
|
37
|
+
export function stripCodeBlocks(text) {
|
|
38
|
+
let hadFences = false;
|
|
39
|
+
let out = text.replace(FENCE_RE, (m) => {
|
|
40
|
+
hadFences = true;
|
|
41
|
+
return blankPreserveNewlines(m);
|
|
42
|
+
});
|
|
43
|
+
out = out.replace(INDENTED_BLOCK_RE, (full, prefix, body) => {
|
|
44
|
+
hadFences = true;
|
|
45
|
+
return prefix + blankPreserveNewlines(body);
|
|
46
|
+
});
|
|
47
|
+
out = out.replace(INLINE_CODE_RE, (m) => {
|
|
48
|
+
hadFences = true;
|
|
49
|
+
return blankPreserveNewlines(m);
|
|
50
|
+
});
|
|
51
|
+
return { stripped: out, hadFences };
|
|
52
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L4 regex-extract — shared types.
|
|
3
|
+
*
|
|
4
|
+
* Cross-ref: specs/2026-05-18-L4-regex-first-extraction.md §4-§7.
|
|
5
|
+
*/
|
|
6
|
+
/** Whitelist of recognized entity types (DIR_PATTERN sources). */
|
|
7
|
+
export declare const NOX_ENTITY_TYPES: readonly ["feedback", "person", "lesson", "decision", "project", "team", "daily", "pending", "graph_node", "agent", "incident", "spec", "audit", "skill", "persona", "reference", "entities"];
|
|
8
|
+
export type NoxEntityType = (typeof NOX_ENTITY_TYPES)[number];
|
|
9
|
+
/** A single extracted entity reference (markdown link / wikilink / bare). */
|
|
10
|
+
export interface EntityRef {
|
|
11
|
+
/** Entity type bucket. */
|
|
12
|
+
entityType: NoxEntityType;
|
|
13
|
+
/** Slug (no extension, no fragment). */
|
|
14
|
+
slug: string;
|
|
15
|
+
/** Canonical key `<entityType>/<slug>` — dedup key. */
|
|
16
|
+
key: string;
|
|
17
|
+
/** Visible display text (markdown alt-text / wikilink pipe). */
|
|
18
|
+
display?: string;
|
|
19
|
+
/** Source pattern that matched. */
|
|
20
|
+
source: "markdown_link" | "wikilink" | "bare_ref";
|
|
21
|
+
}
|
|
22
|
+
/** Frontmatter-derived typed relation (§5 table). */
|
|
23
|
+
export interface FrontmatterRelation {
|
|
24
|
+
relationType: "is_agent_of" | "references" | "supersedes" | "caused_by" | "resolves" | "decided_by";
|
|
25
|
+
/** Target entity key `<entityType>/<slug>`; may be unqualified — caller resolves stub. */
|
|
26
|
+
target: string;
|
|
27
|
+
/** Raw field value from YAML for audit. */
|
|
28
|
+
raw: string;
|
|
29
|
+
}
|
|
30
|
+
/** Code-path reference (e.g. `src/lib/op-audit.ts:42`). */
|
|
31
|
+
export interface CodeRef {
|
|
32
|
+
/** Top-level dir (src, specs, audits, etc.). */
|
|
33
|
+
root: string;
|
|
34
|
+
/** Full path under root (e.g. `lib/op-audit.ts`). */
|
|
35
|
+
path: string;
|
|
36
|
+
/** Optional 1-based line number. */
|
|
37
|
+
line?: number;
|
|
38
|
+
/** Virtual entity key `codepath/<normalized_path>` for KG storage. */
|
|
39
|
+
key: string;
|
|
40
|
+
}
|
|
41
|
+
/** Aggregated regex extraction result. */
|
|
42
|
+
export interface RegexExtractionResult {
|
|
43
|
+
entityRefs: EntityRef[];
|
|
44
|
+
frontmatterRelations: FrontmatterRelation[];
|
|
45
|
+
codeRefs: CodeRef[];
|
|
46
|
+
/** True when stripCodeBlocks removed at least one fence/inline span. */
|
|
47
|
+
hadCodeFences: boolean;
|
|
48
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L4 regex-extract — shared types.
|
|
3
|
+
*
|
|
4
|
+
* Cross-ref: specs/2026-05-18-L4-regex-first-extraction.md §4-§7.
|
|
5
|
+
*/
|
|
6
|
+
/** Whitelist of recognized entity types (DIR_PATTERN sources). */
|
|
7
|
+
export const NOX_ENTITY_TYPES = [
|
|
8
|
+
"feedback",
|
|
9
|
+
"person",
|
|
10
|
+
"lesson",
|
|
11
|
+
"decision",
|
|
12
|
+
"project",
|
|
13
|
+
"team",
|
|
14
|
+
"daily",
|
|
15
|
+
"pending",
|
|
16
|
+
"graph_node",
|
|
17
|
+
"agent",
|
|
18
|
+
"incident",
|
|
19
|
+
"spec",
|
|
20
|
+
"audit",
|
|
21
|
+
"skill",
|
|
22
|
+
"persona",
|
|
23
|
+
"reference",
|
|
24
|
+
"entities", // top-level dir prefix in vault paths
|
|
25
|
+
];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export type RerankerMode = "off" | "shadow" | "active";
|
|
2
|
+
export interface RerankCandidate {
|
|
3
|
+
id?: number;
|
|
4
|
+
chunk_text: string;
|
|
5
|
+
[k: string]: any;
|
|
6
|
+
}
|
|
7
|
+
export interface RerankSummary {
|
|
8
|
+
mode: RerankerMode;
|
|
9
|
+
topKIn: number;
|
|
10
|
+
topKOut: number;
|
|
11
|
+
latencyMs: number;
|
|
12
|
+
positionChanges: number;
|
|
13
|
+
liftScore: number;
|
|
14
|
+
failed: boolean;
|
|
15
|
+
failureReason?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const DEFAULT_TOP_K_IN = 50;
|
|
18
|
+
export declare const DEFAULT_TOP_K_OUT = 10;
|
|
19
|
+
export declare const DEFAULT_MODEL = "Xenova/bge-reranker-base";
|
|
20
|
+
export declare const DEFAULT_TIMEOUT_MS = 2000;
|
|
21
|
+
export declare function getMode(): RerankerMode;
|
|
22
|
+
export declare function getTopKIn(): number;
|
|
23
|
+
export declare function getTopKOut(): number;
|
|
24
|
+
export declare function getModelName(): string;
|
|
25
|
+
export declare function getTimeoutMs(): number;
|
|
26
|
+
export type RerankerFn = (pairs: Array<{
|
|
27
|
+
text: string;
|
|
28
|
+
text_pair: string;
|
|
29
|
+
}>) => Promise<Array<{
|
|
30
|
+
score: number;
|
|
31
|
+
}>>;
|
|
32
|
+
/**
|
|
33
|
+
* Test hook: injetar uma fn mock pra evitar download do modelo.
|
|
34
|
+
* Em produção, NÃO chamar — `rerank()` carrega lazy via @xenova/transformers.
|
|
35
|
+
*
|
|
36
|
+
* Quando fn=null + reset=true (default), limpa singleton + cached error.
|
|
37
|
+
* Use reset=false só pra cenários onde você quer preservar erro cacheado.
|
|
38
|
+
*/
|
|
39
|
+
export declare function __setRerankerFnForTesting(fn: RerankerFn | null, reset?: boolean): void;
|
|
40
|
+
/**
|
|
41
|
+
* Pre-warm o singleton do modelo. Chamado pelo nox-mem-api boot quando
|
|
42
|
+
* NOX_RERANKER_MODE != off, pra evitar cold-start de ~12-90s no primeiro
|
|
43
|
+
* search request (D01 spec §risks §1). Idempotente: subsequent calls são no-op.
|
|
44
|
+
*/
|
|
45
|
+
export declare function preloadModel(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Conta chunks que mudaram posição entre os top-K original e o pós-rerank.
|
|
48
|
+
* Trabalha por id (campo opcional). Chunks sem id são ignorados (não rastreáveis).
|
|
49
|
+
*/
|
|
50
|
+
export declare function computePositionChanges(origTopK: RerankCandidate[], newTopK: RerankCandidate[]): number;
|
|
51
|
+
/**
|
|
52
|
+
* Lift score: mean displacement normalizado em [0, 1].
|
|
53
|
+
*
|
|
54
|
+
* Combina dois sinais:
|
|
55
|
+
* 1) displacement intra-intersection: |orig_pos − new_pos| pra ids em ambos
|
|
56
|
+
* 2) turnover (set churn): id que entrou OU saiu conta como displacement = K
|
|
57
|
+
*
|
|
58
|
+
* Total = sum(deltas) / (count * K), onde K = max(|orig|, |new|).
|
|
59
|
+
*
|
|
60
|
+
* Edge cases:
|
|
61
|
+
* - sets disjoint → todos turnover, score = 1
|
|
62
|
+
* - identical → 0
|
|
63
|
+
* - swap top-2 (K=5) → 2 ids movem 1 cada → 2/(5*4) = 0.1
|
|
64
|
+
*/
|
|
65
|
+
export declare function computeLiftScore(origTopK: RerankCandidate[], newTopK: RerankCandidate[]): number;
|
|
66
|
+
/**
|
|
67
|
+
* Rerank candidates via cross-encoder. Comportamento per mode:
|
|
68
|
+
*
|
|
69
|
+
* - off: no-op, retorna candidates.slice(0, topK), summary mode='off'
|
|
70
|
+
* - shadow: roda reranker, calcula lift, retorna candidates ORIGINAIS top-K
|
|
71
|
+
* (não muta ranking — caller recebe ordem pre-rerank)
|
|
72
|
+
* - active: roda reranker, retorna pós-rerank top-K (muta ranking)
|
|
73
|
+
*
|
|
74
|
+
* Fail-open: qualquer erro (model load, timeout, ONNX crash) → retorna
|
|
75
|
+
* candidates.slice(0, topK) original com summary.failed=true. Não joga.
|
|
76
|
+
*/
|
|
77
|
+
export declare function rerank(query: string, candidates: RerankCandidate[], topKOut?: number): Promise<{
|
|
78
|
+
results: RerankCandidate[];
|
|
79
|
+
summary: RerankSummary;
|
|
80
|
+
}>;
|