@anuma/sdk 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/expo/{chunk-3RXNQBS3.mjs → chunk-IKPPX3GY.mjs} +60 -18
- package/dist/expo/index.cjs +60 -18
- package/dist/expo/index.d.mts +3 -0
- package/dist/expo/index.d.ts +3 -0
- package/dist/expo/index.mjs +1 -1
- package/dist/expo/{recall-GJ6RNZMF.mjs → recall-4JTNZBAW.mjs} +1 -1
- package/dist/index.cjs +13 -6
- package/dist/index.mjs +13 -6
- package/dist/react/{chunk-IMUF4U55.mjs → chunk-KQZ4KVYY.mjs} +60 -18
- package/dist/react/index.cjs +60 -18
- package/dist/react/index.d.mts +3 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.mjs +1 -1
- package/dist/react/{recall-NQ6ANFYN.mjs → recall-Z2HUBS2Y.mjs} +1 -1
- package/dist/server/{chunk-G3DC7QBH.mjs → chunk-KLJBJWWI.mjs} +60 -18
- package/dist/server/index.cjs +60 -18
- package/dist/server/index.d.mts +3 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.mjs +1 -1
- package/dist/server/{recall-LFYTTIIY.mjs → recall-IF2HX7ZA.mjs} +1 -1
- package/package.json +1 -1
|
@@ -3170,6 +3170,20 @@ async function withEmbeddingRetry(call) {
|
|
|
3170
3170
|
if (threw) throw lastThrown;
|
|
3171
3171
|
return last;
|
|
3172
3172
|
}
|
|
3173
|
+
var EmbeddingHttpError = class extends Error {
|
|
3174
|
+
constructor(message, status) {
|
|
3175
|
+
super(message);
|
|
3176
|
+
this.name = "EmbeddingHttpError";
|
|
3177
|
+
this.status = status;
|
|
3178
|
+
}
|
|
3179
|
+
};
|
|
3180
|
+
function isFatalEmbeddingError(err) {
|
|
3181
|
+
return err instanceof EmbeddingHttpError && (err.status === 401 || err.status === 402 || err.status === 403);
|
|
3182
|
+
}
|
|
3183
|
+
function embeddingErrorFrom(response) {
|
|
3184
|
+
const message = typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed";
|
|
3185
|
+
return new EmbeddingHttpError(message, response.response?.status);
|
|
3186
|
+
}
|
|
3173
3187
|
async function generateEmbedding(text, options) {
|
|
3174
3188
|
const { baseUrl = BASE_URL, getToken, apiKey, model, cache } = options;
|
|
3175
3189
|
if (cache) {
|
|
@@ -3201,9 +3215,7 @@ async function generateEmbedding(text, options) {
|
|
|
3201
3215
|
})
|
|
3202
3216
|
);
|
|
3203
3217
|
if (response.error) {
|
|
3204
|
-
throw
|
|
3205
|
-
typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
|
|
3206
|
-
);
|
|
3218
|
+
throw embeddingErrorFrom(response);
|
|
3207
3219
|
}
|
|
3208
3220
|
if (!response.data?.data?.[0]?.embedding) {
|
|
3209
3221
|
throw new Error("No embedding returned from API");
|
|
@@ -3232,9 +3244,7 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
3232
3244
|
})
|
|
3233
3245
|
);
|
|
3234
3246
|
if (response.error) {
|
|
3235
|
-
throw
|
|
3236
|
-
typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
|
|
3237
|
-
);
|
|
3247
|
+
throw embeddingErrorFrom(response);
|
|
3238
3248
|
}
|
|
3239
3249
|
if (!response.data?.data) {
|
|
3240
3250
|
throw new Error("No embeddings returned from API");
|
|
@@ -3370,6 +3380,7 @@ async function embedAllMessages(ctx, options, filter) {
|
|
|
3370
3380
|
await updateMessageEmbeddingOp(ctx, message.uniqueId, embedding, embeddingModel);
|
|
3371
3381
|
embeddedCount++;
|
|
3372
3382
|
} catch (error) {
|
|
3383
|
+
if (isFatalEmbeddingError(error)) throw error;
|
|
3373
3384
|
getLogger().error(`Failed to embed message ${message.uniqueId}:`, error);
|
|
3374
3385
|
}
|
|
3375
3386
|
}
|
|
@@ -3457,6 +3468,7 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
|
|
|
3457
3468
|
}
|
|
3458
3469
|
}
|
|
3459
3470
|
} catch (error) {
|
|
3471
|
+
if (isFatalEmbeddingError(error)) throw error;
|
|
3460
3472
|
getLogger().error("Failed to batch-embed short messages:", error);
|
|
3461
3473
|
}
|
|
3462
3474
|
}
|
|
@@ -3473,6 +3485,7 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
|
|
|
3473
3485
|
await updateMessageChunksOp(ctx, msg.uniqueId, messageChunks, embeddingModel);
|
|
3474
3486
|
embeddedCount++;
|
|
3475
3487
|
} catch (error) {
|
|
3488
|
+
if (isFatalEmbeddingError(error)) throw error;
|
|
3476
3489
|
getLogger().error(`Failed to embed message ${msg.uniqueId}:`, error);
|
|
3477
3490
|
}
|
|
3478
3491
|
}
|
|
@@ -3969,6 +3982,7 @@ function rankVaultMemories(_query, queryEmbedding, items, options) {
|
|
|
3969
3982
|
updatedAt: item.updatedAt,
|
|
3970
3983
|
createdAt: item.createdAt,
|
|
3971
3984
|
eventTimeStart: item.eventTimeStart,
|
|
3985
|
+
sourceChunkIds: item.sourceChunkIds,
|
|
3972
3986
|
eventTimeEnd: item.eventTimeEnd,
|
|
3973
3987
|
eventTimeKind: item.eventTimeKind,
|
|
3974
3988
|
similarity: cosineSimilarity(queryEmbedding, item.embedding)
|
|
@@ -4010,7 +4024,8 @@ function rankVaultMemories(_query, queryEmbedding, items, options) {
|
|
|
4010
4024
|
content: r.content,
|
|
4011
4025
|
similarity: r.similarity,
|
|
4012
4026
|
createdAt: item?.createdAt ?? item?.updatedAt,
|
|
4013
|
-
updatedAt: item?.updatedAt
|
|
4027
|
+
updatedAt: item?.updatedAt,
|
|
4028
|
+
sourceChunkIds: item?.sourceChunkIds
|
|
4014
4029
|
};
|
|
4015
4030
|
});
|
|
4016
4031
|
}
|
|
@@ -4049,6 +4064,7 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
|
|
|
4049
4064
|
createdAt: item.createdAt ?? item.updatedAt,
|
|
4050
4065
|
updatedAt: item.updatedAt,
|
|
4051
4066
|
eventTimeStart: item.eventTimeStart,
|
|
4067
|
+
sourceChunkIds: item.sourceChunkIds,
|
|
4052
4068
|
eventTimeEnd: item.eventTimeEnd,
|
|
4053
4069
|
eventTimeKind: item.eventTimeKind
|
|
4054
4070
|
});
|
|
@@ -4091,7 +4107,8 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
|
|
|
4091
4107
|
content: it.content,
|
|
4092
4108
|
similarity: (fused.get(id) ?? 0) * boostFor(id),
|
|
4093
4109
|
createdAt: it.createdAt ?? it.updatedAt,
|
|
4094
|
-
updatedAt: it.updatedAt
|
|
4110
|
+
updatedAt: it.updatedAt,
|
|
4111
|
+
sourceChunkIds: it.sourceChunkIds
|
|
4095
4112
|
});
|
|
4096
4113
|
seen.add(id);
|
|
4097
4114
|
}
|
|
@@ -4129,13 +4146,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
|
|
|
4129
4146
|
combined = headSlice.map((r) => {
|
|
4130
4147
|
const v2 = v2ScoreById.get(r.uniqueId) ?? 0;
|
|
4131
4148
|
const ce = ceScoreById.get(r.uniqueId) ?? 0;
|
|
4132
|
-
return {
|
|
4133
|
-
uniqueId: r.uniqueId,
|
|
4134
|
-
content: r.content,
|
|
4135
|
-
similarity: v2 * (1 + ceWeight * ce),
|
|
4136
|
-
createdAt: r.createdAt,
|
|
4137
|
-
updatedAt: r.updatedAt
|
|
4138
|
-
};
|
|
4149
|
+
return { ...r, similarity: v2 * (1 + ceWeight * ce) };
|
|
4139
4150
|
});
|
|
4140
4151
|
combined.sort((a, b) => b.similarity - a.similarity);
|
|
4141
4152
|
} catch (err) {
|
|
@@ -4168,7 +4179,8 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
|
|
|
4168
4179
|
content: it.content,
|
|
4169
4180
|
similarity: fused.get(id) ?? 0,
|
|
4170
4181
|
createdAt: it.createdAt ?? it.updatedAt,
|
|
4171
|
-
updatedAt: it.updatedAt
|
|
4182
|
+
updatedAt: it.updatedAt,
|
|
4183
|
+
sourceChunkIds: it.sourceChunkIds
|
|
4172
4184
|
});
|
|
4173
4185
|
seen.add(id);
|
|
4174
4186
|
}
|
|
@@ -4198,6 +4210,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
|
|
|
4198
4210
|
createdAt: orig?.createdAt,
|
|
4199
4211
|
updatedAt: orig?.updatedAt,
|
|
4200
4212
|
eventTimeStart: orig?.eventTimeStart,
|
|
4213
|
+
sourceChunkIds: orig?.sourceChunkIds,
|
|
4201
4214
|
eventTimeEnd: orig?.eventTimeEnd,
|
|
4202
4215
|
eventTimeKind: orig?.eventTimeKind
|
|
4203
4216
|
};
|
|
@@ -4261,6 +4274,7 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
|
|
|
4261
4274
|
createdAt: item.createdAt ?? item.updatedAt,
|
|
4262
4275
|
updatedAt: item.updatedAt,
|
|
4263
4276
|
eventTimeStart: item.eventTimeStart,
|
|
4277
|
+
sourceChunkIds: item.sourceChunkIds,
|
|
4264
4278
|
eventTimeEnd: item.eventTimeEnd,
|
|
4265
4279
|
eventTimeKind: item.eventTimeKind
|
|
4266
4280
|
};
|
|
@@ -4281,6 +4295,7 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
|
|
|
4281
4295
|
createdAt: item.createdAt ?? item.updatedAt,
|
|
4282
4296
|
updatedAt: item.updatedAt,
|
|
4283
4297
|
eventTimeStart: item.eventTimeStart,
|
|
4298
|
+
sourceChunkIds: item.sourceChunkIds,
|
|
4284
4299
|
eventTimeEnd: item.eventTimeEnd,
|
|
4285
4300
|
eventTimeKind: item.eventTimeKind
|
|
4286
4301
|
});
|
|
@@ -4332,6 +4347,7 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
|
|
|
4332
4347
|
createdAt: orig?.createdAt,
|
|
4333
4348
|
updatedAt: orig?.updatedAt,
|
|
4334
4349
|
eventTimeStart: orig?.eventTimeStart,
|
|
4350
|
+
sourceChunkIds: orig?.sourceChunkIds,
|
|
4335
4351
|
eventTimeEnd: orig?.eventTimeEnd,
|
|
4336
4352
|
eventTimeKind: orig?.eventTimeKind
|
|
4337
4353
|
};
|
|
@@ -4473,6 +4489,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
4473
4489
|
updatedAt: m.updatedAt,
|
|
4474
4490
|
proofCount: m.proofCount,
|
|
4475
4491
|
eventTimeStart: m.eventTimeStart,
|
|
4492
|
+
sourceChunkIds: m.sourceChunkIds,
|
|
4476
4493
|
eventTimeEnd: m.eventTimeEnd,
|
|
4477
4494
|
eventTimeKind: normalizeEventTimeKind(m.eventTimeKind)
|
|
4478
4495
|
}));
|
|
@@ -4663,7 +4680,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
4663
4680
|
legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
|
|
4664
4681
|
);
|
|
4665
4682
|
}
|
|
4666
|
-
const { recall: recall2 } = await import("./recall-
|
|
4683
|
+
const { recall: recall2 } = await import("./recall-4JTNZBAW.mjs");
|
|
4667
4684
|
const result = await recall2(
|
|
4668
4685
|
query,
|
|
4669
4686
|
{ vaultCtx, embeddingOptions, vaultCache: cache },
|
|
@@ -5131,7 +5148,31 @@ async function recall(query, ctx, options = {}) {
|
|
|
5131
5148
|
m.scoreBreakdown.fused = r.similarity;
|
|
5132
5149
|
byId.set(key, m);
|
|
5133
5150
|
}
|
|
5134
|
-
const
|
|
5151
|
+
const ordered = [...byId.values()].sort((a, b) => b.score - a.score);
|
|
5152
|
+
const selectWith = (suppressed2) => {
|
|
5153
|
+
const out = [];
|
|
5154
|
+
for (const m of ordered) {
|
|
5155
|
+
if (out.length >= limit) break;
|
|
5156
|
+
if (m.kind === "chunk" && m.messageId && suppressed2.has(m.messageId)) continue;
|
|
5157
|
+
out.push(m);
|
|
5158
|
+
}
|
|
5159
|
+
return out;
|
|
5160
|
+
};
|
|
5161
|
+
const provenanceOf = (selected) => {
|
|
5162
|
+
const s = /* @__PURE__ */ new Set();
|
|
5163
|
+
for (const m of selected) {
|
|
5164
|
+
if (m.kind === "fact" && m.sourceChunkIds) for (const id of m.sourceChunkIds) s.add(id);
|
|
5165
|
+
}
|
|
5166
|
+
return s;
|
|
5167
|
+
};
|
|
5168
|
+
let suppressed = /* @__PURE__ */ new Set();
|
|
5169
|
+
let memories = selectWith(suppressed);
|
|
5170
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
5171
|
+
const next = provenanceOf(memories);
|
|
5172
|
+
if (next.size === suppressed.size && [...next].every((id) => suppressed.has(id))) break;
|
|
5173
|
+
suppressed = next;
|
|
5174
|
+
memories = selectWith(suppressed);
|
|
5175
|
+
}
|
|
5135
5176
|
return {
|
|
5136
5177
|
memories,
|
|
5137
5178
|
usedBudget,
|
|
@@ -5152,6 +5193,7 @@ function toFactMemory(r) {
|
|
|
5152
5193
|
...r.eventTimeStart !== void 0 && { eventTimeStart: r.eventTimeStart },
|
|
5153
5194
|
...r.eventTimeEnd !== void 0 && { eventTimeEnd: r.eventTimeEnd },
|
|
5154
5195
|
...r.eventTimeKind !== void 0 && { eventTimeKind: r.eventTimeKind },
|
|
5196
|
+
...r.sourceChunkIds !== void 0 && r.sourceChunkIds !== null && { sourceChunkIds: r.sourceChunkIds },
|
|
5155
5197
|
// r.similarity from searchVaultMemoriesWithSize is the fused score
|
|
5156
5198
|
// (cosine + BM25 + RRF + recency + proof) when useFusion=true (the
|
|
5157
5199
|
// default) and pure cosine when useFusion=false. The breakdown
|
package/dist/expo/index.cjs
CHANGED
|
@@ -2837,6 +2837,13 @@ async function withEmbeddingRetry(call) {
|
|
|
2837
2837
|
if (threw) throw lastThrown;
|
|
2838
2838
|
return last;
|
|
2839
2839
|
}
|
|
2840
|
+
function isFatalEmbeddingError(err) {
|
|
2841
|
+
return err instanceof EmbeddingHttpError && (err.status === 401 || err.status === 402 || err.status === 403);
|
|
2842
|
+
}
|
|
2843
|
+
function embeddingErrorFrom(response) {
|
|
2844
|
+
const message = typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed";
|
|
2845
|
+
return new EmbeddingHttpError(message, response.response?.status);
|
|
2846
|
+
}
|
|
2840
2847
|
async function generateEmbedding(text11, options) {
|
|
2841
2848
|
const { baseUrl = BASE_URL, getToken, apiKey, model, cache } = options;
|
|
2842
2849
|
if (cache) {
|
|
@@ -2868,9 +2875,7 @@ async function generateEmbedding(text11, options) {
|
|
|
2868
2875
|
})
|
|
2869
2876
|
);
|
|
2870
2877
|
if (response.error) {
|
|
2871
|
-
throw
|
|
2872
|
-
typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
|
|
2873
|
-
);
|
|
2878
|
+
throw embeddingErrorFrom(response);
|
|
2874
2879
|
}
|
|
2875
2880
|
if (!response.data?.data?.[0]?.embedding) {
|
|
2876
2881
|
throw new Error("No embedding returned from API");
|
|
@@ -2897,9 +2902,7 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
2897
2902
|
})
|
|
2898
2903
|
);
|
|
2899
2904
|
if (response.error) {
|
|
2900
|
-
throw
|
|
2901
|
-
typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
|
|
2902
|
-
);
|
|
2905
|
+
throw embeddingErrorFrom(response);
|
|
2903
2906
|
}
|
|
2904
2907
|
if (!response.data?.data) {
|
|
2905
2908
|
throw new Error("No embeddings returned from API");
|
|
@@ -3035,6 +3038,7 @@ async function embedAllMessages(ctx, options, filter) {
|
|
|
3035
3038
|
await updateMessageEmbeddingOp(ctx, message.uniqueId, embedding, embeddingModel);
|
|
3036
3039
|
embeddedCount++;
|
|
3037
3040
|
} catch (error) {
|
|
3041
|
+
if (isFatalEmbeddingError(error)) throw error;
|
|
3038
3042
|
getLogger().error(`Failed to embed message ${message.uniqueId}:`, error);
|
|
3039
3043
|
}
|
|
3040
3044
|
}
|
|
@@ -3122,6 +3126,7 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
|
|
|
3122
3126
|
}
|
|
3123
3127
|
}
|
|
3124
3128
|
} catch (error) {
|
|
3129
|
+
if (isFatalEmbeddingError(error)) throw error;
|
|
3125
3130
|
getLogger().error("Failed to batch-embed short messages:", error);
|
|
3126
3131
|
}
|
|
3127
3132
|
}
|
|
@@ -3138,12 +3143,13 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
|
|
|
3138
3143
|
await updateMessageChunksOp(ctx, msg.uniqueId, messageChunks, embeddingModel);
|
|
3139
3144
|
embeddedCount++;
|
|
3140
3145
|
} catch (error) {
|
|
3146
|
+
if (isFatalEmbeddingError(error)) throw error;
|
|
3141
3147
|
getLogger().error(`Failed to embed message ${msg.uniqueId}:`, error);
|
|
3142
3148
|
}
|
|
3143
3149
|
}
|
|
3144
3150
|
return embeddedCount;
|
|
3145
3151
|
}
|
|
3146
|
-
var DEFAULT_MIN_CONTENT_LENGTH, EMBED_MAX_ATTEMPTS, DEFAULT_EMBEDDING_BATCH_SIZE, DEFAULT_EMBEDDING_BATCH_CONCURRENCY;
|
|
3152
|
+
var DEFAULT_MIN_CONTENT_LENGTH, EMBED_MAX_ATTEMPTS, EmbeddingHttpError, DEFAULT_EMBEDDING_BATCH_SIZE, DEFAULT_EMBEDDING_BATCH_CONCURRENCY;
|
|
3147
3153
|
var init_embeddings = __esm({
|
|
3148
3154
|
"src/lib/memoryEngine/embeddings.ts"() {
|
|
3149
3155
|
"use strict";
|
|
@@ -3155,6 +3161,13 @@ var init_embeddings = __esm({
|
|
|
3155
3161
|
init_constants();
|
|
3156
3162
|
DEFAULT_MIN_CONTENT_LENGTH = 10;
|
|
3157
3163
|
EMBED_MAX_ATTEMPTS = 4;
|
|
3164
|
+
EmbeddingHttpError = class extends Error {
|
|
3165
|
+
constructor(message, status) {
|
|
3166
|
+
super(message);
|
|
3167
|
+
this.name = "EmbeddingHttpError";
|
|
3168
|
+
this.status = status;
|
|
3169
|
+
}
|
|
3170
|
+
};
|
|
3158
3171
|
DEFAULT_EMBEDDING_BATCH_SIZE = 100;
|
|
3159
3172
|
DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
|
|
3160
3173
|
}
|
|
@@ -5546,7 +5559,31 @@ async function recall(query, ctx, options = {}) {
|
|
|
5546
5559
|
m.scoreBreakdown.fused = r.similarity;
|
|
5547
5560
|
byId.set(key, m);
|
|
5548
5561
|
}
|
|
5549
|
-
const
|
|
5562
|
+
const ordered = [...byId.values()].sort((a, b) => b.score - a.score);
|
|
5563
|
+
const selectWith = (suppressed2) => {
|
|
5564
|
+
const out = [];
|
|
5565
|
+
for (const m of ordered) {
|
|
5566
|
+
if (out.length >= limit) break;
|
|
5567
|
+
if (m.kind === "chunk" && m.messageId && suppressed2.has(m.messageId)) continue;
|
|
5568
|
+
out.push(m);
|
|
5569
|
+
}
|
|
5570
|
+
return out;
|
|
5571
|
+
};
|
|
5572
|
+
const provenanceOf = (selected) => {
|
|
5573
|
+
const s = /* @__PURE__ */ new Set();
|
|
5574
|
+
for (const m of selected) {
|
|
5575
|
+
if (m.kind === "fact" && m.sourceChunkIds) for (const id of m.sourceChunkIds) s.add(id);
|
|
5576
|
+
}
|
|
5577
|
+
return s;
|
|
5578
|
+
};
|
|
5579
|
+
let suppressed = /* @__PURE__ */ new Set();
|
|
5580
|
+
let memories = selectWith(suppressed);
|
|
5581
|
+
for (let i = 0; i < ordered.length; i++) {
|
|
5582
|
+
const next = provenanceOf(memories);
|
|
5583
|
+
if (next.size === suppressed.size && [...next].every((id) => suppressed.has(id))) break;
|
|
5584
|
+
suppressed = next;
|
|
5585
|
+
memories = selectWith(suppressed);
|
|
5586
|
+
}
|
|
5550
5587
|
return {
|
|
5551
5588
|
memories,
|
|
5552
5589
|
usedBudget,
|
|
@@ -5567,6 +5604,7 @@ function toFactMemory(r) {
|
|
|
5567
5604
|
...r.eventTimeStart !== void 0 && { eventTimeStart: r.eventTimeStart },
|
|
5568
5605
|
...r.eventTimeEnd !== void 0 && { eventTimeEnd: r.eventTimeEnd },
|
|
5569
5606
|
...r.eventTimeKind !== void 0 && { eventTimeKind: r.eventTimeKind },
|
|
5607
|
+
...r.sourceChunkIds !== void 0 && r.sourceChunkIds !== null && { sourceChunkIds: r.sourceChunkIds },
|
|
5570
5608
|
// r.similarity from searchVaultMemoriesWithSize is the fused score
|
|
5571
5609
|
// (cosine + BM25 + RRF + recency + proof) when useFusion=true (the
|
|
5572
5610
|
// default) and pure cosine when useFusion=false. The breakdown
|
|
@@ -5681,6 +5719,7 @@ function rankVaultMemories(_query, queryEmbedding, items, options) {
|
|
|
5681
5719
|
updatedAt: item.updatedAt,
|
|
5682
5720
|
createdAt: item.createdAt,
|
|
5683
5721
|
eventTimeStart: item.eventTimeStart,
|
|
5722
|
+
sourceChunkIds: item.sourceChunkIds,
|
|
5684
5723
|
eventTimeEnd: item.eventTimeEnd,
|
|
5685
5724
|
eventTimeKind: item.eventTimeKind,
|
|
5686
5725
|
similarity: cosineSimilarity(queryEmbedding, item.embedding)
|
|
@@ -5722,7 +5761,8 @@ function rankVaultMemories(_query, queryEmbedding, items, options) {
|
|
|
5722
5761
|
content: r.content,
|
|
5723
5762
|
similarity: r.similarity,
|
|
5724
5763
|
createdAt: item?.createdAt ?? item?.updatedAt,
|
|
5725
|
-
updatedAt: item?.updatedAt
|
|
5764
|
+
updatedAt: item?.updatedAt,
|
|
5765
|
+
sourceChunkIds: item?.sourceChunkIds
|
|
5726
5766
|
};
|
|
5727
5767
|
});
|
|
5728
5768
|
}
|
|
@@ -5761,6 +5801,7 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
|
|
|
5761
5801
|
createdAt: item.createdAt ?? item.updatedAt,
|
|
5762
5802
|
updatedAt: item.updatedAt,
|
|
5763
5803
|
eventTimeStart: item.eventTimeStart,
|
|
5804
|
+
sourceChunkIds: item.sourceChunkIds,
|
|
5764
5805
|
eventTimeEnd: item.eventTimeEnd,
|
|
5765
5806
|
eventTimeKind: item.eventTimeKind
|
|
5766
5807
|
});
|
|
@@ -5803,7 +5844,8 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
|
|
|
5803
5844
|
content: it.content,
|
|
5804
5845
|
similarity: (fused.get(id) ?? 0) * boostFor(id),
|
|
5805
5846
|
createdAt: it.createdAt ?? it.updatedAt,
|
|
5806
|
-
updatedAt: it.updatedAt
|
|
5847
|
+
updatedAt: it.updatedAt,
|
|
5848
|
+
sourceChunkIds: it.sourceChunkIds
|
|
5807
5849
|
});
|
|
5808
5850
|
seen.add(id);
|
|
5809
5851
|
}
|
|
@@ -5841,13 +5883,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
|
|
|
5841
5883
|
combined = headSlice.map((r) => {
|
|
5842
5884
|
const v2 = v2ScoreById.get(r.uniqueId) ?? 0;
|
|
5843
5885
|
const ce = ceScoreById.get(r.uniqueId) ?? 0;
|
|
5844
|
-
return {
|
|
5845
|
-
uniqueId: r.uniqueId,
|
|
5846
|
-
content: r.content,
|
|
5847
|
-
similarity: v2 * (1 + ceWeight * ce),
|
|
5848
|
-
createdAt: r.createdAt,
|
|
5849
|
-
updatedAt: r.updatedAt
|
|
5850
|
-
};
|
|
5886
|
+
return { ...r, similarity: v2 * (1 + ceWeight * ce) };
|
|
5851
5887
|
});
|
|
5852
5888
|
combined.sort((a, b) => b.similarity - a.similarity);
|
|
5853
5889
|
} catch (err) {
|
|
@@ -5880,7 +5916,8 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
|
|
|
5880
5916
|
content: it.content,
|
|
5881
5917
|
similarity: fused.get(id) ?? 0,
|
|
5882
5918
|
createdAt: it.createdAt ?? it.updatedAt,
|
|
5883
|
-
updatedAt: it.updatedAt
|
|
5919
|
+
updatedAt: it.updatedAt,
|
|
5920
|
+
sourceChunkIds: it.sourceChunkIds
|
|
5884
5921
|
});
|
|
5885
5922
|
seen.add(id);
|
|
5886
5923
|
}
|
|
@@ -5910,6 +5947,7 @@ async function rankFusedVaultMemoriesAsync(query, queryEmbedding, items, options
|
|
|
5910
5947
|
createdAt: orig?.createdAt,
|
|
5911
5948
|
updatedAt: orig?.updatedAt,
|
|
5912
5949
|
eventTimeStart: orig?.eventTimeStart,
|
|
5950
|
+
sourceChunkIds: orig?.sourceChunkIds,
|
|
5913
5951
|
eventTimeEnd: orig?.eventTimeEnd,
|
|
5914
5952
|
eventTimeKind: orig?.eventTimeKind
|
|
5915
5953
|
};
|
|
@@ -5973,6 +6011,7 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
|
|
|
5973
6011
|
createdAt: item.createdAt ?? item.updatedAt,
|
|
5974
6012
|
updatedAt: item.updatedAt,
|
|
5975
6013
|
eventTimeStart: item.eventTimeStart,
|
|
6014
|
+
sourceChunkIds: item.sourceChunkIds,
|
|
5976
6015
|
eventTimeEnd: item.eventTimeEnd,
|
|
5977
6016
|
eventTimeKind: item.eventTimeKind
|
|
5978
6017
|
};
|
|
@@ -5993,6 +6032,7 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
|
|
|
5993
6032
|
createdAt: item.createdAt ?? item.updatedAt,
|
|
5994
6033
|
updatedAt: item.updatedAt,
|
|
5995
6034
|
eventTimeStart: item.eventTimeStart,
|
|
6035
|
+
sourceChunkIds: item.sourceChunkIds,
|
|
5996
6036
|
eventTimeEnd: item.eventTimeEnd,
|
|
5997
6037
|
eventTimeKind: item.eventTimeKind
|
|
5998
6038
|
});
|
|
@@ -6044,6 +6084,7 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
|
|
|
6044
6084
|
createdAt: orig?.createdAt,
|
|
6045
6085
|
updatedAt: orig?.updatedAt,
|
|
6046
6086
|
eventTimeStart: orig?.eventTimeStart,
|
|
6087
|
+
sourceChunkIds: orig?.sourceChunkIds,
|
|
6047
6088
|
eventTimeEnd: orig?.eventTimeEnd,
|
|
6048
6089
|
eventTimeKind: orig?.eventTimeKind
|
|
6049
6090
|
};
|
|
@@ -6185,6 +6226,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
6185
6226
|
updatedAt: m.updatedAt,
|
|
6186
6227
|
proofCount: m.proofCount,
|
|
6187
6228
|
eventTimeStart: m.eventTimeStart,
|
|
6229
|
+
sourceChunkIds: m.sourceChunkIds,
|
|
6188
6230
|
eventTimeEnd: m.eventTimeEnd,
|
|
6189
6231
|
eventTimeKind: normalizeEventTimeKind(m.eventTimeKind)
|
|
6190
6232
|
}));
|
package/dist/expo/index.d.mts
CHANGED
|
@@ -4848,6 +4848,9 @@ interface VaultSearchResult {
|
|
|
4848
4848
|
eventTimeStart?: number | null;
|
|
4849
4849
|
eventTimeEnd?: number | null;
|
|
4850
4850
|
eventTimeKind?: "point" | "range" | "ongoing" | null;
|
|
4851
|
+
/** Message ids this fact was extracted from (provenance). recall() uses
|
|
4852
|
+
* these to suppress the originating chunk in the chunk lane. */
|
|
4853
|
+
sourceChunkIds?: string[] | null;
|
|
4851
4854
|
}
|
|
4852
4855
|
/**
|
|
4853
4856
|
* Search vault memories by semantic similarity. Returns structured results
|
package/dist/expo/index.d.ts
CHANGED
|
@@ -4848,6 +4848,9 @@ interface VaultSearchResult {
|
|
|
4848
4848
|
eventTimeStart?: number | null;
|
|
4849
4849
|
eventTimeEnd?: number | null;
|
|
4850
4850
|
eventTimeKind?: "point" | "range" | "ongoing" | null;
|
|
4851
|
+
/** Message ids this fact was extracted from (provenance). recall() uses
|
|
4852
|
+
* these to suppress the originating chunk in the chunk lane. */
|
|
4853
|
+
sourceChunkIds?: string[] | null;
|
|
4851
4854
|
}
|
|
4852
4855
|
/**
|
|
4853
4856
|
* Search vault memories by semantic similarity. Returns structured results
|
package/dist/expo/index.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2095,6 +2095,17 @@ async function withEmbeddingRetry(call) {
|
|
|
2095
2095
|
if (threw) throw lastThrown;
|
|
2096
2096
|
return last;
|
|
2097
2097
|
}
|
|
2098
|
+
var EmbeddingHttpError = class extends Error {
|
|
2099
|
+
constructor(message, status) {
|
|
2100
|
+
super(message);
|
|
2101
|
+
this.name = "EmbeddingHttpError";
|
|
2102
|
+
this.status = status;
|
|
2103
|
+
}
|
|
2104
|
+
};
|
|
2105
|
+
function embeddingErrorFrom(response) {
|
|
2106
|
+
const message = typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed";
|
|
2107
|
+
return new EmbeddingHttpError(message, response.response?.status);
|
|
2108
|
+
}
|
|
2098
2109
|
async function generateEmbedding(text, options) {
|
|
2099
2110
|
const { baseUrl = BASE_URL, getToken, apiKey, model, cache } = options;
|
|
2100
2111
|
if (cache) {
|
|
@@ -2126,9 +2137,7 @@ async function generateEmbedding(text, options) {
|
|
|
2126
2137
|
})
|
|
2127
2138
|
);
|
|
2128
2139
|
if (response.error) {
|
|
2129
|
-
throw
|
|
2130
|
-
typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
|
|
2131
|
-
);
|
|
2140
|
+
throw embeddingErrorFrom(response);
|
|
2132
2141
|
}
|
|
2133
2142
|
if (!response.data?.data?.[0]?.embedding) {
|
|
2134
2143
|
throw new Error("No embedding returned from API");
|
|
@@ -2157,9 +2166,7 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
2157
2166
|
})
|
|
2158
2167
|
);
|
|
2159
2168
|
if (response.error) {
|
|
2160
|
-
throw
|
|
2161
|
-
typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
|
|
2162
|
-
);
|
|
2169
|
+
throw embeddingErrorFrom(response);
|
|
2163
2170
|
}
|
|
2164
2171
|
if (!response.data?.data) {
|
|
2165
2172
|
throw new Error("No embeddings returned from API");
|
package/dist/index.mjs
CHANGED
|
@@ -1904,6 +1904,17 @@ async function withEmbeddingRetry(call) {
|
|
|
1904
1904
|
if (threw) throw lastThrown;
|
|
1905
1905
|
return last;
|
|
1906
1906
|
}
|
|
1907
|
+
var EmbeddingHttpError = class extends Error {
|
|
1908
|
+
constructor(message, status) {
|
|
1909
|
+
super(message);
|
|
1910
|
+
this.name = "EmbeddingHttpError";
|
|
1911
|
+
this.status = status;
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
function embeddingErrorFrom(response) {
|
|
1915
|
+
const message = typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed";
|
|
1916
|
+
return new EmbeddingHttpError(message, response.response?.status);
|
|
1917
|
+
}
|
|
1907
1918
|
async function generateEmbedding(text, options) {
|
|
1908
1919
|
const { baseUrl = BASE_URL, getToken, apiKey, model, cache } = options;
|
|
1909
1920
|
if (cache) {
|
|
@@ -1935,9 +1946,7 @@ async function generateEmbedding(text, options) {
|
|
|
1935
1946
|
})
|
|
1936
1947
|
);
|
|
1937
1948
|
if (response.error) {
|
|
1938
|
-
throw
|
|
1939
|
-
typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
|
|
1940
|
-
);
|
|
1949
|
+
throw embeddingErrorFrom(response);
|
|
1941
1950
|
}
|
|
1942
1951
|
if (!response.data?.data?.[0]?.embedding) {
|
|
1943
1952
|
throw new Error("No embedding returned from API");
|
|
@@ -1966,9 +1975,7 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
1966
1975
|
})
|
|
1967
1976
|
);
|
|
1968
1977
|
if (response.error) {
|
|
1969
|
-
throw
|
|
1970
|
-
typeof response.error === "object" && response.error && "error" in response.error ? response.error.error : "API embedding failed"
|
|
1971
|
-
);
|
|
1978
|
+
throw embeddingErrorFrom(response);
|
|
1972
1979
|
}
|
|
1973
1980
|
if (!response.data?.data) {
|
|
1974
1981
|
throw new Error("No embeddings returned from API");
|