@anuma/sdk 7.0.0 → 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.
@@ -332,6 +332,12 @@ interface RecallDiagnostics {
332
332
  * LEGACY read path this batch is uncapped, so it can be the whole vault.
333
333
  */
334
334
  vaultRowsEmbedded?: number;
335
+ /** Embedded messages the chunk lane considered; absent when the lane did not run. */
336
+ chunkRowsScanned?: number;
337
+ /** Messages whose vectors the chunk lane read from storage on a cache miss. */
338
+ chunkRowsFetched?: number;
339
+ /** Messages the chunk lane scored from the vector cache. */
340
+ chunkCacheHits?: number;
335
341
  /** Facts the fact lane returned (post-dedupe, pre-fusion). */
336
342
  factCount: number;
337
343
  /** Chunks the chunk lane returned (post-dedupe, pre-fusion). */
@@ -332,6 +332,12 @@ interface RecallDiagnostics {
332
332
  * LEGACY read path this batch is uncapped, so it can be the whole vault.
333
333
  */
334
334
  vaultRowsEmbedded?: number;
335
+ /** Embedded messages the chunk lane considered; absent when the lane did not run. */
336
+ chunkRowsScanned?: number;
337
+ /** Messages whose vectors the chunk lane read from storage on a cache miss. */
338
+ chunkRowsFetched?: number;
339
+ /** Messages the chunk lane scored from the vector cache. */
340
+ chunkCacheHits?: number;
335
341
  /** Facts the fact lane returned (post-dedupe, pre-fusion). */
336
342
  factCount: number;
337
343
  /** Chunks the chunk lane returned (post-dedupe, pre-fusion). */
@@ -1018,13 +1018,35 @@ async function generateEmbedding(text, options) {
1018
1018
  if (total === void 0) return embedOne(text, options, void 0);
1019
1019
  return withDeadline((signal) => embedOne(text, options, signal), total, "embedding");
1020
1020
  }
1021
+ var inFlightByCache = /* @__PURE__ */ new WeakMap();
1021
1022
  async function embedOne(text, options, outer) {
1022
- const { baseUrl = BASE_URL, model, cache } = options;
1023
- const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
1024
- if (cache) {
1025
- const cached = cache.get(text);
1026
- if (cached) return Array.from(cached);
1023
+ const { cache } = options;
1024
+ if (!cache) return Array.from(await requestEmbedding(text, options, outer));
1025
+ const cached = cache.get(text);
1026
+ if (cached) return Array.from(cached);
1027
+ const inFlight = inFlightByCache.get(cache) ?? /* @__PURE__ */ new Map();
1028
+ inFlightByCache.set(cache, inFlight);
1029
+ const pending = inFlight.get(text);
1030
+ if (pending) {
1031
+ try {
1032
+ return Array.from(await pending);
1033
+ } catch (err) {
1034
+ if (outer?.aborted) throw err;
1035
+ }
1036
+ }
1037
+ const request = requestEmbedding(text, options, outer);
1038
+ inFlight.set(text, request);
1039
+ try {
1040
+ const embedding = await request;
1041
+ cache.set(text, embedding);
1042
+ return Array.from(embedding);
1043
+ } finally {
1044
+ if (inFlight.get(text) === request) inFlight.delete(text);
1027
1045
  }
1046
+ }
1047
+ async function requestEmbedding(text, options, outer) {
1048
+ const { baseUrl = BASE_URL, model } = options;
1049
+ const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
1028
1050
  const headers = {
1029
1051
  ...await resolveAuthHeaders(options, outer),
1030
1052
  ...taskTypeHeader(options.taskType)
@@ -1059,11 +1081,7 @@ async function embedOne(text, options, outer) {
1059
1081
  totalTokens: response.data.usage.total_tokens ?? 0
1060
1082
  });
1061
1083
  }
1062
- const f32Embedding = Float32Array.from(embedding);
1063
- if (cache) {
1064
- cache.set(text, f32Embedding);
1065
- }
1066
- return Array.from(f32Embedding);
1084
+ return Float32Array.from(embedding);
1067
1085
  }
1068
1086
  var DEFAULT_EMBEDDING_BATCH_SIZE = 100;
1069
1087
  var DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
@@ -896,13 +896,35 @@ async function generateEmbedding(text, options) {
896
896
  if (total === void 0) return embedOne(text, options, void 0);
897
897
  return withDeadline((signal) => embedOne(text, options, signal), total, "embedding");
898
898
  }
899
+ var inFlightByCache = /* @__PURE__ */ new WeakMap();
899
900
  async function embedOne(text, options, outer) {
900
- const { baseUrl = BASE_URL, model, cache } = options;
901
- const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
902
- if (cache) {
903
- const cached = cache.get(text);
904
- if (cached) return Array.from(cached);
901
+ const { cache } = options;
902
+ if (!cache) return Array.from(await requestEmbedding(text, options, outer));
903
+ const cached = cache.get(text);
904
+ if (cached) return Array.from(cached);
905
+ const inFlight = inFlightByCache.get(cache) ?? /* @__PURE__ */ new Map();
906
+ inFlightByCache.set(cache, inFlight);
907
+ const pending = inFlight.get(text);
908
+ if (pending) {
909
+ try {
910
+ return Array.from(await pending);
911
+ } catch (err) {
912
+ if (outer?.aborted) throw err;
913
+ }
914
+ }
915
+ const request = requestEmbedding(text, options, outer);
916
+ inFlight.set(text, request);
917
+ try {
918
+ const embedding = await request;
919
+ cache.set(text, embedding);
920
+ return Array.from(embedding);
921
+ } finally {
922
+ if (inFlight.get(text) === request) inFlight.delete(text);
905
923
  }
924
+ }
925
+ async function requestEmbedding(text, options, outer) {
926
+ const { baseUrl = BASE_URL, model } = options;
927
+ const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
906
928
  const headers = {
907
929
  ...await resolveAuthHeaders(options, outer),
908
930
  ...taskTypeHeader(options.taskType)
@@ -937,11 +959,7 @@ async function embedOne(text, options, outer) {
937
959
  totalTokens: response.data.usage.total_tokens ?? 0
938
960
  });
939
961
  }
940
- const f32Embedding = Float32Array.from(embedding);
941
- if (cache) {
942
- cache.set(text, f32Embedding);
943
- }
944
- return Array.from(f32Embedding);
962
+ return Float32Array.from(embedding);
945
963
  }
946
964
  var DEFAULT_EMBEDDING_BATCH_SIZE = 100;
947
965
  var DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "7.0.0",
3
+ "version": "7.0.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",