@retrivora-ai/rag-engine 2.5.7 → 2.5.9
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/{ILLMProvider-DwFj0h2u.d.mts → ILLMProvider-B2N3lMBc.d.mts} +10 -1
- package/dist/{ILLMProvider-DwFj0h2u.d.ts → ILLMProvider-B2N3lMBc.d.ts} +10 -1
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +962 -193
- package/dist/handlers/index.mjs +12821 -24
- package/dist/{index-Cb0GsT16.d.ts → index-37V810a-.d.mts} +3 -3
- package/dist/{index-D1jN8KSF.d.mts → index-BxzDv2jd.d.ts} +3 -3
- package/dist/{index-9h_ENWQn.d.mts → index-CAGGPyI7.d.mts} +6 -2
- package/dist/{index-Xci6GfpI.d.ts → index-DdQxoIpu.d.ts} +6 -2
- package/dist/index.css +76 -4
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +138 -96
- package/dist/index.min.css +1 -1
- package/dist/index.mjs +1554 -130
- package/dist/server.d.mts +100 -9
- package/dist/server.d.ts +100 -9
- package/dist/server.js +964 -193
- package/dist/server.mjs +13378 -372
- package/package.json +5 -2
- package/dist/ChromaDBProvider-4RPJN7Y3.mjs +0 -8
- package/dist/MilvusProvider-WJLLZ6TW.mjs +0 -8
- package/dist/MongoDBProvider-QSERELZX.mjs +0 -8
- package/dist/MultiTablePostgresProvider-JF2HEUDZ.mjs +0 -9
- package/dist/PineconeProvider-HLZL7HKU.mjs +0 -10
- package/dist/PostgreSQLProvider-JQMCNHRO.mjs +0 -8
- package/dist/QdrantProvider-6MNFPEVC.mjs +0 -8
- package/dist/RedisProvider-ERQL6AEB.mjs +0 -8
- package/dist/SimpleGraphProvider-OP3HAJJM.mjs +0 -70
- package/dist/UniversalVectorProvider-INM3KH5F.mjs +0 -9
- package/dist/WeaviateProvider-VHWWICCC.mjs +0 -8
- package/dist/chunk-366EFBZC.mjs +0 -165
- package/dist/chunk-6MGVQTU4.mjs +0 -8883
- package/dist/chunk-B4AXIUM7.mjs +0 -49
- package/dist/chunk-BEPLYQBS.mjs +0 -89
- package/dist/chunk-BNOPQCZW.mjs +0 -238
- package/dist/chunk-FJ43J4FW.mjs +0 -654
- package/dist/chunk-GP2AJQRQ.mjs +0 -107
- package/dist/chunk-IMP6FUCY.mjs +0 -30
- package/dist/chunk-JRQWSJNF.mjs +0 -202
- package/dist/chunk-LYHCKUNF.mjs +0 -112
- package/dist/chunk-MFIWWUC7.mjs +0 -152
- package/dist/chunk-MWICNCB2.mjs +0 -157
- package/dist/chunk-N54YTFBN.mjs +0 -76
- package/dist/chunk-POOWU2HR.mjs +0 -211
- package/dist/chunk-QGDGPOZH.mjs +0 -217
- package/dist/chunk-QI3FTN6G.mjs +0 -281
- package/dist/chunk-QJIDGVG6.mjs +0 -334
- package/dist/chunk-W2DKVD3G.mjs +0 -81
- package/dist/chunk-XHSDHPKI.mjs +0 -336
package/dist/chunk-MWICNCB2.mjs
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildPayload,
|
|
3
|
-
resolvePath
|
|
4
|
-
} from "./chunk-B4AXIUM7.mjs";
|
|
5
|
-
import {
|
|
6
|
-
BaseVectorProvider
|
|
7
|
-
} from "./chunk-IMP6FUCY.mjs";
|
|
8
|
-
import {
|
|
9
|
-
__spreadValues
|
|
10
|
-
} from "./chunk-N54YTFBN.mjs";
|
|
11
|
-
|
|
12
|
-
// src/providers/vectordb/UniversalVectorProvider.ts
|
|
13
|
-
import axios from "axios";
|
|
14
|
-
var UniversalVectorProvider = class extends BaseVectorProvider {
|
|
15
|
-
constructor(config) {
|
|
16
|
-
super(config);
|
|
17
|
-
this.opts = config.options;
|
|
18
|
-
if (!this.opts.baseUrl) {
|
|
19
|
-
throw new Error("[UniversalVectorProvider] options.baseUrl is required");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async initialize() {
|
|
23
|
-
var _a;
|
|
24
|
-
this.http = axios.create({
|
|
25
|
-
baseURL: this.opts.baseUrl,
|
|
26
|
-
headers: __spreadValues({
|
|
27
|
-
"Content-Type": "application/json"
|
|
28
|
-
}, this.opts.headers),
|
|
29
|
-
timeout: (_a = this.opts.timeout) != null ? _a : 3e4
|
|
30
|
-
});
|
|
31
|
-
if (!await this.ping()) {
|
|
32
|
-
throw new Error(`[UniversalVectorProvider] Failed to connect to ${this.opts.baseUrl}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
async upsert(doc, namespace) {
|
|
36
|
-
var _a, _b, _c;
|
|
37
|
-
const endpoint = (_a = this.opts.upsertEndpoint) != null ? _a : "/upsert";
|
|
38
|
-
const template = (_b = this.opts.upsertTemplate) != null ? _b : JSON.stringify({
|
|
39
|
-
id: "{{id}}",
|
|
40
|
-
vector: "{{vector}}",
|
|
41
|
-
content: "{{content}}",
|
|
42
|
-
namespace: "{{namespace}}",
|
|
43
|
-
metadata: "{{metadata}}"
|
|
44
|
-
});
|
|
45
|
-
const payload = buildPayload(template, {
|
|
46
|
-
id: doc.id,
|
|
47
|
-
vector: doc.vector,
|
|
48
|
-
content: doc.content,
|
|
49
|
-
namespace: namespace != null ? namespace : this.indexName,
|
|
50
|
-
metadata: (_c = doc.metadata) != null ? _c : {}
|
|
51
|
-
});
|
|
52
|
-
try {
|
|
53
|
-
await this.http.post(endpoint, payload);
|
|
54
|
-
} catch (error) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
`[UniversalVectorProvider] Upsert failed: ${error instanceof Error ? error.message : String(error)}`
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async batchUpsert(docs, namespace) {
|
|
61
|
-
const batchSize = 50;
|
|
62
|
-
for (let i = 0; i < docs.length; i += batchSize) {
|
|
63
|
-
const batch = docs.slice(i, i + batchSize);
|
|
64
|
-
await Promise.all(
|
|
65
|
-
batch.map((doc) => this.upsert(doc, namespace))
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async query(vector, topK, namespace, filter) {
|
|
70
|
-
var _a, _b;
|
|
71
|
-
const endpoint = (_a = this.opts.queryEndpoint) != null ? _a : "/query";
|
|
72
|
-
const template = (_b = this.opts.queryTemplate) != null ? _b : JSON.stringify({
|
|
73
|
-
vector: "{{vector}}",
|
|
74
|
-
limit: "{{topK}}",
|
|
75
|
-
namespace: "{{namespace}}",
|
|
76
|
-
filter: "{{filter}}"
|
|
77
|
-
});
|
|
78
|
-
const sanitizedFilter = this.sanitizeFilter(filter);
|
|
79
|
-
const payload = buildPayload(template, {
|
|
80
|
-
vector,
|
|
81
|
-
topK,
|
|
82
|
-
namespace: namespace != null ? namespace : this.indexName,
|
|
83
|
-
filter: sanitizedFilter
|
|
84
|
-
});
|
|
85
|
-
try {
|
|
86
|
-
const response = await this.http.post(endpoint, payload);
|
|
87
|
-
let results = response.data;
|
|
88
|
-
if (this.opts.queryResponsePath) {
|
|
89
|
-
results = resolvePath(response.data, this.opts.queryResponsePath);
|
|
90
|
-
}
|
|
91
|
-
if (!Array.isArray(results)) {
|
|
92
|
-
throw new Error(
|
|
93
|
-
`[UniversalVectorProvider] Expected array response at "${this.opts.queryResponsePath}", got ${typeof results}`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
return results.map((item) => {
|
|
97
|
-
var _a2, _b2, _c, _d, _e, _f, _g;
|
|
98
|
-
return {
|
|
99
|
-
id: item[(_a2 = this.opts.queryIdField) != null ? _a2 : "id"],
|
|
100
|
-
score: (_c = item[(_b2 = this.opts.queryScoreField) != null ? _b2 : "score"]) != null ? _c : 0,
|
|
101
|
-
content: (_e = item[(_d = this.opts.queryContentField) != null ? _d : "content"]) != null ? _e : "",
|
|
102
|
-
metadata: (_g = item[(_f = this.opts.queryMetadataField) != null ? _f : "metadata"]) != null ? _g : {}
|
|
103
|
-
};
|
|
104
|
-
});
|
|
105
|
-
} catch (error) {
|
|
106
|
-
throw new Error(
|
|
107
|
-
`[UniversalVectorProvider] Query failed: ${error instanceof Error ? error.message : String(error)}`
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async delete(id, namespace) {
|
|
112
|
-
var _a, _b;
|
|
113
|
-
const endpoint = (_a = this.opts.deleteEndpoint) != null ? _a : "/delete";
|
|
114
|
-
const template = (_b = this.opts.deleteTemplate) != null ? _b : JSON.stringify({
|
|
115
|
-
id: "{{id}}",
|
|
116
|
-
namespace: "{{namespace}}"
|
|
117
|
-
});
|
|
118
|
-
const payload = buildPayload(template, {
|
|
119
|
-
id,
|
|
120
|
-
namespace: namespace != null ? namespace : this.indexName
|
|
121
|
-
});
|
|
122
|
-
try {
|
|
123
|
-
await this.http.post(endpoint, payload);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
throw new Error(
|
|
126
|
-
`[UniversalVectorProvider] Delete failed: ${error instanceof Error ? error.message : String(error)}`
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async deleteNamespace(namespace) {
|
|
131
|
-
var _a;
|
|
132
|
-
const endpoint = (_a = this.opts.deleteNamespaceEndpoint) != null ? _a : "/delete-namespace";
|
|
133
|
-
try {
|
|
134
|
-
await this.http.post(endpoint, { namespace });
|
|
135
|
-
} catch (error) {
|
|
136
|
-
throw new Error(
|
|
137
|
-
`[UniversalVectorProvider] DeleteNamespace failed: ${error instanceof Error ? error.message : String(error)}`
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
async ping() {
|
|
142
|
-
var _a;
|
|
143
|
-
try {
|
|
144
|
-
const endpoint = (_a = this.opts.pingEndpoint) != null ? _a : "/health";
|
|
145
|
-
const response = await this.http.get(endpoint, { timeout: 5e3 });
|
|
146
|
-
return response.status >= 200 && response.status < 300;
|
|
147
|
-
} catch (e) {
|
|
148
|
-
return false;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async disconnect() {
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
export {
|
|
156
|
-
UniversalVectorProvider
|
|
157
|
-
};
|
package/dist/chunk-N54YTFBN.mjs
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
24
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
25
|
-
}) : x)(function(x) {
|
|
26
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
27
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
28
|
-
});
|
|
29
|
-
var __objRest = (source, exclude) => {
|
|
30
|
-
var target = {};
|
|
31
|
-
for (var prop in source)
|
|
32
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
if (source != null && __getOwnPropSymbols)
|
|
35
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
36
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
37
|
-
target[prop] = source[prop];
|
|
38
|
-
}
|
|
39
|
-
return target;
|
|
40
|
-
};
|
|
41
|
-
var __copyProps = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames(from))
|
|
44
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
50
|
-
var __await = function(promise, isYieldStar) {
|
|
51
|
-
this[0] = promise;
|
|
52
|
-
this[1] = isYieldStar;
|
|
53
|
-
};
|
|
54
|
-
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
55
|
-
var resume = (k, v, yes, no) => {
|
|
56
|
-
try {
|
|
57
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
58
|
-
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
59
|
-
} catch (e) {
|
|
60
|
-
no(e);
|
|
61
|
-
}
|
|
62
|
-
}, method = (k, call, wait, clear) => it[k] = (x) => (call = new Promise((yes, no, run) => (run = () => resume(k, x, yes, no), q ? q.then(run) : run())), clear = () => q === wait && (q = 0), q = wait = call.then(clear, clear), call), q, it = {};
|
|
63
|
-
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
64
|
-
};
|
|
65
|
-
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
66
|
-
|
|
67
|
-
export {
|
|
68
|
-
__spreadValues,
|
|
69
|
-
__spreadProps,
|
|
70
|
-
__require,
|
|
71
|
-
__objRest,
|
|
72
|
-
__reExport,
|
|
73
|
-
__await,
|
|
74
|
-
__asyncGenerator,
|
|
75
|
-
__forAwait
|
|
76
|
-
};
|
package/dist/chunk-POOWU2HR.mjs
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseVectorProvider
|
|
3
|
-
} from "./chunk-IMP6FUCY.mjs";
|
|
4
|
-
import {
|
|
5
|
-
__spreadValues
|
|
6
|
-
} from "./chunk-N54YTFBN.mjs";
|
|
7
|
-
|
|
8
|
-
// src/providers/vectordb/MongoDBProvider.ts
|
|
9
|
-
import { MongoClient } from "mongodb";
|
|
10
|
-
var MongoDBProvider = class extends BaseVectorProvider {
|
|
11
|
-
constructor(config) {
|
|
12
|
-
super(config);
|
|
13
|
-
this.initialized = false;
|
|
14
|
-
const opts = config.options;
|
|
15
|
-
if (!opts.uri || !opts.database || !opts.collection) {
|
|
16
|
-
throw new Error("[MongoDBProvider] options uri, database, and collection are required.");
|
|
17
|
-
}
|
|
18
|
-
this.client = new MongoClient(opts.uri, { serverSelectionTimeoutMS: 5e3 });
|
|
19
|
-
this.dbName = opts.database;
|
|
20
|
-
this.collectionName = opts.collection;
|
|
21
|
-
this.embeddingKey = opts.embeddingKey || "embedding";
|
|
22
|
-
this.contentKey = opts.contentKey || "content";
|
|
23
|
-
this.metadataKey = opts.metadataKey || "metadata";
|
|
24
|
-
}
|
|
25
|
-
static getValidator() {
|
|
26
|
-
return {
|
|
27
|
-
validate(config) {
|
|
28
|
-
const errors = [];
|
|
29
|
-
const opts = config.options || {};
|
|
30
|
-
if (!opts.uri) {
|
|
31
|
-
errors.push({
|
|
32
|
-
field: "vectorDb.options.uri",
|
|
33
|
-
message: "MongoDB connection URI is required",
|
|
34
|
-
suggestion: "Set MONGODB_URI environment variable",
|
|
35
|
-
severity: "error"
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (!opts.database) {
|
|
39
|
-
errors.push({
|
|
40
|
-
field: "vectorDb.options.database",
|
|
41
|
-
message: "MongoDB database name is required",
|
|
42
|
-
severity: "error"
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
if (!opts.collection) {
|
|
46
|
-
errors.push({
|
|
47
|
-
field: "vectorDb.options.collection",
|
|
48
|
-
message: "MongoDB collection name is required",
|
|
49
|
-
severity: "error"
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return errors;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
static getHealthChecker() {
|
|
57
|
-
return {
|
|
58
|
-
async check(config) {
|
|
59
|
-
const opts = config.options || {};
|
|
60
|
-
const timestamp = Date.now();
|
|
61
|
-
try {
|
|
62
|
-
const { MongoClient: MongoClient2 } = await import("mongodb");
|
|
63
|
-
const client = new MongoClient2(opts.uri);
|
|
64
|
-
await client.connect();
|
|
65
|
-
const db = client.db(opts.database);
|
|
66
|
-
await db.command({ ping: 1 });
|
|
67
|
-
const collections = await db.listCollections({ name: opts.collection }).toArray();
|
|
68
|
-
await client.close();
|
|
69
|
-
return {
|
|
70
|
-
healthy: true,
|
|
71
|
-
provider: "mongodb",
|
|
72
|
-
capabilities: {
|
|
73
|
-
database: opts.database,
|
|
74
|
-
collection: opts.collection,
|
|
75
|
-
exists: collections.length > 0
|
|
76
|
-
},
|
|
77
|
-
timestamp
|
|
78
|
-
};
|
|
79
|
-
} catch (error) {
|
|
80
|
-
return {
|
|
81
|
-
healthy: false,
|
|
82
|
-
provider: "mongodb",
|
|
83
|
-
error: `Connection failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
84
|
-
timestamp
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
async initialize() {
|
|
91
|
-
if (this.initialized) return;
|
|
92
|
-
await this.client.connect();
|
|
93
|
-
this.db = this.client.db(this.dbName);
|
|
94
|
-
this.collection = this.db.collection(this.collectionName);
|
|
95
|
-
this.initialized = true;
|
|
96
|
-
}
|
|
97
|
-
async upsert(doc, namespace) {
|
|
98
|
-
const document = __spreadValues({
|
|
99
|
-
_id: doc.id,
|
|
100
|
-
[this.embeddingKey]: doc.vector,
|
|
101
|
-
[this.contentKey]: doc.content,
|
|
102
|
-
[this.metadataKey]: doc.metadata || {}
|
|
103
|
-
}, namespace ? { namespace } : {});
|
|
104
|
-
await this.collection.updateOne({ _id: doc.id }, { $set: document }, { upsert: true });
|
|
105
|
-
}
|
|
106
|
-
async batchUpsert(docs, namespace) {
|
|
107
|
-
const operations = docs.map((doc) => ({
|
|
108
|
-
updateOne: {
|
|
109
|
-
filter: { _id: doc.id },
|
|
110
|
-
update: {
|
|
111
|
-
$set: __spreadValues({
|
|
112
|
-
[this.embeddingKey]: doc.vector,
|
|
113
|
-
[this.contentKey]: doc.content,
|
|
114
|
-
[this.metadataKey]: doc.metadata || {}
|
|
115
|
-
}, namespace ? { namespace } : {})
|
|
116
|
-
},
|
|
117
|
-
upsert: true
|
|
118
|
-
}
|
|
119
|
-
}));
|
|
120
|
-
await this.collection.bulkWrite(operations);
|
|
121
|
-
}
|
|
122
|
-
async query(vector, topK, namespace, filter) {
|
|
123
|
-
const publicFilter = this.sanitizeFilter(filter);
|
|
124
|
-
const vectorSearchFilter = {};
|
|
125
|
-
const matchFilter = {};
|
|
126
|
-
if (namespace) {
|
|
127
|
-
vectorSearchFilter.namespace = namespace;
|
|
128
|
-
}
|
|
129
|
-
for (const [key, value] of Object.entries(publicFilter)) {
|
|
130
|
-
if (key === "namespace") {
|
|
131
|
-
vectorSearchFilter.namespace = value;
|
|
132
|
-
} else {
|
|
133
|
-
if (typeof value === "string") {
|
|
134
|
-
matchFilter[key] = { $regex: new RegExp(`^${value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`, "i") };
|
|
135
|
-
} else {
|
|
136
|
-
matchFilter[key] = value;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
const pipeline = [
|
|
141
|
-
{
|
|
142
|
-
$vectorSearch: __spreadValues({
|
|
143
|
-
index: this.config.indexName || "vector_index",
|
|
144
|
-
path: this.embeddingKey,
|
|
145
|
-
queryVector: vector,
|
|
146
|
-
numCandidates: this.config.options.numCandidates || Math.max(topK * 20, 200),
|
|
147
|
-
limit: topK * 2
|
|
148
|
-
}, Object.keys(vectorSearchFilter).length > 0 ? { filter: vectorSearchFilter } : {})
|
|
149
|
-
}
|
|
150
|
-
];
|
|
151
|
-
if (Object.keys(matchFilter).length > 0) {
|
|
152
|
-
pipeline.push({ $match: matchFilter });
|
|
153
|
-
}
|
|
154
|
-
pipeline.push(
|
|
155
|
-
{ $limit: topK },
|
|
156
|
-
{
|
|
157
|
-
$project: {
|
|
158
|
-
_id: 1,
|
|
159
|
-
[this.contentKey]: 1,
|
|
160
|
-
[this.metadataKey]: 1,
|
|
161
|
-
namespace: 1,
|
|
162
|
-
score: { $meta: "vectorSearchScore" }
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
);
|
|
166
|
-
const results = await this.collection.aggregate(pipeline).toArray();
|
|
167
|
-
return results.map((res) => {
|
|
168
|
-
const normalizedScore = res.score * 2 - 1;
|
|
169
|
-
return {
|
|
170
|
-
id: res._id,
|
|
171
|
-
content: res[this.contentKey],
|
|
172
|
-
metadata: res[this.metadataKey] || {},
|
|
173
|
-
score: normalizedScore
|
|
174
|
-
};
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
async delete(id, namespace) {
|
|
178
|
-
await this.collection.deleteOne(__spreadValues({ _id: id }, namespace ? { namespace } : {}));
|
|
179
|
-
}
|
|
180
|
-
async deleteNamespace(namespace) {
|
|
181
|
-
await this.collection.deleteMany({ namespace });
|
|
182
|
-
}
|
|
183
|
-
sanitizeFilter(filter) {
|
|
184
|
-
const sanitized = super.sanitizeFilter(filter);
|
|
185
|
-
const mongoFilter = {};
|
|
186
|
-
for (const [key, value] of Object.entries(sanitized)) {
|
|
187
|
-
if (key === "namespace") {
|
|
188
|
-
mongoFilter[key] = value;
|
|
189
|
-
} else {
|
|
190
|
-
mongoFilter[`${this.metadataKey}.${key}`] = value;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return mongoFilter;
|
|
194
|
-
}
|
|
195
|
-
async ping() {
|
|
196
|
-
try {
|
|
197
|
-
await this.db.command({ ping: 1 });
|
|
198
|
-
return true;
|
|
199
|
-
} catch (e) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
async disconnect() {
|
|
204
|
-
await this.client.close();
|
|
205
|
-
this.initialized = false;
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
export {
|
|
210
|
-
MongoDBProvider
|
|
211
|
-
};
|
package/dist/chunk-QGDGPOZH.mjs
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LicenseValidationError,
|
|
3
|
-
LicenseVerifier,
|
|
4
|
-
SDKVersionUnsupportedError
|
|
5
|
-
} from "./chunk-FJ43J4FW.mjs";
|
|
6
|
-
import {
|
|
7
|
-
SDK_VERSION
|
|
8
|
-
} from "./chunk-366EFBZC.mjs";
|
|
9
|
-
import {
|
|
10
|
-
__spreadValues
|
|
11
|
-
} from "./chunk-N54YTFBN.mjs";
|
|
12
|
-
|
|
13
|
-
// src/core/LicenseValidator.ts
|
|
14
|
-
function canUseLocalValidationFallback(baseUrl, status) {
|
|
15
|
-
const explicitFallback = typeof process !== "undefined" && process.env.RETRIVORA_ALLOW_LOCAL_LICENSE_FALLBACK === "true";
|
|
16
|
-
const isLocalSdkRoute = baseUrl.startsWith("/api/retrivora") || baseUrl.includes("/api/retrivora");
|
|
17
|
-
if (status !== void 0) {
|
|
18
|
-
return status === 404 && (explicitFallback || isLocalSdkRoute);
|
|
19
|
-
}
|
|
20
|
-
return explicitFallback || isLocalSdkRoute;
|
|
21
|
-
}
|
|
22
|
-
var _LicenseValidator = class _LicenseValidator {
|
|
23
|
-
// 5-minute TTL for successful validation only
|
|
24
|
-
constructor() {
|
|
25
|
-
this.cache = /* @__PURE__ */ new Map();
|
|
26
|
-
/** In-flight deduplication: concurrent calls for same key share one network request */
|
|
27
|
-
this.inflight = /* @__PURE__ */ new Map();
|
|
28
|
-
}
|
|
29
|
-
/** @returns Singleton instance of the validator (shared cache across all consumers). */
|
|
30
|
-
static getInstance() {
|
|
31
|
-
if (!_LicenseValidator.instance) {
|
|
32
|
-
_LicenseValidator.instance = new _LicenseValidator();
|
|
33
|
-
}
|
|
34
|
-
return _LicenseValidator.instance;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Purge entries from the local success cache.
|
|
38
|
-
*
|
|
39
|
-
* @param licenseKey - Optional. If provided, only that key's cache entry is
|
|
40
|
-
* removed. If omitted the entire cache is cleared.
|
|
41
|
-
* Callers use this after any 401/403 to ensure the next
|
|
42
|
-
* validate() call re-validates against the server.
|
|
43
|
-
*/
|
|
44
|
-
purgeCache(licenseKey) {
|
|
45
|
-
if (licenseKey) {
|
|
46
|
-
this.cache.delete(licenseKey);
|
|
47
|
-
} else {
|
|
48
|
-
this.cache.clear();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Primary validation entry-point for UI / hook consumers.
|
|
53
|
-
*
|
|
54
|
-
* Resolves the license key, consults the local success cache, performs a
|
|
55
|
-
* server POST for authoritative status, and falls back to local RSA
|
|
56
|
-
* signature verification if the server can't be reached.
|
|
57
|
-
*
|
|
58
|
-
* @throws LicenseValidationError - When no key is provided OR both the
|
|
59
|
-
* server call AND the local-RSA fallback report an invalid/expired key.
|
|
60
|
-
* @throws SDKVersionUnsupportedError - When server reports forceUpgrade=true.
|
|
61
|
-
* @returns A `LicenseValidationResponse` that the UI can use to enable or
|
|
62
|
-
* lock the chat widget.
|
|
63
|
-
*/
|
|
64
|
-
async validate(request) {
|
|
65
|
-
const {
|
|
66
|
-
licenseKey,
|
|
67
|
-
projectId,
|
|
68
|
-
sdkVersion = SDK_VERSION,
|
|
69
|
-
sdk = "@retrivora-ai/rag-engine",
|
|
70
|
-
platform = typeof window !== "undefined" ? "browser" : "node",
|
|
71
|
-
retrivoraApiBase,
|
|
72
|
-
headers: customHeaders
|
|
73
|
-
} = request;
|
|
74
|
-
const effectiveProjectId = projectId || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_PROJECT_ID || process.env.RETRIVORA_PROJECT_ID : "") || "";
|
|
75
|
-
const getHeader = (name) => {
|
|
76
|
-
if (!customHeaders) return void 0;
|
|
77
|
-
const target = name.toLowerCase();
|
|
78
|
-
for (const [k, v] of Object.entries(customHeaders)) {
|
|
79
|
-
if (k.toLowerCase() === target) return v;
|
|
80
|
-
}
|
|
81
|
-
return void 0;
|
|
82
|
-
};
|
|
83
|
-
const authHeader = getHeader("authorization");
|
|
84
|
-
let authHeaderKey = "";
|
|
85
|
-
if (authHeader && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
86
|
-
authHeaderKey = authHeader.replace(/^Bearer\s+/i, "");
|
|
87
|
-
if (authHeaderKey) {
|
|
88
|
-
console.warn(
|
|
89
|
-
'[Retrivora SDK] DEPRECATION WARNING (SEC-7): Repurposing the standard "Authorization: Bearer" header to carry the license key is deprecated and will be removed in a future release. Please use the custom "x-license-key" header instead.'
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
const rawKey = licenseKey || getHeader("x-license-key") || authHeaderKey || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
|
|
94
|
-
const effectiveLicenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
|
|
95
|
-
if (!effectiveLicenseKey) {
|
|
96
|
-
this.purgeCache(effectiveLicenseKey);
|
|
97
|
-
throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or pass licenseKey as a prop.");
|
|
98
|
-
}
|
|
99
|
-
const cached = this.cache.get(effectiveLicenseKey);
|
|
100
|
-
if (cached) {
|
|
101
|
-
const isFresh = Date.now() - cached.timestamp < _LicenseValidator.SUCCESS_CACHE_TTL_MS;
|
|
102
|
-
if (isFresh && cached.response.valid && cached.response.licenseStatus === "ACTIVE" && !cached.response.forceUpgrade) {
|
|
103
|
-
return cached.response;
|
|
104
|
-
} else {
|
|
105
|
-
this.cache.delete(effectiveLicenseKey);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const inflightPromise = this._doNetworkValidate(
|
|
109
|
-
effectiveLicenseKey,
|
|
110
|
-
effectiveProjectId,
|
|
111
|
-
sdkVersion,
|
|
112
|
-
sdk,
|
|
113
|
-
platform,
|
|
114
|
-
retrivoraApiBase,
|
|
115
|
-
customHeaders
|
|
116
|
-
);
|
|
117
|
-
this.inflight.set(effectiveLicenseKey, inflightPromise);
|
|
118
|
-
try {
|
|
119
|
-
return await inflightPromise;
|
|
120
|
-
} finally {
|
|
121
|
-
this.inflight.delete(effectiveLicenseKey);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/** Performs the actual network request. Called once; result shared by in-flight dedup. */
|
|
125
|
-
async _doNetworkValidate(effectiveLicenseKey, effectiveProjectId, sdkVersion, sdk, platform, retrivoraApiBase, customHeaders) {
|
|
126
|
-
const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "https://www.retrivora.com/api";
|
|
127
|
-
const validateUrl = `${base.replace(/\/$/, "")}/v1/license/validate`;
|
|
128
|
-
let res = null;
|
|
129
|
-
try {
|
|
130
|
-
res = await fetch(validateUrl, {
|
|
131
|
-
method: "POST",
|
|
132
|
-
cache: "no-store",
|
|
133
|
-
headers: __spreadValues({
|
|
134
|
-
"Content-Type": "application/json",
|
|
135
|
-
"x-license-key": effectiveLicenseKey,
|
|
136
|
-
"x-sdk-version": sdkVersion
|
|
137
|
-
}, customHeaders || {}),
|
|
138
|
-
body: JSON.stringify({
|
|
139
|
-
licenseKey: effectiveLicenseKey,
|
|
140
|
-
projectId: effectiveProjectId,
|
|
141
|
-
sdkVersion,
|
|
142
|
-
sdk,
|
|
143
|
-
platform
|
|
144
|
-
})
|
|
145
|
-
});
|
|
146
|
-
} catch (err) {
|
|
147
|
-
try {
|
|
148
|
-
if (!canUseLocalValidationFallback(base)) {
|
|
149
|
-
throw err;
|
|
150
|
-
}
|
|
151
|
-
const payload = await LicenseVerifier.verifyAsync(effectiveLicenseKey, effectiveProjectId);
|
|
152
|
-
const fallbackResp = {
|
|
153
|
-
valid: true,
|
|
154
|
-
licenseStatus: "ACTIVE",
|
|
155
|
-
minimumSupportedVersion: "2.1.0",
|
|
156
|
-
latestVersion: SDK_VERSION,
|
|
157
|
-
forceUpgrade: false,
|
|
158
|
-
expiresAt: payload.expiresAt ? new Date(payload.expiresAt * 1e3).toISOString() : null,
|
|
159
|
-
message: "Local license verification active."
|
|
160
|
-
};
|
|
161
|
-
this.cache.set(effectiveLicenseKey, { response: fallbackResp, timestamp: Date.now() });
|
|
162
|
-
return fallbackResp;
|
|
163
|
-
} catch (e) {
|
|
164
|
-
this.purgeCache(effectiveLicenseKey);
|
|
165
|
-
throw new LicenseValidationError(`License validation request failed: ${(err == null ? void 0 : err.message) || "Network error"}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (res && !res.ok && canUseLocalValidationFallback(base, res.status)) {
|
|
169
|
-
try {
|
|
170
|
-
const payload = await LicenseVerifier.verifyAsync(effectiveLicenseKey, effectiveProjectId);
|
|
171
|
-
const fallbackResp = {
|
|
172
|
-
valid: true,
|
|
173
|
-
licenseStatus: "ACTIVE",
|
|
174
|
-
minimumSupportedVersion: "2.1.0",
|
|
175
|
-
latestVersion: SDK_VERSION,
|
|
176
|
-
forceUpgrade: false,
|
|
177
|
-
expiresAt: payload.expiresAt ? new Date(payload.expiresAt * 1e3).toISOString() : null,
|
|
178
|
-
message: "Local license verification active."
|
|
179
|
-
};
|
|
180
|
-
this.cache.set(effectiveLicenseKey, { response: fallbackResp, timestamp: Date.now() });
|
|
181
|
-
return fallbackResp;
|
|
182
|
-
} catch (e) {
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
const data = await res.json().catch(() => ({
|
|
186
|
-
valid: false,
|
|
187
|
-
licenseStatus: "REVOKED",
|
|
188
|
-
minimumSupportedVersion: "2.1.0",
|
|
189
|
-
latestVersion: SDK_VERSION,
|
|
190
|
-
forceUpgrade: false,
|
|
191
|
-
expiresAt: null,
|
|
192
|
-
message: "Failed to parse license validation response."
|
|
193
|
-
}));
|
|
194
|
-
if (!res.ok || !data.valid || data.licenseStatus !== "ACTIVE" || data.forceUpgrade) {
|
|
195
|
-
this.purgeCache(effectiveLicenseKey);
|
|
196
|
-
if (data.forceUpgrade || res.status === 426) {
|
|
197
|
-
throw new SDKVersionUnsupportedError(
|
|
198
|
-
data.message || `This SDK version (${sdkVersion}) is no longer supported. Upgrade to version ${data.latestVersion || "2.2.6"} or later.`,
|
|
199
|
-
data
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
const errMsg = data.message || `License validation failed with status: ${data.licenseStatus}. Access denied.`;
|
|
203
|
-
throw new LicenseValidationError(errMsg, data);
|
|
204
|
-
}
|
|
205
|
-
this.cache.set(effectiveLicenseKey, {
|
|
206
|
-
response: data,
|
|
207
|
-
timestamp: Date.now()
|
|
208
|
-
});
|
|
209
|
-
return data;
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
_LicenseValidator.SUCCESS_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
213
|
-
var LicenseValidator = _LicenseValidator;
|
|
214
|
-
|
|
215
|
-
export {
|
|
216
|
-
LicenseValidator
|
|
217
|
-
};
|