@graphorin/memory 0.5.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.
Files changed (287) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +401 -0
  4. package/dist/conflict/index.d.ts +3 -0
  5. package/dist/conflict/index.js +7 -0
  6. package/dist/conflict/locale-packs/en.js +262 -0
  7. package/dist/conflict/locale-packs/en.js.map +1 -0
  8. package/dist/conflict/locale-packs/index.js +4 -0
  9. package/dist/conflict/locale-packs/types.d.ts +103 -0
  10. package/dist/conflict/locale-packs/types.d.ts.map +1 -0
  11. package/dist/conflict/locale-packs/types.js +55 -0
  12. package/dist/conflict/locale-packs/types.js.map +1 -0
  13. package/dist/conflict/pipeline.d.ts +35 -0
  14. package/dist/conflict/pipeline.d.ts.map +1 -0
  15. package/dist/conflict/pipeline.js +257 -0
  16. package/dist/conflict/pipeline.js.map +1 -0
  17. package/dist/conflict/stages/helpers.js +66 -0
  18. package/dist/conflict/stages/helpers.js.map +1 -0
  19. package/dist/conflict/stages/stage1-exact-dedup.js +21 -0
  20. package/dist/conflict/stages/stage1-exact-dedup.js.map +1 -0
  21. package/dist/conflict/stages/stage2-embedding-three-zone.js +37 -0
  22. package/dist/conflict/stages/stage2-embedding-three-zone.js.map +1 -0
  23. package/dist/conflict/stages/stage3-heuristic-regex.js +45 -0
  24. package/dist/conflict/stages/stage3-heuristic-regex.js.map +1 -0
  25. package/dist/conflict/stages/stage4-subject-predicate.js +31 -0
  26. package/dist/conflict/stages/stage4-subject-predicate.js.map +1 -0
  27. package/dist/conflict/stages/stage5-defer-to-deep.js +22 -0
  28. package/dist/conflict/stages/stage5-defer-to-deep.js.map +1 -0
  29. package/dist/conflict/types.d.ts +222 -0
  30. package/dist/conflict/types.d.ts.map +1 -0
  31. package/dist/conflict/types.js +50 -0
  32. package/dist/conflict/types.js.map +1 -0
  33. package/dist/consolidator/budget.d.ts +1 -0
  34. package/dist/consolidator/budget.js +214 -0
  35. package/dist/consolidator/budget.js.map +1 -0
  36. package/dist/consolidator/decay.d.ts +35 -0
  37. package/dist/consolidator/decay.d.ts.map +1 -0
  38. package/dist/consolidator/decay.js +91 -0
  39. package/dist/consolidator/decay.js.map +1 -0
  40. package/dist/consolidator/dlq.js +58 -0
  41. package/dist/consolidator/dlq.js.map +1 -0
  42. package/dist/consolidator/errors.d.ts +54 -0
  43. package/dist/consolidator/errors.d.ts.map +1 -0
  44. package/dist/consolidator/errors.js +67 -0
  45. package/dist/consolidator/errors.js.map +1 -0
  46. package/dist/consolidator/idempotency.d.ts +1 -0
  47. package/dist/consolidator/idempotency.js +22 -0
  48. package/dist/consolidator/idempotency.js.map +1 -0
  49. package/dist/consolidator/index.d.ts +34 -0
  50. package/dist/consolidator/index.d.ts.map +1 -0
  51. package/dist/consolidator/index.js +163 -0
  52. package/dist/consolidator/index.js.map +1 -0
  53. package/dist/consolidator/lock.d.ts +2 -0
  54. package/dist/consolidator/lock.js +89 -0
  55. package/dist/consolidator/lock.js.map +1 -0
  56. package/dist/consolidator/noise-filter.d.ts +2 -0
  57. package/dist/consolidator/noise-filter.js +173 -0
  58. package/dist/consolidator/noise-filter.js.map +1 -0
  59. package/dist/consolidator/phases/deep.d.ts +4 -0
  60. package/dist/consolidator/phases/deep.js +198 -0
  61. package/dist/consolidator/phases/deep.js.map +1 -0
  62. package/dist/consolidator/phases/induce.d.ts +154 -0
  63. package/dist/consolidator/phases/induce.d.ts.map +1 -0
  64. package/dist/consolidator/phases/induce.js +253 -0
  65. package/dist/consolidator/phases/induce.js.map +1 -0
  66. package/dist/consolidator/phases/light.d.ts +4 -0
  67. package/dist/consolidator/phases/light.js +99 -0
  68. package/dist/consolidator/phases/light.js.map +1 -0
  69. package/dist/consolidator/phases/reflect.js +287 -0
  70. package/dist/consolidator/phases/reflect.js.map +1 -0
  71. package/dist/consolidator/phases/standard.d.ts +8 -0
  72. package/dist/consolidator/phases/standard.js +499 -0
  73. package/dist/consolidator/phases/standard.js.map +1 -0
  74. package/dist/consolidator/reconcile.js +192 -0
  75. package/dist/consolidator/reconcile.js.map +1 -0
  76. package/dist/consolidator/runtime.d.ts +62 -0
  77. package/dist/consolidator/runtime.d.ts.map +1 -0
  78. package/dist/consolidator/runtime.js +580 -0
  79. package/dist/consolidator/runtime.js.map +1 -0
  80. package/dist/consolidator/scheduler.d.ts +111 -0
  81. package/dist/consolidator/scheduler.d.ts.map +1 -0
  82. package/dist/consolidator/scheduler.js +71 -0
  83. package/dist/consolidator/scheduler.js.map +1 -0
  84. package/dist/consolidator/triggers.d.ts +40 -0
  85. package/dist/consolidator/triggers.d.ts.map +1 -0
  86. package/dist/consolidator/triggers.js +94 -0
  87. package/dist/consolidator/triggers.js.map +1 -0
  88. package/dist/consolidator/types.d.ts +397 -0
  89. package/dist/consolidator/types.d.ts.map +1 -0
  90. package/dist/consolidator/types.js +117 -0
  91. package/dist/consolidator/types.js.map +1 -0
  92. package/dist/context-engine/annotations.d.ts +118 -0
  93. package/dist/context-engine/annotations.d.ts.map +1 -0
  94. package/dist/context-engine/annotations.js +102 -0
  95. package/dist/context-engine/annotations.js.map +1 -0
  96. package/dist/context-engine/auto-recall.d.ts +52 -0
  97. package/dist/context-engine/auto-recall.d.ts.map +1 -0
  98. package/dist/context-engine/auto-recall.js +41 -0
  99. package/dist/context-engine/auto-recall.js.map +1 -0
  100. package/dist/context-engine/compaction/clear-tool-results.d.ts +55 -0
  101. package/dist/context-engine/compaction/clear-tool-results.d.ts.map +1 -0
  102. package/dist/context-engine/compaction/clear-tool-results.js +97 -0
  103. package/dist/context-engine/compaction/clear-tool-results.js.map +1 -0
  104. package/dist/context-engine/compaction/compactor.d.ts +52 -0
  105. package/dist/context-engine/compaction/compactor.d.ts.map +1 -0
  106. package/dist/context-engine/compaction/compactor.js +196 -0
  107. package/dist/context-engine/compaction/compactor.js.map +1 -0
  108. package/dist/context-engine/compaction/hooks/reanchor-persona-block.d.ts +15 -0
  109. package/dist/context-engine/compaction/hooks/reanchor-persona-block.d.ts.map +1 -0
  110. package/dist/context-engine/compaction/hooks/reanchor-persona-block.js +27 -0
  111. package/dist/context-engine/compaction/hooks/reanchor-persona-block.js.map +1 -0
  112. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.d.ts +18 -0
  113. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.d.ts.map +1 -0
  114. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.js +47 -0
  115. package/dist/context-engine/compaction/hooks/reanchor-pinned-facts.js.map +1 -0
  116. package/dist/context-engine/compaction/hooks/reanchor-project-rules.d.ts +15 -0
  117. package/dist/context-engine/compaction/hooks/reanchor-project-rules.d.ts.map +1 -0
  118. package/dist/context-engine/compaction/hooks/reanchor-project-rules.js +32 -0
  119. package/dist/context-engine/compaction/hooks/reanchor-project-rules.js.map +1 -0
  120. package/dist/context-engine/compaction/hooks/types.d.ts +42 -0
  121. package/dist/context-engine/compaction/hooks/types.d.ts.map +1 -0
  122. package/dist/context-engine/compaction/index.d.ts +9 -0
  123. package/dist/context-engine/compaction/index.js +9 -0
  124. package/dist/context-engine/compaction/templates/summary-9-section.d.ts +84 -0
  125. package/dist/context-engine/compaction/templates/summary-9-section.d.ts.map +1 -0
  126. package/dist/context-engine/compaction/templates/summary-9-section.js +84 -0
  127. package/dist/context-engine/compaction/templates/summary-9-section.js.map +1 -0
  128. package/dist/context-engine/compaction/thresholds.d.ts +68 -0
  129. package/dist/context-engine/compaction/thresholds.d.ts.map +1 -0
  130. package/dist/context-engine/compaction/thresholds.js +63 -0
  131. package/dist/context-engine/compaction/thresholds.js.map +1 -0
  132. package/dist/context-engine/compaction/types.d.ts +202 -0
  133. package/dist/context-engine/compaction/types.d.ts.map +1 -0
  134. package/dist/context-engine/engine.d.ts +258 -0
  135. package/dist/context-engine/engine.d.ts.map +1 -0
  136. package/dist/context-engine/engine.js +424 -0
  137. package/dist/context-engine/engine.js.map +1 -0
  138. package/dist/context-engine/index.d.ts +68 -0
  139. package/dist/context-engine/index.d.ts.map +1 -0
  140. package/dist/context-engine/index.js +24 -0
  141. package/dist/context-engine/locale-packs/en.d.ts +14 -0
  142. package/dist/context-engine/locale-packs/en.d.ts.map +1 -0
  143. package/dist/context-engine/locale-packs/en.js +87 -0
  144. package/dist/context-engine/locale-packs/en.js.map +1 -0
  145. package/dist/context-engine/locale-packs/index.js +4 -0
  146. package/dist/context-engine/locale-packs/resolver.d.ts +41 -0
  147. package/dist/context-engine/locale-packs/resolver.d.ts.map +1 -0
  148. package/dist/context-engine/locale-packs/resolver.js +119 -0
  149. package/dist/context-engine/locale-packs/resolver.js.map +1 -0
  150. package/dist/context-engine/locale-packs/types.d.ts +119 -0
  151. package/dist/context-engine/locale-packs/types.d.ts.map +1 -0
  152. package/dist/context-engine/locale-packs/types.js +24 -0
  153. package/dist/context-engine/locale-packs/types.js.map +1 -0
  154. package/dist/context-engine/metadata.d.ts +40 -0
  155. package/dist/context-engine/metadata.d.ts.map +1 -0
  156. package/dist/context-engine/metadata.js +66 -0
  157. package/dist/context-engine/metadata.js.map +1 -0
  158. package/dist/context-engine/preambles/inbound-en.d.ts +20 -0
  159. package/dist/context-engine/preambles/inbound-en.d.ts.map +1 -0
  160. package/dist/context-engine/preambles/inbound-en.js +23 -0
  161. package/dist/context-engine/preambles/inbound-en.js.map +1 -0
  162. package/dist/context-engine/privacy-filter.d.ts +108 -0
  163. package/dist/context-engine/privacy-filter.d.ts.map +1 -0
  164. package/dist/context-engine/privacy-filter.js +113 -0
  165. package/dist/context-engine/privacy-filter.js.map +1 -0
  166. package/dist/context-engine/templates/base-en.d.ts +19 -0
  167. package/dist/context-engine/templates/base-en.d.ts.map +1 -0
  168. package/dist/context-engine/templates/base-en.js +22 -0
  169. package/dist/context-engine/templates/base-en.js.map +1 -0
  170. package/dist/context-engine/templates/composer.d.ts +55 -0
  171. package/dist/context-engine/templates/composer.d.ts.map +1 -0
  172. package/dist/context-engine/templates/composer.js +51 -0
  173. package/dist/context-engine/templates/composer.js.map +1 -0
  174. package/dist/context-engine/token-budget.d.ts +99 -0
  175. package/dist/context-engine/token-budget.d.ts.map +1 -0
  176. package/dist/context-engine/token-budget.js +211 -0
  177. package/dist/context-engine/token-budget.js.map +1 -0
  178. package/dist/context-engine/token-counter.d.ts +54 -0
  179. package/dist/context-engine/token-counter.d.ts.map +1 -0
  180. package/dist/context-engine/token-counter.js +81 -0
  181. package/dist/context-engine/token-counter.js.map +1 -0
  182. package/dist/errors/index.d.ts +171 -0
  183. package/dist/errors/index.d.ts.map +1 -0
  184. package/dist/errors/index.js +206 -0
  185. package/dist/errors/index.js.map +1 -0
  186. package/dist/facade.d.ts +278 -0
  187. package/dist/facade.d.ts.map +1 -0
  188. package/dist/facade.js +265 -0
  189. package/dist/facade.js.map +1 -0
  190. package/dist/graph/entity-resolver.d.ts +135 -0
  191. package/dist/graph/entity-resolver.d.ts.map +1 -0
  192. package/dist/graph/entity-resolver.js +202 -0
  193. package/dist/graph/entity-resolver.js.map +1 -0
  194. package/dist/graph/index.d.ts +1 -0
  195. package/dist/index.d.ts +103 -0
  196. package/dist/index.d.ts.map +1 -0
  197. package/dist/index.js +95 -0
  198. package/dist/index.js.map +1 -0
  199. package/dist/internal/contextualize.d.ts +14 -0
  200. package/dist/internal/contextualize.d.ts.map +1 -0
  201. package/dist/internal/contextualize.js +110 -0
  202. package/dist/internal/contextualize.js.map +1 -0
  203. package/dist/internal/embedder-binding.js +50 -0
  204. package/dist/internal/embedder-binding.js.map +1 -0
  205. package/dist/internal/id.js +24 -0
  206. package/dist/internal/id.js.map +1 -0
  207. package/dist/internal/injection-heuristics.js +64 -0
  208. package/dist/internal/injection-heuristics.js.map +1 -0
  209. package/dist/internal/spans.js +35 -0
  210. package/dist/internal/spans.js.map +1 -0
  211. package/dist/internal/storage-adapter.d.ts +742 -0
  212. package/dist/internal/storage-adapter.d.ts.map +1 -0
  213. package/dist/migration/embedder-migration.d.ts +124 -0
  214. package/dist/migration/embedder-migration.d.ts.map +1 -0
  215. package/dist/migration/embedder-migration.js +109 -0
  216. package/dist/migration/embedder-migration.js.map +1 -0
  217. package/dist/migration/index.d.ts +2 -0
  218. package/dist/migration/index.js +3 -0
  219. package/dist/search/explain.d.ts +74 -0
  220. package/dist/search/explain.d.ts.map +1 -0
  221. package/dist/search/explain.js +50 -0
  222. package/dist/search/explain.js.map +1 -0
  223. package/dist/search/index.d.ts +6 -0
  224. package/dist/search/index.js +6 -0
  225. package/dist/search/iterative.d.ts +223 -0
  226. package/dist/search/iterative.d.ts.map +1 -0
  227. package/dist/search/iterative.js +330 -0
  228. package/dist/search/iterative.js.map +1 -0
  229. package/dist/search/query-transform.d.ts +112 -0
  230. package/dist/search/query-transform.d.ts.map +1 -0
  231. package/dist/search/query-transform.js +184 -0
  232. package/dist/search/query-transform.js.map +1 -0
  233. package/dist/search/rrf.d.ts +95 -0
  234. package/dist/search/rrf.d.ts.map +1 -0
  235. package/dist/search/rrf.js +166 -0
  236. package/dist/search/rrf.js.map +1 -0
  237. package/dist/search/types.d.ts +50 -0
  238. package/dist/search/types.d.ts.map +1 -0
  239. package/dist/tiers/episodic-memory.d.ts +142 -0
  240. package/dist/tiers/episodic-memory.d.ts.map +1 -0
  241. package/dist/tiers/episodic-memory.js +254 -0
  242. package/dist/tiers/episodic-memory.js.map +1 -0
  243. package/dist/tiers/index.d.ts +8 -0
  244. package/dist/tiers/index.js +9 -0
  245. package/dist/tiers/insight-memory.d.ts +71 -0
  246. package/dist/tiers/insight-memory.d.ts.map +1 -0
  247. package/dist/tiers/insight-memory.js +133 -0
  248. package/dist/tiers/insight-memory.js.map +1 -0
  249. package/dist/tiers/procedural-memory.d.ts +147 -0
  250. package/dist/tiers/procedural-memory.d.ts.map +1 -0
  251. package/dist/tiers/procedural-memory.js +267 -0
  252. package/dist/tiers/procedural-memory.js.map +1 -0
  253. package/dist/tiers/semantic-memory.d.ts +461 -0
  254. package/dist/tiers/semantic-memory.d.ts.map +1 -0
  255. package/dist/tiers/semantic-memory.js +631 -0
  256. package/dist/tiers/semantic-memory.js.map +1 -0
  257. package/dist/tiers/session-memory.d.ts +117 -0
  258. package/dist/tiers/session-memory.d.ts.map +1 -0
  259. package/dist/tiers/session-memory.js +163 -0
  260. package/dist/tiers/session-memory.js.map +1 -0
  261. package/dist/tiers/shared-memory.d.ts +29 -0
  262. package/dist/tiers/shared-memory.d.ts.map +1 -0
  263. package/dist/tiers/shared-memory.js +58 -0
  264. package/dist/tiers/shared-memory.js.map +1 -0
  265. package/dist/tiers/working-memory.d.ts +129 -0
  266. package/dist/tiers/working-memory.d.ts.map +1 -0
  267. package/dist/tiers/working-memory.js +229 -0
  268. package/dist/tiers/working-memory.js.map +1 -0
  269. package/dist/tools/block-tools.d.ts +98 -0
  270. package/dist/tools/block-tools.d.ts.map +1 -0
  271. package/dist/tools/block-tools.js +114 -0
  272. package/dist/tools/block-tools.js.map +1 -0
  273. package/dist/tools/fact-tools.d.ts +294 -0
  274. package/dist/tools/fact-tools.d.ts.map +1 -0
  275. package/dist/tools/fact-tools.js +293 -0
  276. package/dist/tools/fact-tools.js.map +1 -0
  277. package/dist/tools/index.d.ts +35 -0
  278. package/dist/tools/index.d.ts.map +1 -0
  279. package/dist/tools/index.js +36 -0
  280. package/dist/tools/index.js.map +1 -0
  281. package/dist/tools/recall-tools.d.ts +209 -0
  282. package/dist/tools/recall-tools.d.ts.map +1 -0
  283. package/dist/tools/recall-tools.js +170 -0
  284. package/dist/tools/recall-tools.js.map +1 -0
  285. package/dist/tools/types.d.ts +40 -0
  286. package/dist/tools/types.d.ts.map +1 -0
  287. package/package.json +119 -0
@@ -0,0 +1,461 @@
1
+ import { MemoryStoreAdapter } from "../internal/storage-adapter.js";
2
+ import { ConflictDecision, ConflictPipeline } from "../conflict/types.js";
3
+ import "../conflict/index.js";
4
+ import { EntityResolver } from "../graph/entity-resolver.js";
5
+ import { IterativeRetrievalResult, RetrievalGrader } from "../search/iterative.js";
6
+ import { QueryTransformer } from "../search/query-transform.js";
7
+ import { ReRanker } from "../search/types.js";
8
+ import { EmbedderProvider, Fact, MemoryHit, MemoryProvenance, Sensitivity, SessionScope, Tracer } from "@graphorin/core";
9
+
10
+ //#region src/tiers/semantic-memory.d.ts
11
+
12
+ /**
13
+ * Author-time fact payload accepted by {@link SemanticMemory.remember}.
14
+ * The framework derives `id`, `kind: 'semantic'`, `userId`,
15
+ * `createdAt`, `updatedAt`, `validFrom`, the optional `embedder_id`,
16
+ * and the deduplication `hash` from this input.
17
+ *
18
+ * @stable
19
+ */
20
+ interface FactInput {
21
+ readonly text: string;
22
+ readonly subject?: string;
23
+ readonly predicate?: string;
24
+ readonly object?: string;
25
+ readonly tags?: ReadonlyArray<string>;
26
+ readonly confidence?: number;
27
+ readonly sensitivity?: Sensitivity;
28
+ readonly validFrom?: string;
29
+ readonly validTo?: string;
30
+ readonly supersedes?: string;
31
+ /**
32
+ * Trust-provenance tag (P1-4). Writers that synthesize memory pass
33
+ * `'extraction'` / `'reflection'` so the fact lands quarantined;
34
+ * first-party writers pass `'user'` / `'tool'` (or omit it — absent ⇒
35
+ * treated as first-party `active`). The `status` is *derived* from
36
+ * this tag plus the injection heuristics; it is never author-set.
37
+ */
38
+ readonly provenance?: MemoryProvenance;
39
+ /**
40
+ * Importance hint in `[0, 1]` (X-1 / MCON-12). Feeds the multi-signal
41
+ * salience score that orders decay archiving and capacity eviction —
42
+ * higher importance ⇒ evicted later. Values are clamped to `[0, 1]`;
43
+ * non-finite values are dropped. The consolidator's extraction pass
44
+ * fills this from the model's per-fact 1–10 rating
45
+ * (`normalizeImportance`); absent ⇒ the neutral midpoint at scoring
46
+ * time.
47
+ */
48
+ readonly importance?: number;
49
+ }
50
+ /**
51
+ * Per-list weights for {@link FusionStrategy} `'weighted'` fusion (X-2),
52
+ * keyed by retriever *kind* rather than position so they survive the
53
+ * P2-3 multi-query fan-out (which appends extra FTS / vector candidate
54
+ * lists). Each defaults to the neutral `1` (≡ RRF). The HyDE list is a
55
+ * vector list and takes the `vector` weight.
56
+ *
57
+ * @stable
58
+ */
59
+ interface FusionWeights {
60
+ /** Weight applied to every FTS5 (lexical) candidate list. Default `1`. */
61
+ readonly fts?: number;
62
+ /** Weight applied to every vector (incl. HyDE) candidate list. Default `1`. */
63
+ readonly vector?: number;
64
+ }
65
+ /**
66
+ * Score-fusion strategy for {@link SemanticMemory.search} (X-2).
67
+ *
68
+ * - `'rrf'` (the default when `fusion` is omitted) fuses the candidate
69
+ * lists through the configured reranker — the zero-tuning
70
+ * {@link RRFReranker} unless one was overridden.
71
+ * - `'weighted'` fuses through {@link WeightedRRFReranker}, scaling each
72
+ * list's reciprocal-rank contribution by its {@link FusionWeights}, for
73
+ * callers who have calibrated retriever reliability against labels (the
74
+ * P0-1 eval harness). At equal weights it reproduces RRF.
75
+ *
76
+ * @stable
77
+ */
78
+ type FusionStrategy = {
79
+ readonly strategy: 'rrf';
80
+ } | {
81
+ readonly strategy: 'weighted';
82
+ readonly weights: FusionWeights;
83
+ /** Override the RRF constant for the weighted fuse. Default `60`. */
84
+ readonly k?: number;
85
+ };
86
+ /**
87
+ * Per-call options accepted by {@link SemanticMemory.search}.
88
+ *
89
+ * @stable
90
+ */
91
+ interface FactSearchOptions {
92
+ readonly topK?: number;
93
+ readonly signal?: AbortSignal;
94
+ /** Override the per-list candidate count (default `60`). */
95
+ readonly candidateTopK?: number;
96
+ /**
97
+ * Any-of tags filter (MRET-4). A fact matches when it carries at
98
+ * least one of the requested tags; untagged facts never match.
99
+ * Applied in-store on the FTS leg and as a record-level filter on
100
+ * the fused result so every candidate leg (vector / HyDE / graph)
101
+ * obeys it.
102
+ */
103
+ readonly tags?: ReadonlyArray<string>;
104
+ /**
105
+ * Point-in-time ("as of") read. When set, only facts whose
106
+ * bi-temporal validity interval contains this instant are returned
107
+ * (`valid_from <= asOf < valid_to`, open-ended bounds allowed),
108
+ * applied at the store layer to both the FTS and vector candidate
109
+ * lists. ISO-8601. Absent ⇒ current behaviour is unchanged. P0-2.
110
+ *
111
+ * @stable
112
+ */
113
+ readonly asOf?: string;
114
+ /**
115
+ * Include quarantined facts in the result (P1-4). Defaults to
116
+ * `false` — action-driving recall (`fact_search`, auto-recall) never
117
+ * returns quarantined rows. Set `true` only for the validation /
118
+ * inspector path that surfaces quarantined facts to a human for
119
+ * promotion via {@link SemanticMemory.validate}.
120
+ *
121
+ * @stable
122
+ */
123
+ readonly includeQuarantined?: boolean;
124
+ /**
125
+ * Optional decay-aware ranking. When set, the reranker output is
126
+ * post-multiplied by the per-fact retention curve
127
+ * `score *= exp(-elapsedDays / tauDays)` so stale facts drop in
128
+ * the result list without ever being hard-deleted (principle 8).
129
+ * Requires the storage adapter to expose
130
+ * `semantic.listForDecay?(...)` so the search can read
131
+ * `strength` + `lastAccessedAt`; adapters without the surface
132
+ * skip the boost silently.
133
+ *
134
+ * @stable
135
+ */
136
+ readonly decay?: {
137
+ readonly tauDays: number;
138
+ /** Override the wall clock (test seam). */
139
+ readonly now?: () => number;
140
+ };
141
+ /**
142
+ * Multi-query / RAG-Fusion (P2-3). When set to `N > 1` *and* a query
143
+ * transformer is configured (`createMemory({ queryTransform })`), the
144
+ * query is fanned into up to `N - 1` reworded variants via one cheap
145
+ * LLM call; each variant is retrieved (FTS + vector) and **all** lists
146
+ * are fused through the existing RRF reranker — recovering memories
147
+ * whose stored wording differs from the user's phrasing. `N` bounds
148
+ * the *total* query strings, including the original. Offline (no
149
+ * transformer, or `N <= 1`) this is a **silent no-op**: search stays
150
+ * single-shot and makes no provider call. Opt-in + retrieval-heavy, so
151
+ * reserve it for deliberate recall rather than every search.
152
+ *
153
+ * @stable
154
+ */
155
+ readonly multiQuery?: number;
156
+ /**
157
+ * HyDE — Hypothetical Document Embeddings (arXiv:2212.10496), P2-3.
158
+ * When `true` *and* both a query transformer and an embedder are
159
+ * configured, generate a short hypothetical answer, embed it, and fuse
160
+ * its vector neighbours into the result. Helps short / ambiguous
161
+ * queries but adds a generate + embed round-trip and can drift — hence
162
+ * opt-in. With no transformer (or no embedder) this is a silent no-op
163
+ * and no provider call is made.
164
+ *
165
+ * @stable
166
+ */
167
+ readonly hyde?: boolean;
168
+ /**
169
+ * Score-fusion strategy (X-2). Omitted (the default) ⇒ RRF via the
170
+ * configured reranker — behaviour is unchanged. `{ strategy:
171
+ * 'weighted', weights }` fuses through {@link WeightedRRFReranker},
172
+ * up-/down-weighting the FTS vs vector candidate lists per
173
+ * {@link FusionWeights}; reserve it for callers who have calibrated the
174
+ * weights against labels (the P0-1 eval harness). At equal weights it
175
+ * reproduces RRF.
176
+ *
177
+ * @stable
178
+ */
179
+ readonly fusion?: FusionStrategy;
180
+ /**
181
+ * One-hop graph expansion (P2-1). With `1` *and* a graph-capable
182
+ * storage adapter (`store.graph`), the facts retrieved by the lexical /
183
+ * vector candidate pass are treated as seeds: facts sharing a canonical
184
+ * entity (subject / object) are fetched via a recursive CTE and fused
185
+ * in as an extra candidate list before rerank — surfacing connected
186
+ * facts the query never matched directly ("what did the person I met in
187
+ * Tbilisi recommend?"). `0` (the default) or a graph-less adapter ⇒ a
188
+ * silent no-op; recall is unchanged. Opt-in + retrieval-heavy.
189
+ *
190
+ * @stable
191
+ */
192
+ readonly expandHops?: 0 | 1;
193
+ }
194
+ /**
195
+ * Per-call options for {@link SemanticMemory.searchIterative} (P2-4) —
196
+ * the gated grade-then-reformulate loop. Extends {@link FactSearchOptions}
197
+ * (every base option applies to each retrieval pass); `topK` doubles as
198
+ * the cap on the accumulated result count.
199
+ *
200
+ * @stable
201
+ */
202
+ interface IterativeSearchOptions extends FactSearchOptions {
203
+ /**
204
+ * Total-pass cap, clamped to `[1, 5]`. Omitted ⇒ the facade-configured
205
+ * default (`createMemory({ iterativeRetrieval: { maxIterations } })`)
206
+ * or `3`.
207
+ */
208
+ readonly maxIterations?: number;
209
+ /**
210
+ * Skip the heuristic difficulty gate and force the loop (still capped
211
+ * and still a no-op without a grader). For deliberate "deep recall"
212
+ * requests and tests.
213
+ */
214
+ readonly forceHard?: boolean;
215
+ }
216
+ /**
217
+ * Outcome of {@link SemanticMemory.searchIterative}. Beyond the ranked
218
+ * `hits`, `sufficient` / `abstained` tell the caller whether the memory
219
+ * actually answered the query — `abstained: true` means it should say so
220
+ * rather than confabulate.
221
+ *
222
+ * @stable
223
+ */
224
+ type IterativeRecallResult = IterativeRetrievalResult<MemoryHit<Fact>>;
225
+ /**
226
+ * Per-call options accepted by {@link SemanticMemory.remember}. The
227
+ * Phase 10b pipeline writes one row to `fact_conflicts` (and
228
+ * potentially one to `conflict_check_pending`) for every invocation;
229
+ * pass `pipeline: 'off'` to bypass the pipeline for a single call
230
+ * (useful for one-shot data imports).
231
+ *
232
+ * @stable
233
+ */
234
+ interface FactRememberOptions {
235
+ readonly pipeline?: 'on' | 'off';
236
+ /** Cancellation signal forwarded to the embedder + storage layers. */
237
+ readonly signal?: AbortSignal;
238
+ /**
239
+ * Precomputed contextual-retrieval index text (P1-3, advanced). When
240
+ * supplied it overrides the instance's `'late-chunk'` computation: the
241
+ * embedding is computed from — and the FTS row indexed against — this
242
+ * text, while the canonical `text` is stored unchanged. The background
243
+ * consolidator passes this in its `'llm'` mode (the one place an LLM is
244
+ * allowed to write the situating context); first-party callers normally
245
+ * omit it and rely on the offline late-chunk default.
246
+ */
247
+ readonly indexText?: string;
248
+ /**
249
+ * Auto-promotion policy (MCON-2). When `true`, a *synthesized* write
250
+ * (consolidator extraction) that is **clean** by the injection heuristics is
251
+ * stored `active` instead of quarantined. Injection-flagged writes always
252
+ * stay quarantined — the security gate is preserved. Off by default; the
253
+ * consolidator passes it only when the operator opts in via
254
+ * `autoPromoteExtraction`. No effect on non-synthesized writes.
255
+ */
256
+ readonly autoPromoteSynthesized?: boolean;
257
+ }
258
+ /**
259
+ * Returned by {@link SemanticMemory.remember}. The `fact` is the
260
+ * stored row (which may be the *existing* fact when the pipeline
261
+ * dedups). The `decision` mirrors the pipeline outcome so callers can
262
+ * distinguish silent dedups from active inserts.
263
+ *
264
+ * @stable
265
+ */
266
+ interface RememberOutcome {
267
+ readonly fact: Fact;
268
+ readonly decision: ConflictDecision;
269
+ /**
270
+ * Why this write landed quarantined, if it did (P1-4 / MRET-3).
271
+ * `'injection'` — the offline injection heuristics flagged the text
272
+ * (a memory-poisoning candidate). `'synthesized'` — a consolidator /
273
+ * reflection / induction write awaiting validation. Absent when the
274
+ * fact is `active` or when a dedup returned a pre-existing row.
275
+ */
276
+ readonly quarantineReason?: 'injection' | 'synthesized';
277
+ }
278
+ /**
279
+ * `SemanticMemory` — long-term factual store. Hybrid (vector + FTS5)
280
+ * search merges the two ranked lists through the configured
281
+ * {@link ReRanker} (default {@link RRFReranker} with `k = 60`).
282
+ *
283
+ * Phase 10a wrote facts straight through with MD5 deduplication;
284
+ * Phase 10b routes every `remember(...)` call through the multi-stage
285
+ * conflict resolution pipeline (DEC-117 / ADR-018 ext / RB-02). The
286
+ * pipeline can be disabled per-call (`pipeline: 'off'`) or per-`Memory`
287
+ * instance (`createMemory({ conflictPipeline: { mode: 'off' } })`).
288
+ *
289
+ * @stable
290
+ */
291
+ declare class SemanticMemory {
292
+ #private;
293
+ constructor(args: {
294
+ store: MemoryStoreAdapter;
295
+ tracer: Tracer;
296
+ embedder: EmbedderProvider | null;
297
+ embedderIdProvider: () => string | null;
298
+ reranker: ReRanker;
299
+ conflictPipeline?: ConflictPipeline;
300
+ /**
301
+ * Query transformer for multi-query / HyDE retrieval (P2-3). When
302
+ * supplied, `search(..., { multiQuery })` / `{ hyde }` opt into one
303
+ * cheap LLM call to rewrite / hypothesize the query; omitted (the
304
+ * default) ⇒ those options are silent no-ops and search stays
305
+ * offline + single-shot.
306
+ */
307
+ queryTransformer?: QueryTransformer;
308
+ /**
309
+ * Contextual-retrieval mode for the write path (P1-3). `'late-chunk'`
310
+ * (default) prepends a deterministic situating context to the text
311
+ * that is embedded + FTS-indexed, leaving the canonical `text`
312
+ * untouched; `'off'` indexes the bare text. The hot write path never
313
+ * makes an LLM call — the `'llm'` enrichment is confined to the
314
+ * background consolidator, which supplies a precomputed `indexText`.
315
+ */
316
+ contextualRetrieval?: 'off' | 'late-chunk';
317
+ /**
318
+ * Entity resolver for the relation graph (P2-1). When supplied,
319
+ * `remember(...)` resolves a fact's subject / object to canonical
320
+ * entities and links them, enabling `search(..., { expandHops: 1 })`.
321
+ * Omitted (the default) ⇒ writes carry s/p/o but form no entity
322
+ * links, and the write path stays offline + unchanged.
323
+ */
324
+ entityResolver?: EntityResolver;
325
+ /**
326
+ * Retrieval grader for the gated iterative loop (P2-4). When
327
+ * supplied, `searchIterative(...)` can grade a retrieved set and
328
+ * reformulate on hard queries; omitted (the default) ⇒
329
+ * `searchIterative` runs a single, difficulty-gated pass and makes no
330
+ * provider call.
331
+ */
332
+ grader?: RetrievalGrader;
333
+ /** Default total-pass cap for `searchIterative`. Default 3. */
334
+ iterativeMaxIterations?: number;
335
+ });
336
+ /** Replace the active reranker. Returns the previous instance. */
337
+ setReranker(reranker: ReRanker): ReRanker;
338
+ /** Currently active reranker. */
339
+ reranker(): ReRanker;
340
+ /**
341
+ * Persist a fact. Returns the stored record. Phase 10b routes every
342
+ * call through the multi-stage conflict resolution pipeline; the
343
+ * legacy straight-through path is reachable per-call via
344
+ * `{ pipeline: 'off' }` (operators may disable the pipeline globally
345
+ * via `createMemory({ conflictPipeline: { mode: 'off' } })`).
346
+ */
347
+ remember(scope: SessionScope, input: FactInput, options?: FactRememberOptions): Promise<Fact>;
348
+ /**
349
+ * Like {@link remember} but returns the pipeline `decision` alongside
350
+ * the stored fact. Useful for callers that need to distinguish
351
+ * silent dedups (`decision.kind === 'dedup'`) from fresh inserts.
352
+ *
353
+ * @stable
354
+ */
355
+ rememberWithDecision(scope: SessionScope, input: FactInput, options?: FactRememberOptions): Promise<RememberOutcome>;
356
+ /** Hybrid (vector + FTS5) search merged through the configured reranker. */
357
+ search(scope: SessionScope, query: string, opts?: FactSearchOptions): Promise<ReadonlyArray<MemoryHit<Fact>>>;
358
+ /**
359
+ * Gated, iterative ("deep") recall for hard queries (P2-4). A cheap
360
+ * local heuristic ({@link assessQueryDifficulty}) decides whether the
361
+ * query is even a loop candidate; simple lookups take exactly one
362
+ * {@link search} pass and make no provider call. For a query judged
363
+ * hard *and* with a grader configured
364
+ * (`createMemory({ iterativeRetrieval })`), the retrieved set is graded
365
+ * for sufficiency and, when weak, the query is reformulated and
366
+ * retrieved again — **widening to one-hop graph expansion**
367
+ * (`expandHops: 1`) on each reformulation pass — up to `maxIterations`
368
+ * (hard-capped at 5). When still insufficient it returns
369
+ * `abstained: true` so the caller can decline to answer instead of
370
+ * confabulating.
371
+ *
372
+ * Without a grader (the offline default) this degrades to a single,
373
+ * difficulty-gated `search` and never calls a provider.
374
+ *
375
+ * @stable
376
+ */
377
+ searchIterative(scope: SessionScope, query: string, opts?: IterativeSearchOptions): Promise<IterativeRecallResult>;
378
+ /**
379
+ * Raw vector KNN neighbours for the consolidator's reconcile
380
+ * pre-filter (P0-3). Unlike {@link search} this skips FTS, reranking,
381
+ * and decay so the cosine scores survive intact (the conflict-pipeline
382
+ * zone thresholds are calibrated against them), and it **includes
383
+ * quarantined facts** so prior synthesized memories are visible to
384
+ * reconciliation. Returns `[]` when no embedder / vector adapter is
385
+ * configured — the consolidator then treats every candidate as a
386
+ * fresh `add`, degrading gracefully to the pre-reconcile behaviour.
387
+ *
388
+ * @stable
389
+ */
390
+ neighbors(scope: SessionScope, text: string, opts?: {
391
+ readonly topK?: number;
392
+ }): Promise<ReadonlyArray<MemoryHit<Fact>>>;
393
+ /** Lookup a single fact by id. Returns `null` for soft-deleted / missing. */
394
+ get(scope: SessionScope, factId: string): Promise<Fact | null>;
395
+ /**
396
+ * Return the full bi-temporal supersede chain that `factId` belongs
397
+ * to, oldest → newest, including superseded / soft-deleted rows so
398
+ * callers can answer "how did this fact change over time". Requires
399
+ * a storage adapter that implements
400
+ * `SemanticMemoryStoreExt.historyOf(...)` — the default
401
+ * `@graphorin/store-sqlite` adapter wires this through. P0-2.
402
+ *
403
+ * @stable
404
+ */
405
+ history(scope: SessionScope, factId: string): Promise<ReadonlyArray<Fact>>;
406
+ /**
407
+ * Promote a quarantined fact to `active` (P1-4). The validation path
408
+ * that admits a synthesized memory into action-driving recall once a
409
+ * human (or trusted non-agent caller) has reviewed it. Writes a
410
+ * `memory_history` audit row. Requires a storage adapter that
411
+ * implements `SemanticMemoryStoreExt.setStatus(...)` — the default
412
+ * `@graphorin/store-sqlite` adapter wires this through.
413
+ *
414
+ * MRET-3 / MST-1: promotion of a fact whose text still trips the
415
+ * offline injection heuristics is **refused** with
416
+ * {@link QuarantinePromotionRefusedError} — the model-facing
417
+ * `fact_validate` tool calls this with no `force`, so a poisoned
418
+ * memory can never be promoted by the agent itself (the one-turn
419
+ * `fact_remember(poison)` → `fact_validate(id)` chain is closed). An
420
+ * operator can override after review by passing `{ force: true }`
421
+ * from a trusted (non-agent) context. Synthesized-but-clean writes
422
+ * (consolidator / reflection) promote normally.
423
+ *
424
+ * @stable
425
+ */
426
+ validate(scope: SessionScope, factId: string, reason?: string, options?: {
427
+ readonly force?: boolean;
428
+ }): Promise<void>;
429
+ /** Mark `oldId` superseded by a new fact. Returns the new record. */
430
+ supersede(scope: SessionScope, oldId: string, newInput: FactInput, reason?: string): Promise<{
431
+ readonly old: string;
432
+ readonly new: Fact;
433
+ }>;
434
+ /** Soft-delete a fact (kept for replay; never hard-deleted). */
435
+ forget(scope: SessionScope, factId: string, reason?: string): Promise<void>;
436
+ /**
437
+ * Hard-delete a fact (GDPR path). Distinct from {@link forget}: the
438
+ * record is removed from storage entirely instead of soft-archived.
439
+ * Requires a storage adapter that implements
440
+ * `SemanticMemoryStoreExt.purge(...)` — the default
441
+ * `@graphorin/store-sqlite` adapter wires this through.
442
+ */
443
+ purge(scope: SessionScope, factId: string, reason?: string): Promise<void>;
444
+ /** Fuse multiple ranked lists outside of a `search()` call. */
445
+ fuse(query: string, lists: ReadonlyArray<ReadonlyArray<MemoryHit<Fact>>>, options?: {
446
+ topK?: number;
447
+ signal?: AbortSignal;
448
+ }): Promise<ReadonlyArray<MemoryHit<Fact>>>;
449
+ /** Pure-fusion helper — exposed for callers that already collected results. */
450
+ static fuseRrf<TRecord extends Fact>(lists: ReadonlyArray<ReadonlyArray<MemoryHit<TRecord>>>, k?: number): ReadonlyArray<MemoryHit<TRecord>>;
451
+ /**
452
+ * Pure weighted-fusion helper (X-2) — like {@link SemanticMemory.fuseRrf}
453
+ * but scales each list `i`'s reciprocal-rank contribution by
454
+ * `weights[i]`. A missing / invalid entry defaults to `1`, so equal or
455
+ * absent weights reproduce RRF.
456
+ */
457
+ static fuseWeighted<TRecord extends Fact>(lists: ReadonlyArray<ReadonlyArray<MemoryHit<TRecord>>>, weights: ReadonlyArray<number> | undefined, k?: number): ReadonlyArray<MemoryHit<TRecord>>;
458
+ }
459
+ //#endregion
460
+ export { FactInput, FactRememberOptions, FactSearchOptions, FusionStrategy, FusionWeights, IterativeRecallResult, IterativeSearchOptions, RememberOutcome, SemanticMemory };
461
+ //# sourceMappingURL=semantic-memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semantic-memory.d.ts","names":[],"sources":["../../src/tiers/semantic-memory.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;AAsCA;;;;;AAwCiB,UAxCA,SAAA,CAwCa;EAoBlB,SAAA,IAAA,EAAA,MAAc;EAcT,SAAA,OAAA,CAAA,EAAA,MAAiB;EAEd,SAAA,SAAA,CAAA,EAAA,MAAA;EAUF,SAAA,MAAA,CAAA,EAAA,MAAA;EA4EE,SAAA,IAAA,CAAA,EA7JF,aA6JE,CAAA,MAAA,CAAA;EAAc,SAAA,UAAA,CAAA,EAAA,MAAA;EAwBjB,SAAA,WAAA,CAAA,EAnLQ,WAmLe;EAuB5B,SAAA,SAAA,CAAA,EAAA,MAAqB;EAAsC,SAAA,OAAA,CAAA,EAAA,MAAA;EAAV,SAAA,UAAA,CAAA,EAAA,MAAA;EAAzB;;AAWpC;AAiCA;AA0BA;;;EAgBc,SAAA,UAAA,CAAA,EArRU,gBAqRV;EAEA;;;;;;;;;EAwEH,SAAA,UAAA,CAAA,EAAA,MAAA;;;;;;;;;;;AAqO0B,UA9iBpB,aAAA,CA8iBoB;EAAV;EAAd,SAAA,GAAA,CAAA,EAAA,MAAA;EAAR;EAqLM,SAAA,MAAA,CAAA,EAAA,MAAA;;;;;;;;;;;;;;;AA0G2C,KAzzB1C,cAAA,GAyzB0C;EAyC3C,SAAA,QAAA,EAAA,KAAA;CAIN,GAAA;EAoCM,SAAA,QAAA,EAAA,UAAA;EAEG,SAAA,OAAA,EAx4BU,aAw4BV;EAEqC;EAA9C,SAAA,CAAA,CAAA,EAAA,MAAA;CAwBiB;;;;;;AAwCG,UAh8BR,iBAAA,CAg8BQ;EAAd,SAAA,IAAA,CAAA,EAAA,MAAA;EAC4B,SAAA,MAAA,CAAA,EA/7BnB,WA+7BmB;EACF;EAAV,SAAA,aAAA,CAAA,EAAA,MAAA;EAAd;;;;;;;EAQgB,SAAA,IAAA,CAAA,EA97BX,aA87BW,CAAA,MAAA,CAAA;EAAV;;;;;;;;;EAcA,SAAA,IAAA,CAAA,EAAA,MAAA;EAAd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAh4Be;;;;;;;;;;;;;;;;;;;;;;;UAwBH,sBAAA,SAA+B;;;;;;;;;;;;;;;;;;;;;;KAuBpC,qBAAA,GAAwB,yBAAyB,UAAU;;;;;;;;;;UAWtD,mBAAA;;;oBAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA8BH,eAAA;iBACA;qBACI;;;;;;;;;;;;;;;;;;;;;;;cAwBR,cAAA;;;WAcF;YACC;cACE;;cAEA;uBACS;;;;;;;;uBAQA;;;;;;;;;;;;;;;;;qBAiBF;;;;;;;;aAQR;;;;;wBAkBW,WAAW;;cAOrB;;;;;;;;kBAYH,qBACA,qBACE,sBACR,QAAQ;;;;;;;;8BAaF,qBACA,qBACE,sBACR,QAAQ;;gBAgNF,oCAED,oBACL,QAAQ,cAAc,UAAU;;;;;;;;;;;;;;;;;;;;yBAqL1B,oCAED,yBACL,QAAQ;;;;;;;;;;;;;mBAiEF;;MAGN,QAAQ,cAAc,UAAU;;aAKlB,+BAA+B,QAAQ;;;;;;;;;;;iBA8BnC,+BAA+B,QAAQ,cAAc;;;;;;;;;;;;;;;;;;;;;kBAyCjE;;MAIN;;mBAoCM,uCAEG,6BAET;;kBAA8C;;;gBAwB7B,gDAAgD;;;;;;;;eAmBjD,gDAAgD;;6BAqB1D,cAAc,cAAc,UAAU;;aACV;MAClC,QAAQ,cAAc,UAAU;;iCAKJ,aACtB,cAAc,cAAc,UAAU,yBAE5C,cAAc,UAAU;;;;;;;sCAUS,aAC3B,cAAc,cAAc,UAAU,qBACpC,gDAER,cAAc,UAAU"}