@workglow/storage 0.0.102 → 0.0.104
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 +200 -4
- package/dist/browser.js.map +11 -9
- package/dist/bun.js +200 -4
- package/dist/bun.js.map +12 -10
- package/dist/common-server.d.ts +1 -0
- package/dist/common-server.d.ts.map +1 -1
- package/dist/common.d.ts +1 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/credentials/EncryptedKvCredentialStore.d.ts +52 -0
- package/dist/credentials/EncryptedKvCredentialStore.d.ts.map +1 -0
- package/dist/kv/InMemoryKvStorage.d.ts.map +1 -1
- package/dist/kv/KvStorage.d.ts.map +1 -1
- package/dist/node.js +200 -4
- package/dist/node.js.map +12 -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 +9 -9
package/dist/common-server.d.ts
CHANGED
|
@@ -25,5 +25,6 @@ export * from "./kv/IndexedDbKvStorage";
|
|
|
25
25
|
export * from "./queue-limiter/IndexedDbRateLimiterStorage";
|
|
26
26
|
export * from "./queue/IndexedDbQueueStorage";
|
|
27
27
|
export * from "./tabular/IndexedDbTabularStorage";
|
|
28
|
+
export * from "./vector/IndexedDbVectorStorage";
|
|
28
29
|
export * from "./util/IndexedDbTable";
|
|
29
30
|
//# sourceMappingURL=common-server.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-server.d.ts","sourceRoot":"","sources":["../src/common-server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,UAAU,CAAC;AAEzB,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;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AAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,uBAAuB,CAAC"}
|
package/dist/common.d.ts
CHANGED
|
@@ -21,4 +21,5 @@ export * from "./util/HybridSubscriptionManager";
|
|
|
21
21
|
export * from "./util/PollingSubscriptionManager";
|
|
22
22
|
export * from "./vector/InMemoryVectorStorage";
|
|
23
23
|
export * from "./vector/IVectorStorage";
|
|
24
|
+
export * from "./credentials/EncryptedKvCredentialStore";
|
|
24
25
|
//# sourceMappingURL=common.d.ts.map
|
package/dist/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AAEjD,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AAEzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AAEtC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qCAAqC,CAAC;AAEpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAElD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AAEjD,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AAEzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AAEtC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qCAAqC,CAAC;AAEpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAElD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AAExC,cAAc,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { CredentialPutOptions, ICredentialStore } from "@workglow/util";
|
|
7
|
+
import type { IKvStorage } from "../kv/IKvStorage";
|
|
8
|
+
/**
|
|
9
|
+
* Serialized form of a credential stored in the KV backend
|
|
10
|
+
*/
|
|
11
|
+
interface StoredCredential {
|
|
12
|
+
readonly encrypted: string;
|
|
13
|
+
readonly iv: string;
|
|
14
|
+
readonly label: string | undefined;
|
|
15
|
+
readonly provider: string | undefined;
|
|
16
|
+
readonly createdAt: string;
|
|
17
|
+
readonly updatedAt: string;
|
|
18
|
+
readonly expiresAt: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Credential store that encrypts values with AES-256-GCM before persisting
|
|
22
|
+
* them to an {@link IKvStorage} backend.
|
|
23
|
+
*
|
|
24
|
+
* Works with any KV backend (SQLite, PostgreSQL, IndexedDB, in-memory, etc.).
|
|
25
|
+
* Uses the Web Crypto API (available in Node 20+, Bun, and browsers).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { SqliteKvStorage } from "@workglow/storage";
|
|
30
|
+
*
|
|
31
|
+
* const kv = new SqliteKvStorage(":memory:");
|
|
32
|
+
* const store = new EncryptedKvCredentialStore(kv, "my-encryption-key");
|
|
33
|
+
*
|
|
34
|
+
* await store.put("openai-api-key", "sk-...", { provider: "openai" });
|
|
35
|
+
* const key = await store.get("openai-api-key"); // "sk-..."
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class EncryptedKvCredentialStore implements ICredentialStore {
|
|
39
|
+
private readonly kv;
|
|
40
|
+
private readonly passphrase;
|
|
41
|
+
/** Per-instance cache of derived CryptoKey instances keyed by base64(salt). */
|
|
42
|
+
private readonly keyCache;
|
|
43
|
+
constructor(kv: IKvStorage<string, StoredCredential>, passphrase: string);
|
|
44
|
+
get(key: string): Promise<string | undefined>;
|
|
45
|
+
put(key: string, value: string, options?: CredentialPutOptions): Promise<void>;
|
|
46
|
+
delete(key: string): Promise<boolean>;
|
|
47
|
+
has(key: string): Promise<boolean>;
|
|
48
|
+
keys(): Promise<readonly string[]>;
|
|
49
|
+
deleteAll(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=EncryptedKvCredentialStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EncryptedKvCredentialStore.d.ts","sourceRoot":"","sources":["../../src/credentials/EncryptedKvCredentialStore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,UAAU,gBAAgB;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC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BAAoB,qEAEhC,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,mBAAmB;IACjD,iBAAiB,EAAE,sBAAsB,CAC9C,OAAO,qBAAqB,EAC5B,OAAO,kBAAkB,CAC1B,CAAC;IAEF;;OAEG;gBACS,SAAS,GAAE,UAA+B,EAAE,WAAW,GAAE,UAAe;
|
|
1
|
+
{"version":3,"file":"InMemoryKvStorage.d.ts","sourceRoot":"","sources":["../../src/kv/InMemoryKvStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAsB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,eAAO,MAAM,oBAAoB,qEAEhC,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,mBAAmB;IACjD,iBAAiB,EAAE,sBAAsB,CAC9C,OAAO,qBAAqB,EAC5B,OAAO,kBAAkB,CAC1B,CAAC;IAEF;;OAEG;gBACS,SAAS,GAAE,UAA+B,EAAE,WAAW,GAAE,UAAe;CAIrF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KvStorage.d.ts","sourceRoot":"","sources":["../../src/kv/KvStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAsB,YAAY,EAAE,UAAU,EAAmB,MAAM,gBAAgB,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,
|
|
1
|
+
{"version":3,"file":"KvStorage.d.ts","sourceRoot":"","sources":["../../src/kv/KvStorage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAsB,YAAY,EAAE,UAAU,EAAmB,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QAAQ,CAAC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAEnC;;;OAGG;IACH,QAAQ,CAAC,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAEhC;;;;;OAKG;IACU,mBAAmB,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAIpE;;;;OAIG;IACH,EAAE,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC;IAI3F;;;;OAIG;IACH,GAAG,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC;IAI5F;;;;OAIG;IACH,IAAI,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC;IAI7F;;;;OAIG;IACH,IAAI,CAAC,KAAK,SAAS,WAAW,EAC5B,IAAI,EAAE,KAAK,EACX,GAAG,IAAI,EAAE,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC;IAKzD;;;;OAIG;IACH,MAAM,CAAC,KAAK,SAAS,WAAW,EAC9B,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;CAG3D"}
|
package/dist/node.js
CHANGED
|
@@ -1031,7 +1031,14 @@ class InMemoryKvStorage extends KvViaTabularStorage {
|
|
|
1031
1031
|
}
|
|
1032
1032
|
}
|
|
1033
1033
|
// src/queue/InMemoryQueueStorage.ts
|
|
1034
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|
|
@@ -1675,6 +1694,81 @@ class InMemoryVectorStorage extends InMemoryTabularStorage {
|
|
|
1675
1694
|
return topResults;
|
|
1676
1695
|
}
|
|
1677
1696
|
}
|
|
1697
|
+
// src/credentials/EncryptedKvCredentialStore.ts
|
|
1698
|
+
import { decrypt, encrypt } from "@workglow/util";
|
|
1699
|
+
|
|
1700
|
+
class EncryptedKvCredentialStore {
|
|
1701
|
+
kv;
|
|
1702
|
+
passphrase;
|
|
1703
|
+
keyCache = new Map;
|
|
1704
|
+
constructor(kv, passphrase) {
|
|
1705
|
+
this.kv = kv;
|
|
1706
|
+
this.passphrase = passphrase;
|
|
1707
|
+
if (!passphrase) {
|
|
1708
|
+
throw new Error("EncryptedKvCredentialStore requires a non-empty passphrase.");
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
async get(key) {
|
|
1712
|
+
const raw = await this.kv.get(key);
|
|
1713
|
+
if (!raw)
|
|
1714
|
+
return;
|
|
1715
|
+
if (raw.expiresAt && new Date(raw.expiresAt) <= new Date) {
|
|
1716
|
+
await this.kv.delete(key);
|
|
1717
|
+
return;
|
|
1718
|
+
}
|
|
1719
|
+
return decrypt(raw.encrypted, raw.iv, this.passphrase, this.keyCache);
|
|
1720
|
+
}
|
|
1721
|
+
async put(key, value, options) {
|
|
1722
|
+
const now = new Date;
|
|
1723
|
+
const existing = await this.kv.get(key);
|
|
1724
|
+
const { encrypted, iv } = await encrypt(value, this.passphrase, this.keyCache);
|
|
1725
|
+
const stored = {
|
|
1726
|
+
encrypted,
|
|
1727
|
+
iv,
|
|
1728
|
+
label: options?.label ?? existing?.label,
|
|
1729
|
+
provider: options?.provider ?? existing?.provider,
|
|
1730
|
+
createdAt: existing?.createdAt ?? now.toISOString(),
|
|
1731
|
+
updatedAt: now.toISOString(),
|
|
1732
|
+
expiresAt: options?.expiresAt ? options.expiresAt.toISOString() : existing?.expiresAt
|
|
1733
|
+
};
|
|
1734
|
+
await this.kv.put(key, stored);
|
|
1735
|
+
}
|
|
1736
|
+
async delete(key) {
|
|
1737
|
+
const exists = await this.kv.get(key) !== undefined;
|
|
1738
|
+
if (exists) {
|
|
1739
|
+
await this.kv.delete(key);
|
|
1740
|
+
}
|
|
1741
|
+
return exists;
|
|
1742
|
+
}
|
|
1743
|
+
async has(key) {
|
|
1744
|
+
const raw = await this.kv.get(key);
|
|
1745
|
+
if (!raw)
|
|
1746
|
+
return false;
|
|
1747
|
+
if (raw.expiresAt && new Date(raw.expiresAt) <= new Date) {
|
|
1748
|
+
await this.kv.delete(key);
|
|
1749
|
+
return false;
|
|
1750
|
+
}
|
|
1751
|
+
return true;
|
|
1752
|
+
}
|
|
1753
|
+
async keys() {
|
|
1754
|
+
const all = await this.kv.getAll();
|
|
1755
|
+
if (!all)
|
|
1756
|
+
return [];
|
|
1757
|
+
const now = new Date;
|
|
1758
|
+
const result = [];
|
|
1759
|
+
for (const entry of all) {
|
|
1760
|
+
if (entry.value.expiresAt && new Date(entry.value.expiresAt) <= now) {
|
|
1761
|
+
await this.kv.delete(entry.key);
|
|
1762
|
+
continue;
|
|
1763
|
+
}
|
|
1764
|
+
result.push(entry.key);
|
|
1765
|
+
}
|
|
1766
|
+
return result;
|
|
1767
|
+
}
|
|
1768
|
+
async deleteAll() {
|
|
1769
|
+
await this.kv.deleteAll();
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1678
1772
|
// src/tabular/FsFolderTabularStorage.ts
|
|
1679
1773
|
import {
|
|
1680
1774
|
createServiceToken as createServiceToken12,
|
|
@@ -7088,6 +7182,105 @@ class IndexedDbQueueStorage {
|
|
|
7088
7182
|
}
|
|
7089
7183
|
}
|
|
7090
7184
|
}
|
|
7185
|
+
// src/vector/IndexedDbVectorStorage.ts
|
|
7186
|
+
import { cosineSimilarity as cosineSimilarity4, createServiceToken as createServiceToken31 } from "@workglow/util";
|
|
7187
|
+
var IDB_VECTOR_REPOSITORY = createServiceToken31("storage.vectorRepository.indexedDb");
|
|
7188
|
+
function matchesFilter3(metadata, filter) {
|
|
7189
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
7190
|
+
if (metadata[key] !== value) {
|
|
7191
|
+
return false;
|
|
7192
|
+
}
|
|
7193
|
+
}
|
|
7194
|
+
return true;
|
|
7195
|
+
}
|
|
7196
|
+
function textRelevance2(text, query) {
|
|
7197
|
+
const textLower = text.toLowerCase();
|
|
7198
|
+
const queryLower = query.toLowerCase();
|
|
7199
|
+
const queryWords = queryLower.split(/\s+/).filter((w) => w.length > 0);
|
|
7200
|
+
if (queryWords.length === 0) {
|
|
7201
|
+
return 0;
|
|
7202
|
+
}
|
|
7203
|
+
let matches = 0;
|
|
7204
|
+
for (const word of queryWords) {
|
|
7205
|
+
if (textLower.includes(word)) {
|
|
7206
|
+
matches++;
|
|
7207
|
+
}
|
|
7208
|
+
}
|
|
7209
|
+
return matches / queryWords.length;
|
|
7210
|
+
}
|
|
7211
|
+
|
|
7212
|
+
class IndexedDbVectorStorage extends IndexedDbTabularStorage {
|
|
7213
|
+
vectorDimensions;
|
|
7214
|
+
VectorType;
|
|
7215
|
+
vectorPropertyName;
|
|
7216
|
+
metadataPropertyName;
|
|
7217
|
+
constructor(table = "vectors", schema, primaryKeyNames, indexes = [], dimensions, VectorType = Float32Array, migrationOptions = {}, clientProvidedKeys = "if-missing") {
|
|
7218
|
+
super(table, schema, primaryKeyNames, indexes, migrationOptions, clientProvidedKeys);
|
|
7219
|
+
this.vectorDimensions = dimensions;
|
|
7220
|
+
this.VectorType = VectorType;
|
|
7221
|
+
const vectorProp = getVectorProperty(schema);
|
|
7222
|
+
if (!vectorProp) {
|
|
7223
|
+
throw new Error("Schema must have a property with type array and format TypedArray");
|
|
7224
|
+
}
|
|
7225
|
+
this.vectorPropertyName = vectorProp;
|
|
7226
|
+
this.metadataPropertyName = getMetadataProperty(schema);
|
|
7227
|
+
}
|
|
7228
|
+
getVectorDimensions() {
|
|
7229
|
+
return this.vectorDimensions;
|
|
7230
|
+
}
|
|
7231
|
+
async similaritySearch(query, options = {}) {
|
|
7232
|
+
const { topK = 10, filter, scoreThreshold = 0 } = options;
|
|
7233
|
+
const results = [];
|
|
7234
|
+
const allEntities = await this.getAll() || [];
|
|
7235
|
+
for (const entity of allEntities) {
|
|
7236
|
+
const vector = entity[this.vectorPropertyName];
|
|
7237
|
+
const metadata = this.metadataPropertyName ? entity[this.metadataPropertyName] : {};
|
|
7238
|
+
if (filter && !matchesFilter3(metadata, filter)) {
|
|
7239
|
+
continue;
|
|
7240
|
+
}
|
|
7241
|
+
const score = cosineSimilarity4(query, vector);
|
|
7242
|
+
if (score < scoreThreshold) {
|
|
7243
|
+
continue;
|
|
7244
|
+
}
|
|
7245
|
+
results.push({
|
|
7246
|
+
...entity,
|
|
7247
|
+
score
|
|
7248
|
+
});
|
|
7249
|
+
}
|
|
7250
|
+
results.sort((a, b) => b.score - a.score);
|
|
7251
|
+
const topResults = results.slice(0, topK);
|
|
7252
|
+
return topResults;
|
|
7253
|
+
}
|
|
7254
|
+
async hybridSearch(query, options) {
|
|
7255
|
+
const { topK = 10, filter, scoreThreshold = 0, textQuery, vectorWeight = 0.7 } = options;
|
|
7256
|
+
if (!textQuery || textQuery.trim().length === 0) {
|
|
7257
|
+
return this.similaritySearch(query, { topK, filter, scoreThreshold });
|
|
7258
|
+
}
|
|
7259
|
+
const results = [];
|
|
7260
|
+
const allEntities = await this.getAll() || [];
|
|
7261
|
+
for (const entity of allEntities) {
|
|
7262
|
+
const vector = entity[this.vectorPropertyName];
|
|
7263
|
+
const metadata = this.metadataPropertyName ? entity[this.metadataPropertyName] : {};
|
|
7264
|
+
if (filter && !matchesFilter3(metadata, filter)) {
|
|
7265
|
+
continue;
|
|
7266
|
+
}
|
|
7267
|
+
const vectorScore = cosineSimilarity4(query, vector);
|
|
7268
|
+
const metadataText = Object.values(metadata).join(" ").toLowerCase();
|
|
7269
|
+
const textScore = textRelevance2(metadataText, textQuery);
|
|
7270
|
+
const combinedScore = vectorWeight * vectorScore + (1 - vectorWeight) * textScore;
|
|
7271
|
+
if (combinedScore < scoreThreshold) {
|
|
7272
|
+
continue;
|
|
7273
|
+
}
|
|
7274
|
+
results.push({
|
|
7275
|
+
...entity,
|
|
7276
|
+
score: combinedScore
|
|
7277
|
+
});
|
|
7278
|
+
}
|
|
7279
|
+
results.sort((a, b) => b.score - a.score);
|
|
7280
|
+
const topResults = results.slice(0, topK);
|
|
7281
|
+
return topResults;
|
|
7282
|
+
}
|
|
7283
|
+
}
|
|
7091
7284
|
export {
|
|
7092
7285
|
registerTabularRepository,
|
|
7093
7286
|
isSearchCondition,
|
|
@@ -7134,6 +7327,7 @@ export {
|
|
|
7134
7327
|
KvStorage,
|
|
7135
7328
|
KV_REPOSITORY,
|
|
7136
7329
|
JobStatus,
|
|
7330
|
+
IndexedDbVectorStorage,
|
|
7137
7331
|
IndexedDbTabularStorage,
|
|
7138
7332
|
IndexedDbRateLimiterStorage,
|
|
7139
7333
|
IndexedDbQueueStorage,
|
|
@@ -7147,6 +7341,7 @@ export {
|
|
|
7147
7341
|
IN_MEMORY_QUEUE_STORAGE,
|
|
7148
7342
|
INDEXED_DB_RATE_LIMITER_STORAGE,
|
|
7149
7343
|
INDEXED_DB_QUEUE_STORAGE,
|
|
7344
|
+
IDB_VECTOR_REPOSITORY,
|
|
7150
7345
|
IDB_TABULAR_REPOSITORY,
|
|
7151
7346
|
IDB_KV_REPOSITORY,
|
|
7152
7347
|
HybridSubscriptionManager,
|
|
@@ -7158,6 +7353,7 @@ export {
|
|
|
7158
7353
|
FS_FOLDER_TABULAR_REPOSITORY,
|
|
7159
7354
|
FS_FOLDER_KV_REPOSITORY,
|
|
7160
7355
|
FS_FOLDER_JSON_KV_REPOSITORY,
|
|
7356
|
+
EncryptedKvCredentialStore,
|
|
7161
7357
|
DefaultKeyValueSchema,
|
|
7162
7358
|
DefaultKeyValueKey,
|
|
7163
7359
|
CachedTabularStorage,
|
|
@@ -7165,4 +7361,4 @@ export {
|
|
|
7165
7361
|
BaseTabularStorage
|
|
7166
7362
|
};
|
|
7167
7363
|
|
|
7168
|
-
//# debugId=
|
|
7364
|
+
//# debugId=2D59BEA4EF2DA70564756E2164756E21
|