@workglow/storage 0.0.102 → 0.0.103

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/browser.js CHANGED
@@ -1031,7 +1031,14 @@ class InMemoryKvStorage extends KvViaTabularStorage {
1031
1031
  }
1032
1032
  }
1033
1033
  // src/queue/InMemoryQueueStorage.ts
1034
- import { createServiceToken as createServiceToken9, EventEmitter as EventEmitter3, makeFingerprint as makeFingerprint4, sleep, uuid4 as uuid42 } from "@workglow/util";
1034
+ import {
1035
+ createServiceToken as createServiceToken9,
1036
+ EventEmitter as EventEmitter3,
1037
+ getLogger,
1038
+ makeFingerprint as makeFingerprint4,
1039
+ sleep,
1040
+ uuid4 as uuid42
1041
+ } from "@workglow/util";
1035
1042
 
1036
1043
  // src/queue/IQueueStorage.ts
1037
1044
  import { createServiceToken as createServiceToken8 } from "@workglow/util";
@@ -1125,11 +1132,23 @@ class InMemoryQueueStorage {
1125
1132
  await sleep(0);
1126
1133
  const job = this.jobQueue.find((j) => j.id === id && this.matchesPrefixes(j));
1127
1134
  if (!job) {
1128
- console.warn("Job not found for progress update", id);
1135
+ const jobWithAnyPrefix = this.jobQueue.find((j) => j.id === id);
1136
+ getLogger().warn("Job not found for progress update", {
1137
+ id,
1138
+ reason: jobWithAnyPrefix ? "prefix_mismatch" : "missing",
1139
+ existingStatus: jobWithAnyPrefix?.status,
1140
+ queueName: this.queueName,
1141
+ prefixValues: this.prefixValues
1142
+ });
1129
1143
  return;
1130
1144
  }
1131
1145
  if (job.status === JobStatus.COMPLETED || job.status === JobStatus.FAILED) {
1132
- console.warn("Job already completed or failed for progress update", id);
1146
+ getLogger().warn("Job already completed or failed for progress update", {
1147
+ id,
1148
+ status: job.status,
1149
+ completedAt: job.completed_at,
1150
+ error: job.error
1151
+ });
1133
1152
  return;
1134
1153
  }
1135
1154
  const oldJob = { ...job };
@@ -4740,6 +4759,105 @@ class SupabaseRateLimiterStorage {
4740
4759
  throw nextError;
4741
4760
  }
4742
4761
  }
4762
+ // src/vector/IndexedDbVectorStorage.ts
4763
+ import { cosineSimilarity as cosineSimilarity2, createServiceToken as createServiceToken21 } from "@workglow/util";
4764
+ var IDB_VECTOR_REPOSITORY = createServiceToken21("storage.vectorRepository.indexedDb");
4765
+ function matchesFilter2(metadata, filter) {
4766
+ for (const [key, value] of Object.entries(filter)) {
4767
+ if (metadata[key] !== value) {
4768
+ return false;
4769
+ }
4770
+ }
4771
+ return true;
4772
+ }
4773
+ function textRelevance2(text, query) {
4774
+ const textLower = text.toLowerCase();
4775
+ const queryLower = query.toLowerCase();
4776
+ const queryWords = queryLower.split(/\s+/).filter((w) => w.length > 0);
4777
+ if (queryWords.length === 0) {
4778
+ return 0;
4779
+ }
4780
+ let matches = 0;
4781
+ for (const word of queryWords) {
4782
+ if (textLower.includes(word)) {
4783
+ matches++;
4784
+ }
4785
+ }
4786
+ return matches / queryWords.length;
4787
+ }
4788
+
4789
+ class IndexedDbVectorStorage extends IndexedDbTabularStorage {
4790
+ vectorDimensions;
4791
+ VectorType;
4792
+ vectorPropertyName;
4793
+ metadataPropertyName;
4794
+ constructor(table = "vectors", schema, primaryKeyNames, indexes = [], dimensions, VectorType = Float32Array, migrationOptions = {}, clientProvidedKeys = "if-missing") {
4795
+ super(table, schema, primaryKeyNames, indexes, migrationOptions, clientProvidedKeys);
4796
+ this.vectorDimensions = dimensions;
4797
+ this.VectorType = VectorType;
4798
+ const vectorProp = getVectorProperty(schema);
4799
+ if (!vectorProp) {
4800
+ throw new Error("Schema must have a property with type array and format TypedArray");
4801
+ }
4802
+ this.vectorPropertyName = vectorProp;
4803
+ this.metadataPropertyName = getMetadataProperty(schema);
4804
+ }
4805
+ getVectorDimensions() {
4806
+ return this.vectorDimensions;
4807
+ }
4808
+ async similaritySearch(query, options = {}) {
4809
+ const { topK = 10, filter, scoreThreshold = 0 } = options;
4810
+ const results = [];
4811
+ const allEntities = await this.getAll() || [];
4812
+ for (const entity of allEntities) {
4813
+ const vector = entity[this.vectorPropertyName];
4814
+ const metadata = this.metadataPropertyName ? entity[this.metadataPropertyName] : {};
4815
+ if (filter && !matchesFilter2(metadata, filter)) {
4816
+ continue;
4817
+ }
4818
+ const score = cosineSimilarity2(query, vector);
4819
+ if (score < scoreThreshold) {
4820
+ continue;
4821
+ }
4822
+ results.push({
4823
+ ...entity,
4824
+ score
4825
+ });
4826
+ }
4827
+ results.sort((a, b) => b.score - a.score);
4828
+ const topResults = results.slice(0, topK);
4829
+ return topResults;
4830
+ }
4831
+ async hybridSearch(query, options) {
4832
+ const { topK = 10, filter, scoreThreshold = 0, textQuery, vectorWeight = 0.7 } = options;
4833
+ if (!textQuery || textQuery.trim().length === 0) {
4834
+ return this.similaritySearch(query, { topK, filter, scoreThreshold });
4835
+ }
4836
+ const results = [];
4837
+ const allEntities = await this.getAll() || [];
4838
+ for (const entity of allEntities) {
4839
+ const vector = entity[this.vectorPropertyName];
4840
+ const metadata = this.metadataPropertyName ? entity[this.metadataPropertyName] : {};
4841
+ if (filter && !matchesFilter2(metadata, filter)) {
4842
+ continue;
4843
+ }
4844
+ const vectorScore = cosineSimilarity2(query, vector);
4845
+ const metadataText = Object.values(metadata).join(" ").toLowerCase();
4846
+ const textScore = textRelevance2(metadataText, textQuery);
4847
+ const combinedScore = vectorWeight * vectorScore + (1 - vectorWeight) * textScore;
4848
+ if (combinedScore < scoreThreshold) {
4849
+ continue;
4850
+ }
4851
+ results.push({
4852
+ ...entity,
4853
+ score: combinedScore
4854
+ });
4855
+ }
4856
+ results.sort((a, b) => b.score - a.score);
4857
+ const topResults = results.slice(0, topK);
4858
+ return topResults;
4859
+ }
4860
+ }
4743
4861
  export {
4744
4862
  registerTabularRepository,
4745
4863
  isSearchCondition,
@@ -4770,6 +4888,7 @@ export {
4770
4888
  KvStorage,
4771
4889
  KV_REPOSITORY,
4772
4890
  JobStatus,
4891
+ IndexedDbVectorStorage,
4773
4892
  IndexedDbTabularStorage,
4774
4893
  IndexedDbRateLimiterStorage,
4775
4894
  IndexedDbQueueStorage,
@@ -4783,6 +4902,7 @@ export {
4783
4902
  IN_MEMORY_QUEUE_STORAGE,
4784
4903
  INDEXED_DB_RATE_LIMITER_STORAGE,
4785
4904
  INDEXED_DB_QUEUE_STORAGE,
4905
+ IDB_VECTOR_REPOSITORY,
4786
4906
  IDB_TABULAR_REPOSITORY,
4787
4907
  IDB_KV_REPOSITORY,
4788
4908
  HybridSubscriptionManager,
@@ -4795,4 +4915,4 @@ export {
4795
4915
  BaseTabularStorage
4796
4916
  };
4797
4917
 
4798
- //# debugId=B7E554C36B7CCFEF64756E2164756E21
4918
+ //# debugId=E59320A7A95CC7EE64756E2164756E21