@workglow/storage 0.0.101 → 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/bun.js CHANGED
@@ -190,11 +190,12 @@ class BaseTabularStorage {
190
190
  const valueNames = this.valueColumns();
191
191
  const value = {};
192
192
  const key = {};
193
+ const objRecord = obj;
193
194
  for (const k of primaryKeyNames) {
194
- key[k] = obj[k];
195
+ key[k] = objRecord[k];
195
196
  }
196
197
  for (const k of valueNames) {
197
- value[k] = obj[k];
198
+ value[k] = objRecord[k];
198
199
  }
199
200
  return { value, key };
200
201
  }
@@ -1031,7 +1032,14 @@ class InMemoryKvStorage extends KvViaTabularStorage {
1031
1032
  }
1032
1033
  }
1033
1034
  // src/queue/InMemoryQueueStorage.ts
1034
- import { createServiceToken as createServiceToken9, EventEmitter as EventEmitter3, makeFingerprint as makeFingerprint4, sleep, uuid4 as uuid42 } from "@workglow/util";
1035
+ import {
1036
+ createServiceToken as createServiceToken9,
1037
+ EventEmitter as EventEmitter3,
1038
+ getLogger,
1039
+ makeFingerprint as makeFingerprint4,
1040
+ sleep,
1041
+ uuid4 as uuid42
1042
+ } from "@workglow/util";
1035
1043
 
1036
1044
  // src/queue/IQueueStorage.ts
1037
1045
  import { createServiceToken as createServiceToken8 } from "@workglow/util";
@@ -1125,11 +1133,23 @@ class InMemoryQueueStorage {
1125
1133
  await sleep(0);
1126
1134
  const job = this.jobQueue.find((j) => j.id === id && this.matchesPrefixes(j));
1127
1135
  if (!job) {
1128
- console.warn("Job not found for progress update", id);
1136
+ const jobWithAnyPrefix = this.jobQueue.find((j) => j.id === id);
1137
+ getLogger().warn("Job not found for progress update", {
1138
+ id,
1139
+ reason: jobWithAnyPrefix ? "prefix_mismatch" : "missing",
1140
+ existingStatus: jobWithAnyPrefix?.status,
1141
+ queueName: this.queueName,
1142
+ prefixValues: this.prefixValues
1143
+ });
1129
1144
  return;
1130
1145
  }
1131
1146
  if (job.status === JobStatus.COMPLETED || job.status === JobStatus.FAILED) {
1132
- console.warn("Job already completed or failed for progress update", id);
1147
+ getLogger().warn("Job already completed or failed for progress update", {
1148
+ id,
1149
+ status: job.status,
1150
+ completedAt: job.completed_at,
1151
+ error: job.error
1152
+ });
1133
1153
  return;
1134
1154
  }
1135
1155
  const oldJob = { ...job };
@@ -2003,17 +2023,16 @@ class BaseSqlTabularStorage extends BaseTabularStorage {
2003
2023
  return value;
2004
2024
  }
2005
2025
  if (actualType.contentEncoding === "blob") {
2006
- const v = value;
2007
- if (v instanceof Uint8Array) {
2008
- return v;
2026
+ if (value instanceof Uint8Array) {
2027
+ return value;
2009
2028
  }
2010
- if (typeof Buffer !== "undefined" && v instanceof Buffer) {
2011
- return new Uint8Array(v);
2029
+ if (typeof Buffer !== "undefined" && value instanceof Buffer) {
2030
+ return new Uint8Array(value);
2012
2031
  }
2013
- if (Array.isArray(v)) {
2014
- return new Uint8Array(v);
2032
+ if (Array.isArray(value)) {
2033
+ return new Uint8Array(value);
2015
2034
  }
2016
- return v;
2035
+ return value;
2017
2036
  } else if (value instanceof Date) {
2018
2037
  return value.toISOString();
2019
2038
  } else {
@@ -2033,14 +2052,13 @@ class BaseSqlTabularStorage extends BaseTabularStorage {
2033
2052
  return value;
2034
2053
  }
2035
2054
  if (actualType.contentEncoding === "blob") {
2036
- const v = value;
2037
- if (typeof Buffer !== "undefined" && v instanceof Buffer) {
2038
- return new Uint8Array(v);
2055
+ if (typeof Buffer !== "undefined" && value instanceof Buffer) {
2056
+ return new Uint8Array(value);
2039
2057
  }
2040
- if (v instanceof Uint8Array) {
2041
- return v;
2058
+ if (value instanceof Uint8Array) {
2059
+ return value;
2042
2060
  }
2043
- return v;
2061
+ return value;
2044
2062
  } else {
2045
2063
  return value;
2046
2064
  }
@@ -2283,11 +2301,10 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2283
2301
  }
2284
2302
  }
2285
2303
  if (typeof actualType !== "boolean" && (actualType.type === "number" || actualType.type === "integer")) {
2286
- const v = value;
2287
- if (typeof v === "number")
2288
- return v;
2289
- if (typeof v === "string") {
2290
- const parsed = Number(v);
2304
+ if (typeof value === "number")
2305
+ return value;
2306
+ if (typeof value === "string") {
2307
+ const parsed = Number(value);
2291
2308
  if (!isNaN(parsed))
2292
2309
  return parsed;
2293
2310
  }
@@ -2350,10 +2367,11 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2350
2367
  const paramsToInsert = [];
2351
2368
  let paramIndex = 1;
2352
2369
  const pkColumns = this.primaryKeyColumns();
2370
+ const entityRecord = entity;
2353
2371
  for (const col of pkColumns) {
2354
2372
  const colStr = String(col);
2355
2373
  if (this.isAutoGeneratedKey(colStr)) {
2356
- const clientProvidedValue = entity[col];
2374
+ const clientProvidedValue = entityRecord[colStr];
2357
2375
  const hasClientValue = clientProvidedValue !== undefined && clientProvidedValue !== null;
2358
2376
  let shouldUseClientValue = false;
2359
2377
  if (this.clientProvidedKeys === "never") {
@@ -2373,14 +2391,14 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2373
2391
  continue;
2374
2392
  }
2375
2393
  columnsToInsert.push(colStr);
2376
- const value = entity[col];
2394
+ const value = entityRecord[colStr];
2377
2395
  paramsToInsert.push(this.jsToSqlValue(colStr, value));
2378
2396
  }
2379
2397
  const valueColumns = this.valueColumns();
2380
2398
  for (const col of valueColumns) {
2381
2399
  const colStr = String(col);
2382
2400
  columnsToInsert.push(colStr);
2383
- const value = entity[col];
2401
+ const value = entityRecord[colStr];
2384
2402
  paramsToInsert.push(this.jsToSqlValue(colStr, value));
2385
2403
  }
2386
2404
  const columnList = columnsToInsert.map((c) => `"${c}"`).join(", ");
@@ -2402,8 +2420,9 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2402
2420
  const params = paramsToInsert;
2403
2421
  const result = await db.query(sql, params);
2404
2422
  const updatedEntity = result.rows[0];
2423
+ const updatedRecord = updatedEntity;
2405
2424
  for (const key in this.schema.properties) {
2406
- updatedEntity[key] = this.sqlToJsValue(key, updatedEntity[key]);
2425
+ updatedRecord[key] = this.sqlToJsValue(key, updatedRecord[key]);
2407
2426
  }
2408
2427
  this.events.emit("put", updatedEntity);
2409
2428
  return updatedEntity;
@@ -2422,8 +2441,9 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2422
2441
  let val;
2423
2442
  if (result.rows.length > 0) {
2424
2443
  val = result.rows[0];
2444
+ const valRecord = val;
2425
2445
  for (const key2 in this.schema.properties) {
2426
- val[key2] = this.sqlToJsValue(key2, val[key2]);
2446
+ valRecord[key2] = this.sqlToJsValue(key2, valRecord[key2]);
2427
2447
  }
2428
2448
  } else {
2429
2449
  val = undefined;
@@ -2452,8 +2472,9 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2452
2472
  const result = await db.query(sql, whereClauseValues);
2453
2473
  if (result.rows.length > 0) {
2454
2474
  for (const row of result.rows) {
2475
+ const record = row;
2455
2476
  for (const k in this.schema.properties) {
2456
- row[k] = this.sqlToJsValue(k, row[k]);
2477
+ record[k] = this.sqlToJsValue(k, record[k]);
2457
2478
  }
2458
2479
  }
2459
2480
  this.events.emit("search", key, result.rows);
@@ -2477,8 +2498,9 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2477
2498
  const result = await db.query(sql);
2478
2499
  if (result.rows.length > 0) {
2479
2500
  for (const row of result.rows) {
2501
+ const record = row;
2480
2502
  for (const key in this.schema.properties) {
2481
- row[key] = this.sqlToJsValue(key, row[key]);
2503
+ record[key] = this.sqlToJsValue(key, record[key]);
2482
2504
  }
2483
2505
  }
2484
2506
  return result.rows;
@@ -2503,8 +2525,9 @@ class PostgresTabularStorage extends BaseSqlTabularStorage {
2503
2525
  return;
2504
2526
  }
2505
2527
  for (const row of result.rows) {
2528
+ const record = row;
2506
2529
  for (const key in this.schema.properties) {
2507
- row[key] = this.sqlToJsValue(key, row[key]);
2530
+ record[key] = this.sqlToJsValue(key, record[key]);
2508
2531
  }
2509
2532
  }
2510
2533
  return result.rows;
@@ -2644,13 +2667,12 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2644
2667
  const isArray = typeDef === true || typeof actualType !== "boolean" && actualType.type === "array";
2645
2668
  const isBoolean = typeDef === true || typeof actualType !== "boolean" && actualType.type === "boolean";
2646
2669
  if (isBoolean) {
2647
- const v = value;
2648
- if (typeof v === "boolean")
2649
- return v ? 1 : 0;
2650
- if (typeof v === "number")
2651
- return v ? 1 : 0;
2652
- if (typeof v === "string")
2653
- return v === "1" || v.toLowerCase() === "true" ? 1 : 0;
2670
+ if (typeof value === "boolean")
2671
+ return value ? 1 : 0;
2672
+ if (typeof value === "number")
2673
+ return value ? 1 : 0;
2674
+ if (typeof value === "string")
2675
+ return value === "1" || value.toLowerCase() === "true" ? 1 : 0;
2654
2676
  }
2655
2677
  if ((isObject || isArray) && value !== null && typeof value === "object") {
2656
2678
  if (!(value instanceof Date) && !(value instanceof Uint8Array) && (typeof Buffer === "undefined" || !(value instanceof Buffer))) {
@@ -2680,13 +2702,12 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2680
2702
  const isArray = typeDef === true || typeof actualType !== "boolean" && actualType.type === "array";
2681
2703
  const isBoolean = typeDef === true || typeof actualType !== "boolean" && actualType.type === "boolean";
2682
2704
  if (isBoolean) {
2683
- const v = value;
2684
- if (typeof v === "boolean")
2685
- return v;
2686
- if (typeof v === "number")
2687
- return v !== 0 ? true : false;
2688
- if (typeof v === "string")
2689
- return v === "1" || v.toLowerCase() === "true" ? true : false;
2705
+ if (typeof value === "boolean")
2706
+ return value;
2707
+ if (typeof value === "number")
2708
+ return value !== 0 ? true : false;
2709
+ if (typeof value === "string")
2710
+ return value === "1" || value.toLowerCase() === "true" ? true : false;
2690
2711
  }
2691
2712
  if (isArray || isObject) {
2692
2713
  if (typeof value === "string") {
@@ -2744,7 +2765,8 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2744
2765
  let entityToInsert = entity;
2745
2766
  if (this.hasAutoGeneratedKey() && this.autoGeneratedKeyName) {
2746
2767
  const keyName = String(this.autoGeneratedKeyName);
2747
- const clientProvidedValue = entity[keyName];
2768
+ const entityRecord = entity;
2769
+ const clientProvidedValue = entityRecord[keyName];
2748
2770
  const hasClientValue = clientProvidedValue !== undefined && clientProvidedValue !== null;
2749
2771
  let shouldUseClientValue = false;
2750
2772
  if (this.clientProvidedKeys === "never") {
@@ -2770,7 +2792,8 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2770
2792
  for (const col of pkColumns) {
2771
2793
  const colStr = String(col);
2772
2794
  if (this.isAutoGeneratedKey(colStr) && this.autoGeneratedKeyStrategy === "autoincrement" && this.clientProvidedKeys !== "always") {
2773
- const clientProvidedValue = entityToInsert[colStr];
2795
+ const insertRecord2 = entityToInsert;
2796
+ const clientProvidedValue = insertRecord2[colStr];
2774
2797
  const hasClientValue = clientProvidedValue !== undefined && clientProvidedValue !== null;
2775
2798
  if (this.clientProvidedKeys === "if-missing" && hasClientValue) {
2776
2799
  columnsToInsert.push(colStr);
@@ -2783,10 +2806,11 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2783
2806
  paramsToInsert.push(this.jsToSqlValue(colStr, value));
2784
2807
  }
2785
2808
  const valueColumns = this.valueColumns();
2809
+ const insertRecord = entityToInsert;
2786
2810
  for (const col of valueColumns) {
2787
2811
  const colStr = String(col);
2788
2812
  columnsToInsert.push(colStr);
2789
- const value = entityToInsert[colStr];
2813
+ const value = insertRecord[colStr];
2790
2814
  paramsToInsert.push(this.jsToSqlValue(colStr, value));
2791
2815
  }
2792
2816
  const columnList = columnsToInsert.map((c) => `\`${c}\``).join(", ");
@@ -2843,8 +2867,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2843
2867
  throw new Error(`Invalid SQLite params detected at indices: ${invalidParams.map((p) => p.index).join(", ")}`);
2844
2868
  }
2845
2869
  const updatedEntity = stmt.get(...params);
2870
+ const updatedRecord = updatedEntity;
2846
2871
  for (const k in this.schema.properties) {
2847
- updatedEntity[k] = this.sqlToJsValue(k, updatedEntity[k]);
2872
+ updatedRecord[k] = this.sqlToJsValue(k, updatedRecord[k]);
2848
2873
  }
2849
2874
  this.events.emit("put", updatedEntity);
2850
2875
  return updatedEntity;
@@ -2864,8 +2889,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2864
2889
  const params = this.getPrimaryKeyAsOrderedArray(key);
2865
2890
  const value = stmt.get(...params);
2866
2891
  if (value) {
2892
+ const row = value;
2867
2893
  for (const k in this.schema.properties) {
2868
- value[k] = this.sqlToJsValue(k, value[k]);
2894
+ row[k] = this.sqlToJsValue(k, row[k]);
2869
2895
  }
2870
2896
  this.events.emit("get", key, value);
2871
2897
  return value;
@@ -2896,8 +2922,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2896
2922
  const result = stmt.all(...whereClauseValues);
2897
2923
  if (result.length > 0) {
2898
2924
  for (const row of result) {
2925
+ const record = row;
2899
2926
  for (const k in this.schema.properties) {
2900
- row[k] = this.sqlToJsValue(k, row[k]);
2927
+ record[k] = this.sqlToJsValue(k, record[k]);
2901
2928
  }
2902
2929
  }
2903
2930
  this.events.emit("search", key, result);
@@ -2923,8 +2950,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2923
2950
  if (!value.length)
2924
2951
  return;
2925
2952
  for (const row of value) {
2953
+ const record = row;
2926
2954
  for (const k in this.schema.properties) {
2927
- row[k] = this.sqlToJsValue(k, row[k]);
2955
+ record[k] = this.sqlToJsValue(k, record[k]);
2928
2956
  }
2929
2957
  }
2930
2958
  return value;
@@ -2952,8 +2980,9 @@ class SqliteTabularStorage extends BaseSqlTabularStorage {
2952
2980
  return;
2953
2981
  }
2954
2982
  for (const row of rows) {
2983
+ const record = row;
2955
2984
  for (const k in this.schema.properties) {
2956
- row[k] = this.sqlToJsValue(k, row[k]);
2985
+ record[k] = this.sqlToJsValue(k, record[k]);
2957
2986
  }
2958
2987
  }
2959
2988
  return rows;
@@ -3184,11 +3213,10 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3184
3213
  }
3185
3214
  const actualType = this.getNonNullType(typeDef);
3186
3215
  if (typeof actualType !== "boolean" && (actualType.type === "number" || actualType.type === "integer")) {
3187
- const v = value;
3188
- if (typeof v === "number")
3189
- return v;
3190
- if (typeof v === "string") {
3191
- const parsed = Number(v);
3216
+ if (typeof value === "number")
3217
+ return value;
3218
+ if (typeof value === "string") {
3219
+ const parsed = Number(value);
3192
3220
  if (!isNaN(parsed))
3193
3221
  return parsed;
3194
3222
  }
@@ -3210,7 +3238,8 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3210
3238
  let entityToInsert = { ...entity };
3211
3239
  if (this.hasAutoGeneratedKey() && this.autoGeneratedKeyName) {
3212
3240
  const keyName = String(this.autoGeneratedKeyName);
3213
- const clientProvidedValue = entity[keyName];
3241
+ const entityRecord = entity;
3242
+ const clientProvidedValue = entityRecord[keyName];
3214
3243
  const hasClientValue = clientProvidedValue !== undefined && clientProvidedValue !== null;
3215
3244
  let shouldOmitKey = false;
3216
3245
  if (this.clientProvidedKeys === "never") {
@@ -3240,8 +3269,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3240
3269
  if (error)
3241
3270
  throw error;
3242
3271
  const updatedEntity = data;
3272
+ const updatedRecord = updatedEntity;
3243
3273
  for (const key in this.schema.properties) {
3244
- updatedEntity[key] = this.sqlToJsValue(key, updatedEntity[key]);
3274
+ updatedRecord[key] = this.sqlToJsValue(key, updatedRecord[key]);
3245
3275
  }
3246
3276
  this.events.emit("put", updatedEntity);
3247
3277
  return updatedEntity;
@@ -3253,8 +3283,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3253
3283
  }
3254
3284
  async get(key) {
3255
3285
  let query = this.client.from(this.table).select("*");
3286
+ const keyRecord = key;
3256
3287
  for (const pkName of this.primaryKeyNames) {
3257
- query = query.eq(String(pkName), key[pkName]);
3288
+ query = query.eq(String(pkName), keyRecord[String(pkName)]);
3258
3289
  }
3259
3290
  const { data, error } = await query.single();
3260
3291
  if (error) {
@@ -3266,8 +3297,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3266
3297
  }
3267
3298
  const val = data;
3268
3299
  if (val) {
3300
+ const valRecord = val;
3269
3301
  for (const key2 in this.schema.properties) {
3270
- val[key2] = this.sqlToJsValue(key2, val[key2]);
3302
+ valRecord[key2] = this.sqlToJsValue(key2, valRecord[key2]);
3271
3303
  }
3272
3304
  }
3273
3305
  this.events.emit("get", key, val);
@@ -3296,8 +3328,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3296
3328
  throw error;
3297
3329
  if (data && data.length > 0) {
3298
3330
  for (const row of data) {
3331
+ const record = row;
3299
3332
  for (const key in this.schema.properties) {
3300
- row[key] = this.sqlToJsValue(key, row[key]);
3333
+ record[key] = this.sqlToJsValue(key, record[key]);
3301
3334
  }
3302
3335
  }
3303
3336
  this.events.emit("search", searchCriteria, data);
@@ -3310,8 +3343,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3310
3343
  async delete(value) {
3311
3344
  const { key } = this.separateKeyValueFromCombined(value);
3312
3345
  let query = this.client.from(this.table).delete();
3346
+ const deleteKeyRecord = key;
3313
3347
  for (const pkName of this.primaryKeyNames) {
3314
- query = query.eq(String(pkName), key[pkName]);
3348
+ query = query.eq(String(pkName), deleteKeyRecord[String(pkName)]);
3315
3349
  }
3316
3350
  const { error } = await query;
3317
3351
  if (error)
@@ -3324,8 +3358,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3324
3358
  throw error;
3325
3359
  if (data && data.length) {
3326
3360
  for (const row of data) {
3361
+ const record = row;
3327
3362
  for (const key in this.schema.properties) {
3328
- row[key] = this.sqlToJsValue(key, row[key]);
3363
+ record[key] = this.sqlToJsValue(key, record[key]);
3329
3364
  }
3330
3365
  }
3331
3366
  return data;
@@ -3357,8 +3392,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3357
3392
  return;
3358
3393
  }
3359
3394
  for (const row of data) {
3395
+ const record = row;
3360
3396
  for (const key in this.schema.properties) {
3361
- row[key] = this.sqlToJsValue(key, row[key]);
3397
+ record[key] = this.sqlToJsValue(key, record[key]);
3362
3398
  }
3363
3399
  }
3364
3400
  return data;
@@ -3407,8 +3443,9 @@ class SupabaseTabularStorage extends BaseSqlTabularStorage {
3407
3443
  }
3408
3444
  convertRealtimeRow(row) {
3409
3445
  const entity = { ...row };
3446
+ const record = entity;
3410
3447
  for (const key in this.schema.properties) {
3411
- entity[key] = this.sqlToJsValue(key, row[key]);
3448
+ record[key] = this.sqlToJsValue(key, row[key]);
3412
3449
  }
3413
3450
  return entity;
3414
3451
  }
@@ -7071,6 +7108,105 @@ class IndexedDbQueueStorage {
7071
7108
  }
7072
7109
  }
7073
7110
  }
7111
+ // src/vector/IndexedDbVectorStorage.ts
7112
+ import { cosineSimilarity as cosineSimilarity4, createServiceToken as createServiceToken31 } from "@workglow/util";
7113
+ var IDB_VECTOR_REPOSITORY = createServiceToken31("storage.vectorRepository.indexedDb");
7114
+ function matchesFilter3(metadata, filter) {
7115
+ for (const [key, value] of Object.entries(filter)) {
7116
+ if (metadata[key] !== value) {
7117
+ return false;
7118
+ }
7119
+ }
7120
+ return true;
7121
+ }
7122
+ function textRelevance2(text, query) {
7123
+ const textLower = text.toLowerCase();
7124
+ const queryLower = query.toLowerCase();
7125
+ const queryWords = queryLower.split(/\s+/).filter((w) => w.length > 0);
7126
+ if (queryWords.length === 0) {
7127
+ return 0;
7128
+ }
7129
+ let matches = 0;
7130
+ for (const word of queryWords) {
7131
+ if (textLower.includes(word)) {
7132
+ matches++;
7133
+ }
7134
+ }
7135
+ return matches / queryWords.length;
7136
+ }
7137
+
7138
+ class IndexedDbVectorStorage extends IndexedDbTabularStorage {
7139
+ vectorDimensions;
7140
+ VectorType;
7141
+ vectorPropertyName;
7142
+ metadataPropertyName;
7143
+ constructor(table = "vectors", schema, primaryKeyNames, indexes = [], dimensions, VectorType = Float32Array, migrationOptions = {}, clientProvidedKeys = "if-missing") {
7144
+ super(table, schema, primaryKeyNames, indexes, migrationOptions, clientProvidedKeys);
7145
+ this.vectorDimensions = dimensions;
7146
+ this.VectorType = VectorType;
7147
+ const vectorProp = getVectorProperty(schema);
7148
+ if (!vectorProp) {
7149
+ throw new Error("Schema must have a property with type array and format TypedArray");
7150
+ }
7151
+ this.vectorPropertyName = vectorProp;
7152
+ this.metadataPropertyName = getMetadataProperty(schema);
7153
+ }
7154
+ getVectorDimensions() {
7155
+ return this.vectorDimensions;
7156
+ }
7157
+ async similaritySearch(query, options = {}) {
7158
+ const { topK = 10, filter, scoreThreshold = 0 } = options;
7159
+ const results = [];
7160
+ const allEntities = await this.getAll() || [];
7161
+ for (const entity of allEntities) {
7162
+ const vector = entity[this.vectorPropertyName];
7163
+ const metadata = this.metadataPropertyName ? entity[this.metadataPropertyName] : {};
7164
+ if (filter && !matchesFilter3(metadata, filter)) {
7165
+ continue;
7166
+ }
7167
+ const score = cosineSimilarity4(query, vector);
7168
+ if (score < scoreThreshold) {
7169
+ continue;
7170
+ }
7171
+ results.push({
7172
+ ...entity,
7173
+ score
7174
+ });
7175
+ }
7176
+ results.sort((a, b) => b.score - a.score);
7177
+ const topResults = results.slice(0, topK);
7178
+ return topResults;
7179
+ }
7180
+ async hybridSearch(query, options) {
7181
+ const { topK = 10, filter, scoreThreshold = 0, textQuery, vectorWeight = 0.7 } = options;
7182
+ if (!textQuery || textQuery.trim().length === 0) {
7183
+ return this.similaritySearch(query, { topK, filter, scoreThreshold });
7184
+ }
7185
+ const results = [];
7186
+ const allEntities = await this.getAll() || [];
7187
+ for (const entity of allEntities) {
7188
+ const vector = entity[this.vectorPropertyName];
7189
+ const metadata = this.metadataPropertyName ? entity[this.metadataPropertyName] : {};
7190
+ if (filter && !matchesFilter3(metadata, filter)) {
7191
+ continue;
7192
+ }
7193
+ const vectorScore = cosineSimilarity4(query, vector);
7194
+ const metadataText = Object.values(metadata).join(" ").toLowerCase();
7195
+ const textScore = textRelevance2(metadataText, textQuery);
7196
+ const combinedScore = vectorWeight * vectorScore + (1 - vectorWeight) * textScore;
7197
+ if (combinedScore < scoreThreshold) {
7198
+ continue;
7199
+ }
7200
+ results.push({
7201
+ ...entity,
7202
+ score: combinedScore
7203
+ });
7204
+ }
7205
+ results.sort((a, b) => b.score - a.score);
7206
+ const topResults = results.slice(0, topK);
7207
+ return topResults;
7208
+ }
7209
+ }
7074
7210
  export {
7075
7211
  registerTabularRepository,
7076
7212
  isSearchCondition,
@@ -7117,6 +7253,7 @@ export {
7117
7253
  KvStorage,
7118
7254
  KV_REPOSITORY,
7119
7255
  JobStatus,
7256
+ IndexedDbVectorStorage,
7120
7257
  IndexedDbTabularStorage,
7121
7258
  IndexedDbRateLimiterStorage,
7122
7259
  IndexedDbQueueStorage,
@@ -7130,6 +7267,7 @@ export {
7130
7267
  IN_MEMORY_QUEUE_STORAGE,
7131
7268
  INDEXED_DB_RATE_LIMITER_STORAGE,
7132
7269
  INDEXED_DB_QUEUE_STORAGE,
7270
+ IDB_VECTOR_REPOSITORY,
7133
7271
  IDB_TABULAR_REPOSITORY,
7134
7272
  IDB_KV_REPOSITORY,
7135
7273
  HybridSubscriptionManager,
@@ -7148,4 +7286,4 @@ export {
7148
7286
  BaseTabularStorage
7149
7287
  };
7150
7288
 
7151
- //# debugId=3F19856BE0970CD364756E2164756E21
7289
+ //# debugId=DB5310BD3588935D64756E2164756E21