@anuma/sdk 7.0.1 → 7.0.2

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/index.mjs CHANGED
@@ -1973,13 +1973,35 @@ async function generateEmbedding(text2, options) {
1973
1973
  if (total === void 0) return embedOne(text2, options, void 0);
1974
1974
  return withDeadline((signal) => embedOne(text2, options, signal), total, "embedding");
1975
1975
  }
1976
+ var inFlightByCache = /* @__PURE__ */ new WeakMap();
1976
1977
  async function embedOne(text2, options, outer) {
1977
- const { baseUrl = BASE_URL, model, cache } = options;
1978
- const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
1979
- if (cache) {
1980
- const cached = cache.get(text2);
1981
- if (cached) return Array.from(cached);
1978
+ const { cache } = options;
1979
+ if (!cache) return Array.from(await requestEmbedding(text2, options, outer));
1980
+ const cached = cache.get(text2);
1981
+ if (cached) return Array.from(cached);
1982
+ const inFlight = inFlightByCache.get(cache) ?? /* @__PURE__ */ new Map();
1983
+ inFlightByCache.set(cache, inFlight);
1984
+ const pending = inFlight.get(text2);
1985
+ if (pending) {
1986
+ try {
1987
+ return Array.from(await pending);
1988
+ } catch (err) {
1989
+ if (outer?.aborted) throw err;
1990
+ }
1991
+ }
1992
+ const request = requestEmbedding(text2, options, outer);
1993
+ inFlight.set(text2, request);
1994
+ try {
1995
+ const embedding = await request;
1996
+ cache.set(text2, embedding);
1997
+ return Array.from(embedding);
1998
+ } finally {
1999
+ if (inFlight.get(text2) === request) inFlight.delete(text2);
1982
2000
  }
2001
+ }
2002
+ async function requestEmbedding(text2, options, outer) {
2003
+ const { baseUrl = BASE_URL, model } = options;
2004
+ const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
1983
2005
  const headers = {
1984
2006
  ...await resolveAuthHeaders(options, outer),
1985
2007
  ...taskTypeHeader(options.taskType)
@@ -2014,11 +2036,7 @@ async function embedOne(text2, options, outer) {
2014
2036
  totalTokens: response.data.usage.total_tokens ?? 0
2015
2037
  });
2016
2038
  }
2017
- const f32Embedding = Float32Array.from(embedding);
2018
- if (cache) {
2019
- cache.set(text2, f32Embedding);
2020
- }
2021
- return Array.from(f32Embedding);
2039
+ return Float32Array.from(embedding);
2022
2040
  }
2023
2041
  var DEFAULT_EMBEDDING_BATCH_SIZE = 100;
2024
2042
  var DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
@@ -299,6 +299,8 @@ interface RankedMemory {
299
299
  updatedAt: Date;
300
300
  }
301
301
  interface RecallOptions {
302
+ /** Embedding cache shared with the rest of the turn, so the query is embedded once across lanes and the send. */
303
+ embeddingCache?: Map<string, Float32Array>;
302
304
  /** Which kinds to search. Default: ['fact']. */
303
305
  types?: MemoryKind[];
304
306
  /** Max items returned. Default: 8. */
@@ -554,6 +556,12 @@ interface RecallDiagnostics {
554
556
  * LEGACY read path this batch is uncapped, so it can be the whole vault.
555
557
  */
556
558
  vaultRowsEmbedded?: number;
559
+ /** Embedded messages the chunk lane considered; absent when the lane did not run. */
560
+ chunkRowsScanned?: number;
561
+ /** Messages whose vectors the chunk lane read from storage on a cache miss. */
562
+ chunkRowsFetched?: number;
563
+ /** Messages the chunk lane scored from the vector cache. */
564
+ chunkCacheHits?: number;
557
565
  /** Facts the fact lane returned (post-dedupe, pre-fusion). */
558
566
  factCount: number;
559
567
  /** Chunks the chunk lane returned (post-dedupe, pre-fusion). */
@@ -299,6 +299,8 @@ interface RankedMemory {
299
299
  updatedAt: Date;
300
300
  }
301
301
  interface RecallOptions {
302
+ /** Embedding cache shared with the rest of the turn, so the query is embedded once across lanes and the send. */
303
+ embeddingCache?: Map<string, Float32Array>;
302
304
  /** Which kinds to search. Default: ['fact']. */
303
305
  types?: MemoryKind[];
304
306
  /** Max items returned. Default: 8. */
@@ -554,6 +556,12 @@ interface RecallDiagnostics {
554
556
  * LEGACY read path this batch is uncapped, so it can be the whole vault.
555
557
  */
556
558
  vaultRowsEmbedded?: number;
559
+ /** Embedded messages the chunk lane considered; absent when the lane did not run. */
560
+ chunkRowsScanned?: number;
561
+ /** Messages whose vectors the chunk lane read from storage on a cache miss. */
562
+ chunkRowsFetched?: number;
563
+ /** Messages the chunk lane scored from the vector cache. */
564
+ chunkCacheHits?: number;
557
565
  /** Facts the fact lane returned (post-dedupe, pre-fusion). */
558
566
  factCount: number;
559
567
  /** Chunks the chunk lane returned (post-dedupe, pre-fusion). */