@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 +124 -4
- package/dist/browser.js.map +10 -9
- package/dist/bun.js +124 -4
- package/dist/bun.js.map +11 -10
- package/dist/common-server.d.ts +1 -0
- package/dist/common-server.d.ts.map +1 -1
- package/dist/kv/InMemoryKvStorage.d.ts.map +1 -1
- package/dist/kv/KvStorage.d.ts.map +1 -1
- package/dist/node.js +124 -4
- package/dist/node.js.map +11 -10
- package/dist/queue/InMemoryQueueStorage.d.ts.map +1 -1
- package/dist/tabular/HuggingFaceTabularStorage.d.ts.map +1 -1
- package/dist/util/IndexedDbTable.d.ts.map +1 -1
- package/dist/vector/IndexedDbVectorStorage.d.ts +55 -0
- package/dist/vector/IndexedDbVectorStorage.d.ts.map +1 -0
- package/dist/vector/PostgresVectorStorage.d.ts.map +1 -1
- package/package.json +7 -7
package/dist/bun.js
CHANGED
|
@@ -1032,7 +1032,14 @@ class InMemoryKvStorage extends KvViaTabularStorage {
|
|
|
1032
1032
|
}
|
|
1033
1033
|
}
|
|
1034
1034
|
// src/queue/InMemoryQueueStorage.ts
|
|
1035
|
-
import {
|
|
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";
|
|
1036
1043
|
|
|
1037
1044
|
// src/queue/IQueueStorage.ts
|
|
1038
1045
|
import { createServiceToken as createServiceToken8 } from "@workglow/util";
|
|
@@ -1126,11 +1133,23 @@ class InMemoryQueueStorage {
|
|
|
1126
1133
|
await sleep(0);
|
|
1127
1134
|
const job = this.jobQueue.find((j) => j.id === id && this.matchesPrefixes(j));
|
|
1128
1135
|
if (!job) {
|
|
1129
|
-
|
|
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
|
+
});
|
|
1130
1144
|
return;
|
|
1131
1145
|
}
|
|
1132
1146
|
if (job.status === JobStatus.COMPLETED || job.status === JobStatus.FAILED) {
|
|
1133
|
-
|
|
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
|
+
});
|
|
1134
1153
|
return;
|
|
1135
1154
|
}
|
|
1136
1155
|
const oldJob = { ...job };
|
|
@@ -7089,6 +7108,105 @@ class IndexedDbQueueStorage {
|
|
|
7089
7108
|
}
|
|
7090
7109
|
}
|
|
7091
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
|
+
}
|
|
7092
7210
|
export {
|
|
7093
7211
|
registerTabularRepository,
|
|
7094
7212
|
isSearchCondition,
|
|
@@ -7135,6 +7253,7 @@ export {
|
|
|
7135
7253
|
KvStorage,
|
|
7136
7254
|
KV_REPOSITORY,
|
|
7137
7255
|
JobStatus,
|
|
7256
|
+
IndexedDbVectorStorage,
|
|
7138
7257
|
IndexedDbTabularStorage,
|
|
7139
7258
|
IndexedDbRateLimiterStorage,
|
|
7140
7259
|
IndexedDbQueueStorage,
|
|
@@ -7148,6 +7267,7 @@ export {
|
|
|
7148
7267
|
IN_MEMORY_QUEUE_STORAGE,
|
|
7149
7268
|
INDEXED_DB_RATE_LIMITER_STORAGE,
|
|
7150
7269
|
INDEXED_DB_QUEUE_STORAGE,
|
|
7270
|
+
IDB_VECTOR_REPOSITORY,
|
|
7151
7271
|
IDB_TABULAR_REPOSITORY,
|
|
7152
7272
|
IDB_KV_REPOSITORY,
|
|
7153
7273
|
HybridSubscriptionManager,
|
|
@@ -7166,4 +7286,4 @@ export {
|
|
|
7166
7286
|
BaseTabularStorage
|
|
7167
7287
|
};
|
|
7168
7288
|
|
|
7169
|
-
//# debugId=
|
|
7289
|
+
//# debugId=DB5310BD3588935D64756E2164756E21
|