@anuma/sdk 3.4.0 → 3.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.
@@ -3357,11 +3357,20 @@ async function getModel() {
3357
3357
  function sigmoid(x) {
3358
3358
  return 1 / (1 + Math.exp(-x));
3359
3359
  }
3360
+ function formatRerankDoc(content, dateMs) {
3361
+ if (dateMs === null || dateMs === void 0 || !Number.isFinite(dateMs)) return content;
3362
+ const d = new Date(dateMs);
3363
+ if (!Number.isFinite(d.getTime())) return content;
3364
+ const yyyy = d.getFullYear();
3365
+ const mm = String(d.getMonth() + 1).padStart(2, "0");
3366
+ const dd = String(d.getDate()).padStart(2, "0");
3367
+ return `[Date: ${yyyy}-${mm}-${dd}] ${content}`;
3368
+ }
3360
3369
  async function rerankPairs(query, items) {
3361
3370
  if (items.length === 0 || !query) return [];
3362
3371
  const { tokenizer, model } = await getModel();
3363
3372
  const queries = items.map(() => query);
3364
- const docs = items.map((i) => i.content);
3373
+ const docs = items.map((i) => formatRerankDoc(i.content, i.dateMs));
3365
3374
  const tokenize2 = tokenizer;
3366
3375
  const inputs = tokenize2(queries, { text_pair: docs, padding: true, truncation: true });
3367
3376
  const forward = model;
@@ -3710,6 +3719,23 @@ function createVaultEmbeddingCache(maxSize = DEFAULT_VAULT_CACHE_SIZE) {
3710
3719
  function normalizeEventTimeKind(kind) {
3711
3720
  return kind === "point" || kind === "range" || kind === "ongoing" ? kind : null;
3712
3721
  }
3722
+ function rerankDateMs(item) {
3723
+ if (item.eventTimeStart !== null && item.eventTimeStart !== void 0 && Number.isFinite(item.eventTimeStart) && item.eventTimeStart > 0) {
3724
+ return item.eventTimeStart;
3725
+ }
3726
+ if (item.lastObservedAt !== null && item.lastObservedAt !== void 0 && Number.isFinite(item.lastObservedAt) && item.lastObservedAt > 0) {
3727
+ return item.lastObservedAt;
3728
+ }
3729
+ const updatedMs = item.updatedAt?.getTime();
3730
+ if (updatedMs !== null && updatedMs !== void 0 && Number.isFinite(updatedMs) && updatedMs > 0) {
3731
+ return updatedMs;
3732
+ }
3733
+ const createdMs = item.createdAt?.getTime();
3734
+ if (createdMs !== null && createdMs !== void 0 && Number.isFinite(createdMs) && createdMs > 0) {
3735
+ return createdMs;
3736
+ }
3737
+ return void 0;
3738
+ }
3713
3739
  var SUPERSESSION_SIMILARITY_THRESHOLD = 0.7;
3714
3740
  var SUPERSESSION_MIN_AGE_GAP_MS = 30 * 24 * 60 * 60 * 1e3;
3715
3741
  var SUPERSESSION_BOOST_FACTOR = 0.8;
@@ -3916,6 +3942,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
3916
3942
  }
3917
3943
  let combined;
3918
3944
  let tailSlice = [];
3945
+ const itemById = new Map(items.map((i) => [i.id, i]));
3919
3946
  if (options?.rerank) {
3920
3947
  const rerankTopN = options.rerankTopN ?? 30;
3921
3948
  const ceWeight = options.ceWeight ?? 0.1;
@@ -3923,7 +3950,12 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
3923
3950
  try {
3924
3951
  const reranked = await rerankPairs(
3925
3952
  query,
3926
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
3953
+ headSlice.map((r) => ({
3954
+ id: r.uniqueId,
3955
+ content: r.content,
3956
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
3957
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
3958
+ }))
3927
3959
  );
3928
3960
  tailSlice = v2Ranked.slice(rerankTopN);
3929
3961
  const v2ScoreById = new Map(headSlice.map((r) => [r.uniqueId, r.similarity]));
@@ -3958,11 +3990,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
3958
3990
  const fused = rrfFuse([headIds, headIds, ...sideLanesAsync], options?.rrfK);
3959
3991
  const fusedHead = combined.map((r) => ({ ...r, similarity: fused.get(r.uniqueId) ?? r.similarity })).sort((a, b) => b.similarity - a.similarity);
3960
3992
  const seen = new Set(combined.map((r) => r.uniqueId));
3961
- const itemById = new Map(items.map((i) => [i.id, i]));
3993
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
3962
3994
  for (const lane of sideLanesAsync) {
3963
3995
  for (const id of lane) {
3964
3996
  if (seen.has(id)) continue;
3965
- const it = itemById.get(id);
3997
+ const it = itemById2.get(id);
3966
3998
  if (!it) continue;
3967
3999
  fusedHead.push({
3968
4000
  uniqueId: id,
@@ -3981,11 +4013,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
3981
4013
  if (options?.mmr) {
3982
4014
  const lambda = options.mmrLambda ?? 0.7;
3983
4015
  const mmrTopN = options.mmrTopN ?? 20;
3984
- const itemById = new Map(items.map((i) => [i.id, i]));
4016
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
3985
4017
  const mmrCandidates = combined.slice(0, mmrTopN).map((r) => ({
3986
4018
  id: r.uniqueId,
3987
4019
  score: r.similarity,
3988
- embedding: itemById.get(r.uniqueId)?.embedding ?? [],
4020
+ embedding: itemById2.get(r.uniqueId)?.embedding ?? [],
3989
4021
  content: r.content
3990
4022
  }));
3991
4023
  const picked = applyMMR(mmrCandidates, limit, lambda);
@@ -4107,7 +4139,12 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
4107
4139
  try {
4108
4140
  const reranked = await rerankPairs(
4109
4141
  originalQuery,
4110
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
4142
+ headSlice.map((r) => ({
4143
+ id: r.uniqueId,
4144
+ content: r.content,
4145
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
4146
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
4147
+ }))
4111
4148
  );
4112
4149
  const ceById = new Map(reranked.map((r) => [r.id, r.score]));
4113
4150
  const head = headSlice.map((r) => ({
@@ -4525,7 +4562,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
4525
4562
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
4526
4563
  );
4527
4564
  }
4528
- const { recall: recall2 } = await import("./recall-7ZX6T2VD.mjs");
4565
+ const { recall: recall2 } = await import("./recall-IO4KJ5W7.mjs");
4529
4566
  const result = await recall2(
4530
4567
  query,
4531
4568
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -4442,11 +4442,20 @@ async function getModel() {
4442
4442
  function sigmoid(x) {
4443
4443
  return 1 / (1 + Math.exp(-x));
4444
4444
  }
4445
+ function formatRerankDoc(content, dateMs) {
4446
+ if (dateMs === null || dateMs === void 0 || !Number.isFinite(dateMs)) return content;
4447
+ const d = new Date(dateMs);
4448
+ if (!Number.isFinite(d.getTime())) return content;
4449
+ const yyyy = d.getFullYear();
4450
+ const mm = String(d.getMonth() + 1).padStart(2, "0");
4451
+ const dd = String(d.getDate()).padStart(2, "0");
4452
+ return `[Date: ${yyyy}-${mm}-${dd}] ${content}`;
4453
+ }
4445
4454
  async function rerankPairs(query, items) {
4446
4455
  if (items.length === 0 || !query) return [];
4447
4456
  const { tokenizer, model } = await getModel();
4448
4457
  const queries = items.map(() => query);
4449
- const docs = items.map((i) => i.content);
4458
+ const docs = items.map((i) => formatRerankDoc(i.content, i.dateMs));
4450
4459
  const tokenize2 = tokenizer;
4451
4460
  const inputs = tokenize2(queries, { text_pair: docs, padding: true, truncation: true });
4452
4461
  const forward = model;
@@ -5721,6 +5730,23 @@ var init_recall = __esm({
5721
5730
  function normalizeEventTimeKind(kind) {
5722
5731
  return kind === "point" || kind === "range" || kind === "ongoing" ? kind : null;
5723
5732
  }
5733
+ function rerankDateMs(item) {
5734
+ if (item.eventTimeStart !== null && item.eventTimeStart !== void 0 && Number.isFinite(item.eventTimeStart) && item.eventTimeStart > 0) {
5735
+ return item.eventTimeStart;
5736
+ }
5737
+ if (item.lastObservedAt !== null && item.lastObservedAt !== void 0 && Number.isFinite(item.lastObservedAt) && item.lastObservedAt > 0) {
5738
+ return item.lastObservedAt;
5739
+ }
5740
+ const updatedMs = item.updatedAt?.getTime();
5741
+ if (updatedMs !== null && updatedMs !== void 0 && Number.isFinite(updatedMs) && updatedMs > 0) {
5742
+ return updatedMs;
5743
+ }
5744
+ const createdMs = item.createdAt?.getTime();
5745
+ if (createdMs !== null && createdMs !== void 0 && Number.isFinite(createdMs) && createdMs > 0) {
5746
+ return createdMs;
5747
+ }
5748
+ return void 0;
5749
+ }
5724
5750
  function supersessionDelta(olderScore, newerScore, boostFactor = SUPERSESSION_BOOST_FACTOR) {
5725
5751
  const gap = olderScore - newerScore;
5726
5752
  return gap * boostFactor;
@@ -5923,6 +5949,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
5923
5949
  }
5924
5950
  let combined;
5925
5951
  let tailSlice = [];
5952
+ const itemById = new Map(items.map((i) => [i.id, i]));
5926
5953
  if (options?.rerank) {
5927
5954
  const rerankTopN = options.rerankTopN ?? 30;
5928
5955
  const ceWeight = options.ceWeight ?? 0.1;
@@ -5930,7 +5957,12 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
5930
5957
  try {
5931
5958
  const reranked = await rerankPairs(
5932
5959
  query,
5933
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
5960
+ headSlice.map((r) => ({
5961
+ id: r.uniqueId,
5962
+ content: r.content,
5963
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
5964
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
5965
+ }))
5934
5966
  );
5935
5967
  tailSlice = v2Ranked.slice(rerankTopN);
5936
5968
  const v2ScoreById = new Map(headSlice.map((r) => [r.uniqueId, r.similarity]));
@@ -5965,11 +5997,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
5965
5997
  const fused = rrfFuse([headIds, headIds, ...sideLanesAsync], options?.rrfK);
5966
5998
  const fusedHead = combined.map((r) => ({ ...r, similarity: fused.get(r.uniqueId) ?? r.similarity })).sort((a, b) => b.similarity - a.similarity);
5967
5999
  const seen = new Set(combined.map((r) => r.uniqueId));
5968
- const itemById = new Map(items.map((i) => [i.id, i]));
6000
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
5969
6001
  for (const lane of sideLanesAsync) {
5970
6002
  for (const id of lane) {
5971
6003
  if (seen.has(id)) continue;
5972
- const it = itemById.get(id);
6004
+ const it = itemById2.get(id);
5973
6005
  if (!it) continue;
5974
6006
  fusedHead.push({
5975
6007
  uniqueId: id,
@@ -5988,11 +6020,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
5988
6020
  if (options?.mmr) {
5989
6021
  const lambda = options.mmrLambda ?? 0.7;
5990
6022
  const mmrTopN = options.mmrTopN ?? 20;
5991
- const itemById = new Map(items.map((i) => [i.id, i]));
6023
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
5992
6024
  const mmrCandidates = combined.slice(0, mmrTopN).map((r) => ({
5993
6025
  id: r.uniqueId,
5994
6026
  score: r.similarity,
5995
- embedding: itemById.get(r.uniqueId)?.embedding ?? [],
6027
+ embedding: itemById2.get(r.uniqueId)?.embedding ?? [],
5996
6028
  content: r.content
5997
6029
  }));
5998
6030
  const picked = applyMMR(mmrCandidates, limit, lambda);
@@ -6114,7 +6146,12 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
6114
6146
  try {
6115
6147
  const reranked = await rerankPairs(
6116
6148
  originalQuery,
6117
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
6149
+ headSlice.map((r) => ({
6150
+ id: r.uniqueId,
6151
+ content: r.content,
6152
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
6153
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
6154
+ }))
6118
6155
  );
6119
6156
  const ceById = new Map(reranked.map((r) => [r.id, r.score]));
6120
6157
  const head = headSlice.map((r) => ({
@@ -4887,7 +4887,7 @@ interface VaultSearchResult {
4887
4887
  updatedAt?: Date;
4888
4888
  /** Times this fact has been re-observed — for C2 trend labels. */
4889
4889
  proofCount?: number | null;
4890
- /** C3 re-observation watermark (Unix ms) — for C2 trend labels. */
4890
+ /** C3 re-observation watermark (Unix ms) — for C2 trends + C4 CE dates. */
4891
4891
  lastObservedAt?: number | null;
4892
4892
  /** W6 temporal-lane anchors carried through to downstream `RankedMemory`
4893
4893
  * so the recall executor can surface dates to the answer model without
@@ -4887,7 +4887,7 @@ interface VaultSearchResult {
4887
4887
  updatedAt?: Date;
4888
4888
  /** Times this fact has been re-observed — for C2 trend labels. */
4889
4889
  proofCount?: number | null;
4890
- /** C3 re-observation watermark (Unix ms) — for C2 trend labels. */
4890
+ /** C3 re-observation watermark (Unix ms) — for C2 trends + C4 CE dates. */
4891
4891
  lastObservedAt?: number | null;
4892
4892
  /** W6 temporal-lane anchors carried through to downstream `RankedMemory`
4893
4893
  * so the recall executor can surface dates to the answer model without
@@ -103,7 +103,7 @@ import {
103
103
  upsertMessageOp,
104
104
  useEncryption,
105
105
  vaultMemoryToStored
106
- } from "./chunk-C7PGRFBG.mjs";
106
+ } from "./chunk-7TATXBC5.mjs";
107
107
  import {
108
108
  PII_PATTERNS,
109
109
  PiiRedactor,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-C7PGRFBG.mjs";
3
+ } from "./chunk-7TATXBC5.mjs";
4
4
  import "./chunk-DFVCS3QQ.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -3564,11 +3564,20 @@ async function getModel() {
3564
3564
  function sigmoid(x) {
3565
3565
  return 1 / (1 + Math.exp(-x));
3566
3566
  }
3567
+ function formatRerankDoc(content, dateMs) {
3568
+ if (dateMs === null || dateMs === void 0 || !Number.isFinite(dateMs)) return content;
3569
+ const d = new Date(dateMs);
3570
+ if (!Number.isFinite(d.getTime())) return content;
3571
+ const yyyy = d.getFullYear();
3572
+ const mm = String(d.getMonth() + 1).padStart(2, "0");
3573
+ const dd = String(d.getDate()).padStart(2, "0");
3574
+ return `[Date: ${yyyy}-${mm}-${dd}] ${content}`;
3575
+ }
3567
3576
  async function rerankPairs(query, items) {
3568
3577
  if (items.length === 0 || !query) return [];
3569
3578
  const { tokenizer, model } = await getModel();
3570
3579
  const queries = items.map(() => query);
3571
- const docs = items.map((i) => i.content);
3580
+ const docs = items.map((i) => formatRerankDoc(i.content, i.dateMs));
3572
3581
  const tokenize2 = tokenizer;
3573
3582
  const inputs = tokenize2(queries, { text_pair: docs, padding: true, truncation: true });
3574
3583
  const forward = model;
@@ -3917,6 +3926,23 @@ function createVaultEmbeddingCache(maxSize = DEFAULT_VAULT_CACHE_SIZE) {
3917
3926
  function normalizeEventTimeKind(kind) {
3918
3927
  return kind === "point" || kind === "range" || kind === "ongoing" ? kind : null;
3919
3928
  }
3929
+ function rerankDateMs(item) {
3930
+ if (item.eventTimeStart !== null && item.eventTimeStart !== void 0 && Number.isFinite(item.eventTimeStart) && item.eventTimeStart > 0) {
3931
+ return item.eventTimeStart;
3932
+ }
3933
+ if (item.lastObservedAt !== null && item.lastObservedAt !== void 0 && Number.isFinite(item.lastObservedAt) && item.lastObservedAt > 0) {
3934
+ return item.lastObservedAt;
3935
+ }
3936
+ const updatedMs = item.updatedAt?.getTime();
3937
+ if (updatedMs !== null && updatedMs !== void 0 && Number.isFinite(updatedMs) && updatedMs > 0) {
3938
+ return updatedMs;
3939
+ }
3940
+ const createdMs = item.createdAt?.getTime();
3941
+ if (createdMs !== null && createdMs !== void 0 && Number.isFinite(createdMs) && createdMs > 0) {
3942
+ return createdMs;
3943
+ }
3944
+ return void 0;
3945
+ }
3920
3946
  var SUPERSESSION_SIMILARITY_THRESHOLD = 0.7;
3921
3947
  var SUPERSESSION_MIN_AGE_GAP_MS = 30 * 24 * 60 * 60 * 1e3;
3922
3948
  var SUPERSESSION_BOOST_FACTOR = 0.8;
@@ -4123,6 +4149,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
4123
4149
  }
4124
4150
  let combined;
4125
4151
  let tailSlice = [];
4152
+ const itemById = new Map(items.map((i) => [i.id, i]));
4126
4153
  if (options?.rerank) {
4127
4154
  const rerankTopN = options.rerankTopN ?? 30;
4128
4155
  const ceWeight = options.ceWeight ?? 0.1;
@@ -4130,7 +4157,12 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
4130
4157
  try {
4131
4158
  const reranked = await rerankPairs(
4132
4159
  query,
4133
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
4160
+ headSlice.map((r) => ({
4161
+ id: r.uniqueId,
4162
+ content: r.content,
4163
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
4164
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
4165
+ }))
4134
4166
  );
4135
4167
  tailSlice = v2Ranked.slice(rerankTopN);
4136
4168
  const v2ScoreById = new Map(headSlice.map((r) => [r.uniqueId, r.similarity]));
@@ -4165,11 +4197,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
4165
4197
  const fused = rrfFuse([headIds, headIds, ...sideLanesAsync], options?.rrfK);
4166
4198
  const fusedHead = combined.map((r) => ({ ...r, similarity: fused.get(r.uniqueId) ?? r.similarity })).sort((a, b) => b.similarity - a.similarity);
4167
4199
  const seen = new Set(combined.map((r) => r.uniqueId));
4168
- const itemById = new Map(items.map((i) => [i.id, i]));
4200
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
4169
4201
  for (const lane of sideLanesAsync) {
4170
4202
  for (const id of lane) {
4171
4203
  if (seen.has(id)) continue;
4172
- const it = itemById.get(id);
4204
+ const it = itemById2.get(id);
4173
4205
  if (!it) continue;
4174
4206
  fusedHead.push({
4175
4207
  uniqueId: id,
@@ -4188,11 +4220,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
4188
4220
  if (options?.mmr) {
4189
4221
  const lambda = options.mmrLambda ?? 0.7;
4190
4222
  const mmrTopN = options.mmrTopN ?? 20;
4191
- const itemById = new Map(items.map((i) => [i.id, i]));
4223
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
4192
4224
  const mmrCandidates = combined.slice(0, mmrTopN).map((r) => ({
4193
4225
  id: r.uniqueId,
4194
4226
  score: r.similarity,
4195
- embedding: itemById.get(r.uniqueId)?.embedding ?? [],
4227
+ embedding: itemById2.get(r.uniqueId)?.embedding ?? [],
4196
4228
  content: r.content
4197
4229
  }));
4198
4230
  const picked = applyMMR(mmrCandidates, limit, lambda);
@@ -4314,7 +4346,12 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
4314
4346
  try {
4315
4347
  const reranked = await rerankPairs(
4316
4348
  originalQuery,
4317
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
4349
+ headSlice.map((r) => ({
4350
+ id: r.uniqueId,
4351
+ content: r.content,
4352
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
4353
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
4354
+ }))
4318
4355
  );
4319
4356
  const ceById = new Map(reranked.map((r) => [r.id, r.score]));
4320
4357
  const head = headSlice.map((r) => ({
@@ -4732,7 +4769,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
4732
4769
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
4733
4770
  );
4734
4771
  }
4735
- const { recall: recall2 } = await import("./recall-OTUNGQHQ.mjs");
4772
+ const { recall: recall2 } = await import("./recall-OPKHWKZX.mjs");
4736
4773
  const result = await recall2(
4737
4774
  query,
4738
4775
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -4649,11 +4649,20 @@ async function getModel() {
4649
4649
  function sigmoid(x) {
4650
4650
  return 1 / (1 + Math.exp(-x));
4651
4651
  }
4652
+ function formatRerankDoc(content, dateMs) {
4653
+ if (dateMs === null || dateMs === void 0 || !Number.isFinite(dateMs)) return content;
4654
+ const d = new Date(dateMs);
4655
+ if (!Number.isFinite(d.getTime())) return content;
4656
+ const yyyy = d.getFullYear();
4657
+ const mm = String(d.getMonth() + 1).padStart(2, "0");
4658
+ const dd = String(d.getDate()).padStart(2, "0");
4659
+ return `[Date: ${yyyy}-${mm}-${dd}] ${content}`;
4660
+ }
4652
4661
  async function rerankPairs(query, items) {
4653
4662
  if (items.length === 0 || !query) return [];
4654
4663
  const { tokenizer, model } = await getModel();
4655
4664
  const queries = items.map(() => query);
4656
- const docs = items.map((i) => i.content);
4665
+ const docs = items.map((i) => formatRerankDoc(i.content, i.dateMs));
4657
4666
  const tokenize2 = tokenizer;
4658
4667
  const inputs = tokenize2(queries, { text_pair: docs, padding: true, truncation: true });
4659
4668
  const forward = model;
@@ -5928,6 +5937,23 @@ var init_recall = __esm({
5928
5937
  function normalizeEventTimeKind(kind) {
5929
5938
  return kind === "point" || kind === "range" || kind === "ongoing" ? kind : null;
5930
5939
  }
5940
+ function rerankDateMs(item) {
5941
+ if (item.eventTimeStart !== null && item.eventTimeStart !== void 0 && Number.isFinite(item.eventTimeStart) && item.eventTimeStart > 0) {
5942
+ return item.eventTimeStart;
5943
+ }
5944
+ if (item.lastObservedAt !== null && item.lastObservedAt !== void 0 && Number.isFinite(item.lastObservedAt) && item.lastObservedAt > 0) {
5945
+ return item.lastObservedAt;
5946
+ }
5947
+ const updatedMs = item.updatedAt?.getTime();
5948
+ if (updatedMs !== null && updatedMs !== void 0 && Number.isFinite(updatedMs) && updatedMs > 0) {
5949
+ return updatedMs;
5950
+ }
5951
+ const createdMs = item.createdAt?.getTime();
5952
+ if (createdMs !== null && createdMs !== void 0 && Number.isFinite(createdMs) && createdMs > 0) {
5953
+ return createdMs;
5954
+ }
5955
+ return void 0;
5956
+ }
5931
5957
  function supersessionDelta(olderScore, newerScore, boostFactor = SUPERSESSION_BOOST_FACTOR) {
5932
5958
  const gap = olderScore - newerScore;
5933
5959
  return gap * boostFactor;
@@ -6130,6 +6156,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
6130
6156
  }
6131
6157
  let combined;
6132
6158
  let tailSlice = [];
6159
+ const itemById = new Map(items.map((i) => [i.id, i]));
6133
6160
  if (options?.rerank) {
6134
6161
  const rerankTopN = options.rerankTopN ?? 30;
6135
6162
  const ceWeight = options.ceWeight ?? 0.1;
@@ -6137,7 +6164,12 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
6137
6164
  try {
6138
6165
  const reranked = await rerankPairs(
6139
6166
  query,
6140
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
6167
+ headSlice.map((r) => ({
6168
+ id: r.uniqueId,
6169
+ content: r.content,
6170
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
6171
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
6172
+ }))
6141
6173
  );
6142
6174
  tailSlice = v2Ranked.slice(rerankTopN);
6143
6175
  const v2ScoreById = new Map(headSlice.map((r) => [r.uniqueId, r.similarity]));
@@ -6172,11 +6204,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
6172
6204
  const fused = rrfFuse([headIds, headIds, ...sideLanesAsync], options?.rrfK);
6173
6205
  const fusedHead = combined.map((r) => ({ ...r, similarity: fused.get(r.uniqueId) ?? r.similarity })).sort((a, b) => b.similarity - a.similarity);
6174
6206
  const seen = new Set(combined.map((r) => r.uniqueId));
6175
- const itemById = new Map(items.map((i) => [i.id, i]));
6207
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
6176
6208
  for (const lane of sideLanesAsync) {
6177
6209
  for (const id of lane) {
6178
6210
  if (seen.has(id)) continue;
6179
- const it = itemById.get(id);
6211
+ const it = itemById2.get(id);
6180
6212
  if (!it) continue;
6181
6213
  fusedHead.push({
6182
6214
  uniqueId: id,
@@ -6195,11 +6227,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
6195
6227
  if (options?.mmr) {
6196
6228
  const lambda = options.mmrLambda ?? 0.7;
6197
6229
  const mmrTopN = options.mmrTopN ?? 20;
6198
- const itemById = new Map(items.map((i) => [i.id, i]));
6230
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
6199
6231
  const mmrCandidates = combined.slice(0, mmrTopN).map((r) => ({
6200
6232
  id: r.uniqueId,
6201
6233
  score: r.similarity,
6202
- embedding: itemById.get(r.uniqueId)?.embedding ?? [],
6234
+ embedding: itemById2.get(r.uniqueId)?.embedding ?? [],
6203
6235
  content: r.content
6204
6236
  }));
6205
6237
  const picked = applyMMR(mmrCandidates, limit, lambda);
@@ -6321,7 +6353,12 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
6321
6353
  try {
6322
6354
  const reranked = await rerankPairs(
6323
6355
  originalQuery,
6324
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
6356
+ headSlice.map((r) => ({
6357
+ id: r.uniqueId,
6358
+ content: r.content,
6359
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
6360
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
6361
+ }))
6325
6362
  );
6326
6363
  const ceById = new Map(reranked.map((r) => [r.id, r.score]));
6327
6364
  const head = headSlice.map((r) => ({
@@ -6195,7 +6195,7 @@ interface VaultSearchResult {
6195
6195
  updatedAt?: Date;
6196
6196
  /** Times this fact has been re-observed — for C2 trend labels. */
6197
6197
  proofCount?: number | null;
6198
- /** C3 re-observation watermark (Unix ms) — for C2 trend labels. */
6198
+ /** C3 re-observation watermark (Unix ms) — for C2 trends + C4 CE dates. */
6199
6199
  lastObservedAt?: number | null;
6200
6200
  /** W6 temporal-lane anchors carried through to downstream `RankedMemory`
6201
6201
  * so the recall executor can surface dates to the answer model without
@@ -6195,7 +6195,7 @@ interface VaultSearchResult {
6195
6195
  updatedAt?: Date;
6196
6196
  /** Times this fact has been re-observed — for C2 trend labels. */
6197
6197
  proofCount?: number | null;
6198
- /** C3 re-observation watermark (Unix ms) — for C2 trend labels. */
6198
+ /** C3 re-observation watermark (Unix ms) — for C2 trends + C4 CE dates. */
6199
6199
  lastObservedAt?: number | null;
6200
6200
  /** W6 temporal-lane anchors carried through to downstream `RankedMemory`
6201
6201
  * so the recall executor can surface dates to the answer model without
@@ -129,7 +129,7 @@ import {
129
129
  updateVaultMemoryOp,
130
130
  useEncryption,
131
131
  vaultMemoryToStored
132
- } from "./chunk-CGC3UJHM.mjs";
132
+ } from "./chunk-DDHTJGZN.mjs";
133
133
  import {
134
134
  PiiRedactor,
135
135
  createStreamingDeAnonymizer,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-CGC3UJHM.mjs";
3
+ } from "./chunk-DDHTJGZN.mjs";
4
4
  import "./chunk-DFVCS3QQ.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -17559,11 +17559,20 @@ async function getModel() {
17559
17559
  function sigmoid(x) {
17560
17560
  return 1 / (1 + Math.exp(-x));
17561
17561
  }
17562
+ function formatRerankDoc(content, dateMs) {
17563
+ if (dateMs === null || dateMs === void 0 || !Number.isFinite(dateMs)) return content;
17564
+ const d = new Date(dateMs);
17565
+ if (!Number.isFinite(d.getTime())) return content;
17566
+ const yyyy = d.getFullYear();
17567
+ const mm = String(d.getMonth() + 1).padStart(2, "0");
17568
+ const dd = String(d.getDate()).padStart(2, "0");
17569
+ return `[Date: ${yyyy}-${mm}-${dd}] ${content}`;
17570
+ }
17562
17571
  async function rerankPairs(query, items) {
17563
17572
  if (items.length === 0 || !query) return [];
17564
17573
  const { tokenizer, model } = await getModel();
17565
17574
  const queries = items.map(() => query);
17566
- const docs = items.map((i) => i.content);
17575
+ const docs = items.map((i) => formatRerankDoc(i.content, i.dateMs));
17567
17576
  const tokenize2 = tokenizer;
17568
17577
  const inputs = tokenize2(queries, { text_pair: docs, padding: true, truncation: true });
17569
17578
  const forward = model;
@@ -17912,6 +17921,23 @@ function createVaultEmbeddingCache(maxSize = DEFAULT_VAULT_CACHE_SIZE) {
17912
17921
  function normalizeEventTimeKind(kind) {
17913
17922
  return kind === "point" || kind === "range" || kind === "ongoing" ? kind : null;
17914
17923
  }
17924
+ function rerankDateMs(item) {
17925
+ if (item.eventTimeStart !== null && item.eventTimeStart !== void 0 && Number.isFinite(item.eventTimeStart) && item.eventTimeStart > 0) {
17926
+ return item.eventTimeStart;
17927
+ }
17928
+ if (item.lastObservedAt !== null && item.lastObservedAt !== void 0 && Number.isFinite(item.lastObservedAt) && item.lastObservedAt > 0) {
17929
+ return item.lastObservedAt;
17930
+ }
17931
+ const updatedMs = item.updatedAt?.getTime();
17932
+ if (updatedMs !== null && updatedMs !== void 0 && Number.isFinite(updatedMs) && updatedMs > 0) {
17933
+ return updatedMs;
17934
+ }
17935
+ const createdMs = item.createdAt?.getTime();
17936
+ if (createdMs !== null && createdMs !== void 0 && Number.isFinite(createdMs) && createdMs > 0) {
17937
+ return createdMs;
17938
+ }
17939
+ return void 0;
17940
+ }
17915
17941
  var SUPERSESSION_SIMILARITY_THRESHOLD = 0.7;
17916
17942
  var SUPERSESSION_MIN_AGE_GAP_MS = 30 * 24 * 60 * 60 * 1e3;
17917
17943
  var SUPERSESSION_BOOST_FACTOR = 0.8;
@@ -18118,6 +18144,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
18118
18144
  }
18119
18145
  let combined;
18120
18146
  let tailSlice = [];
18147
+ const itemById = new Map(items.map((i) => [i.id, i]));
18121
18148
  if (options?.rerank) {
18122
18149
  const rerankTopN = options.rerankTopN ?? 30;
18123
18150
  const ceWeight = options.ceWeight ?? 0.1;
@@ -18125,7 +18152,12 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
18125
18152
  try {
18126
18153
  const reranked = await rerankPairs(
18127
18154
  query,
18128
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
18155
+ headSlice.map((r) => ({
18156
+ id: r.uniqueId,
18157
+ content: r.content,
18158
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
18159
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
18160
+ }))
18129
18161
  );
18130
18162
  tailSlice = v2Ranked.slice(rerankTopN);
18131
18163
  const v2ScoreById = new Map(headSlice.map((r) => [r.uniqueId, r.similarity]));
@@ -18160,11 +18192,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
18160
18192
  const fused = rrfFuse([headIds, headIds, ...sideLanesAsync], options?.rrfK);
18161
18193
  const fusedHead = combined.map((r) => ({ ...r, similarity: fused.get(r.uniqueId) ?? r.similarity })).sort((a, b) => b.similarity - a.similarity);
18162
18194
  const seen = new Set(combined.map((r) => r.uniqueId));
18163
- const itemById = new Map(items.map((i) => [i.id, i]));
18195
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
18164
18196
  for (const lane of sideLanesAsync) {
18165
18197
  for (const id of lane) {
18166
18198
  if (seen.has(id)) continue;
18167
- const it = itemById.get(id);
18199
+ const it = itemById2.get(id);
18168
18200
  if (!it) continue;
18169
18201
  fusedHead.push({
18170
18202
  uniqueId: id,
@@ -18183,11 +18215,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
18183
18215
  if (options?.mmr) {
18184
18216
  const lambda = options.mmrLambda ?? 0.7;
18185
18217
  const mmrTopN = options.mmrTopN ?? 20;
18186
- const itemById = new Map(items.map((i) => [i.id, i]));
18218
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
18187
18219
  const mmrCandidates = combined.slice(0, mmrTopN).map((r) => ({
18188
18220
  id: r.uniqueId,
18189
18221
  score: r.similarity,
18190
- embedding: itemById.get(r.uniqueId)?.embedding ?? [],
18222
+ embedding: itemById2.get(r.uniqueId)?.embedding ?? [],
18191
18223
  content: r.content
18192
18224
  }));
18193
18225
  const picked = applyMMR(mmrCandidates, limit, lambda);
@@ -18309,7 +18341,12 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
18309
18341
  try {
18310
18342
  const reranked = await rerankPairs(
18311
18343
  originalQuery,
18312
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
18344
+ headSlice.map((r) => ({
18345
+ id: r.uniqueId,
18346
+ content: r.content,
18347
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
18348
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
18349
+ }))
18313
18350
  );
18314
18351
  const ceById = new Map(reranked.map((r) => [r.id, r.score]));
18315
18352
  const head = headSlice.map((r) => ({
@@ -18727,7 +18764,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
18727
18764
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
18728
18765
  );
18729
18766
  }
18730
- const { recall: recall2 } = await import("./recall-GWRWPGE4.mjs");
18767
+ const { recall: recall2 } = await import("./recall-IWY2MYHR.mjs");
18731
18768
  const result = await recall2(
18732
18769
  query,
18733
18770
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -18411,11 +18411,20 @@ async function getModel() {
18411
18411
  function sigmoid(x) {
18412
18412
  return 1 / (1 + Math.exp(-x));
18413
18413
  }
18414
+ function formatRerankDoc(content, dateMs) {
18415
+ if (dateMs === null || dateMs === void 0 || !Number.isFinite(dateMs)) return content;
18416
+ const d = new Date(dateMs);
18417
+ if (!Number.isFinite(d.getTime())) return content;
18418
+ const yyyy = d.getFullYear();
18419
+ const mm = String(d.getMonth() + 1).padStart(2, "0");
18420
+ const dd = String(d.getDate()).padStart(2, "0");
18421
+ return `[Date: ${yyyy}-${mm}-${dd}] ${content}`;
18422
+ }
18414
18423
  async function rerankPairs(query, items) {
18415
18424
  if (items.length === 0 || !query) return [];
18416
18425
  const { tokenizer, model } = await getModel();
18417
18426
  const queries = items.map(() => query);
18418
- const docs = items.map((i) => i.content);
18427
+ const docs = items.map((i) => formatRerankDoc(i.content, i.dateMs));
18419
18428
  const tokenize2 = tokenizer;
18420
18429
  const inputs = tokenize2(queries, { text_pair: docs, padding: true, truncation: true });
18421
18430
  const forward = model;
@@ -19905,6 +19914,23 @@ var init_recall = __esm({
19905
19914
  function normalizeEventTimeKind(kind) {
19906
19915
  return kind === "point" || kind === "range" || kind === "ongoing" ? kind : null;
19907
19916
  }
19917
+ function rerankDateMs(item) {
19918
+ if (item.eventTimeStart !== null && item.eventTimeStart !== void 0 && Number.isFinite(item.eventTimeStart) && item.eventTimeStart > 0) {
19919
+ return item.eventTimeStart;
19920
+ }
19921
+ if (item.lastObservedAt !== null && item.lastObservedAt !== void 0 && Number.isFinite(item.lastObservedAt) && item.lastObservedAt > 0) {
19922
+ return item.lastObservedAt;
19923
+ }
19924
+ const updatedMs = item.updatedAt?.getTime();
19925
+ if (updatedMs !== null && updatedMs !== void 0 && Number.isFinite(updatedMs) && updatedMs > 0) {
19926
+ return updatedMs;
19927
+ }
19928
+ const createdMs = item.createdAt?.getTime();
19929
+ if (createdMs !== null && createdMs !== void 0 && Number.isFinite(createdMs) && createdMs > 0) {
19930
+ return createdMs;
19931
+ }
19932
+ return void 0;
19933
+ }
19908
19934
  function supersessionDelta(olderScore, newerScore, boostFactor = SUPERSESSION_BOOST_FACTOR) {
19909
19935
  const gap = olderScore - newerScore;
19910
19936
  return gap * boostFactor;
@@ -20107,6 +20133,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
20107
20133
  }
20108
20134
  let combined;
20109
20135
  let tailSlice = [];
20136
+ const itemById = new Map(items.map((i) => [i.id, i]));
20110
20137
  if (options?.rerank) {
20111
20138
  const rerankTopN = options.rerankTopN ?? 30;
20112
20139
  const ceWeight = options.ceWeight ?? 0.1;
@@ -20114,7 +20141,12 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
20114
20141
  try {
20115
20142
  const reranked = await rerankPairs(
20116
20143
  query,
20117
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
20144
+ headSlice.map((r) => ({
20145
+ id: r.uniqueId,
20146
+ content: r.content,
20147
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
20148
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
20149
+ }))
20118
20150
  );
20119
20151
  tailSlice = v2Ranked.slice(rerankTopN);
20120
20152
  const v2ScoreById = new Map(headSlice.map((r) => [r.uniqueId, r.similarity]));
@@ -20149,11 +20181,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
20149
20181
  const fused = rrfFuse([headIds, headIds, ...sideLanesAsync], options?.rrfK);
20150
20182
  const fusedHead = combined.map((r) => ({ ...r, similarity: fused.get(r.uniqueId) ?? r.similarity })).sort((a, b) => b.similarity - a.similarity);
20151
20183
  const seen = new Set(combined.map((r) => r.uniqueId));
20152
- const itemById = new Map(items.map((i) => [i.id, i]));
20184
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
20153
20185
  for (const lane of sideLanesAsync) {
20154
20186
  for (const id of lane) {
20155
20187
  if (seen.has(id)) continue;
20156
- const it = itemById.get(id);
20188
+ const it = itemById2.get(id);
20157
20189
  if (!it) continue;
20158
20190
  fusedHead.push({
20159
20191
  uniqueId: id,
@@ -20172,11 +20204,11 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
20172
20204
  if (options?.mmr) {
20173
20205
  const lambda = options.mmrLambda ?? 0.7;
20174
20206
  const mmrTopN = options.mmrTopN ?? 20;
20175
- const itemById = new Map(items.map((i) => [i.id, i]));
20207
+ const itemById2 = new Map(items.map((i) => [i.id, i]));
20176
20208
  const mmrCandidates = combined.slice(0, mmrTopN).map((r) => ({
20177
20209
  id: r.uniqueId,
20178
20210
  score: r.similarity,
20179
- embedding: itemById.get(r.uniqueId)?.embedding ?? [],
20211
+ embedding: itemById2.get(r.uniqueId)?.embedding ?? [],
20180
20212
  content: r.content
20181
20213
  }));
20182
20214
  const picked = applyMMR(mmrCandidates, limit, lambda);
@@ -20298,7 +20330,12 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
20298
20330
  try {
20299
20331
  const reranked = await rerankPairs(
20300
20332
  originalQuery,
20301
- headSlice.map((r) => ({ id: r.uniqueId, content: r.content }))
20333
+ headSlice.map((r) => ({
20334
+ id: r.uniqueId,
20335
+ content: r.content,
20336
+ // C4: date-prefix the CE doc so temporal alignment influences rank.
20337
+ dateMs: rerankDateMs(itemById.get(r.uniqueId) ?? r)
20338
+ }))
20302
20339
  );
20303
20340
  const ceById = new Map(reranked.map((r) => [r.id, r.score]));
20304
20341
  const head = headSlice.map((r) => ({
@@ -4792,7 +4792,7 @@ interface VaultSearchResult {
4792
4792
  updatedAt?: Date;
4793
4793
  /** Times this fact has been re-observed — for C2 trend labels. */
4794
4794
  proofCount?: number | null;
4795
- /** C3 re-observation watermark (Unix ms) — for C2 trend labels. */
4795
+ /** C3 re-observation watermark (Unix ms) — for C2 trends + C4 CE dates. */
4796
4796
  lastObservedAt?: number | null;
4797
4797
  /** W6 temporal-lane anchors carried through to downstream `RankedMemory`
4798
4798
  * so the recall executor can surface dates to the answer model without
@@ -4792,7 +4792,7 @@ interface VaultSearchResult {
4792
4792
  updatedAt?: Date;
4793
4793
  /** Times this fact has been re-observed — for C2 trend labels. */
4794
4794
  proofCount?: number | null;
4795
- /** C3 re-observation watermark (Unix ms) — for C2 trend labels. */
4795
+ /** C3 re-observation watermark (Unix ms) — for C2 trends + C4 CE dates. */
4796
4796
  lastObservedAt?: number | null;
4797
4797
  /** W6 temporal-lane anchors carried through to downstream `RankedMemory`
4798
4798
  * so the recall executor can surface dates to the answer model without
@@ -124,7 +124,7 @@ import {
124
124
  updateVaultMemoryOp,
125
125
  upsertMessageOp,
126
126
  vaultMemoryToStored
127
- } from "./chunk-LUDHA4X4.mjs";
127
+ } from "./chunk-V7SVKIXQ.mjs";
128
128
  import {
129
129
  createStreamingDeAnonymizer,
130
130
  resolvePiiRedactor
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-LUDHA4X4.mjs";
3
+ } from "./chunk-V7SVKIXQ.mjs";
4
4
  import "./chunk-AHJT66EO.mjs";
5
5
  import "./chunk-3RPGXXPZ.mjs";
6
6
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",