nox-mem 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -16
- package/dist/__tests__/brief-diversity.test.js +266 -0
- package/dist/__tests__/brief.test.js +287 -0
- package/dist/__tests__/churn.test.js +66 -0
- package/dist/__tests__/edge-typing.test.js +99 -0
- package/dist/__tests__/ingest-event.test.js +151 -0
- package/dist/__tests__/op-audit-e2e.test.js +130 -0
- package/dist/__tests__/pragma-alignment.test.js +123 -0
- package/dist/__tests__/reranker.test.js +326 -0
- package/dist/__tests__/retention.test.js +99 -0
- package/dist/__tests__/search-track-access.test.js +49 -0
- package/dist/__tests__/spo-injection.test.js +172 -0
- package/dist/__tests__/temporal-detector.test.js +103 -0
- package/dist/api/wire-up.js +12 -381
- package/dist/api-server.js +6 -102
- package/dist/db.js +61 -2
- package/dist/embed.js +23 -2
- package/dist/index.js +1 -22
- package/dist/knowledge-graph.js +20 -0
- package/dist/lib/answer/__tests__/e2e-gemini.test.js +229 -0
- package/dist/lib/answer/__tests__/integration-sqlite.test.js +388 -0
- package/dist/lib/answer/__tests__/integration.test.js +347 -0
- package/dist/lib/answer/__tests__/prompt.test.js +117 -0
- package/dist/lib/answer/__tests__/t5-t10.test.js +501 -0
- package/dist/lib/answer/provider.js +29 -4
- package/dist/lib/api/__tests__/safe-error-message.test.js +155 -0
- package/dist/lib/auth/__tests__/localhost-guard.test.js +144 -0
- package/dist/lib/error-sanitizer/__tests__/sanitize.test.js +354 -0
- package/dist/lib/events/__tests__/bus.test.js +208 -0
- package/dist/lib/ingest-router.js +0 -43
- package/dist/lib/op-audit-extension/__tests__/ran-at-guard.test.js +109 -0
- package/dist/lib/regex-extract/__tests__/extractor.test.js +197 -0
- package/dist/lib/regex-extract/__tests__/frontmatter.test.js +75 -0
- package/dist/lib/regex-extract/__tests__/ingest-router-l4.test.js +139 -0
- package/dist/lib/regex-extract/__tests__/production-wire.test.js +177 -0
- package/dist/lib/regex-extract/__tests__/reconcile.test.js +170 -0
- package/dist/lib/regex-extract/__tests__/strip-code.test.js +36 -0
- package/dist/privacy/__tests__/filter.test.js +352 -0
- package/dist/providers/__tests__/conformance-extended.test.js +249 -0
- package/dist/providers/__tests__/conformance.test.js +98 -0
- package/dist/providers/__tests__/cost-cap.test.js +151 -0
- package/dist/providers/__tests__/e2e-real.test.js +79 -0
- package/dist/providers/__tests__/factory.test.js +80 -0
- package/dist/providers/__tests__/fallback.test.js +223 -0
- package/dist/providers/__tests__/gemini.test.js +191 -0
- package/dist/providers/__tests__/health.test.js +128 -0
- package/dist/providers/__tests__/telemetry.test.js +219 -0
- package/dist/reindex.js +2 -2
- package/package.json +3 -4
- package/dist/api/answer.d.ts +0 -116
- package/dist/api/answer.validate-patch.d.ts +0 -72
- package/dist/api/brief-diversity.d.ts +0 -64
- package/dist/api/brief.d.ts +0 -114
- package/dist/api/conflict.d.ts +0 -33
- package/dist/api/conflict.js +0 -143
- package/dist/api/cors.d.ts +0 -73
- package/dist/api/events-stream-limited.d.ts +0 -133
- package/dist/api/events-stream-limited.js +0 -217
- package/dist/api/events-stream.d.ts +0 -53
- package/dist/api/events-stream.js +0 -125
- package/dist/api/export.d.ts +0 -42
- package/dist/api/export.js +0 -85
- package/dist/api/health-confidence-adapter.d.ts +0 -29
- package/dist/api/health-confidence-adapter.js +0 -73
- package/dist/api/health-confidence.d.ts +0 -36
- package/dist/api/health-confidence.js +0 -141
- package/dist/api/hooks.d.ts +0 -50
- package/dist/api/hooks.js +0 -115
- package/dist/api/import.d.ts +0 -38
- package/dist/api/import.js +0 -87
- package/dist/api/ingest-event.d.ts +0 -65
- package/dist/api/mark.d.ts +0 -42
- package/dist/api/mark.js +0 -127
- package/dist/api/server-deps-a2.d.ts +0 -55
- package/dist/api/server-deps-a2.js +0 -138
- package/dist/api/server-deps-l2-l3.d.ts +0 -68
- package/dist/api/server-deps-l2-l3.js +0 -123
- package/dist/api/server-deps-p1.d.ts +0 -84
- package/dist/api/server-deps-p2.d.ts +0 -32
- package/dist/api/server-deps-p2.js +0 -84
- package/dist/api/server-deps-p5.d.ts +0 -66
- package/dist/api/server-deps-p5.js +0 -139
- package/dist/api/viewer-static.d.ts +0 -30
- package/dist/api/viewer-static.js +0 -102
- package/dist/api/wire-up.d.ts +0 -54
- package/dist/api-impact.d.ts +0 -30
- package/dist/api-server.d.ts +0 -2
- package/dist/backfill-fts-anchor.d.ts +0 -15
- package/dist/backfill-source-type.d.ts +0 -20
- package/dist/churn.d.ts +0 -31
- package/dist/cli/answer.d.ts +0 -66
- package/dist/cli/conflict.d.ts +0 -38
- package/dist/cli/conflict.js +0 -282
- package/dist/cli/export.d.ts +0 -51
- package/dist/cli/export.js +0 -280
- package/dist/cli/hooks.d.ts +0 -54
- package/dist/cli/hooks.js +0 -133
- package/dist/cli/import.d.ts +0 -52
- package/dist/cli/import.js +0 -274
- package/dist/cli/mark.d.ts +0 -33
- package/dist/cli/mark.js +0 -130
- package/dist/cli/ocr-batch.d.ts +0 -12
- package/dist/cli/ocr-batch.js +0 -411
- package/dist/cli/snapshot-main.d.ts +0 -30
- package/dist/cli/snapshot-main.js +0 -47
- package/dist/cli/viewer.d.ts +0 -35
- package/dist/cli/viewer.js +0 -71
- package/dist/cli-telemetry.d.ts +0 -36
- package/dist/cli-telemetry.js +0 -150
- package/dist/compact.d.ts +0 -7
- package/dist/consolidate.d.ts +0 -18
- package/dist/consolidation.d.ts +0 -32
- package/dist/cross-agent-v2.d.ts +0 -45
- package/dist/cross-search.d.ts +0 -11
- package/dist/crystallize.d.ts +0 -43
- package/dist/db.d.ts +0 -11
- package/dist/dedup.d.ts +0 -1
- package/dist/detect-changes.d.ts +0 -29
- package/dist/digest.d.ts +0 -1
- package/dist/doctor.d.ts +0 -1
- package/dist/embed.d.ts +0 -57
- package/dist/evals.d.ts +0 -176
- package/dist/evals.js +0 -351
- package/dist/generate-user-profile.d.ts +0 -18
- package/dist/graphify-ingest.d.ts +0 -18
- package/dist/impact.d.ts +0 -39
- package/dist/index.d.ts +0 -2
- package/dist/ingest-entity.d.ts +0 -44
- package/dist/ingest.d.ts +0 -13
- package/dist/kg-llm.d.ts +0 -39
- package/dist/knowledge-graph.d.ts +0 -72
- package/dist/lib/answer/config.d.ts +0 -41
- package/dist/lib/answer/index.d.ts +0 -47
- package/dist/lib/answer/prompt.d.ts +0 -37
- package/dist/lib/answer/provider.d.ts +0 -47
- package/dist/lib/answer/retrieval.d.ts +0 -36
- package/dist/lib/answer/telemetry.d.ts +0 -99
- package/dist/lib/answer/types.d.ts +0 -108
- package/dist/lib/api/error-leak-fix.d.ts +0 -54
- package/dist/lib/api/safe-error-message.d.ts +0 -70
- package/dist/lib/archive/common-passwords.d.ts +0 -37
- package/dist/lib/archive/common-passwords.js +0 -753
- package/dist/lib/archive/encryption.d.ts +0 -81
- package/dist/lib/archive/encryption.js +0 -236
- package/dist/lib/archive/enforce-strength.d.ts +0 -54
- package/dist/lib/archive/enforce-strength.js +0 -70
- package/dist/lib/archive/entropy.d.ts +0 -34
- package/dist/lib/archive/entropy.js +0 -180
- package/dist/lib/archive/export-locking.d.ts +0 -102
- package/dist/lib/archive/export-locking.js +0 -202
- package/dist/lib/archive/format.d.ts +0 -20
- package/dist/lib/archive/format.js +0 -174
- package/dist/lib/archive/index.d.ts +0 -23
- package/dist/lib/archive/index.js +0 -17
- package/dist/lib/archive/manifest.d.ts +0 -53
- package/dist/lib/archive/manifest.js +0 -183
- package/dist/lib/archive/migration.d.ts +0 -36
- package/dist/lib/archive/migration.js +0 -100
- package/dist/lib/archive/migrations/v18_to_v19.d.ts +0 -16
- package/dist/lib/archive/migrations/v18_to_v19.js +0 -18
- package/dist/lib/archive/orchestrator.d.ts +0 -166
- package/dist/lib/archive/orchestrator.js +0 -428
- package/dist/lib/archive/serializers/chunks.d.ts +0 -30
- package/dist/lib/archive/serializers/chunks.js +0 -113
- package/dist/lib/archive/serializers/embeddings.d.ts +0 -36
- package/dist/lib/archive/serializers/embeddings.js +0 -115
- package/dist/lib/archive/serializers/kg.d.ts +0 -28
- package/dist/lib/archive/serializers/kg.js +0 -184
- package/dist/lib/archive/serializers/ops_audit.d.ts +0 -21
- package/dist/lib/archive/serializers/ops_audit.js +0 -97
- package/dist/lib/archive/server-deps.d.ts +0 -131
- package/dist/lib/archive/server-deps.js +0 -232
- package/dist/lib/archive/strength.d.ts +0 -50
- package/dist/lib/archive/strength.js +0 -77
- package/dist/lib/archive/types.d.ts +0 -159
- package/dist/lib/archive/types.js +0 -45
- package/dist/lib/archive/unpack-streaming.d.ts +0 -70
- package/dist/lib/archive/unpack-streaming.js +0 -255
- package/dist/lib/auth/localhost-guard.d.ts +0 -106
- package/dist/lib/confidence/config.d.ts +0 -37
- package/dist/lib/confidence/config.js +0 -107
- package/dist/lib/confidence/db-shim-singleton.d.ts +0 -20
- package/dist/lib/confidence/db-shim-singleton.js +0 -41
- package/dist/lib/confidence/db-shim.d.ts +0 -47
- package/dist/lib/confidence/db-shim.js +0 -141
- package/dist/lib/confidence/mark.d.ts +0 -58
- package/dist/lib/confidence/mark.js +0 -168
- package/dist/lib/confidence/ranking.d.ts +0 -69
- package/dist/lib/confidence/ranking.js +0 -101
- package/dist/lib/confidence/search-filter.d.ts +0 -44
- package/dist/lib/confidence/search-filter.js +0 -103
- package/dist/lib/confidence/types.d.ts +0 -146
- package/dist/lib/confidence/types.js +0 -20
- package/dist/lib/confidence/write-hooks.d.ts +0 -50
- package/dist/lib/confidence/write-hooks.js +0 -159
- package/dist/lib/conflict/audit-fk-check.d.ts +0 -72
- package/dist/lib/conflict/audit-fk-check.js +0 -131
- package/dist/lib/conflict/audit-writer.d.ts +0 -39
- package/dist/lib/conflict/audit-writer.js +0 -133
- package/dist/lib/conflict/db-singleton.d.ts +0 -28
- package/dist/lib/conflict/db-singleton.js +0 -61
- package/dist/lib/conflict/db.d.ts +0 -27
- package/dist/lib/conflict/db.js +0 -20
- package/dist/lib/conflict/detector-direct.d.ts +0 -21
- package/dist/lib/conflict/detector-direct.js +0 -105
- package/dist/lib/conflict/evidence.d.ts +0 -24
- package/dist/lib/conflict/evidence.js +0 -76
- package/dist/lib/conflict/index.d.ts +0 -14
- package/dist/lib/conflict/index.js +0 -12
- package/dist/lib/conflict/scheduler.d.ts +0 -78
- package/dist/lib/conflict/scheduler.js +0 -111
- package/dist/lib/conflict/shadow.d.ts +0 -75
- package/dist/lib/conflict/shadow.js +0 -161
- package/dist/lib/conflict/types.d.ts +0 -133
- package/dist/lib/conflict/types.js +0 -19
- package/dist/lib/cost-cap.d.ts +0 -94
- package/dist/lib/deps/deps-registry.d.ts +0 -111
- package/dist/lib/error-sanitizer/middleware.d.ts +0 -43
- package/dist/lib/error-sanitizer/sanitize.d.ts +0 -78
- package/dist/lib/eval-batch.d.ts +0 -34
- package/dist/lib/eval-batch.js +0 -103
- package/dist/lib/eval-metrics.d.ts +0 -36
- package/dist/lib/eval-metrics.js +0 -95
- package/dist/lib/eval.d.ts +0 -106
- package/dist/lib/eval.js +0 -343
- package/dist/lib/events/bus.d.ts +0 -135
- package/dist/lib/fts-anchor.d.ts +0 -1
- package/dist/lib/hooks/classifier.d.ts +0 -47
- package/dist/lib/hooks/classifier.js +0 -129
- package/dist/lib/hooks/config.d.ts +0 -49
- package/dist/lib/hooks/config.js +0 -106
- package/dist/lib/hooks/decorators.d.ts +0 -35
- package/dist/lib/hooks/decorators.js +0 -59
- package/dist/lib/hooks/pipeline.d.ts +0 -76
- package/dist/lib/hooks/pipeline.js +0 -213
- package/dist/lib/hooks/privacy-filter-adapter.d.ts +0 -55
- package/dist/lib/hooks/privacy-filter-adapter.js +0 -84
- package/dist/lib/hooks/rate-limit-constant-time.d.ts +0 -57
- package/dist/lib/hooks/rate-limit-constant-time.js +0 -69
- package/dist/lib/hooks/rate-limit-dryrun-fix.d.ts +0 -71
- package/dist/lib/hooks/rate-limit-dryrun-fix.js +0 -110
- package/dist/lib/hooks/rate-limit.d.ts +0 -54
- package/dist/lib/hooks/rate-limit.js +0 -122
- package/dist/lib/hooks/server-deps.d.ts +0 -61
- package/dist/lib/hooks/server-deps.js +0 -92
- package/dist/lib/hooks/source-allowlist.d.ts +0 -26
- package/dist/lib/hooks/source-allowlist.js +0 -53
- package/dist/lib/hooks/types.d.ts +0 -129
- package/dist/lib/hooks/types.js +0 -24
- package/dist/lib/hooks/worker.d.ts +0 -56
- package/dist/lib/hooks/worker.js +0 -150
- package/dist/lib/ingest-router.d.ts +0 -25
- package/dist/lib/ocr-detector.d.ts +0 -61
- package/dist/lib/ocr-detector.js +0 -138
- package/dist/lib/ocr-engine-stub.d.ts +0 -48
- package/dist/lib/ocr-engine-stub.js +0 -190
- package/dist/lib/ocr-engines/google-doc-ai.d.ts +0 -36
- package/dist/lib/ocr-engines/google-doc-ai.js +0 -164
- package/dist/lib/ocr-jobs.d.ts +0 -67
- package/dist/lib/ocr-jobs.js +0 -129
- package/dist/lib/op-audit-extension/ran-at-guard.d.ts +0 -86
- package/dist/lib/op-audit.d.ts +0 -71
- package/dist/lib/privacy-br/detector.d.ts +0 -42
- package/dist/lib/privacy-br/detector.js +0 -130
- package/dist/lib/privacy-br/index.d.ts +0 -20
- package/dist/lib/privacy-br/index.js +0 -20
- package/dist/lib/privacy-br/integration.d.ts +0 -71
- package/dist/lib/privacy-br/integration.js +0 -74
- package/dist/lib/privacy-br/patterns.d.ts +0 -117
- package/dist/lib/privacy-br/patterns.js +0 -434
- package/dist/lib/privacy-br/redact.d.ts +0 -42
- package/dist/lib/privacy-br/redact.js +0 -103
- package/dist/lib/privacy-br/types.d.ts +0 -55
- package/dist/lib/privacy-br/types.js +0 -25
- package/dist/lib/regex-extract/extractor.d.ts +0 -30
- package/dist/lib/regex-extract/frontmatter.d.ts +0 -44
- package/dist/lib/regex-extract/index.d.ts +0 -14
- package/dist/lib/regex-extract/ingest-router-l4.d.ts +0 -76
- package/dist/lib/regex-extract/patterns.d.ts +0 -61
- package/dist/lib/regex-extract/production-wire.d.ts +0 -128
- package/dist/lib/regex-extract/reconcile.d.ts +0 -162
- package/dist/lib/regex-extract/strip-code.d.ts +0 -24
- package/dist/lib/regex-extract/types.d.ts +0 -48
- package/dist/lib/reranker.d.ts +0 -80
- package/dist/lib/shadow-tracker.d.ts +0 -191
- package/dist/lib/shadow-tracker.js +0 -384
- package/dist/lib/spo-injection.d.ts +0 -52
- package/dist/lib/telemetry-collector.d.ts +0 -158
- package/dist/lib/telemetry-collector.js +0 -249
- package/dist/lib/temporal-detector.d.ts +0 -27
- package/dist/lib/viewer/auth.d.ts +0 -37
- package/dist/lib/viewer/auth.js +0 -70
- package/dist/lib/viewer/backpressure.d.ts +0 -59
- package/dist/lib/viewer/backpressure.js +0 -100
- package/dist/lib/viewer/broadcast-singleton.d.ts +0 -34
- package/dist/lib/viewer/broadcast-singleton.js +0 -49
- package/dist/lib/viewer/broadcast.d.ts +0 -66
- package/dist/lib/viewer/broadcast.js +0 -96
- package/dist/lib/viewer/event-types.d.ts +0 -132
- package/dist/lib/viewer/event-types.js +0 -74
- package/dist/lib/viewer/instrumentation.d.ts +0 -106
- package/dist/lib/viewer/instrumentation.js +0 -224
- package/dist/lib/viewer/migration.d.ts +0 -23
- package/dist/lib/viewer/migration.js +0 -56
- package/dist/lib/viewer/redaction.d.ts +0 -44
- package/dist/lib/viewer/redaction.js +0 -139
- package/dist/lib/viewer/session.d.ts +0 -51
- package/dist/lib/viewer/session.js +0 -87
- package/dist/mcp/tools/answer.d.ts +0 -94
- package/dist/mcp/tools/archive.d.ts +0 -152
- package/dist/mcp/tools/archive.js +0 -170
- package/dist/mcp/tools/conflict.d.ts +0 -44
- package/dist/mcp/tools/conflict.js +0 -130
- package/dist/mcp/tools/hooks.d.ts +0 -29
- package/dist/mcp/tools/hooks.js +0 -78
- package/dist/mcp/tools/mark.d.ts +0 -38
- package/dist/mcp/tools/mark.js +0 -82
- package/dist/mcp/tools/viewer.d.ts +0 -58
- package/dist/mcp/tools/viewer.js +0 -64
- package/dist/mcp-server.d.ts +0 -2
- package/dist/metrics.d.ts +0 -3
- package/dist/noise-filter.d.ts +0 -18
- package/dist/notion-sync.d.ts +0 -7
- package/dist/notion-sync.js +0 -97
- package/dist/observability/adapters/a3-adapter.d.ts +0 -63
- package/dist/observability/adapters/a3-adapter.js +0 -83
- package/dist/observability/adapters/p1-adapter.d.ts +0 -49
- package/dist/observability/adapters/p1-adapter.js +0 -63
- package/dist/observability/adapters/p5-adapter.d.ts +0 -36
- package/dist/observability/adapters/p5-adapter.js +0 -71
- package/dist/observability/cardinality.d.ts +0 -61
- package/dist/observability/cardinality.js +0 -300
- package/dist/observability/collectors/db-stats.collector.d.ts +0 -9
- package/dist/observability/collectors/db-stats.collector.js +0 -88
- package/dist/observability/collectors/eventbus.collector.d.ts +0 -6
- package/dist/observability/collectors/eventbus.collector.js +0 -50
- package/dist/observability/collectors/process.collector.d.ts +0 -7
- package/dist/observability/collectors/process.collector.js +0 -93
- package/dist/observability/collectors/provider-telemetry.collector.d.ts +0 -11
- package/dist/observability/collectors/provider-telemetry.collector.js +0 -112
- package/dist/observability/collectors/search-telemetry.collector.d.ts +0 -12
- package/dist/observability/collectors/search-telemetry.collector.js +0 -76
- package/dist/observability/exporter.d.ts +0 -30
- package/dist/observability/exporter.js +0 -182
- package/dist/observability/index.d.ts +0 -22
- package/dist/observability/index.js +0 -21
- package/dist/observability/metrics.d.ts +0 -53
- package/dist/observability/metrics.js +0 -213
- package/dist/observability/privacy-guard.d.ts +0 -32
- package/dist/observability/privacy-guard.js +0 -116
- package/dist/observability/record.d.ts +0 -83
- package/dist/observability/record.js +0 -217
- package/dist/observability/registry.d.ts +0 -60
- package/dist/observability/registry.js +0 -93
- package/dist/observability/types.d.ts +0 -115
- package/dist/observability/types.js +0 -235
- package/dist/observability.d.ts +0 -131
- package/dist/plugins/nox-hooks/index.d.ts +0 -61
- package/dist/plugins/nox-hooks/index.js +0 -99
- package/dist/primer.d.ts +0 -1
- package/dist/privacy/filter.d.ts +0 -27
- package/dist/privacy/patterns.d.ts +0 -29
- package/dist/privacy/tag-parser.d.ts +0 -24
- package/dist/project-context-gen.d.ts +0 -10
- package/dist/providers/embedding/gemini.d.ts +0 -73
- package/dist/providers/embedding/openai.d.ts +0 -76
- package/dist/providers/embedding/types.d.ts +0 -39
- package/dist/providers/embedding/voyage.d.ts +0 -36
- package/dist/providers/index.d.ts +0 -116
- package/dist/providers/llm/anthropic.d.ts +0 -29
- package/dist/providers/llm/chain.d.ts +0 -99
- package/dist/providers/llm/gemini.d.ts +0 -48
- package/dist/providers/llm/openai.d.ts +0 -64
- package/dist/providers/llm/types.d.ts +0 -47
- package/dist/providers/telemetry.d.ts +0 -87
- package/dist/providers/types.d.ts +0 -42
- package/dist/query-entity-count.d.ts +0 -54
- package/dist/reflect.d.ts +0 -26
- package/dist/reindex-errors.d.ts +0 -7
- package/dist/reindex.d.ts +0 -16
- package/dist/retention.d.ts +0 -40
- package/dist/salience.d.ts +0 -85
- package/dist/scripts/migrate-v17-ops-audit.d.ts +0 -17
- package/dist/search-dedup.d.ts +0 -44
- package/dist/search-expansion.d.ts +0 -20
- package/dist/search.d.ts +0 -62
- package/dist/seh-detector.d.ts +0 -31
- package/dist/self-improve.d.ts +0 -1
- package/dist/session-distill.d.ts +0 -29
- package/dist/session-update.d.ts +0 -1
- package/dist/shared-memory.d.ts +0 -24
- package/dist/stats.d.ts +0 -1
- package/dist/temporal-retrieval.d.ts +0 -132
- package/dist/tier-manager.d.ts +0 -69
- package/dist/vectorize.d.ts +0 -16
- package/dist/version.d.ts +0 -1
- package/dist/watch.d.ts +0 -8
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/lib/confidence/db-shim.ts — minimal Database surface used by the L3
|
|
3
|
-
* implementation. Mirrors better-sqlite3's `Database`, `Statement` so that the
|
|
4
|
-
* staged module compiles without depending on the runtime driver.
|
|
5
|
-
*
|
|
6
|
-
* Production callers pass a real `better-sqlite3` `Database` here; the
|
|
7
|
-
* interface is structurally compatible.
|
|
8
|
-
*/
|
|
9
|
-
/** In-memory mock DB for tests. Implements a tiny subset of behaviour. */
|
|
10
|
-
export class MockDb {
|
|
11
|
-
rows = new Map();
|
|
12
|
-
audit = [];
|
|
13
|
-
idCounter = 1;
|
|
14
|
-
prepare(sql) {
|
|
15
|
-
const self = this;
|
|
16
|
-
const sqlNorm = sql.trim();
|
|
17
|
-
return {
|
|
18
|
-
run(...params) {
|
|
19
|
-
if (/^UPDATE chunks/i.test(sqlNorm)) {
|
|
20
|
-
// expect (confidence, provenance_kind, updated_at, id) or (superseded_by, id)
|
|
21
|
-
const id = params[params.length - 1];
|
|
22
|
-
const chunks = self.rows.get("chunks") ?? [];
|
|
23
|
-
const row = chunks.find((r) => r.id === id);
|
|
24
|
-
if (!row)
|
|
25
|
-
return { changes: 0, lastInsertRowid: 0 };
|
|
26
|
-
if (/SET confidence/i.test(sqlNorm)) {
|
|
27
|
-
row.confidence = params[0];
|
|
28
|
-
row.provenance_kind = params[1];
|
|
29
|
-
row.updated_at = params[2];
|
|
30
|
-
}
|
|
31
|
-
else if (/SET superseded_by/i.test(sqlNorm)) {
|
|
32
|
-
row.superseded_by = params[0];
|
|
33
|
-
row.provenance_kind = "user-marked";
|
|
34
|
-
row.confidence = 0.05;
|
|
35
|
-
row.updated_at = params[1];
|
|
36
|
-
}
|
|
37
|
-
return { changes: 1, lastInsertRowid: 0 };
|
|
38
|
-
}
|
|
39
|
-
if (/^INSERT INTO ops_audit/i.test(sqlNorm)) {
|
|
40
|
-
const id = self.idCounter++;
|
|
41
|
-
self.audit.push({
|
|
42
|
-
id,
|
|
43
|
-
op: params[0],
|
|
44
|
-
status: params[1],
|
|
45
|
-
details: params[2],
|
|
46
|
-
started_at: params[3],
|
|
47
|
-
});
|
|
48
|
-
return { changes: 1, lastInsertRowid: id };
|
|
49
|
-
}
|
|
50
|
-
if (/^INSERT INTO chunks/i.test(sqlNorm)) {
|
|
51
|
-
const id = self.idCounter++;
|
|
52
|
-
const list = self.rows.get("chunks") ?? [];
|
|
53
|
-
const row = {
|
|
54
|
-
id,
|
|
55
|
-
content: params[0],
|
|
56
|
-
confidence: params[1],
|
|
57
|
-
provenance_kind: params[2],
|
|
58
|
-
pain: params[3] ?? 0.2,
|
|
59
|
-
created_at: Date.now(),
|
|
60
|
-
};
|
|
61
|
-
list.push(row);
|
|
62
|
-
self.rows.set("chunks", list);
|
|
63
|
-
return { changes: 1, lastInsertRowid: id };
|
|
64
|
-
}
|
|
65
|
-
return { changes: 0, lastInsertRowid: 0 };
|
|
66
|
-
},
|
|
67
|
-
get(...params) {
|
|
68
|
-
if (/FROM chunks WHERE id/i.test(sqlNorm)) {
|
|
69
|
-
const id = params[0];
|
|
70
|
-
const chunks = self.rows.get("chunks") ?? [];
|
|
71
|
-
return chunks.find((r) => r.id === id);
|
|
72
|
-
}
|
|
73
|
-
if (/COUNT\(\*\).*FROM chunks WHERE superseded_by IS NOT NULL/i.test(sqlNorm)) {
|
|
74
|
-
const chunks = self.rows.get("chunks") ?? [];
|
|
75
|
-
const c = chunks.filter((r) => r.superseded_by !== null && r.superseded_by !== undefined).length;
|
|
76
|
-
return { count: c };
|
|
77
|
-
}
|
|
78
|
-
if (/COUNT\(\*\).*chunks/i.test(sqlNorm)) {
|
|
79
|
-
const chunks = self.rows.get("chunks") ?? [];
|
|
80
|
-
return { count: chunks.length };
|
|
81
|
-
}
|
|
82
|
-
return undefined;
|
|
83
|
-
},
|
|
84
|
-
all(..._params) {
|
|
85
|
-
if (/GROUP BY provenance_kind/i.test(sqlNorm)) {
|
|
86
|
-
const chunks = self.rows.get("chunks") ?? [];
|
|
87
|
-
const buckets = new Map();
|
|
88
|
-
for (const c of chunks) {
|
|
89
|
-
const k = c.provenance_kind ?? null;
|
|
90
|
-
buckets.set(k, (buckets.get(k) ?? 0) + 1);
|
|
91
|
-
}
|
|
92
|
-
const out = [];
|
|
93
|
-
for (const [k, count] of buckets.entries()) {
|
|
94
|
-
out.push({ provenance_kind: k, count });
|
|
95
|
-
}
|
|
96
|
-
return out;
|
|
97
|
-
}
|
|
98
|
-
if (/SELECT confidence FROM chunks WHERE confidence IS NOT NULL/i.test(sqlNorm)) {
|
|
99
|
-
const chunks = self.rows.get("chunks") ?? [];
|
|
100
|
-
const vals = chunks
|
|
101
|
-
.map((r) => r.confidence)
|
|
102
|
-
.filter((v) => typeof v === "number" && Number.isFinite(v))
|
|
103
|
-
.sort((a, b) => a - b);
|
|
104
|
-
return vals.map((v) => ({ confidence: v }));
|
|
105
|
-
}
|
|
106
|
-
if (/FROM chunks/i.test(sqlNorm)) {
|
|
107
|
-
return (self.rows.get("chunks") ?? []);
|
|
108
|
-
}
|
|
109
|
-
if (/FROM ops_audit/i.test(sqlNorm)) {
|
|
110
|
-
return self.audit;
|
|
111
|
-
}
|
|
112
|
-
return [];
|
|
113
|
-
},
|
|
114
|
-
iterate(..._params) {
|
|
115
|
-
return [];
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
exec(_sql) {
|
|
120
|
-
/* no-op */
|
|
121
|
-
}
|
|
122
|
-
transaction(fn) {
|
|
123
|
-
return fn;
|
|
124
|
-
}
|
|
125
|
-
pragma(_sql, _opts) {
|
|
126
|
-
return 19;
|
|
127
|
-
}
|
|
128
|
-
/** Test helper: seed a chunk row. */
|
|
129
|
-
seedChunk(row) {
|
|
130
|
-
const list = this.rows.get("chunks") ?? [];
|
|
131
|
-
list.push({
|
|
132
|
-
content: "",
|
|
133
|
-
confidence: 0.8,
|
|
134
|
-
provenance_kind: null,
|
|
135
|
-
pain: 0.2,
|
|
136
|
-
superseded_by: null,
|
|
137
|
-
...row,
|
|
138
|
-
});
|
|
139
|
-
this.rows.set("chunks", list);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/lib/confidence/mark.ts — core mark/supersede operations.
|
|
3
|
-
*
|
|
4
|
-
* All writes:
|
|
5
|
-
* 1. Resolve target confidence + provenance_kind from MarkKind + cfg
|
|
6
|
-
* 2. Update chunks SET confidence, provenance_kind, updated_at
|
|
7
|
-
* 3. Append row to ops_audit (status='success' on success, 'failed' on error)
|
|
8
|
-
*
|
|
9
|
-
* ops_audit is append-only (CLAUDE.md regra #6 — DB trigger blocks DELETE/UPDATE
|
|
10
|
-
* on terminal rows).
|
|
11
|
-
*
|
|
12
|
-
* Mark mapping (DB-level provenance_kind is single bucket 'user-marked' per
|
|
13
|
-
* v19.sql; confidence differentiates intent):
|
|
14
|
-
* canonical → confidence = cfg.user_marked_canonical (1.0), kind = 'user-marked'
|
|
15
|
-
* refuted → confidence = cfg.user_marked_refuted (0.05), kind = 'user-marked'
|
|
16
|
-
* stale → confidence = unchanged, kind = 'user-marked'
|
|
17
|
-
* (we annotate the chunk as user-touched; supersession is separate)
|
|
18
|
-
*
|
|
19
|
-
* Caller is responsible for verifying the chunk exists before invoking;
|
|
20
|
-
* markChunk() returns an error result if the row is missing.
|
|
21
|
-
*/
|
|
22
|
-
import type { Db } from "./db-shim.js";
|
|
23
|
-
import type { ConfidenceConfig, MarkKind, MarkResult, ProvenanceKind, SupersedeReason } from "./types.js";
|
|
24
|
-
export interface MarkChunkArgs {
|
|
25
|
-
db: Db;
|
|
26
|
-
chunk_id: number;
|
|
27
|
-
kind: MarkKind;
|
|
28
|
-
notes?: string;
|
|
29
|
-
cfg?: ConfidenceConfig;
|
|
30
|
-
/** Override Date.now() for test determinism. */
|
|
31
|
-
now?: () => number;
|
|
32
|
-
}
|
|
33
|
-
export interface SupersedeChunkArgs {
|
|
34
|
-
db: Db;
|
|
35
|
-
chunk_id: number;
|
|
36
|
-
by_chunk_id: number;
|
|
37
|
-
notes?: string;
|
|
38
|
-
reason?: SupersedeReason;
|
|
39
|
-
cfg?: ConfidenceConfig;
|
|
40
|
-
now?: () => number;
|
|
41
|
-
}
|
|
42
|
-
interface ChunkRow {
|
|
43
|
-
id: number;
|
|
44
|
-
confidence: number;
|
|
45
|
-
provenance_kind: ProvenanceKind | null;
|
|
46
|
-
pain?: number;
|
|
47
|
-
superseded_by?: number | null;
|
|
48
|
-
}
|
|
49
|
-
/** Compute target (confidence, provenance_kind) for a MarkKind. */
|
|
50
|
-
export declare function targetForMark(kind: MarkKind, existing: ChunkRow, cfg: ConfidenceConfig): {
|
|
51
|
-
confidence: number;
|
|
52
|
-
provenance_kind: ProvenanceKind;
|
|
53
|
-
};
|
|
54
|
-
/** Mark a chunk canonical / refuted / stale. Returns success or throws. */
|
|
55
|
-
export declare function markChunk(args: MarkChunkArgs): MarkResult;
|
|
56
|
-
/** Supersede a chunk by pointing it to a newer one. */
|
|
57
|
-
export declare function supersedeChunk(args: SupersedeChunkArgs): MarkResult;
|
|
58
|
-
export {};
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/lib/confidence/mark.ts — core mark/supersede operations.
|
|
3
|
-
*
|
|
4
|
-
* All writes:
|
|
5
|
-
* 1. Resolve target confidence + provenance_kind from MarkKind + cfg
|
|
6
|
-
* 2. Update chunks SET confidence, provenance_kind, updated_at
|
|
7
|
-
* 3. Append row to ops_audit (status='success' on success, 'failed' on error)
|
|
8
|
-
*
|
|
9
|
-
* ops_audit is append-only (CLAUDE.md regra #6 — DB trigger blocks DELETE/UPDATE
|
|
10
|
-
* on terminal rows).
|
|
11
|
-
*
|
|
12
|
-
* Mark mapping (DB-level provenance_kind is single bucket 'user-marked' per
|
|
13
|
-
* v19.sql; confidence differentiates intent):
|
|
14
|
-
* canonical → confidence = cfg.user_marked_canonical (1.0), kind = 'user-marked'
|
|
15
|
-
* refuted → confidence = cfg.user_marked_refuted (0.05), kind = 'user-marked'
|
|
16
|
-
* stale → confidence = unchanged, kind = 'user-marked'
|
|
17
|
-
* (we annotate the chunk as user-touched; supersession is separate)
|
|
18
|
-
*
|
|
19
|
-
* Caller is responsible for verifying the chunk exists before invoking;
|
|
20
|
-
* markChunk() returns an error result if the row is missing.
|
|
21
|
-
*/
|
|
22
|
-
import { resolveConfig } from "./config.js";
|
|
23
|
-
function nowIso(now) {
|
|
24
|
-
return new Date(now()).toISOString();
|
|
25
|
-
}
|
|
26
|
-
/** Compute target (confidence, provenance_kind) for a MarkKind. */
|
|
27
|
-
export function targetForMark(kind, existing, cfg) {
|
|
28
|
-
switch (kind) {
|
|
29
|
-
case "canonical":
|
|
30
|
-
return {
|
|
31
|
-
confidence: cfg.user_marked_canonical,
|
|
32
|
-
provenance_kind: "user-marked",
|
|
33
|
-
};
|
|
34
|
-
case "refuted":
|
|
35
|
-
return {
|
|
36
|
-
confidence: cfg.user_marked_refuted,
|
|
37
|
-
provenance_kind: "user-marked",
|
|
38
|
-
};
|
|
39
|
-
case "stale":
|
|
40
|
-
// Keep existing confidence but mark as user-touched; ranking integration
|
|
41
|
-
// treats provenance_kind='user-marked' + low confidence as filterable.
|
|
42
|
-
return {
|
|
43
|
-
confidence: existing.confidence,
|
|
44
|
-
provenance_kind: "user-marked",
|
|
45
|
-
};
|
|
46
|
-
default: {
|
|
47
|
-
const _exhaustive = kind;
|
|
48
|
-
void _exhaustive;
|
|
49
|
-
throw new Error(`unknown mark kind: ${String(kind)}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
/** Mark a chunk canonical / refuted / stale. Returns success or throws. */
|
|
54
|
-
export function markChunk(args) {
|
|
55
|
-
const cfg = args.cfg ?? resolveConfig();
|
|
56
|
-
const now = args.now ?? Date.now;
|
|
57
|
-
const existing = args.db
|
|
58
|
-
.prepare("SELECT id, confidence, provenance_kind, pain, superseded_by FROM chunks WHERE id = ?")
|
|
59
|
-
.get(args.chunk_id);
|
|
60
|
-
if (!existing) {
|
|
61
|
-
appendAudit(args.db, {
|
|
62
|
-
op: `confidence-mark-${args.kind}`,
|
|
63
|
-
status: "failed",
|
|
64
|
-
details: JSON.stringify({
|
|
65
|
-
chunk_id: args.chunk_id,
|
|
66
|
-
reason: "chunk_not_found",
|
|
67
|
-
}),
|
|
68
|
-
now,
|
|
69
|
-
});
|
|
70
|
-
throw new Error(`chunk ${args.chunk_id} not found`);
|
|
71
|
-
}
|
|
72
|
-
const target = targetForMark(args.kind, existing, cfg);
|
|
73
|
-
args.db
|
|
74
|
-
.prepare("UPDATE chunks SET confidence = ?, provenance_kind = ?, updated_at = ? WHERE id = ?")
|
|
75
|
-
.run(target.confidence, target.provenance_kind, nowIso(now), args.chunk_id);
|
|
76
|
-
const auditId = appendAudit(args.db, {
|
|
77
|
-
op: `confidence-mark-${args.kind}`,
|
|
78
|
-
status: "success",
|
|
79
|
-
details: JSON.stringify({
|
|
80
|
-
chunk_id: args.chunk_id,
|
|
81
|
-
kind: args.kind,
|
|
82
|
-
before: {
|
|
83
|
-
confidence: existing.confidence,
|
|
84
|
-
provenance_kind: existing.provenance_kind,
|
|
85
|
-
},
|
|
86
|
-
after: target,
|
|
87
|
-
notes: args.notes ?? null,
|
|
88
|
-
}),
|
|
89
|
-
now,
|
|
90
|
-
});
|
|
91
|
-
return {
|
|
92
|
-
ok: true,
|
|
93
|
-
chunk_id: args.chunk_id,
|
|
94
|
-
applied: {
|
|
95
|
-
confidence: target.confidence,
|
|
96
|
-
provenance_kind: target.provenance_kind,
|
|
97
|
-
superseded_by: existing.superseded_by ?? null,
|
|
98
|
-
},
|
|
99
|
-
audit_id: auditId,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/** Supersede a chunk by pointing it to a newer one. */
|
|
103
|
-
export function supersedeChunk(args) {
|
|
104
|
-
const cfg = args.cfg ?? resolveConfig();
|
|
105
|
-
void cfg; // not used directly but kept for future expansion (e.g., supersede policy)
|
|
106
|
-
const now = args.now ?? Date.now;
|
|
107
|
-
if (args.chunk_id === args.by_chunk_id) {
|
|
108
|
-
appendAudit(args.db, {
|
|
109
|
-
op: "confidence-supersede",
|
|
110
|
-
status: "failed",
|
|
111
|
-
details: JSON.stringify({
|
|
112
|
-
chunk_id: args.chunk_id,
|
|
113
|
-
reason: "self_supersede",
|
|
114
|
-
}),
|
|
115
|
-
now,
|
|
116
|
-
});
|
|
117
|
-
throw new Error(`cannot supersede chunk ${args.chunk_id} by itself`);
|
|
118
|
-
}
|
|
119
|
-
const existing = args.db
|
|
120
|
-
.prepare("SELECT id, confidence, provenance_kind, pain, superseded_by FROM chunks WHERE id = ?")
|
|
121
|
-
.get(args.chunk_id);
|
|
122
|
-
const newer = args.db
|
|
123
|
-
.prepare("SELECT id, confidence, provenance_kind, pain, superseded_by FROM chunks WHERE id = ?")
|
|
124
|
-
.get(args.by_chunk_id);
|
|
125
|
-
if (!existing || !newer) {
|
|
126
|
-
appendAudit(args.db, {
|
|
127
|
-
op: "confidence-supersede",
|
|
128
|
-
status: "failed",
|
|
129
|
-
details: JSON.stringify({
|
|
130
|
-
chunk_id: args.chunk_id,
|
|
131
|
-
by_chunk_id: args.by_chunk_id,
|
|
132
|
-
reason: !existing ? "chunk_not_found" : "supersede_target_not_found",
|
|
133
|
-
}),
|
|
134
|
-
now,
|
|
135
|
-
});
|
|
136
|
-
throw new Error(`missing row(s) — chunk_id=${args.chunk_id} or by_chunk_id=${args.by_chunk_id}`);
|
|
137
|
-
}
|
|
138
|
-
args.db
|
|
139
|
-
.prepare("UPDATE chunks SET superseded_by = ?, updated_at = ? WHERE id = ?")
|
|
140
|
-
.run(args.by_chunk_id, nowIso(now), args.chunk_id);
|
|
141
|
-
const auditId = appendAudit(args.db, {
|
|
142
|
-
op: "confidence-supersede",
|
|
143
|
-
status: "success",
|
|
144
|
-
details: JSON.stringify({
|
|
145
|
-
chunk_id: args.chunk_id,
|
|
146
|
-
by_chunk_id: args.by_chunk_id,
|
|
147
|
-
reason: args.reason ?? "manual_resolution",
|
|
148
|
-
notes: args.notes ?? null,
|
|
149
|
-
}),
|
|
150
|
-
now,
|
|
151
|
-
});
|
|
152
|
-
return {
|
|
153
|
-
ok: true,
|
|
154
|
-
chunk_id: args.chunk_id,
|
|
155
|
-
applied: {
|
|
156
|
-
confidence: existing.confidence,
|
|
157
|
-
provenance_kind: "user-marked",
|
|
158
|
-
superseded_by: args.by_chunk_id,
|
|
159
|
-
},
|
|
160
|
-
audit_id: auditId,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
function appendAudit(db, args) {
|
|
164
|
-
const result = db
|
|
165
|
-
.prepare("INSERT INTO ops_audit (op, status, details, started_at) VALUES (?, ?, ?, ?)")
|
|
166
|
-
.run(args.op, args.status, args.details, nowIso(args.now));
|
|
167
|
-
return Number(result.lastInsertRowid);
|
|
168
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/lib/confidence/ranking.ts — confidence × salience ranking integration.
|
|
3
|
-
*
|
|
4
|
-
* GATED per CLAUDE.md regra #5: ranking changes require ≥+1.0pp nDCG@10 over
|
|
5
|
-
* R01a/R01b baseline + 7d shadow validation. Default mode is "disabled" — the
|
|
6
|
-
* wrapper returns the original salience unchanged, no telemetry collected.
|
|
7
|
-
*
|
|
8
|
-
* Modes:
|
|
9
|
-
* disabled → no-op, returns salience as-is
|
|
10
|
-
* shadow → computes new salience, logs delta, RETURNS ORIGINAL (no behavior change)
|
|
11
|
-
* active → applies multiplier + stale/superseded filter
|
|
12
|
-
*
|
|
13
|
-
* Formula (active mode, per spec §5):
|
|
14
|
-
* salience' = salience × confidence
|
|
15
|
-
* clamp to [active_floor, 1.5]
|
|
16
|
-
*
|
|
17
|
-
* Skip rules (active mode):
|
|
18
|
-
* - chunks with provenance_kind='user-marked' AND confidence < active_floor → SKIP
|
|
19
|
-
* - chunks with confidence < active_floor (any provenance) → SKIP
|
|
20
|
-
* - chunks where superseded_by IS NOT NULL → de-prioritized by 0.5 multiplier
|
|
21
|
-
* (NOT skipped; preserves audit trail per CLAUDE.md regra #6)
|
|
22
|
-
*
|
|
23
|
-
* Test-side: feed a stable seed chunk list + cfg, verify same input/output
|
|
24
|
-
* across modes; verify shadow returns original despite computing delta.
|
|
25
|
-
*/
|
|
26
|
-
import type { ConfidenceConfig, RankingMode } from "./types.js";
|
|
27
|
-
export interface RankableChunk {
|
|
28
|
-
chunk_id: number;
|
|
29
|
-
/** Pre-ranking salience score from existing pipeline. */
|
|
30
|
-
salience: number;
|
|
31
|
-
/** Chunk confidence (DB field). Defaults to 0.8 if NULL/missing. */
|
|
32
|
-
confidence?: number | null;
|
|
33
|
-
/** Provenance kind. */
|
|
34
|
-
provenance_kind?: string | null;
|
|
35
|
-
/** Superseded chain — non-null means this chunk has been replaced. */
|
|
36
|
-
superseded_by?: number | null;
|
|
37
|
-
}
|
|
38
|
-
export interface RankedChunk extends RankableChunk {
|
|
39
|
-
/** Final salience after L3 transformation (may equal input if disabled/shadow). */
|
|
40
|
-
ranked_salience: number;
|
|
41
|
-
/** Delta computed but possibly not applied (always populated in shadow). */
|
|
42
|
-
shadow_delta?: number;
|
|
43
|
-
/** Reason the chunk was skipped (active mode only). */
|
|
44
|
-
skip_reason?: "stale_low_confidence" | "below_floor";
|
|
45
|
-
}
|
|
46
|
-
export interface RankingResult {
|
|
47
|
-
chunks: RankedChunk[];
|
|
48
|
-
mode: RankingMode;
|
|
49
|
-
/** Stats for telemetry. */
|
|
50
|
-
stats: {
|
|
51
|
-
input_count: number;
|
|
52
|
-
output_count: number;
|
|
53
|
-
skipped: number;
|
|
54
|
-
superseded_deprioritized: number;
|
|
55
|
-
mean_delta: number;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
declare const CLAMP_MIN = 0.3;
|
|
59
|
-
declare const CLAMP_MAX = 1.5;
|
|
60
|
-
declare const SUPERSEDED_MULTIPLIER = 0.5;
|
|
61
|
-
/**
|
|
62
|
-
* applyConfidenceRanking(chunks, cfgOverride?) → RankingResult
|
|
63
|
-
*
|
|
64
|
-
* Mode is read from cfg.ranking_mode (env-resolved by default).
|
|
65
|
-
*/
|
|
66
|
-
export declare function applyConfidenceRanking(chunks: RankableChunk[], cfgOverride?: ConfidenceConfig): RankingResult;
|
|
67
|
-
/** Pure helper for tests / external callers: compute one chunk's new salience. */
|
|
68
|
-
export declare function computeRankedSalience(salience: number, confidence: number, superseded: boolean): number;
|
|
69
|
-
export { CLAMP_MIN, CLAMP_MAX, SUPERSEDED_MULTIPLIER };
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/lib/confidence/ranking.ts — confidence × salience ranking integration.
|
|
3
|
-
*
|
|
4
|
-
* GATED per CLAUDE.md regra #5: ranking changes require ≥+1.0pp nDCG@10 over
|
|
5
|
-
* R01a/R01b baseline + 7d shadow validation. Default mode is "disabled" — the
|
|
6
|
-
* wrapper returns the original salience unchanged, no telemetry collected.
|
|
7
|
-
*
|
|
8
|
-
* Modes:
|
|
9
|
-
* disabled → no-op, returns salience as-is
|
|
10
|
-
* shadow → computes new salience, logs delta, RETURNS ORIGINAL (no behavior change)
|
|
11
|
-
* active → applies multiplier + stale/superseded filter
|
|
12
|
-
*
|
|
13
|
-
* Formula (active mode, per spec §5):
|
|
14
|
-
* salience' = salience × confidence
|
|
15
|
-
* clamp to [active_floor, 1.5]
|
|
16
|
-
*
|
|
17
|
-
* Skip rules (active mode):
|
|
18
|
-
* - chunks with provenance_kind='user-marked' AND confidence < active_floor → SKIP
|
|
19
|
-
* - chunks with confidence < active_floor (any provenance) → SKIP
|
|
20
|
-
* - chunks where superseded_by IS NOT NULL → de-prioritized by 0.5 multiplier
|
|
21
|
-
* (NOT skipped; preserves audit trail per CLAUDE.md regra #6)
|
|
22
|
-
*
|
|
23
|
-
* Test-side: feed a stable seed chunk list + cfg, verify same input/output
|
|
24
|
-
* across modes; verify shadow returns original despite computing delta.
|
|
25
|
-
*/
|
|
26
|
-
import { resolveConfig } from "./config.js";
|
|
27
|
-
const CLAMP_MIN = 0.3;
|
|
28
|
-
const CLAMP_MAX = 1.5;
|
|
29
|
-
const SUPERSEDED_MULTIPLIER = 0.5;
|
|
30
|
-
function clampSalience(v) {
|
|
31
|
-
if (!Number.isFinite(v))
|
|
32
|
-
return CLAMP_MIN;
|
|
33
|
-
return Math.min(CLAMP_MAX, Math.max(CLAMP_MIN, v));
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* applyConfidenceRanking(chunks, cfgOverride?) → RankingResult
|
|
37
|
-
*
|
|
38
|
-
* Mode is read from cfg.ranking_mode (env-resolved by default).
|
|
39
|
-
*/
|
|
40
|
-
export function applyConfidenceRanking(chunks, cfgOverride) {
|
|
41
|
-
const cfg = cfgOverride ?? resolveConfig();
|
|
42
|
-
const mode = cfg.ranking_mode;
|
|
43
|
-
const stats = {
|
|
44
|
-
input_count: chunks.length,
|
|
45
|
-
output_count: 0,
|
|
46
|
-
skipped: 0,
|
|
47
|
-
superseded_deprioritized: 0,
|
|
48
|
-
mean_delta: 0,
|
|
49
|
-
};
|
|
50
|
-
const out = [];
|
|
51
|
-
let totalDelta = 0;
|
|
52
|
-
let deltaSamples = 0;
|
|
53
|
-
for (const chunk of chunks) {
|
|
54
|
-
const conf = typeof chunk.confidence === "number" && Number.isFinite(chunk.confidence)
|
|
55
|
-
? chunk.confidence
|
|
56
|
-
: 0.8;
|
|
57
|
-
const provenance = chunk.provenance_kind ?? null;
|
|
58
|
-
const superseded = chunk.superseded_by !== null &&
|
|
59
|
-
chunk.superseded_by !== undefined;
|
|
60
|
-
// Compute potential new salience (always done; only applied in active mode)
|
|
61
|
-
let newSalience = chunk.salience * conf;
|
|
62
|
-
if (superseded) {
|
|
63
|
-
newSalience *= SUPERSEDED_MULTIPLIER;
|
|
64
|
-
}
|
|
65
|
-
newSalience = clampSalience(newSalience);
|
|
66
|
-
const delta = newSalience - chunk.salience;
|
|
67
|
-
totalDelta += delta;
|
|
68
|
-
deltaSamples++;
|
|
69
|
-
// Skip-detection logic — only acts in active mode
|
|
70
|
-
const stale = provenance === "user-marked" && conf < cfg.active_floor;
|
|
71
|
-
const belowFloor = conf < cfg.active_floor;
|
|
72
|
-
if (mode === "active" && (stale || belowFloor)) {
|
|
73
|
-
stats.skipped++;
|
|
74
|
-
// Do NOT push skipped chunks to output (active behaviour).
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (mode === "active" && superseded) {
|
|
78
|
-
stats.superseded_deprioritized++;
|
|
79
|
-
}
|
|
80
|
-
const ranked_salience = mode === "active" ? newSalience : chunk.salience;
|
|
81
|
-
const rec = {
|
|
82
|
-
...chunk,
|
|
83
|
-
ranked_salience,
|
|
84
|
-
};
|
|
85
|
-
if (mode === "shadow") {
|
|
86
|
-
rec.shadow_delta = delta;
|
|
87
|
-
}
|
|
88
|
-
out.push(rec);
|
|
89
|
-
}
|
|
90
|
-
stats.output_count = out.length;
|
|
91
|
-
stats.mean_delta = deltaSamples > 0 ? totalDelta / deltaSamples : 0;
|
|
92
|
-
return { chunks: out, mode, stats };
|
|
93
|
-
}
|
|
94
|
-
/** Pure helper for tests / external callers: compute one chunk's new salience. */
|
|
95
|
-
export function computeRankedSalience(salience, confidence, superseded) {
|
|
96
|
-
let v = salience * confidence;
|
|
97
|
-
if (superseded)
|
|
98
|
-
v *= SUPERSEDED_MULTIPLIER;
|
|
99
|
-
return clampSalience(v);
|
|
100
|
-
}
|
|
101
|
-
export { CLAMP_MIN, CLAMP_MAX, SUPERSEDED_MULTIPLIER };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/lib/confidence/search-filter.ts — opt-in `--min-confidence` filter.
|
|
3
|
-
*
|
|
4
|
-
* Wired into search via CLI flag `--min-confidence 0.5`, HTTP query param
|
|
5
|
-
* `min_confidence=0.5`, MCP arg `min_confidence: 0.5`.
|
|
6
|
-
*
|
|
7
|
-
* Default: undefined (no filter). When set, chunks with confidence < threshold
|
|
8
|
-
* are removed from the search result set BEFORE ranking. This is purely
|
|
9
|
-
* additive and DOES NOT depend on NOX_RANKING_CONFIDENCE mode — caller-side
|
|
10
|
-
* choice, useful for "show me only high-trust facts" client UX.
|
|
11
|
-
*
|
|
12
|
-
* Threshold range: [0.0, 1.0]. Out-of-range values are clamped (loose
|
|
13
|
-
* validation; we never want to drop entire results due to typo).
|
|
14
|
-
*/
|
|
15
|
-
export interface SearchResultWithConfidence {
|
|
16
|
-
chunk_id: number;
|
|
17
|
-
confidence?: number | null;
|
|
18
|
-
[key: string]: unknown;
|
|
19
|
-
}
|
|
20
|
-
export interface SearchFilterOpts {
|
|
21
|
-
/** Minimum confidence to include. undefined = no filter. */
|
|
22
|
-
min_confidence?: number | null;
|
|
23
|
-
/** If true, also exclude chunks with NULL confidence (default false — NULL passes). */
|
|
24
|
-
exclude_null?: boolean;
|
|
25
|
-
/** If true, exclude superseded chunks (default false). */
|
|
26
|
-
exclude_superseded?: boolean;
|
|
27
|
-
/** If true, exclude refuted (provenance=user-marked + low conf) chunks (default false). */
|
|
28
|
-
exclude_refuted?: boolean;
|
|
29
|
-
}
|
|
30
|
-
/** Validates + normalises the threshold. Returns undefined to skip filtering. */
|
|
31
|
-
export declare function parseMinConfidence(raw: number | string | undefined | null): number | undefined;
|
|
32
|
-
/** Apply filter to a result set. Returns new array — does not mutate input. */
|
|
33
|
-
export declare function filterByConfidence<T extends SearchResultWithConfidence>(results: T[], opts?: SearchFilterOpts): T[];
|
|
34
|
-
/**
|
|
35
|
-
* Convenience: build the SQL WHERE clause fragment for direct DB-level
|
|
36
|
-
* filtering (more efficient than client-side). Returns null if no filter.
|
|
37
|
-
*
|
|
38
|
-
* Example output:
|
|
39
|
-
* { sql: "AND chunks.confidence >= ?", params: [0.5] }
|
|
40
|
-
*/
|
|
41
|
-
export declare function buildConfidenceWhereClause(opts: SearchFilterOpts): {
|
|
42
|
-
sql: string;
|
|
43
|
-
params: unknown[];
|
|
44
|
-
} | null;
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* src/lib/confidence/search-filter.ts — opt-in `--min-confidence` filter.
|
|
3
|
-
*
|
|
4
|
-
* Wired into search via CLI flag `--min-confidence 0.5`, HTTP query param
|
|
5
|
-
* `min_confidence=0.5`, MCP arg `min_confidence: 0.5`.
|
|
6
|
-
*
|
|
7
|
-
* Default: undefined (no filter). When set, chunks with confidence < threshold
|
|
8
|
-
* are removed from the search result set BEFORE ranking. This is purely
|
|
9
|
-
* additive and DOES NOT depend on NOX_RANKING_CONFIDENCE mode — caller-side
|
|
10
|
-
* choice, useful for "show me only high-trust facts" client UX.
|
|
11
|
-
*
|
|
12
|
-
* Threshold range: [0.0, 1.0]. Out-of-range values are clamped (loose
|
|
13
|
-
* validation; we never want to drop entire results due to typo).
|
|
14
|
-
*/
|
|
15
|
-
function clamp01(v) {
|
|
16
|
-
if (!Number.isFinite(v))
|
|
17
|
-
return 0;
|
|
18
|
-
return Math.min(1, Math.max(0, v));
|
|
19
|
-
}
|
|
20
|
-
/** Validates + normalises the threshold. Returns undefined to skip filtering. */
|
|
21
|
-
export function parseMinConfidence(raw) {
|
|
22
|
-
if (raw === undefined || raw === null)
|
|
23
|
-
return undefined;
|
|
24
|
-
let n;
|
|
25
|
-
if (typeof raw === "number")
|
|
26
|
-
n = raw;
|
|
27
|
-
else {
|
|
28
|
-
const parsed = parseFloat(raw);
|
|
29
|
-
if (!Number.isFinite(parsed))
|
|
30
|
-
return undefined;
|
|
31
|
-
n = parsed;
|
|
32
|
-
}
|
|
33
|
-
return clamp01(n);
|
|
34
|
-
}
|
|
35
|
-
/** Apply filter to a result set. Returns new array — does not mutate input. */
|
|
36
|
-
export function filterByConfidence(results, opts = {}) {
|
|
37
|
-
const threshold = opts.min_confidence ?? undefined;
|
|
38
|
-
const excludeNull = opts.exclude_null === true;
|
|
39
|
-
const excludeSuperseded = opts.exclude_superseded === true;
|
|
40
|
-
const excludeRefuted = opts.exclude_refuted === true;
|
|
41
|
-
if (threshold === undefined &&
|
|
42
|
-
!excludeNull &&
|
|
43
|
-
!excludeSuperseded &&
|
|
44
|
-
!excludeRefuted) {
|
|
45
|
-
return results; // no-op
|
|
46
|
-
}
|
|
47
|
-
return results.filter((r) => {
|
|
48
|
-
const conf = r.confidence;
|
|
49
|
-
const confIsNull = conf === null || conf === undefined;
|
|
50
|
-
if (excludeNull && confIsNull)
|
|
51
|
-
return false;
|
|
52
|
-
if (threshold !== undefined) {
|
|
53
|
-
if (confIsNull) {
|
|
54
|
-
// NULL counts as 0.8 baseline (DB default before v19); allow through
|
|
55
|
-
// unless excludeNull also requested.
|
|
56
|
-
if (0.8 < threshold)
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
else if (conf < threshold) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (excludeSuperseded) {
|
|
64
|
-
const sb = r.superseded_by;
|
|
65
|
-
if (sb !== null && sb !== undefined)
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
if (excludeRefuted) {
|
|
69
|
-
const kind = r.provenance_kind;
|
|
70
|
-
const c = confIsNull ? 0.8 : conf;
|
|
71
|
-
if (kind === "user-marked" && c < 0.3)
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
return true;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Convenience: build the SQL WHERE clause fragment for direct DB-level
|
|
79
|
-
* filtering (more efficient than client-side). Returns null if no filter.
|
|
80
|
-
*
|
|
81
|
-
* Example output:
|
|
82
|
-
* { sql: "AND chunks.confidence >= ?", params: [0.5] }
|
|
83
|
-
*/
|
|
84
|
-
export function buildConfidenceWhereClause(opts) {
|
|
85
|
-
const fragments = [];
|
|
86
|
-
const params = [];
|
|
87
|
-
if (opts.min_confidence !== undefined && opts.min_confidence !== null) {
|
|
88
|
-
fragments.push("(chunks.confidence >= ? OR (chunks.confidence IS NULL AND 0.8 >= ?))");
|
|
89
|
-
params.push(opts.min_confidence, opts.min_confidence);
|
|
90
|
-
}
|
|
91
|
-
if (opts.exclude_null) {
|
|
92
|
-
fragments.push("chunks.confidence IS NOT NULL");
|
|
93
|
-
}
|
|
94
|
-
if (opts.exclude_superseded) {
|
|
95
|
-
fragments.push("chunks.superseded_by IS NULL");
|
|
96
|
-
}
|
|
97
|
-
if (opts.exclude_refuted) {
|
|
98
|
-
fragments.push("NOT (chunks.provenance_kind = 'user-marked' AND chunks.confidence < 0.3)");
|
|
99
|
-
}
|
|
100
|
-
if (fragments.length === 0)
|
|
101
|
-
return null;
|
|
102
|
-
return { sql: " AND " + fragments.join(" AND "), params };
|
|
103
|
-
}
|