@anuma/sdk 7.0.4 → 7.0.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/index.cjs +101 -58
- package/dist/expo/index.d.mts +1 -8
- package/dist/expo/index.d.ts +1 -8
- package/dist/expo/index.mjs +99 -58
- package/dist/index.cjs +29 -7
- package/dist/index.mjs +29 -7
- package/dist/react/index.cjs +101 -58
- package/dist/react/index.d.mts +1 -8
- package/dist/react/index.d.ts +1 -8
- package/dist/react/index.mjs +99 -58
- package/dist/server/index.cjs +84 -47
- package/dist/server/index.d.mts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.mjs +82 -47
- package/dist/tools/selection/index.cjs +29 -7
- package/dist/tools/selection/index.mjs +29 -7
- package/package.json +2 -2
package/dist/react/index.mjs
CHANGED
|
@@ -4537,6 +4537,22 @@ var postApiV1WalletsBinding = (options) => (options.client ?? client).post({
|
|
|
4537
4537
|
var postApiV1WalletsBindingNonce = (options) => (options?.client ?? client).post({ url: "/api/v1/wallets/binding/nonce", ...options });
|
|
4538
4538
|
var deleteApiV1WalletsBindingByAddress = (options) => (options.client ?? client).delete({ url: "/api/v1/wallets/binding/{address}", ...options });
|
|
4539
4539
|
|
|
4540
|
+
// src/lib/memoryEngine/embeddingCacheState.ts
|
|
4541
|
+
var EMBEDDING_CACHE_STATE_KEY = /* @__PURE__ */ Symbol.for("@anuma/sdk/embedding-cache/v1");
|
|
4542
|
+
var cacheGlobal = globalThis;
|
|
4543
|
+
var fallbackState = {
|
|
4544
|
+
scopedViews: /* @__PURE__ */ new WeakMap(),
|
|
4545
|
+
inFlightByCache: /* @__PURE__ */ new WeakMap(),
|
|
4546
|
+
cachedEmbeddingModels: /* @__PURE__ */ new WeakMap()
|
|
4547
|
+
};
|
|
4548
|
+
function getEmbeddingCacheState() {
|
|
4549
|
+
try {
|
|
4550
|
+
return cacheGlobal[EMBEDDING_CACHE_STATE_KEY] ?? (cacheGlobal[EMBEDDING_CACHE_STATE_KEY] = fallbackState);
|
|
4551
|
+
} catch {
|
|
4552
|
+
return fallbackState;
|
|
4553
|
+
}
|
|
4554
|
+
}
|
|
4555
|
+
|
|
4540
4556
|
// src/lib/memoryEngine/generate.ts
|
|
4541
4557
|
var EMBED_MAX_ATTEMPTS = 4;
|
|
4542
4558
|
var DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS = 15e3;
|
|
@@ -4628,15 +4644,18 @@ async function generateEmbedding(text14, options) {
|
|
|
4628
4644
|
if (total === void 0) return embedOne(text14, options, void 0);
|
|
4629
4645
|
return withDeadline((signal) => embedOne(text14, options, signal), total, "embedding");
|
|
4630
4646
|
}
|
|
4631
|
-
var inFlightByCache
|
|
4647
|
+
var { inFlightByCache, cachedEmbeddingModels } = getEmbeddingCacheState();
|
|
4632
4648
|
async function embedOne(text14, options, outer) {
|
|
4633
4649
|
const { cache } = options;
|
|
4634
4650
|
if (!cache) return Array.from(await requestEmbedding(text14, options, outer));
|
|
4651
|
+
const model = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
4635
4652
|
const cached = cache.get(text14);
|
|
4636
|
-
|
|
4653
|
+
const cachedModel = cached && cachedEmbeddingModels.get(cached);
|
|
4654
|
+
if (cached && (cachedModel === void 0 || cachedModel === model)) return Array.from(cached);
|
|
4637
4655
|
const inFlight = inFlightByCache.get(cache) ?? /* @__PURE__ */ new Map();
|
|
4638
4656
|
inFlightByCache.set(cache, inFlight);
|
|
4639
|
-
const
|
|
4657
|
+
const requestKey = JSON.stringify([model, text14]);
|
|
4658
|
+
const pending = inFlight.get(requestKey);
|
|
4640
4659
|
if (pending) {
|
|
4641
4660
|
try {
|
|
4642
4661
|
return Array.from(await pending);
|
|
@@ -4645,13 +4664,14 @@ async function embedOne(text14, options, outer) {
|
|
|
4645
4664
|
}
|
|
4646
4665
|
}
|
|
4647
4666
|
const request = requestEmbedding(text14, options, outer);
|
|
4648
|
-
inFlight.set(
|
|
4667
|
+
inFlight.set(requestKey, request);
|
|
4649
4668
|
try {
|
|
4650
4669
|
const embedding2 = await request;
|
|
4670
|
+
cachedEmbeddingModels.set(embedding2, model);
|
|
4651
4671
|
cache.set(text14, embedding2);
|
|
4652
4672
|
return Array.from(embedding2);
|
|
4653
4673
|
} finally {
|
|
4654
|
-
if (inFlight.get(
|
|
4674
|
+
if (inFlight.get(requestKey) === request) inFlight.delete(requestKey);
|
|
4655
4675
|
}
|
|
4656
4676
|
}
|
|
4657
4677
|
async function requestEmbedding(text14, options, outer) {
|
|
@@ -4734,13 +4754,15 @@ async function embedMany(texts, options, outer) {
|
|
|
4734
4754
|
const { baseUrl = BASE_URL, model, batchSize, cache } = options;
|
|
4735
4755
|
const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
|
|
4736
4756
|
const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
|
|
4757
|
+
const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
4737
4758
|
const results = new Array(texts.length).fill(null);
|
|
4738
4759
|
const uncachedIndices = [];
|
|
4739
4760
|
const uncachedTexts = [];
|
|
4740
4761
|
for (let i = 0; i < texts.length; i++) {
|
|
4741
4762
|
if (cache) {
|
|
4742
4763
|
const cached = cache.get(texts[i]);
|
|
4743
|
-
|
|
4764
|
+
const cachedModel = cached && cachedEmbeddingModels.get(cached);
|
|
4765
|
+
if (cached && (cachedModel === void 0 || cachedModel === embeddingModel)) {
|
|
4744
4766
|
results[i] = Array.from(cached);
|
|
4745
4767
|
continue;
|
|
4746
4768
|
}
|
|
@@ -4756,7 +4778,6 @@ async function embedMany(texts, options, outer) {
|
|
|
4756
4778
|
...taskTypeHeader(options.taskType)
|
|
4757
4779
|
};
|
|
4758
4780
|
if (outer?.aborted) throw outer.reason;
|
|
4759
|
-
const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
4760
4781
|
let newEmbeddings;
|
|
4761
4782
|
if (uncachedTexts.length <= chunkSize) {
|
|
4762
4783
|
newEmbeddings = await generateEmbeddingsBatch(
|
|
@@ -4804,6 +4825,7 @@ async function embedMany(texts, options, outer) {
|
|
|
4804
4825
|
const f32Embedding = Float32Array.from(newEmbeddings[i]);
|
|
4805
4826
|
results[uncachedIndices[i]] = Array.from(f32Embedding);
|
|
4806
4827
|
if (cache) {
|
|
4828
|
+
cachedEmbeddingModels.set(f32Embedding, embeddingModel);
|
|
4807
4829
|
cache.set(uncachedTexts[i], f32Embedding);
|
|
4808
4830
|
}
|
|
4809
4831
|
}
|
|
@@ -19448,7 +19470,7 @@ var MaskScopedEmbeddingCache = class extends Map {
|
|
|
19448
19470
|
return this;
|
|
19449
19471
|
}
|
|
19450
19472
|
};
|
|
19451
|
-
var scopedViews =
|
|
19473
|
+
var { scopedViews } = getEmbeddingCacheState();
|
|
19452
19474
|
function maskScopedEmbeddingCache(cache, masked) {
|
|
19453
19475
|
const views = scopedViews.get(cache) ?? {};
|
|
19454
19476
|
scopedViews.set(cache, views);
|
|
@@ -19870,44 +19892,48 @@ async function recall(query, ctx, options = {}) {
|
|
|
19870
19892
|
embeddingOptions,
|
|
19871
19893
|
ctx.vaultCache,
|
|
19872
19894
|
searchOptions
|
|
19873
|
-
)))(
|
|
19874
|
-
|
|
19875
|
-
|
|
19876
|
-
|
|
19877
|
-
|
|
19878
|
-
|
|
19879
|
-
|
|
19880
|
-
|
|
19881
|
-
|
|
19882
|
-
|
|
19883
|
-
|
|
19884
|
-
|
|
19885
|
-
|
|
19886
|
-
|
|
19887
|
-
|
|
19888
|
-
|
|
19889
|
-
|
|
19890
|
-
|
|
19891
|
-
|
|
19892
|
-
|
|
19893
|
-
|
|
19894
|
-
|
|
19895
|
-
|
|
19896
|
-
|
|
19895
|
+
)))(
|
|
19896
|
+
query,
|
|
19897
|
+
{
|
|
19898
|
+
limit: types.includes("chunk") ? Math.max(limit * 2, 16) : limit,
|
|
19899
|
+
minSimilarity: vaultMinScore,
|
|
19900
|
+
useFusion: true,
|
|
19901
|
+
rerank: flags.rerank,
|
|
19902
|
+
...options.rerankTopN !== void 0 && { rerankTopN: options.rerankTopN },
|
|
19903
|
+
...options.ceWeight !== void 0 && { ceWeight: options.ceWeight },
|
|
19904
|
+
...options.rerankLoadTimeoutMs !== void 0 && {
|
|
19905
|
+
rerankLoadTimeoutMs: options.rerankLoadTimeoutMs
|
|
19906
|
+
},
|
|
19907
|
+
...options.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
|
|
19908
|
+
...options.recency && { recency: options.recency },
|
|
19909
|
+
...options.mmr !== void 0 && { mmr: options.mmr },
|
|
19910
|
+
...options.supersessionBoost !== void 0 && {
|
|
19911
|
+
supersessionBoost: options.supersessionBoost
|
|
19912
|
+
},
|
|
19913
|
+
...options.supersessionWindow !== void 0 && {
|
|
19914
|
+
supersessionWindow: options.supersessionWindow
|
|
19915
|
+
},
|
|
19916
|
+
...options.proofCountAlpha !== void 0 && {
|
|
19917
|
+
proofCountAlpha: options.proofCountAlpha
|
|
19918
|
+
},
|
|
19919
|
+
...options.bm25AdmissionDivisor !== void 0 && {
|
|
19920
|
+
bm25AdmissionDivisor: options.bm25AdmissionDivisor
|
|
19921
|
+
},
|
|
19922
|
+
...options.rrfK !== void 0 && { rrfK: options.rrfK },
|
|
19923
|
+
...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
|
|
19924
|
+
...subQueries && { subQueries },
|
|
19925
|
+
...options.scopes && { scopes: options.scopes },
|
|
19926
|
+
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
19927
|
+
...options.factTypes?.length && { factTypes: options.factTypes },
|
|
19928
|
+
...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
|
|
19929
|
+
...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
|
|
19930
|
+
...entityRanking.length > 0 && { entityRanking },
|
|
19931
|
+
...temporalRanking.length > 0 && { temporalRanking },
|
|
19932
|
+
...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
|
|
19933
|
+
queryEmbedTotalTimeoutMs
|
|
19897
19934
|
},
|
|
19898
|
-
|
|
19899
|
-
|
|
19900
|
-
...subQueries && { subQueries },
|
|
19901
|
-
...options.scopes && { scopes: options.scopes },
|
|
19902
|
-
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
19903
|
-
...options.factTypes?.length && { factTypes: options.factTypes },
|
|
19904
|
-
...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
|
|
19905
|
-
...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
|
|
19906
|
-
...entityRanking.length > 0 && { entityRanking },
|
|
19907
|
-
...temporalRanking.length > 0 && { temporalRanking },
|
|
19908
|
-
...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
|
|
19909
|
-
queryEmbedTotalTimeoutMs
|
|
19910
|
-
});
|
|
19935
|
+
options.embeddingCache
|
|
19936
|
+
);
|
|
19911
19937
|
factResults.push(
|
|
19912
19938
|
...dedupeBy(
|
|
19913
19939
|
results,
|
|
@@ -21046,10 +21072,19 @@ function createLocalMemoryStore(options) {
|
|
|
21046
21072
|
retainOptions
|
|
21047
21073
|
),
|
|
21048
21074
|
factSource: {
|
|
21049
|
-
search: (query, searchOptions) => searchVaultMemoriesWithSize(
|
|
21075
|
+
search: (query, searchOptions, embeddingCache) => searchVaultMemoriesWithSize(
|
|
21050
21076
|
query,
|
|
21051
21077
|
vaultCtx,
|
|
21052
|
-
{
|
|
21078
|
+
{
|
|
21079
|
+
...options.embeddingOptions,
|
|
21080
|
+
taskType: "memory_recall_embed",
|
|
21081
|
+
...embeddingCache && !options.embeddingOptions.cache && {
|
|
21082
|
+
cache: maskScopedEmbeddingCache(
|
|
21083
|
+
embeddingCache,
|
|
21084
|
+
Boolean(options.embeddingOptions.maskInput)
|
|
21085
|
+
)
|
|
21086
|
+
}
|
|
21087
|
+
},
|
|
21053
21088
|
vaultCache,
|
|
21054
21089
|
searchOptions
|
|
21055
21090
|
),
|
|
@@ -21679,7 +21714,7 @@ function stored(row) {
|
|
|
21679
21714
|
function createRemoteMemoryPipeline(options) {
|
|
21680
21715
|
const { persistence, embeddingOptions } = options;
|
|
21681
21716
|
const model = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
21682
|
-
const operation = (mode) => {
|
|
21717
|
+
const operation = (mode, queryOptions = embeddingOptions) => {
|
|
21683
21718
|
const rejectUndecryptable = (failed) => {
|
|
21684
21719
|
if (!failed.length) return;
|
|
21685
21720
|
if (mode === "retain")
|
|
@@ -21710,7 +21745,7 @@ function createRemoteMemoryPipeline(options) {
|
|
|
21710
21745
|
const start = Date.now();
|
|
21711
21746
|
const budgetMs = search.queryEmbedTotalTimeoutMs ?? 8e3;
|
|
21712
21747
|
const embed = (texts) => generateEmbeddings(texts, {
|
|
21713
|
-
...
|
|
21748
|
+
...queryOptions,
|
|
21714
21749
|
taskType: mode === "retain" ? "memory_retain_embed" : "memory_recall_embed",
|
|
21715
21750
|
totalTimeoutMs: budgetMs
|
|
21716
21751
|
});
|
|
@@ -21730,7 +21765,11 @@ function createRemoteMemoryPipeline(options) {
|
|
|
21730
21765
|
}
|
|
21731
21766
|
};
|
|
21732
21767
|
const [primary, facetEmbeddings] = await Promise.all([
|
|
21733
|
-
search.queryEmbedding ??
|
|
21768
|
+
search.queryEmbedding ?? (mode === "recall" && queryOptions.cache ? generateEmbedding(query, {
|
|
21769
|
+
...queryOptions,
|
|
21770
|
+
taskType: "memory_recall_embed",
|
|
21771
|
+
totalTimeoutMs: budgetMs
|
|
21772
|
+
}) : embed([query]).then((vectors2) => vectors2[0])),
|
|
21734
21773
|
embedFacets()
|
|
21735
21774
|
]);
|
|
21736
21775
|
const queryEmbedding = storedVector(primary);
|
|
@@ -21954,15 +21993,17 @@ function createRemoteMemoryPipeline(options) {
|
|
|
21954
21993
|
const factSource = {
|
|
21955
21994
|
graphRanking: options.graphRanking,
|
|
21956
21995
|
temporalRanking: options.temporalRanking,
|
|
21957
|
-
search: async (text14, searchOptions) => {
|
|
21958
|
-
const
|
|
21996
|
+
search: async (text14, searchOptions, embeddingCache) => {
|
|
21997
|
+
const queryOptions = {
|
|
21998
|
+
...embeddingOptions,
|
|
21999
|
+
taskType: "memory_recall_embed",
|
|
22000
|
+
...embeddingCache && !embeddingOptions.cache && {
|
|
22001
|
+
cache: maskScopedEmbeddingCache(embeddingCache, Boolean(embeddingOptions.maskInput))
|
|
22002
|
+
}
|
|
22003
|
+
};
|
|
22004
|
+
const { prepare } = operation("recall", queryOptions);
|
|
21959
22005
|
const prepared = await prepare(text14, searchOptions);
|
|
21960
|
-
const ranked = await rankPreparedVaultCandidates(
|
|
21961
|
-
text14,
|
|
21962
|
-
prepared,
|
|
21963
|
-
{ ...embeddingOptions, taskType: "memory_recall_embed" },
|
|
21964
|
-
searchOptions
|
|
21965
|
-
);
|
|
22006
|
+
const ranked = await rankPreparedVaultCandidates(text14, prepared, queryOptions, searchOptions);
|
|
21966
22007
|
return {
|
|
21967
22008
|
...ranked,
|
|
21968
22009
|
rankedOnCosine: prepared.memories.length > 0 && !prepared.embeddingsUnavailable,
|
package/dist/server/index.cjs
CHANGED
|
@@ -20138,6 +20138,24 @@ var postApiV1Embeddings = (options) => (options.client ?? client).post({
|
|
|
20138
20138
|
// src/lib/memoryEngine/generate.ts
|
|
20139
20139
|
init_clientConfig();
|
|
20140
20140
|
init_taskType();
|
|
20141
|
+
|
|
20142
|
+
// src/lib/memoryEngine/embeddingCacheState.ts
|
|
20143
|
+
var EMBEDDING_CACHE_STATE_KEY = /* @__PURE__ */ Symbol.for("@anuma/sdk/embedding-cache/v1");
|
|
20144
|
+
var cacheGlobal = globalThis;
|
|
20145
|
+
var fallbackState = {
|
|
20146
|
+
scopedViews: /* @__PURE__ */ new WeakMap(),
|
|
20147
|
+
inFlightByCache: /* @__PURE__ */ new WeakMap(),
|
|
20148
|
+
cachedEmbeddingModels: /* @__PURE__ */ new WeakMap()
|
|
20149
|
+
};
|
|
20150
|
+
function getEmbeddingCacheState() {
|
|
20151
|
+
try {
|
|
20152
|
+
return cacheGlobal[EMBEDDING_CACHE_STATE_KEY] ?? (cacheGlobal[EMBEDDING_CACHE_STATE_KEY] = fallbackState);
|
|
20153
|
+
} catch {
|
|
20154
|
+
return fallbackState;
|
|
20155
|
+
}
|
|
20156
|
+
}
|
|
20157
|
+
|
|
20158
|
+
// src/lib/memoryEngine/generate.ts
|
|
20141
20159
|
var EMBED_MAX_ATTEMPTS = 4;
|
|
20142
20160
|
var DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS = 15e3;
|
|
20143
20161
|
var DEFAULT_EMBEDDING_TOKEN_TIMEOUT_MS = 1e4;
|
|
@@ -20228,15 +20246,18 @@ async function generateEmbedding(text12, options) {
|
|
|
20228
20246
|
if (total === void 0) return embedOne(text12, options, void 0);
|
|
20229
20247
|
return withDeadline((signal) => embedOne(text12, options, signal), total, "embedding");
|
|
20230
20248
|
}
|
|
20231
|
-
var inFlightByCache
|
|
20249
|
+
var { inFlightByCache, cachedEmbeddingModels } = getEmbeddingCacheState();
|
|
20232
20250
|
async function embedOne(text12, options, outer) {
|
|
20233
20251
|
const { cache } = options;
|
|
20234
20252
|
if (!cache) return Array.from(await requestEmbedding(text12, options, outer));
|
|
20253
|
+
const model = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
20235
20254
|
const cached = cache.get(text12);
|
|
20236
|
-
|
|
20255
|
+
const cachedModel = cached && cachedEmbeddingModels.get(cached);
|
|
20256
|
+
if (cached && (cachedModel === void 0 || cachedModel === model)) return Array.from(cached);
|
|
20237
20257
|
const inFlight = inFlightByCache.get(cache) ?? /* @__PURE__ */ new Map();
|
|
20238
20258
|
inFlightByCache.set(cache, inFlight);
|
|
20239
|
-
const
|
|
20259
|
+
const requestKey = JSON.stringify([model, text12]);
|
|
20260
|
+
const pending = inFlight.get(requestKey);
|
|
20240
20261
|
if (pending) {
|
|
20241
20262
|
try {
|
|
20242
20263
|
return Array.from(await pending);
|
|
@@ -20245,13 +20266,14 @@ async function embedOne(text12, options, outer) {
|
|
|
20245
20266
|
}
|
|
20246
20267
|
}
|
|
20247
20268
|
const request = requestEmbedding(text12, options, outer);
|
|
20248
|
-
inFlight.set(
|
|
20269
|
+
inFlight.set(requestKey, request);
|
|
20249
20270
|
try {
|
|
20250
20271
|
const embedding = await request;
|
|
20272
|
+
cachedEmbeddingModels.set(embedding, model);
|
|
20251
20273
|
cache.set(text12, embedding);
|
|
20252
20274
|
return Array.from(embedding);
|
|
20253
20275
|
} finally {
|
|
20254
|
-
if (inFlight.get(
|
|
20276
|
+
if (inFlight.get(requestKey) === request) inFlight.delete(requestKey);
|
|
20255
20277
|
}
|
|
20256
20278
|
}
|
|
20257
20279
|
async function requestEmbedding(text12, options, outer) {
|
|
@@ -20334,13 +20356,15 @@ async function embedMany(texts, options, outer) {
|
|
|
20334
20356
|
const { baseUrl = BASE_URL, model, batchSize, cache } = options;
|
|
20335
20357
|
const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
|
|
20336
20358
|
const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
|
|
20359
|
+
const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
20337
20360
|
const results = new Array(texts.length).fill(null);
|
|
20338
20361
|
const uncachedIndices = [];
|
|
20339
20362
|
const uncachedTexts = [];
|
|
20340
20363
|
for (let i = 0; i < texts.length; i++) {
|
|
20341
20364
|
if (cache) {
|
|
20342
20365
|
const cached = cache.get(texts[i]);
|
|
20343
|
-
|
|
20366
|
+
const cachedModel = cached && cachedEmbeddingModels.get(cached);
|
|
20367
|
+
if (cached && (cachedModel === void 0 || cachedModel === embeddingModel)) {
|
|
20344
20368
|
results[i] = Array.from(cached);
|
|
20345
20369
|
continue;
|
|
20346
20370
|
}
|
|
@@ -20356,7 +20380,6 @@ async function embedMany(texts, options, outer) {
|
|
|
20356
20380
|
...taskTypeHeader(options.taskType)
|
|
20357
20381
|
};
|
|
20358
20382
|
if (outer?.aborted) throw outer.reason;
|
|
20359
|
-
const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
20360
20383
|
let newEmbeddings;
|
|
20361
20384
|
if (uncachedTexts.length <= chunkSize) {
|
|
20362
20385
|
newEmbeddings = await generateEmbeddingsBatch(
|
|
@@ -20404,6 +20427,7 @@ async function embedMany(texts, options, outer) {
|
|
|
20404
20427
|
const f32Embedding = Float32Array.from(newEmbeddings[i]);
|
|
20405
20428
|
results[uncachedIndices[i]] = Array.from(f32Embedding);
|
|
20406
20429
|
if (cache) {
|
|
20430
|
+
cachedEmbeddingModels.set(f32Embedding, embeddingModel);
|
|
20407
20431
|
cache.set(uncachedTexts[i], f32Embedding);
|
|
20408
20432
|
}
|
|
20409
20433
|
}
|
|
@@ -34246,7 +34270,7 @@ var MaskScopedEmbeddingCache = class extends Map {
|
|
|
34246
34270
|
return this;
|
|
34247
34271
|
}
|
|
34248
34272
|
};
|
|
34249
|
-
var scopedViews =
|
|
34273
|
+
var { scopedViews } = getEmbeddingCacheState();
|
|
34250
34274
|
function maskScopedEmbeddingCache(cache, masked) {
|
|
34251
34275
|
const views = scopedViews.get(cache) ?? {};
|
|
34252
34276
|
scopedViews.set(cache, views);
|
|
@@ -34671,44 +34695,48 @@ async function recall(query, ctx, options = {}) {
|
|
|
34671
34695
|
embeddingOptions,
|
|
34672
34696
|
ctx.vaultCache,
|
|
34673
34697
|
searchOptions
|
|
34674
|
-
)))(
|
|
34675
|
-
|
|
34676
|
-
|
|
34677
|
-
|
|
34678
|
-
|
|
34679
|
-
|
|
34680
|
-
|
|
34681
|
-
|
|
34682
|
-
|
|
34683
|
-
|
|
34684
|
-
|
|
34685
|
-
|
|
34686
|
-
|
|
34687
|
-
|
|
34688
|
-
|
|
34689
|
-
|
|
34690
|
-
|
|
34691
|
-
|
|
34692
|
-
|
|
34693
|
-
|
|
34694
|
-
|
|
34695
|
-
|
|
34696
|
-
|
|
34697
|
-
|
|
34698
|
+
)))(
|
|
34699
|
+
query,
|
|
34700
|
+
{
|
|
34701
|
+
limit: types.includes("chunk") ? Math.max(limit * 2, 16) : limit,
|
|
34702
|
+
minSimilarity: vaultMinScore,
|
|
34703
|
+
useFusion: true,
|
|
34704
|
+
rerank: flags.rerank,
|
|
34705
|
+
...options.rerankTopN !== void 0 && { rerankTopN: options.rerankTopN },
|
|
34706
|
+
...options.ceWeight !== void 0 && { ceWeight: options.ceWeight },
|
|
34707
|
+
...options.rerankLoadTimeoutMs !== void 0 && {
|
|
34708
|
+
rerankLoadTimeoutMs: options.rerankLoadTimeoutMs
|
|
34709
|
+
},
|
|
34710
|
+
...options.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
|
|
34711
|
+
...options.recency && { recency: options.recency },
|
|
34712
|
+
...options.mmr !== void 0 && { mmr: options.mmr },
|
|
34713
|
+
...options.supersessionBoost !== void 0 && {
|
|
34714
|
+
supersessionBoost: options.supersessionBoost
|
|
34715
|
+
},
|
|
34716
|
+
...options.supersessionWindow !== void 0 && {
|
|
34717
|
+
supersessionWindow: options.supersessionWindow
|
|
34718
|
+
},
|
|
34719
|
+
...options.proofCountAlpha !== void 0 && {
|
|
34720
|
+
proofCountAlpha: options.proofCountAlpha
|
|
34721
|
+
},
|
|
34722
|
+
...options.bm25AdmissionDivisor !== void 0 && {
|
|
34723
|
+
bm25AdmissionDivisor: options.bm25AdmissionDivisor
|
|
34724
|
+
},
|
|
34725
|
+
...options.rrfK !== void 0 && { rrfK: options.rrfK },
|
|
34726
|
+
...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
|
|
34727
|
+
...subQueries && { subQueries },
|
|
34728
|
+
...options.scopes && { scopes: options.scopes },
|
|
34729
|
+
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
34730
|
+
...options.factTypes?.length && { factTypes: options.factTypes },
|
|
34731
|
+
...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
|
|
34732
|
+
...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
|
|
34733
|
+
...entityRanking.length > 0 && { entityRanking },
|
|
34734
|
+
...temporalRanking.length > 0 && { temporalRanking },
|
|
34735
|
+
...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
|
|
34736
|
+
queryEmbedTotalTimeoutMs
|
|
34698
34737
|
},
|
|
34699
|
-
|
|
34700
|
-
|
|
34701
|
-
...subQueries && { subQueries },
|
|
34702
|
-
...options.scopes && { scopes: options.scopes },
|
|
34703
|
-
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
34704
|
-
...options.factTypes?.length && { factTypes: options.factTypes },
|
|
34705
|
-
...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
|
|
34706
|
-
...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
|
|
34707
|
-
...entityRanking.length > 0 && { entityRanking },
|
|
34708
|
-
...temporalRanking.length > 0 && { temporalRanking },
|
|
34709
|
-
...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
|
|
34710
|
-
queryEmbedTotalTimeoutMs
|
|
34711
|
-
});
|
|
34738
|
+
options.embeddingCache
|
|
34739
|
+
);
|
|
34712
34740
|
factResults.push(
|
|
34713
34741
|
...dedupeBy(
|
|
34714
34742
|
results,
|
|
@@ -35855,10 +35883,19 @@ function createLocalMemoryStore(options) {
|
|
|
35855
35883
|
retainOptions
|
|
35856
35884
|
),
|
|
35857
35885
|
factSource: {
|
|
35858
|
-
search: (query, searchOptions) => searchVaultMemoriesWithSize(
|
|
35886
|
+
search: (query, searchOptions, embeddingCache) => searchVaultMemoriesWithSize(
|
|
35859
35887
|
query,
|
|
35860
35888
|
vaultCtx,
|
|
35861
|
-
{
|
|
35889
|
+
{
|
|
35890
|
+
...options.embeddingOptions,
|
|
35891
|
+
taskType: "memory_recall_embed",
|
|
35892
|
+
...embeddingCache && !options.embeddingOptions.cache && {
|
|
35893
|
+
cache: maskScopedEmbeddingCache(
|
|
35894
|
+
embeddingCache,
|
|
35895
|
+
Boolean(options.embeddingOptions.maskInput)
|
|
35896
|
+
)
|
|
35897
|
+
}
|
|
35898
|
+
},
|
|
35862
35899
|
vaultCache,
|
|
35863
35900
|
searchOptions
|
|
35864
35901
|
),
|
package/dist/server/index.d.mts
CHANGED
|
@@ -4190,7 +4190,7 @@ interface RecallOptions {
|
|
|
4190
4190
|
}
|
|
4191
4191
|
/** A fact source supplies bounded candidates; recall owns ranking and result handling. */
|
|
4192
4192
|
interface RecallFactSource {
|
|
4193
|
-
search: (query: string, options?: MemoryVaultSearchOptions) => ReturnType<typeof searchVaultMemoriesWithSize>;
|
|
4193
|
+
search: (query: string, options?: MemoryVaultSearchOptions, embeddingCache?: Map<string, Float32Array>) => ReturnType<typeof searchVaultMemoriesWithSize>;
|
|
4194
4194
|
graphRanking: (query: string, traverse: boolean, options: RecallOptions) => Promise<string[]>;
|
|
4195
4195
|
temporalRanking: (query: string, now?: number) => Promise<string[]>;
|
|
4196
4196
|
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -4190,7 +4190,7 @@ interface RecallOptions {
|
|
|
4190
4190
|
}
|
|
4191
4191
|
/** A fact source supplies bounded candidates; recall owns ranking and result handling. */
|
|
4192
4192
|
interface RecallFactSource {
|
|
4193
|
-
search: (query: string, options?: MemoryVaultSearchOptions) => ReturnType<typeof searchVaultMemoriesWithSize>;
|
|
4193
|
+
search: (query: string, options?: MemoryVaultSearchOptions, embeddingCache?: Map<string, Float32Array>) => ReturnType<typeof searchVaultMemoriesWithSize>;
|
|
4194
4194
|
graphRanking: (query: string, traverse: boolean, options: RecallOptions) => Promise<string[]>;
|
|
4195
4195
|
temporalRanking: (query: string, now?: number) => Promise<string[]>;
|
|
4196
4196
|
}
|