@tangleai/memory 0.20.1 → 0.24.1
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 +72 -0
- package/README.md +64 -3
- package/package.json +13 -6
- package/schemas/policy.contract.json +256 -0
- package/schemas/policy.schema.json +110 -0
- package/src/contradiction.d.ts +4 -4
- package/src/contradiction.js +5 -4
- package/src/crystallize.d.ts +2 -2
- package/src/crystallize.js +4 -3
- package/src/index.d.ts +3 -1
- package/src/index.js +2 -1
- package/src/ingest.d.ts +1 -1
- package/src/ingest.js +1 -1
- package/src/novelty.d.ts +1 -1
- package/src/novelty.js +3 -2
- package/src/outcome.d.ts +3 -1
- package/src/outcome.js +10 -3
- package/src/policy.d.ts +13 -0
- package/src/policy.gen.d.ts +64 -0
- package/src/policy.gen.js +695 -0
- package/src/policy.js +13 -0
- package/src/policy.types.d.ts +36 -0
- package/src/policy.types.js +3 -0
- package/src/retrieval.d.ts +1 -1
- package/src/retrieval.js +5 -4
- package/src/store.d.ts +1 -1
- package/src/store.js +1 -1
package/src/ingest.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Turning raw observations into memory units.
|
|
3
3
|
*
|
|
4
4
|
* Ids are content-addressed — `m-<fnv1a(text)>-<length>` via the same
|
|
5
|
-
* `hashContent` the @
|
|
5
|
+
* `hashContent` the @tangleai/context recall slots use — so ingesting the same
|
|
6
6
|
* observation twice produces the same id and the second write is an
|
|
7
7
|
* overwrite, not a duplicate. Idempotence by construction beats
|
|
8
8
|
* deduplication by policy; the crystallizer then only has to handle
|
package/src/novelty.d.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* Pure: no store, no clock, no log. The caller applies the result.
|
|
22
22
|
*/
|
|
23
23
|
import type { MemoryUnit } from '@tangleai/core/schemas/memory';
|
|
24
|
-
export declare const DEFAULT_NOVELTY_THRESHOLD
|
|
24
|
+
export declare const DEFAULT_NOVELTY_THRESHOLD: number;
|
|
25
25
|
export interface NoveltyOptions {
|
|
26
26
|
threshold?: number;
|
|
27
27
|
}
|
package/src/novelty.js
CHANGED
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
* Pure: no store, no clock, no log. The caller applies the result.
|
|
22
22
|
*/
|
|
23
23
|
import { cosineSimilarity } from '@jarenjs/core/vector';
|
|
24
|
-
import { sameIdentity } from '@
|
|
25
|
-
|
|
24
|
+
import { sameIdentity } from '@tangleai/context/ledger';
|
|
25
|
+
import { policyThresholds, DEFAULT_MEMORY_POLICY } from "./policy.js";
|
|
26
|
+
export const DEFAULT_NOVELTY_THRESHOLD = policyThresholds().novelty;
|
|
26
27
|
export function noveltyGate(candidates, existing, options = {}) {
|
|
27
28
|
const threshold = options.threshold ?? DEFAULT_NOVELTY_THRESHOLD;
|
|
28
29
|
const novel = [];
|
package/src/outcome.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* down to the floor but never silently erased by arithmetic — deletion
|
|
12
12
|
* is a separate, auditable decision.
|
|
13
13
|
*/
|
|
14
|
-
import type { OutcomeReport } from '@tangleai/core/schemas/memory';
|
|
14
|
+
import type { MemoryUnit, OutcomeReport } from '@tangleai/core/schemas/memory';
|
|
15
15
|
import type { MemoryStore } from './store.ts';
|
|
16
16
|
export interface OutcomeOptions {
|
|
17
17
|
successBoost: number;
|
|
@@ -28,6 +28,8 @@ export interface ApplyOutcomeResult {
|
|
|
28
28
|
adjustment: number;
|
|
29
29
|
missing: string[];
|
|
30
30
|
}
|
|
31
|
+
/** Detached confidence projection; preserves fact time and all other fields. */
|
|
32
|
+
export declare function projectOutcomeConfidence(unit: MemoryUnit, category: OutcomeReport['outcome'], options?: OutcomeOptions): MemoryUnit;
|
|
31
33
|
/** Apply an outcome report to the store. */
|
|
32
34
|
export declare function applyOutcome(store: MemoryStore, report: OutcomeReport, config?: {
|
|
33
35
|
options?: OutcomeOptions;
|
package/src/outcome.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* down to the floor but never silently erased by arithmetic — deletion
|
|
12
12
|
* is a separate, auditable decision.
|
|
13
13
|
*/
|
|
14
|
+
import { cloneJson } from '@jarenjs/core/object';
|
|
14
15
|
export const DEFAULT_OUTCOME_OPTIONS = {
|
|
15
16
|
successBoost: 0.15,
|
|
16
17
|
failurePenalty: 0.25,
|
|
@@ -27,6 +28,12 @@ export function outcomeAdjustment(outcome, options = DEFAULT_OUTCOME_OPTIONS) {
|
|
|
27
28
|
default: return 0;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
31
|
+
/** Detached confidence projection; preserves fact time and all other fields. */
|
|
32
|
+
export function projectOutcomeConfidence(unit, category, options = DEFAULT_OUTCOME_OPTIONS) {
|
|
33
|
+
const next = cloneJson(unit);
|
|
34
|
+
next.confidence = Math.min(options.maxConfidence, Math.max(options.minConfidence, (unit.confidence ?? 0.5) + outcomeAdjustment(category, options)));
|
|
35
|
+
return next;
|
|
36
|
+
}
|
|
30
37
|
/** Apply an outcome report to the store. */
|
|
31
38
|
export async function applyOutcome(store, report, config = {}) {
|
|
32
39
|
const options = config.options ?? DEFAULT_OUTCOME_OPTIONS;
|
|
@@ -39,9 +46,9 @@ export async function applyOutcome(store, report, config = {}) {
|
|
|
39
46
|
missing.push(id); // reported, not swallowed — a report citing a
|
|
40
47
|
continue; // vanished memory is a fact the host should see
|
|
41
48
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
await store.put(
|
|
49
|
+
const next = projectOutcomeConfidence(unit, report.outcome, options);
|
|
50
|
+
next.at = report.at;
|
|
51
|
+
await store.put(next);
|
|
45
52
|
adjusted++;
|
|
46
53
|
}
|
|
47
54
|
return { adjusted, adjustment, missing };
|
package/src/policy.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Policy as MemoryPolicyValues } from './policy.types.ts';
|
|
2
|
+
export type { Policy as MemoryPolicyValues } from './policy.types.ts';
|
|
3
|
+
export { DEFAULT_MEMORY_POLICY, POLICY_PROVENANCE, MEASURED_MEMORY_POLICIES, SHIPPED_LEGACY_CELL_ID, POLICY_CONTRACT_REVISION } from './policy.gen.ts';
|
|
4
|
+
/** The historical control is an explicit opt-in, including its historical hash width. */
|
|
5
|
+
export declare const SHIPPED_LEGACY_POLICY: MemoryPolicyValues & {
|
|
6
|
+
label: string;
|
|
7
|
+
};
|
|
8
|
+
/** Disabled cosine policies lower to the existing threshold-2 seam. */
|
|
9
|
+
export declare function policyThresholds(policy?: MemoryPolicyValues): {
|
|
10
|
+
novelty: number;
|
|
11
|
+
contradiction: number;
|
|
12
|
+
crystallize: number;
|
|
13
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { MemoryPolicyValues } from './policy.ts';
|
|
2
|
+
export declare const DEFAULT_MEMORY_POLICY: Readonly<MemoryPolicyValues>;
|
|
3
|
+
export declare const POLICY_PROVENANCE: {
|
|
4
|
+
readonly reportId: "b003bccaac49b44931787955e5caa0efddb58fec706da029760e50540d8f5b14";
|
|
5
|
+
readonly registrationId: "617b777166ab601600cc8ff330e7f0edf7ba2fb0011368ef3089f2650d6c783f";
|
|
6
|
+
readonly cellId: "f9a742d02a54a2f222065707243200d84c7bd8afb9d2aacbd8b9ca524aaf49a6";
|
|
7
|
+
readonly sourceId: "74b047084f6109350af686fe5809d0c921f6c3381c7903562391a49aa107df6c";
|
|
8
|
+
readonly transitionId: "dc50dbb1fb2a572f2b0086584c641bca8a9f9cc02ceae6423b50f3d3ca36f7db";
|
|
9
|
+
readonly challengerId: "5121f66d7bcda05e6c56b8e950d361240fac3b25a8a89163f84ba0f25fca5e16";
|
|
10
|
+
readonly ingestTier: "live";
|
|
11
|
+
readonly retrievalTier: "live";
|
|
12
|
+
readonly embeddingTier: "keyless";
|
|
13
|
+
readonly qualifiesAsDefault: false;
|
|
14
|
+
readonly statement: "the challenger did not pass every registered clause, so the inert cell is the default and the result is a bounded null: no effect larger than 0.0024 was detectable at 89 pairs (paired SD 0.0115, standard error 0.0012, 86 tied, 3 acting)";
|
|
15
|
+
readonly power: {
|
|
16
|
+
readonly pairedSd: 0.011457984574326978;
|
|
17
|
+
readonly standardError: 0.0012145439357932172;
|
|
18
|
+
readonly minimumDetectableEffect: 0.002380462373715384;
|
|
19
|
+
readonly tiedPairs: 86;
|
|
20
|
+
readonly actingSetSize: 3;
|
|
21
|
+
};
|
|
22
|
+
readonly interval: {
|
|
23
|
+
readonly low: -0.0014640789921688796;
|
|
24
|
+
readonly high: 0.003215677372980744;
|
|
25
|
+
};
|
|
26
|
+
readonly clauses: readonly [{
|
|
27
|
+
readonly clause: "eligible";
|
|
28
|
+
readonly passed: true;
|
|
29
|
+
readonly detail: "both rows answered the same questions with no hidden failure";
|
|
30
|
+
}, {
|
|
31
|
+
readonly clause: "primary-objective";
|
|
32
|
+
readonly passed: true;
|
|
33
|
+
readonly detail: "locomo-f1, the registered primary";
|
|
34
|
+
}, {
|
|
35
|
+
readonly clause: "held-out-split";
|
|
36
|
+
readonly passed: true;
|
|
37
|
+
readonly detail: "measured on the held-out split";
|
|
38
|
+
}, {
|
|
39
|
+
readonly clause: "overall-interval";
|
|
40
|
+
readonly passed: false;
|
|
41
|
+
readonly detail: "the 95% lower bound is -0.0015";
|
|
42
|
+
}, {
|
|
43
|
+
readonly clause: "category-floor";
|
|
44
|
+
readonly passed: true;
|
|
45
|
+
readonly detail: "every category's one-sided lower bound is at least -0.05";
|
|
46
|
+
}, {
|
|
47
|
+
readonly clause: "token-ratio";
|
|
48
|
+
readonly passed: true;
|
|
49
|
+
readonly detail: "1.000× the control's tokens per answered question, against a ceiling of 1.10";
|
|
50
|
+
}, {
|
|
51
|
+
readonly clause: "call-ratio";
|
|
52
|
+
readonly passed: true;
|
|
53
|
+
readonly detail: "1.000× the control's calls per answered question, against a ceiling of 1.00";
|
|
54
|
+
}, {
|
|
55
|
+
readonly clause: "acting-set";
|
|
56
|
+
readonly passed: true;
|
|
57
|
+
readonly detail: "on the 3 prompts it changed the interval is [-0.0601, 0.0741]";
|
|
58
|
+
}];
|
|
59
|
+
};
|
|
60
|
+
export declare const MEASURED_MEMORY_POLICIES: Readonly<Record<string, MemoryPolicyValues & {
|
|
61
|
+
label: string;
|
|
62
|
+
}>>;
|
|
63
|
+
export declare const SHIPPED_LEGACY_CELL_ID = "f67151cea75f246c313378d12b7217f7b7b9898b6d9a5e0bf7e6a8d060c1e306";
|
|
64
|
+
export declare const POLICY_CONTRACT_REVISION = "18108e1b0da8a91306e58b309004cbbdb43df9b43923b30c8a6b366bd8178e24";
|