mem-os-python 1.6.27__py3-none-any.whl
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.
- mem_os_python-1.6.27.dist-info/METADATA +1032 -0
- mem_os_python-1.6.27.dist-info/RECORD +253 -0
- mem_os_python-1.6.27.dist-info/WHEEL +4 -0
- mem_os_python-1.6.27.dist-info/entry_points.txt +2 -0
- mem_os_python-1.6.27.dist-info/licenses/LICENSE +21 -0
- memos/__init__.py +16 -0
- memos/_js/adapters/anthropic.d.ts +279 -0
- memos/_js/adapters/anthropic.d.ts.map +1 -0
- memos/_js/adapters/anthropic.js +348 -0
- memos/_js/adapters/anthropic.js.map +1 -0
- memos/_js/adapters/base.d.ts +10 -0
- memos/_js/adapters/base.d.ts.map +1 -0
- memos/_js/adapters/base.js +2 -0
- memos/_js/adapters/base.js.map +1 -0
- memos/_js/adapters/openai.d.ts +264 -0
- memos/_js/adapters/openai.d.ts.map +1 -0
- memos/_js/adapters/openai.js +342 -0
- memos/_js/adapters/openai.js.map +1 -0
- memos/_js/apps/explorer.d.ts +244 -0
- memos/_js/apps/explorer.d.ts.map +1 -0
- memos/_js/apps/explorer.js +738 -0
- memos/_js/apps/explorer.js.map +1 -0
- memos/_js/citations.d.ts +65 -0
- memos/_js/citations.d.ts.map +1 -0
- memos/_js/citations.js +143 -0
- memos/_js/citations.js.map +1 -0
- memos/_js/cli-browse.d.ts +3 -0
- memos/_js/cli-browse.d.ts.map +1 -0
- memos/_js/cli-browse.js +129 -0
- memos/_js/cli-browse.js.map +1 -0
- memos/_js/cli-completion.d.ts +31 -0
- memos/_js/cli-completion.d.ts.map +1 -0
- memos/_js/cli-completion.js +340 -0
- memos/_js/cli-completion.js.map +1 -0
- memos/_js/cli-help.d.ts +18 -0
- memos/_js/cli-help.d.ts.map +1 -0
- memos/_js/cli-help.js +357 -0
- memos/_js/cli-help.js.map +1 -0
- memos/_js/cli.d.ts +28 -0
- memos/_js/cli.d.ts.map +1 -0
- memos/_js/cli.js +2880 -0
- memos/_js/cli.js.map +1 -0
- memos/_js/compression.d.ts +25 -0
- memos/_js/compression.d.ts.map +1 -0
- memos/_js/compression.js +319 -0
- memos/_js/compression.js.map +1 -0
- memos/_js/confidence-machine.d.ts +99 -0
- memos/_js/confidence-machine.d.ts.map +1 -0
- memos/_js/confidence-machine.js +222 -0
- memos/_js/confidence-machine.js.map +1 -0
- memos/_js/context-pack.d.ts +506 -0
- memos/_js/context-pack.d.ts.map +1 -0
- memos/_js/context-pack.js +1435 -0
- memos/_js/context-pack.js.map +1 -0
- memos/_js/contradictions.d.ts +160 -0
- memos/_js/contradictions.d.ts.map +1 -0
- memos/_js/contradictions.js +255 -0
- memos/_js/contradictions.js.map +1 -0
- memos/_js/dashboard.d.ts +30 -0
- memos/_js/dashboard.d.ts.map +1 -0
- memos/_js/dashboard.js +302 -0
- memos/_js/dashboard.js.map +1 -0
- memos/_js/ebbinghaus.d.ts +29 -0
- memos/_js/ebbinghaus.d.ts.map +1 -0
- memos/_js/ebbinghaus.js +32 -0
- memos/_js/ebbinghaus.js.map +1 -0
- memos/_js/embedding-queue.d.ts +190 -0
- memos/_js/embedding-queue.d.ts.map +1 -0
- memos/_js/embedding-queue.js +316 -0
- memos/_js/embedding-queue.js.map +1 -0
- memos/_js/embeddings.d.ts +187 -0
- memos/_js/embeddings.d.ts.map +1 -0
- memos/_js/embeddings.js +633 -0
- memos/_js/embeddings.js.map +1 -0
- memos/_js/entity-extraction.d.ts +54 -0
- memos/_js/entity-extraction.d.ts.map +1 -0
- memos/_js/entity-extraction.js +325 -0
- memos/_js/entity-extraction.js.map +1 -0
- memos/_js/entity-index.d.ts +93 -0
- memos/_js/entity-index.d.ts.map +1 -0
- memos/_js/entity-index.js +165 -0
- memos/_js/entity-index.js.map +1 -0
- memos/_js/event-memory.d.ts +147 -0
- memos/_js/event-memory.d.ts.map +1 -0
- memos/_js/event-memory.js +290 -0
- memos/_js/event-memory.js.map +1 -0
- memos/_js/external-import.d.ts +98 -0
- memos/_js/external-import.d.ts.map +1 -0
- memos/_js/external-import.js +669 -0
- memos/_js/external-import.js.map +1 -0
- memos/_js/fidelity.d.ts +367 -0
- memos/_js/fidelity.d.ts.map +1 -0
- memos/_js/fidelity.js +911 -0
- memos/_js/fidelity.js.map +1 -0
- memos/_js/graph-expansion.d.ts +119 -0
- memos/_js/graph-expansion.d.ts.map +1 -0
- memos/_js/graph-expansion.js +213 -0
- memos/_js/graph-expansion.js.map +1 -0
- memos/_js/graph-mermaid.d.ts +13 -0
- memos/_js/graph-mermaid.d.ts.map +1 -0
- memos/_js/graph-mermaid.js +32 -0
- memos/_js/graph-mermaid.js.map +1 -0
- memos/_js/graph.d.ts +170 -0
- memos/_js/graph.d.ts.map +1 -0
- memos/_js/graph.js +482 -0
- memos/_js/graph.js.map +1 -0
- memos/_js/harness.d.ts +63 -0
- memos/_js/harness.d.ts.map +1 -0
- memos/_js/harness.js +93 -0
- memos/_js/harness.js.map +1 -0
- memos/_js/importance.d.ts +118 -0
- memos/_js/importance.d.ts.map +1 -0
- memos/_js/importance.js +144 -0
- memos/_js/importance.js.map +1 -0
- memos/_js/index.d.ts +51 -0
- memos/_js/index.d.ts.map +1 -0
- memos/_js/index.js +53 -0
- memos/_js/index.js.map +1 -0
- memos/_js/mcp.d.ts +58 -0
- memos/_js/mcp.d.ts.map +1 -0
- memos/_js/mcp.js +1853 -0
- memos/_js/mcp.js.map +1 -0
- memos/_js/memory.d.ts +1762 -0
- memos/_js/memory.d.ts.map +1 -0
- memos/_js/memory.js +6283 -0
- memos/_js/memory.js.map +1 -0
- memos/_js/procedural.d.ts +74 -0
- memos/_js/procedural.d.ts.map +1 -0
- memos/_js/procedural.js +125 -0
- memos/_js/procedural.js.map +1 -0
- memos/_js/project-config.d.ts +68 -0
- memos/_js/project-config.d.ts.map +1 -0
- memos/_js/project-config.js +59 -0
- memos/_js/project-config.js.map +1 -0
- memos/_js/proof-of-forgetting.d.ts +57 -0
- memos/_js/proof-of-forgetting.d.ts.map +1 -0
- memos/_js/proof-of-forgetting.js +80 -0
- memos/_js/proof-of-forgetting.js.map +1 -0
- memos/_js/provenance.d.ts +122 -0
- memos/_js/provenance.d.ts.map +1 -0
- memos/_js/provenance.js +182 -0
- memos/_js/provenance.js.map +1 -0
- memos/_js/quarantine-commands.d.ts +23 -0
- memos/_js/quarantine-commands.d.ts.map +1 -0
- memos/_js/quarantine-commands.js +42 -0
- memos/_js/quarantine-commands.js.map +1 -0
- memos/_js/quarantine.d.ts +120 -0
- memos/_js/quarantine.d.ts.map +1 -0
- memos/_js/quarantine.js +873 -0
- memos/_js/quarantine.js.map +1 -0
- memos/_js/redact.d.ts +12 -0
- memos/_js/redact.d.ts.map +1 -0
- memos/_js/redact.js +26 -0
- memos/_js/redact.js.map +1 -0
- memos/_js/repl.d.ts +57 -0
- memos/_js/repl.d.ts.map +1 -0
- memos/_js/repl.js +295 -0
- memos/_js/repl.js.map +1 -0
- memos/_js/rerank-local.d.ts +61 -0
- memos/_js/rerank-local.d.ts.map +1 -0
- memos/_js/rerank-local.js +210 -0
- memos/_js/rerank-local.js.map +1 -0
- memos/_js/retain-filter.d.ts +98 -0
- memos/_js/retain-filter.d.ts.map +1 -0
- memos/_js/retain-filter.js +232 -0
- memos/_js/retain-filter.js.map +1 -0
- memos/_js/retrieval.d.ts +265 -0
- memos/_js/retrieval.d.ts.map +1 -0
- memos/_js/retrieval.js +1018 -0
- memos/_js/retrieval.js.map +1 -0
- memos/_js/revert.d.ts +77 -0
- memos/_js/revert.d.ts.map +1 -0
- memos/_js/revert.js +252 -0
- memos/_js/revert.js.map +1 -0
- memos/_js/scope.d.ts +30 -0
- memos/_js/scope.d.ts.map +1 -0
- memos/_js/scope.js +71 -0
- memos/_js/scope.js.map +1 -0
- memos/_js/semantic-screen.d.ts +152 -0
- memos/_js/semantic-screen.d.ts.map +1 -0
- memos/_js/semantic-screen.js +290 -0
- memos/_js/semantic-screen.js.map +1 -0
- memos/_js/session-hooks.d.ts +127 -0
- memos/_js/session-hooks.d.ts.map +1 -0
- memos/_js/session-hooks.js +482 -0
- memos/_js/session-hooks.js.map +1 -0
- memos/_js/storage/sqlite.d.ts +427 -0
- memos/_js/storage/sqlite.d.ts.map +1 -0
- memos/_js/storage/sqlite.js +2428 -0
- memos/_js/storage/sqlite.js.map +1 -0
- memos/_js/sync.d.ts +213 -0
- memos/_js/sync.d.ts.map +1 -0
- memos/_js/sync.js +389 -0
- memos/_js/sync.js.map +1 -0
- memos/_js/tamper-log.d.ts +98 -0
- memos/_js/tamper-log.d.ts.map +1 -0
- memos/_js/tamper-log.js +327 -0
- memos/_js/tamper-log.js.map +1 -0
- memos/_js/temporal.d.ts +92 -0
- memos/_js/temporal.d.ts.map +1 -0
- memos/_js/temporal.js +536 -0
- memos/_js/temporal.js.map +1 -0
- memos/_js/time-travel.d.ts +38 -0
- memos/_js/time-travel.d.ts.map +1 -0
- memos/_js/time-travel.js +46 -0
- memos/_js/time-travel.js.map +1 -0
- memos/_js/timestamp-format.d.ts +18 -0
- memos/_js/timestamp-format.d.ts.map +1 -0
- memos/_js/timestamp-format.js +52 -0
- memos/_js/timestamp-format.js.map +1 -0
- memos/_js/triple-extraction.d.ts +31 -0
- memos/_js/triple-extraction.d.ts.map +1 -0
- memos/_js/triple-extraction.js +116 -0
- memos/_js/triple-extraction.js.map +1 -0
- memos/_js/types.d.ts +2474 -0
- memos/_js/types.d.ts.map +1 -0
- memos/_js/types.js +20 -0
- memos/_js/types.js.map +1 -0
- memos/_js/updater.d.ts +95 -0
- memos/_js/updater.d.ts.map +1 -0
- memos/_js/updater.js +268 -0
- memos/_js/updater.js.map +1 -0
- memos/_js/version.d.ts +17 -0
- memos/_js/version.d.ts.map +1 -0
- memos/_js/version.js +34 -0
- memos/_js/version.js.map +1 -0
- memos/_js/vision/clip-query-cache.d.ts +58 -0
- memos/_js/vision/clip-query-cache.d.ts.map +1 -0
- memos/_js/vision/clip-query-cache.js +79 -0
- memos/_js/vision/clip-query-cache.js.map +1 -0
- memos/_js/vision/clip.d.ts +113 -0
- memos/_js/vision/clip.d.ts.map +1 -0
- memos/_js/vision/clip.js +224 -0
- memos/_js/vision/clip.js.map +1 -0
- memos/_js/vision/fake-clip.d.ts +55 -0
- memos/_js/vision/fake-clip.d.ts.map +1 -0
- memos/_js/vision/fake-clip.js +122 -0
- memos/_js/vision/fake-clip.js.map +1 -0
- memos/_js/vision/index.d.ts +15 -0
- memos/_js/vision/index.d.ts.map +1 -0
- memos/_js/vision/index.js +13 -0
- memos/_js/vision/index.js.map +1 -0
- memos/_js/vision/store.d.ts +137 -0
- memos/_js/vision/store.d.ts.map +1 -0
- memos/_js/vision/store.js +383 -0
- memos/_js/vision/store.js.map +1 -0
- memos/adapters/__init__.py +0 -0
- memos/adapters/crewai.py +385 -0
- memos/adapters/langchain.py +301 -0
- memos/adapters/ollama.py +396 -0
- memos/server/__init__.py +0 -0
- memos/server/main.py +547 -0
- memos/server/routes.py +360 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confidence score state machine for MemOS memory nodes.
|
|
3
|
+
*
|
|
4
|
+
* Implements the reinforce/revise/supersede pattern described in
|
|
5
|
+
* Mem0's "AI Memory Confidence Score" blog post, adapted for MemOS's
|
|
6
|
+
* local-first architecture.
|
|
7
|
+
*
|
|
8
|
+
* Every memory node carries a `confidence` [0,1] and `evidenceCount`
|
|
9
|
+
* in its metadata. When a new observation touches an existing memory,
|
|
10
|
+
* the confidence score is adjusted:
|
|
11
|
+
*
|
|
12
|
+
* - CONFIRMED (new evidence agrees) → confidence increases (diminishing returns)
|
|
13
|
+
* - PARTIAL_CONFLICT (new evidence partially conflicts) → confidence decreases
|
|
14
|
+
* - CONTRADICTED (new evidence clearly replaces) → supersede old memory
|
|
15
|
+
*
|
|
16
|
+
* The confidence score feeds into the trust-weighted hybrid search,
|
|
17
|
+
* so lower-confidence memories rank lower in retrieval results.
|
|
18
|
+
*/
|
|
19
|
+
/** Default confidence floor — memories below this get flagged for review. */
|
|
20
|
+
export declare const CONFIDENCE_FLOOR = 0.3;
|
|
21
|
+
/** Initial confidence for a new memory before any evidence. */
|
|
22
|
+
export declare const INITIAL_CONFIDENCE = 0.5;
|
|
23
|
+
/** Maximum confidence cap. */
|
|
24
|
+
export declare const CONFIDENCE_CAP = 1;
|
|
25
|
+
/**
|
|
26
|
+
* Keyword signals that mark new content as a negation/update of an
|
|
27
|
+
* existing fact ("no longer", "moved", …). Exported so the store-path
|
|
28
|
+
* evidence wiring (src/memory.ts) uses the SAME word list as
|
|
29
|
+
* {@link classifyEvidence} instead of duplicating it.
|
|
30
|
+
*/
|
|
31
|
+
export declare const CONTRADICTION_SIGNALS: readonly ["not", "never", "no longer", "changed", "moved", "left", "different"];
|
|
32
|
+
/**
|
|
33
|
+
* The outcome of comparing a new observation against an existing memory.
|
|
34
|
+
*/
|
|
35
|
+
export type EvidenceOutcome = "confirmed" | "partial_conflict" | "contradicted";
|
|
36
|
+
/**
|
|
37
|
+
* The result of applying evidence to a memory's confidence score.
|
|
38
|
+
*/
|
|
39
|
+
export interface ConfidenceUpdate {
|
|
40
|
+
/** New confidence score in [0, 1]. */
|
|
41
|
+
confidence: number;
|
|
42
|
+
/** New evidence count (total reinforce + revise events). */
|
|
43
|
+
evidenceCount: number;
|
|
44
|
+
/** Whether the memory was superseded (i.e. should be marked historical). */
|
|
45
|
+
superseded: boolean;
|
|
46
|
+
/** Whether the memory is now below the confidence floor (flagged for review). */
|
|
47
|
+
flaggedForReview: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Apply a single evidence event to a memory's confidence score.
|
|
51
|
+
*
|
|
52
|
+
* Uses a diminishing-returns formula for reinforcement:
|
|
53
|
+
* confidence += (CAP - confidence) * REINFORCE_RATE
|
|
54
|
+
*
|
|
55
|
+
* For partial conflicts (down-adjust):
|
|
56
|
+
* confidence -= confidence * REVISE_RATE
|
|
57
|
+
*
|
|
58
|
+
* @param currentConfidence — Current confidence score [0, 1].
|
|
59
|
+
* @param currentEvidence — Current evidence count.
|
|
60
|
+
* @param outcome — The evidence outcome from comparing new observation.
|
|
61
|
+
* @returns Updated ConfidenceUpdate.
|
|
62
|
+
*/
|
|
63
|
+
export declare function applyEvidence(currentConfidence: number, currentEvidence: number, outcome: EvidenceOutcome): ConfidenceUpdate;
|
|
64
|
+
/**
|
|
65
|
+
* Compare a new observation against an existing memory to determine
|
|
66
|
+
* the evidence outcome.
|
|
67
|
+
*
|
|
68
|
+
* This is a simple heuristic-based classifier. For production use,
|
|
69
|
+
* you may want to replace this with an LLM-based classifier.
|
|
70
|
+
*
|
|
71
|
+
* @param existingContent — The existing memory's content.
|
|
72
|
+
* @param newContent — The new observation's content.
|
|
73
|
+
* @param similarity — Semantic similarity between the two (0-1).
|
|
74
|
+
* @returns The EvidenceOutcome.
|
|
75
|
+
*/
|
|
76
|
+
export declare function classifyEvidence(existingContent: string, newContent: string, similarity: number): EvidenceOutcome;
|
|
77
|
+
/**
|
|
78
|
+
* Do two texts talk about the same SUBJECT?
|
|
79
|
+
*
|
|
80
|
+
* Guard used by the store-path evidence wiring before a contradiction is
|
|
81
|
+
* allowed to supersede a memory: the texts must share at least one
|
|
82
|
+
* meaningful content word (length > 2, not a stop word). This prevents
|
|
83
|
+
* "User no longer drinks coffee" from nuking an unrelated memory that
|
|
84
|
+
* merely happens to contain a signal word.
|
|
85
|
+
*/
|
|
86
|
+
export declare function sharesSubject(a: string, b: string): boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Get the effective retrieval weight for a memory, combining
|
|
89
|
+
* trust and confidence scores.
|
|
90
|
+
*
|
|
91
|
+
* Higher trust (source) + higher confidence → higher weight.
|
|
92
|
+
* Memories below the confidence floor get suppressed.
|
|
93
|
+
*
|
|
94
|
+
* @param trustScore — The static trust score [0, 1] from provenance.
|
|
95
|
+
* @param confidence — The dynamic confidence score [0, 1].
|
|
96
|
+
* @returns Combined weight multiplier in [0, 1].
|
|
97
|
+
*/
|
|
98
|
+
export declare function confidenceWeight(trustScore: number, confidence?: number): number;
|
|
99
|
+
//# sourceMappingURL=confidence-machine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confidence-machine.d.ts","sourceRoot":"","sources":["../src/confidence-machine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,6EAA6E;AAC7E,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAEpC,+DAA+D;AAC/D,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,8BAA8B;AAC9B,eAAO,MAAM,cAAc,IAAM,CAAC;AAElC;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,YAChC,KAAK,EACL,OAAO,EACP,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,WAAW,CACH,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,kBAAkB,GAAG,cAAc,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,aAAa,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,UAAU,EAAE,OAAO,CAAC;IACpB,iFAAiF;IACjF,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,iBAAiB,EAAE,MAAM,EACzB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,eAAe,GACvB,gBAAgB,CAqClB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,eAAe,CA+BjB;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAoE3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAYR"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Confidence score state machine for MemOS memory nodes.
|
|
3
|
+
*
|
|
4
|
+
* Implements the reinforce/revise/supersede pattern described in
|
|
5
|
+
* Mem0's "AI Memory Confidence Score" blog post, adapted for MemOS's
|
|
6
|
+
* local-first architecture.
|
|
7
|
+
*
|
|
8
|
+
* Every memory node carries a `confidence` [0,1] and `evidenceCount`
|
|
9
|
+
* in its metadata. When a new observation touches an existing memory,
|
|
10
|
+
* the confidence score is adjusted:
|
|
11
|
+
*
|
|
12
|
+
* - CONFIRMED (new evidence agrees) → confidence increases (diminishing returns)
|
|
13
|
+
* - PARTIAL_CONFLICT (new evidence partially conflicts) → confidence decreases
|
|
14
|
+
* - CONTRADICTED (new evidence clearly replaces) → supersede old memory
|
|
15
|
+
*
|
|
16
|
+
* The confidence score feeds into the trust-weighted hybrid search,
|
|
17
|
+
* so lower-confidence memories rank lower in retrieval results.
|
|
18
|
+
*/
|
|
19
|
+
/** Default confidence floor — memories below this get flagged for review. */
|
|
20
|
+
export const CONFIDENCE_FLOOR = 0.3;
|
|
21
|
+
/** Initial confidence for a new memory before any evidence. */
|
|
22
|
+
export const INITIAL_CONFIDENCE = 0.5;
|
|
23
|
+
/** Maximum confidence cap. */
|
|
24
|
+
export const CONFIDENCE_CAP = 1.0;
|
|
25
|
+
/**
|
|
26
|
+
* Keyword signals that mark new content as a negation/update of an
|
|
27
|
+
* existing fact ("no longer", "moved", …). Exported so the store-path
|
|
28
|
+
* evidence wiring (src/memory.ts) uses the SAME word list as
|
|
29
|
+
* {@link classifyEvidence} instead of duplicating it.
|
|
30
|
+
*/
|
|
31
|
+
export const CONTRADICTION_SIGNALS = [
|
|
32
|
+
"not",
|
|
33
|
+
"never",
|
|
34
|
+
"no longer",
|
|
35
|
+
"changed",
|
|
36
|
+
"moved",
|
|
37
|
+
"left",
|
|
38
|
+
"different",
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* Apply a single evidence event to a memory's confidence score.
|
|
42
|
+
*
|
|
43
|
+
* Uses a diminishing-returns formula for reinforcement:
|
|
44
|
+
* confidence += (CAP - confidence) * REINFORCE_RATE
|
|
45
|
+
*
|
|
46
|
+
* For partial conflicts (down-adjust):
|
|
47
|
+
* confidence -= confidence * REVISE_RATE
|
|
48
|
+
*
|
|
49
|
+
* @param currentConfidence — Current confidence score [0, 1].
|
|
50
|
+
* @param currentEvidence — Current evidence count.
|
|
51
|
+
* @param outcome — The evidence outcome from comparing new observation.
|
|
52
|
+
* @returns Updated ConfidenceUpdate.
|
|
53
|
+
*/
|
|
54
|
+
export function applyEvidence(currentConfidence, currentEvidence, outcome) {
|
|
55
|
+
if (outcome === "contradicted") {
|
|
56
|
+
// Superseded — mark as historical, don't delete
|
|
57
|
+
return {
|
|
58
|
+
confidence: 0,
|
|
59
|
+
evidenceCount: currentEvidence + 1,
|
|
60
|
+
superseded: true,
|
|
61
|
+
flaggedForReview: false, // superseded is a stronger signal
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (outcome === "confirmed") {
|
|
65
|
+
// Reinforce: confidence increases with diminishing returns
|
|
66
|
+
// New = old + (CAP - old) * rate
|
|
67
|
+
const newConfidence = Math.min(CONFIDENCE_CAP, currentConfidence + (CONFIDENCE_CAP - currentConfidence) * 0.15);
|
|
68
|
+
return {
|
|
69
|
+
confidence: newConfidence,
|
|
70
|
+
evidenceCount: currentEvidence + 1,
|
|
71
|
+
superseded: false,
|
|
72
|
+
flaggedForReview: newConfidence < CONFIDENCE_FLOOR,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// partial_conflict — confidence decreases
|
|
76
|
+
const newConfidence = Math.max(0, currentConfidence - currentConfidence * 0.25);
|
|
77
|
+
return {
|
|
78
|
+
confidence: newConfidence,
|
|
79
|
+
evidenceCount: currentEvidence + 1,
|
|
80
|
+
superseded: false,
|
|
81
|
+
flaggedForReview: newConfidence < CONFIDENCE_FLOOR,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Compare a new observation against an existing memory to determine
|
|
86
|
+
* the evidence outcome.
|
|
87
|
+
*
|
|
88
|
+
* This is a simple heuristic-based classifier. For production use,
|
|
89
|
+
* you may want to replace this with an LLM-based classifier.
|
|
90
|
+
*
|
|
91
|
+
* @param existingContent — The existing memory's content.
|
|
92
|
+
* @param newContent — The new observation's content.
|
|
93
|
+
* @param similarity — Semantic similarity between the two (0-1).
|
|
94
|
+
* @returns The EvidenceOutcome.
|
|
95
|
+
*/
|
|
96
|
+
export function classifyEvidence(existingContent, newContent, similarity) {
|
|
97
|
+
// High similarity (>= 0.85) → confirmed (reinforced)
|
|
98
|
+
if (similarity >= 0.85) {
|
|
99
|
+
return "confirmed";
|
|
100
|
+
}
|
|
101
|
+
// Medium similarity (0.5 - 0.85) → partial conflict
|
|
102
|
+
if (similarity >= 0.5) {
|
|
103
|
+
return "partial_conflict";
|
|
104
|
+
}
|
|
105
|
+
// Low similarity (< 0.5) → check if they contradict
|
|
106
|
+
// Simple keyword-based contradiction detection
|
|
107
|
+
const newLower = newContent.toLowerCase();
|
|
108
|
+
// If the NEW content carries a contradiction signal and similarity is
|
|
109
|
+
// low, treat as contradicted (e.g. "user likes coffee" vs "user no
|
|
110
|
+
// longer likes coffee").
|
|
111
|
+
if (CONTRADICTION_SIGNALS.some((w) => newLower.includes(w)) &&
|
|
112
|
+
similarity < 0.3) {
|
|
113
|
+
return "contradicted";
|
|
114
|
+
}
|
|
115
|
+
// Very low similarity and no contradiction → unrelated (no change).
|
|
116
|
+
// NOTE for callers: this is the NEUTRAL fallthrough, not a positive
|
|
117
|
+
// confirmation — unrelated content must NOT reinforce a memory. The
|
|
118
|
+
// store-path wiring (src/memory.ts) distinguishes the two by requiring
|
|
119
|
+
// pair similarity >= 0.85 before treating "confirmed" as a reinforce.
|
|
120
|
+
return "confirmed";
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Do two texts talk about the same SUBJECT?
|
|
124
|
+
*
|
|
125
|
+
* Guard used by the store-path evidence wiring before a contradiction is
|
|
126
|
+
* allowed to supersede a memory: the texts must share at least one
|
|
127
|
+
* meaningful content word (length > 2, not a stop word). This prevents
|
|
128
|
+
* "User no longer drinks coffee" from nuking an unrelated memory that
|
|
129
|
+
* merely happens to contain a signal word.
|
|
130
|
+
*/
|
|
131
|
+
export function sharesSubject(a, b) {
|
|
132
|
+
const STOP = new Set([
|
|
133
|
+
"the",
|
|
134
|
+
"a",
|
|
135
|
+
"an",
|
|
136
|
+
"and",
|
|
137
|
+
"or",
|
|
138
|
+
"but",
|
|
139
|
+
"if",
|
|
140
|
+
"then",
|
|
141
|
+
"else",
|
|
142
|
+
"when",
|
|
143
|
+
"at",
|
|
144
|
+
"by",
|
|
145
|
+
"for",
|
|
146
|
+
"with",
|
|
147
|
+
"about",
|
|
148
|
+
"into",
|
|
149
|
+
"through",
|
|
150
|
+
"during",
|
|
151
|
+
"to",
|
|
152
|
+
"from",
|
|
153
|
+
"in",
|
|
154
|
+
"on",
|
|
155
|
+
"of",
|
|
156
|
+
"is",
|
|
157
|
+
"are",
|
|
158
|
+
"was",
|
|
159
|
+
"were",
|
|
160
|
+
"be",
|
|
161
|
+
"been",
|
|
162
|
+
"being",
|
|
163
|
+
"have",
|
|
164
|
+
"has",
|
|
165
|
+
"had",
|
|
166
|
+
"do",
|
|
167
|
+
"does",
|
|
168
|
+
"did",
|
|
169
|
+
"will",
|
|
170
|
+
"would",
|
|
171
|
+
"can",
|
|
172
|
+
"could",
|
|
173
|
+
"should",
|
|
174
|
+
"may",
|
|
175
|
+
"might",
|
|
176
|
+
"must",
|
|
177
|
+
"shall",
|
|
178
|
+
"user",
|
|
179
|
+
"prefers",
|
|
180
|
+
"likes",
|
|
181
|
+
"not",
|
|
182
|
+
"no",
|
|
183
|
+
"longer",
|
|
184
|
+
]);
|
|
185
|
+
const words = (t) => new Set(t
|
|
186
|
+
.toLowerCase()
|
|
187
|
+
.replace(/[^a-z0-9\s]/g, " ")
|
|
188
|
+
.split(/\s+/)
|
|
189
|
+
.filter((w) => w.length > 2 && !STOP.has(w)));
|
|
190
|
+
const setA = words(a);
|
|
191
|
+
const setB = words(b);
|
|
192
|
+
for (const w of setA) {
|
|
193
|
+
if (setB.has(w))
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get the effective retrieval weight for a memory, combining
|
|
200
|
+
* trust and confidence scores.
|
|
201
|
+
*
|
|
202
|
+
* Higher trust (source) + higher confidence → higher weight.
|
|
203
|
+
* Memories below the confidence floor get suppressed.
|
|
204
|
+
*
|
|
205
|
+
* @param trustScore — The static trust score [0, 1] from provenance.
|
|
206
|
+
* @param confidence — The dynamic confidence score [0, 1].
|
|
207
|
+
* @returns Combined weight multiplier in [0, 1].
|
|
208
|
+
*/
|
|
209
|
+
export function confidenceWeight(trustScore, confidence) {
|
|
210
|
+
if (confidence === undefined || confidence === null) {
|
|
211
|
+
// No confidence tracking yet — use trust score only
|
|
212
|
+
return trustScore;
|
|
213
|
+
}
|
|
214
|
+
if (confidence < CONFIDENCE_FLOOR) {
|
|
215
|
+
// Below floor: heavily suppress
|
|
216
|
+
return trustScore * 0.1;
|
|
217
|
+
}
|
|
218
|
+
// Combine trust and confidence with a geometric mean
|
|
219
|
+
// This penalizes memories that are low on either dimension
|
|
220
|
+
return Math.sqrt(trustScore * confidence);
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=confidence-machine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confidence-machine.js","sourceRoot":"","sources":["../src/confidence-machine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MA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