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.
Files changed (253) hide show
  1. mem_os_python-1.6.27.dist-info/METADATA +1032 -0
  2. mem_os_python-1.6.27.dist-info/RECORD +253 -0
  3. mem_os_python-1.6.27.dist-info/WHEEL +4 -0
  4. mem_os_python-1.6.27.dist-info/entry_points.txt +2 -0
  5. mem_os_python-1.6.27.dist-info/licenses/LICENSE +21 -0
  6. memos/__init__.py +16 -0
  7. memos/_js/adapters/anthropic.d.ts +279 -0
  8. memos/_js/adapters/anthropic.d.ts.map +1 -0
  9. memos/_js/adapters/anthropic.js +348 -0
  10. memos/_js/adapters/anthropic.js.map +1 -0
  11. memos/_js/adapters/base.d.ts +10 -0
  12. memos/_js/adapters/base.d.ts.map +1 -0
  13. memos/_js/adapters/base.js +2 -0
  14. memos/_js/adapters/base.js.map +1 -0
  15. memos/_js/adapters/openai.d.ts +264 -0
  16. memos/_js/adapters/openai.d.ts.map +1 -0
  17. memos/_js/adapters/openai.js +342 -0
  18. memos/_js/adapters/openai.js.map +1 -0
  19. memos/_js/apps/explorer.d.ts +244 -0
  20. memos/_js/apps/explorer.d.ts.map +1 -0
  21. memos/_js/apps/explorer.js +738 -0
  22. memos/_js/apps/explorer.js.map +1 -0
  23. memos/_js/citations.d.ts +65 -0
  24. memos/_js/citations.d.ts.map +1 -0
  25. memos/_js/citations.js +143 -0
  26. memos/_js/citations.js.map +1 -0
  27. memos/_js/cli-browse.d.ts +3 -0
  28. memos/_js/cli-browse.d.ts.map +1 -0
  29. memos/_js/cli-browse.js +129 -0
  30. memos/_js/cli-browse.js.map +1 -0
  31. memos/_js/cli-completion.d.ts +31 -0
  32. memos/_js/cli-completion.d.ts.map +1 -0
  33. memos/_js/cli-completion.js +340 -0
  34. memos/_js/cli-completion.js.map +1 -0
  35. memos/_js/cli-help.d.ts +18 -0
  36. memos/_js/cli-help.d.ts.map +1 -0
  37. memos/_js/cli-help.js +357 -0
  38. memos/_js/cli-help.js.map +1 -0
  39. memos/_js/cli.d.ts +28 -0
  40. memos/_js/cli.d.ts.map +1 -0
  41. memos/_js/cli.js +2880 -0
  42. memos/_js/cli.js.map +1 -0
  43. memos/_js/compression.d.ts +25 -0
  44. memos/_js/compression.d.ts.map +1 -0
  45. memos/_js/compression.js +319 -0
  46. memos/_js/compression.js.map +1 -0
  47. memos/_js/confidence-machine.d.ts +99 -0
  48. memos/_js/confidence-machine.d.ts.map +1 -0
  49. memos/_js/confidence-machine.js +222 -0
  50. memos/_js/confidence-machine.js.map +1 -0
  51. memos/_js/context-pack.d.ts +506 -0
  52. memos/_js/context-pack.d.ts.map +1 -0
  53. memos/_js/context-pack.js +1435 -0
  54. memos/_js/context-pack.js.map +1 -0
  55. memos/_js/contradictions.d.ts +160 -0
  56. memos/_js/contradictions.d.ts.map +1 -0
  57. memos/_js/contradictions.js +255 -0
  58. memos/_js/contradictions.js.map +1 -0
  59. memos/_js/dashboard.d.ts +30 -0
  60. memos/_js/dashboard.d.ts.map +1 -0
  61. memos/_js/dashboard.js +302 -0
  62. memos/_js/dashboard.js.map +1 -0
  63. memos/_js/ebbinghaus.d.ts +29 -0
  64. memos/_js/ebbinghaus.d.ts.map +1 -0
  65. memos/_js/ebbinghaus.js +32 -0
  66. memos/_js/ebbinghaus.js.map +1 -0
  67. memos/_js/embedding-queue.d.ts +190 -0
  68. memos/_js/embedding-queue.d.ts.map +1 -0
  69. memos/_js/embedding-queue.js +316 -0
  70. memos/_js/embedding-queue.js.map +1 -0
  71. memos/_js/embeddings.d.ts +187 -0
  72. memos/_js/embeddings.d.ts.map +1 -0
  73. memos/_js/embeddings.js +633 -0
  74. memos/_js/embeddings.js.map +1 -0
  75. memos/_js/entity-extraction.d.ts +54 -0
  76. memos/_js/entity-extraction.d.ts.map +1 -0
  77. memos/_js/entity-extraction.js +325 -0
  78. memos/_js/entity-extraction.js.map +1 -0
  79. memos/_js/entity-index.d.ts +93 -0
  80. memos/_js/entity-index.d.ts.map +1 -0
  81. memos/_js/entity-index.js +165 -0
  82. memos/_js/entity-index.js.map +1 -0
  83. memos/_js/event-memory.d.ts +147 -0
  84. memos/_js/event-memory.d.ts.map +1 -0
  85. memos/_js/event-memory.js +290 -0
  86. memos/_js/event-memory.js.map +1 -0
  87. memos/_js/external-import.d.ts +98 -0
  88. memos/_js/external-import.d.ts.map +1 -0
  89. memos/_js/external-import.js +669 -0
  90. memos/_js/external-import.js.map +1 -0
  91. memos/_js/fidelity.d.ts +367 -0
  92. memos/_js/fidelity.d.ts.map +1 -0
  93. memos/_js/fidelity.js +911 -0
  94. memos/_js/fidelity.js.map +1 -0
  95. memos/_js/graph-expansion.d.ts +119 -0
  96. memos/_js/graph-expansion.d.ts.map +1 -0
  97. memos/_js/graph-expansion.js +213 -0
  98. memos/_js/graph-expansion.js.map +1 -0
  99. memos/_js/graph-mermaid.d.ts +13 -0
  100. memos/_js/graph-mermaid.d.ts.map +1 -0
  101. memos/_js/graph-mermaid.js +32 -0
  102. memos/_js/graph-mermaid.js.map +1 -0
  103. memos/_js/graph.d.ts +170 -0
  104. memos/_js/graph.d.ts.map +1 -0
  105. memos/_js/graph.js +482 -0
  106. memos/_js/graph.js.map +1 -0
  107. memos/_js/harness.d.ts +63 -0
  108. memos/_js/harness.d.ts.map +1 -0
  109. memos/_js/harness.js +93 -0
  110. memos/_js/harness.js.map +1 -0
  111. memos/_js/importance.d.ts +118 -0
  112. memos/_js/importance.d.ts.map +1 -0
  113. memos/_js/importance.js +144 -0
  114. memos/_js/importance.js.map +1 -0
  115. memos/_js/index.d.ts +51 -0
  116. memos/_js/index.d.ts.map +1 -0
  117. memos/_js/index.js +53 -0
  118. memos/_js/index.js.map +1 -0
  119. memos/_js/mcp.d.ts +58 -0
  120. memos/_js/mcp.d.ts.map +1 -0
  121. memos/_js/mcp.js +1853 -0
  122. memos/_js/mcp.js.map +1 -0
  123. memos/_js/memory.d.ts +1762 -0
  124. memos/_js/memory.d.ts.map +1 -0
  125. memos/_js/memory.js +6283 -0
  126. memos/_js/memory.js.map +1 -0
  127. memos/_js/procedural.d.ts +74 -0
  128. memos/_js/procedural.d.ts.map +1 -0
  129. memos/_js/procedural.js +125 -0
  130. memos/_js/procedural.js.map +1 -0
  131. memos/_js/project-config.d.ts +68 -0
  132. memos/_js/project-config.d.ts.map +1 -0
  133. memos/_js/project-config.js +59 -0
  134. memos/_js/project-config.js.map +1 -0
  135. memos/_js/proof-of-forgetting.d.ts +57 -0
  136. memos/_js/proof-of-forgetting.d.ts.map +1 -0
  137. memos/_js/proof-of-forgetting.js +80 -0
  138. memos/_js/proof-of-forgetting.js.map +1 -0
  139. memos/_js/provenance.d.ts +122 -0
  140. memos/_js/provenance.d.ts.map +1 -0
  141. memos/_js/provenance.js +182 -0
  142. memos/_js/provenance.js.map +1 -0
  143. memos/_js/quarantine-commands.d.ts +23 -0
  144. memos/_js/quarantine-commands.d.ts.map +1 -0
  145. memos/_js/quarantine-commands.js +42 -0
  146. memos/_js/quarantine-commands.js.map +1 -0
  147. memos/_js/quarantine.d.ts +120 -0
  148. memos/_js/quarantine.d.ts.map +1 -0
  149. memos/_js/quarantine.js +873 -0
  150. memos/_js/quarantine.js.map +1 -0
  151. memos/_js/redact.d.ts +12 -0
  152. memos/_js/redact.d.ts.map +1 -0
  153. memos/_js/redact.js +26 -0
  154. memos/_js/redact.js.map +1 -0
  155. memos/_js/repl.d.ts +57 -0
  156. memos/_js/repl.d.ts.map +1 -0
  157. memos/_js/repl.js +295 -0
  158. memos/_js/repl.js.map +1 -0
  159. memos/_js/rerank-local.d.ts +61 -0
  160. memos/_js/rerank-local.d.ts.map +1 -0
  161. memos/_js/rerank-local.js +210 -0
  162. memos/_js/rerank-local.js.map +1 -0
  163. memos/_js/retain-filter.d.ts +98 -0
  164. memos/_js/retain-filter.d.ts.map +1 -0
  165. memos/_js/retain-filter.js +232 -0
  166. memos/_js/retain-filter.js.map +1 -0
  167. memos/_js/retrieval.d.ts +265 -0
  168. memos/_js/retrieval.d.ts.map +1 -0
  169. memos/_js/retrieval.js +1018 -0
  170. memos/_js/retrieval.js.map +1 -0
  171. memos/_js/revert.d.ts +77 -0
  172. memos/_js/revert.d.ts.map +1 -0
  173. memos/_js/revert.js +252 -0
  174. memos/_js/revert.js.map +1 -0
  175. memos/_js/scope.d.ts +30 -0
  176. memos/_js/scope.d.ts.map +1 -0
  177. memos/_js/scope.js +71 -0
  178. memos/_js/scope.js.map +1 -0
  179. memos/_js/semantic-screen.d.ts +152 -0
  180. memos/_js/semantic-screen.d.ts.map +1 -0
  181. memos/_js/semantic-screen.js +290 -0
  182. memos/_js/semantic-screen.js.map +1 -0
  183. memos/_js/session-hooks.d.ts +127 -0
  184. memos/_js/session-hooks.d.ts.map +1 -0
  185. memos/_js/session-hooks.js +482 -0
  186. memos/_js/session-hooks.js.map +1 -0
  187. memos/_js/storage/sqlite.d.ts +427 -0
  188. memos/_js/storage/sqlite.d.ts.map +1 -0
  189. memos/_js/storage/sqlite.js +2428 -0
  190. memos/_js/storage/sqlite.js.map +1 -0
  191. memos/_js/sync.d.ts +213 -0
  192. memos/_js/sync.d.ts.map +1 -0
  193. memos/_js/sync.js +389 -0
  194. memos/_js/sync.js.map +1 -0
  195. memos/_js/tamper-log.d.ts +98 -0
  196. memos/_js/tamper-log.d.ts.map +1 -0
  197. memos/_js/tamper-log.js +327 -0
  198. memos/_js/tamper-log.js.map +1 -0
  199. memos/_js/temporal.d.ts +92 -0
  200. memos/_js/temporal.d.ts.map +1 -0
  201. memos/_js/temporal.js +536 -0
  202. memos/_js/temporal.js.map +1 -0
  203. memos/_js/time-travel.d.ts +38 -0
  204. memos/_js/time-travel.d.ts.map +1 -0
  205. memos/_js/time-travel.js +46 -0
  206. memos/_js/time-travel.js.map +1 -0
  207. memos/_js/timestamp-format.d.ts +18 -0
  208. memos/_js/timestamp-format.d.ts.map +1 -0
  209. memos/_js/timestamp-format.js +52 -0
  210. memos/_js/timestamp-format.js.map +1 -0
  211. memos/_js/triple-extraction.d.ts +31 -0
  212. memos/_js/triple-extraction.d.ts.map +1 -0
  213. memos/_js/triple-extraction.js +116 -0
  214. memos/_js/triple-extraction.js.map +1 -0
  215. memos/_js/types.d.ts +2474 -0
  216. memos/_js/types.d.ts.map +1 -0
  217. memos/_js/types.js +20 -0
  218. memos/_js/types.js.map +1 -0
  219. memos/_js/updater.d.ts +95 -0
  220. memos/_js/updater.d.ts.map +1 -0
  221. memos/_js/updater.js +268 -0
  222. memos/_js/updater.js.map +1 -0
  223. memos/_js/version.d.ts +17 -0
  224. memos/_js/version.d.ts.map +1 -0
  225. memos/_js/version.js +34 -0
  226. memos/_js/version.js.map +1 -0
  227. memos/_js/vision/clip-query-cache.d.ts +58 -0
  228. memos/_js/vision/clip-query-cache.d.ts.map +1 -0
  229. memos/_js/vision/clip-query-cache.js +79 -0
  230. memos/_js/vision/clip-query-cache.js.map +1 -0
  231. memos/_js/vision/clip.d.ts +113 -0
  232. memos/_js/vision/clip.d.ts.map +1 -0
  233. memos/_js/vision/clip.js +224 -0
  234. memos/_js/vision/clip.js.map +1 -0
  235. memos/_js/vision/fake-clip.d.ts +55 -0
  236. memos/_js/vision/fake-clip.d.ts.map +1 -0
  237. memos/_js/vision/fake-clip.js +122 -0
  238. memos/_js/vision/fake-clip.js.map +1 -0
  239. memos/_js/vision/index.d.ts +15 -0
  240. memos/_js/vision/index.d.ts.map +1 -0
  241. memos/_js/vision/index.js +13 -0
  242. memos/_js/vision/index.js.map +1 -0
  243. memos/_js/vision/store.d.ts +137 -0
  244. memos/_js/vision/store.d.ts.map +1 -0
  245. memos/_js/vision/store.js +383 -0
  246. memos/_js/vision/store.js.map +1 -0
  247. memos/adapters/__init__.py +0 -0
  248. memos/adapters/crewai.py +385 -0
  249. memos/adapters/langchain.py +301 -0
  250. memos/adapters/ollama.py +396 -0
  251. memos/server/__init__.py +0 -0
  252. memos/server/main.py +547 -0
  253. 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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 /**
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,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAEpC,+DAA+D;AAC/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAEtC,8BAA8B;AAC9B,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAElC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,KAAK;IACL,OAAO;IACP,WAAW;IACX,SAAS;IACT,OAAO;IACP,MAAM;IACN,WAAW;CACH,CAAC;AAqBX;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAC3B,iBAAyB,EACzB,eAAuB,EACvB,OAAwB;IAExB,IAAI,OAAO,KAAK,cAAc,EAAE,CAAC;QAC/B,gDAAgD;QAChD,OAAO;YACL,UAAU,EAAE,CAAC;YACb,aAAa,EAAE,eAAe,GAAG,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