@retrivora-ai/rag-engine 2.5.4 → 2.5.6
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-DO5gj-e5.d.mts → ILLMProvider-DwFj0h2u.d.mts} +2 -2
- package/dist/{ILLMProvider-DO5gj-e5.d.ts → ILLMProvider-DwFj0h2u.d.ts} +2 -2
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +208 -28
- package/dist/handlers/index.mjs +202 -22
- package/dist/{index-Dex_gQ3P.d.mts → index-Byv5MaYi.d.mts} +16 -1
- package/dist/{index-DkOhRqEc.d.ts → index-Cb0GsT16.d.ts} +1 -1
- package/dist/{index-DE8qPWpI.d.mts → index-D1jN8KSF.d.mts} +1 -1
- package/dist/{index--RhMcXrt.d.ts → index-DP3_OpuB.d.ts} +16 -1
- package/dist/index.css +12 -83
- package/dist/index.d.mts +21 -16
- package/dist/index.d.ts +21 -16
- package/dist/index.js +3797 -3847
- package/dist/index.min.css +1 -1
- package/dist/index.mjs +3845 -3896
- package/dist/server.d.mts +57 -10
- package/dist/server.d.ts +57 -10
- package/dist/server.js +236 -34
- package/dist/server.mjs +229 -28
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -332,7 +332,7 @@ var init_package = __esm({
|
|
|
332
332
|
"package.json"() {
|
|
333
333
|
package_default = {
|
|
334
334
|
name: "@retrivora-ai/rag-engine",
|
|
335
|
-
version: "2.5.
|
|
335
|
+
version: "2.5.6",
|
|
336
336
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
337
337
|
author: "Abhinav Alkuchi",
|
|
338
338
|
license: "UNLICENSED",
|
|
@@ -525,13 +525,27 @@ var init_ConfigFetcher = __esm({
|
|
|
525
525
|
* PINECONE_API_KEY if available, or vector operations are handled server-side.
|
|
526
526
|
*/
|
|
527
527
|
static async fetchRemoteConfig(projectId, licenseKey) {
|
|
528
|
-
var _a2, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k;
|
|
529
528
|
const cacheKey = `${projectId}:${licenseKey || ""}`;
|
|
530
529
|
const now = Date.now();
|
|
531
530
|
const cached = this.cache.get(cacheKey);
|
|
532
531
|
if (cached && now - cached.cachedAt < this.TTL_MS) {
|
|
533
532
|
return cached.config;
|
|
534
533
|
}
|
|
534
|
+
const existingInflight = this.inflight.get(cacheKey);
|
|
535
|
+
if (existingInflight) {
|
|
536
|
+
return existingInflight;
|
|
537
|
+
}
|
|
538
|
+
const promise = this._doFetch(projectId, licenseKey, cacheKey, now);
|
|
539
|
+
this.inflight.set(cacheKey, promise);
|
|
540
|
+
try {
|
|
541
|
+
return await promise;
|
|
542
|
+
} finally {
|
|
543
|
+
this.inflight.delete(cacheKey);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
/** Internal: performs the actual HTTP fetch. Shared by all callers via inflight dedup. */
|
|
547
|
+
static async _doFetch(projectId, licenseKey, cacheKey, now) {
|
|
548
|
+
var _a2, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k;
|
|
535
549
|
const controlPlaneUrls = [
|
|
536
550
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
537
551
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
@@ -644,6 +658,8 @@ var init_ConfigFetcher = __esm({
|
|
|
644
658
|
}
|
|
645
659
|
};
|
|
646
660
|
ConfigFetcher.cache = /* @__PURE__ */ new Map();
|
|
661
|
+
/** In-flight deduplication: concurrent callers for the same key share one network request */
|
|
662
|
+
ConfigFetcher.inflight = /* @__PURE__ */ new Map();
|
|
647
663
|
ConfigFetcher.TTL_MS = 5 * 60 * 1e3;
|
|
648
664
|
}
|
|
649
665
|
});
|
|
@@ -1760,11 +1776,11 @@ var MilvusProvider_exports = {};
|
|
|
1760
1776
|
__export(MilvusProvider_exports, {
|
|
1761
1777
|
MilvusProvider: () => MilvusProvider
|
|
1762
1778
|
});
|
|
1763
|
-
var
|
|
1779
|
+
var import_axios4, MilvusProvider;
|
|
1764
1780
|
var init_MilvusProvider = __esm({
|
|
1765
1781
|
"src/providers/vectordb/MilvusProvider.ts"() {
|
|
1766
1782
|
"use strict";
|
|
1767
|
-
|
|
1783
|
+
import_axios4 = __toESM(require("axios"));
|
|
1768
1784
|
init_BaseVectorProvider();
|
|
1769
1785
|
MilvusProvider = class extends BaseVectorProvider {
|
|
1770
1786
|
constructor(config) {
|
|
@@ -1772,7 +1788,7 @@ var init_MilvusProvider = __esm({
|
|
|
1772
1788
|
const opts = config.options;
|
|
1773
1789
|
const baseUrl = opts.baseUrl || opts.uri || (opts.host ? `http://${opts.host}:${opts.port || 19530}` : void 0);
|
|
1774
1790
|
if (!baseUrl) throw new Error("[MilvusProvider] options.baseUrl (or uri / host+port) is required");
|
|
1775
|
-
this.http =
|
|
1791
|
+
this.http = import_axios4.default.create({
|
|
1776
1792
|
baseURL: baseUrl,
|
|
1777
1793
|
headers: __spreadValues(__spreadValues({
|
|
1778
1794
|
"Content-Type": "application/json"
|
|
@@ -1873,11 +1889,11 @@ var QdrantProvider_exports = {};
|
|
|
1873
1889
|
__export(QdrantProvider_exports, {
|
|
1874
1890
|
QdrantProvider: () => QdrantProvider
|
|
1875
1891
|
});
|
|
1876
|
-
var
|
|
1892
|
+
var import_axios5, import_crypto, QdrantProvider;
|
|
1877
1893
|
var init_QdrantProvider = __esm({
|
|
1878
1894
|
"src/providers/vectordb/QdrantProvider.ts"() {
|
|
1879
1895
|
"use strict";
|
|
1880
|
-
|
|
1896
|
+
import_axios5 = __toESM(require("axios"));
|
|
1881
1897
|
import_crypto = __toESM(require("crypto"));
|
|
1882
1898
|
init_BaseVectorProvider();
|
|
1883
1899
|
QdrantProvider = class extends BaseVectorProvider {
|
|
@@ -1890,7 +1906,7 @@ var init_QdrantProvider = __esm({
|
|
|
1890
1906
|
this.contentField = opts.contentField || "content";
|
|
1891
1907
|
this.metadataField = opts.metadataField || "metadata";
|
|
1892
1908
|
this.isFlatPayload = !!opts.flatPayload;
|
|
1893
|
-
this.http =
|
|
1909
|
+
this.http = import_axios5.default.create({
|
|
1894
1910
|
baseURL: baseUrl,
|
|
1895
1911
|
timeout: 15e3,
|
|
1896
1912
|
// 15s timeout for vector DB operations
|
|
@@ -1958,7 +1974,7 @@ var init_QdrantProvider = __esm({
|
|
|
1958
1974
|
try {
|
|
1959
1975
|
await this.http.get(`/collections/${this.indexName}`);
|
|
1960
1976
|
} catch (err) {
|
|
1961
|
-
if (
|
|
1977
|
+
if (import_axios5.default.isAxiosError(err) && ((_a2 = err.response) == null ? void 0 : _a2.status) === 404) {
|
|
1962
1978
|
const opts = this.config.options;
|
|
1963
1979
|
const dimensionsForCreate = opts.dimensions || 1536;
|
|
1964
1980
|
await this.http.put(`/collections/${this.indexName}`, {
|
|
@@ -1988,7 +2004,7 @@ var init_QdrantProvider = __esm({
|
|
|
1988
2004
|
});
|
|
1989
2005
|
} catch (err) {
|
|
1990
2006
|
let status;
|
|
1991
|
-
if (
|
|
2007
|
+
if (import_axios5.default.isAxiosError(err)) status = (_a2 = err.response) == null ? void 0 : _a2.status;
|
|
1992
2008
|
if (status === 409) return;
|
|
1993
2009
|
console.warn(`[QdrantProvider] \u26A0\uFE0F Could not ensure index for "${fullPath}":`, err instanceof Error ? err.message : String(err));
|
|
1994
2010
|
}
|
|
@@ -2112,11 +2128,11 @@ var ChromaDBProvider_exports = {};
|
|
|
2112
2128
|
__export(ChromaDBProvider_exports, {
|
|
2113
2129
|
ChromaDBProvider: () => ChromaDBProvider
|
|
2114
2130
|
});
|
|
2115
|
-
var
|
|
2131
|
+
var import_axios6, ChromaDBProvider;
|
|
2116
2132
|
var init_ChromaDBProvider = __esm({
|
|
2117
2133
|
"src/providers/vectordb/ChromaDBProvider.ts"() {
|
|
2118
2134
|
"use strict";
|
|
2119
|
-
|
|
2135
|
+
import_axios6 = __toESM(require("axios"));
|
|
2120
2136
|
init_BaseVectorProvider();
|
|
2121
2137
|
ChromaDBProvider = class extends BaseVectorProvider {
|
|
2122
2138
|
constructor(config) {
|
|
@@ -2125,7 +2141,7 @@ var init_ChromaDBProvider = __esm({
|
|
|
2125
2141
|
const opts = config.options;
|
|
2126
2142
|
const baseUrl = opts.baseUrl || (opts.host ? `http://${opts.host}:${opts.port || 8e3}` : void 0);
|
|
2127
2143
|
if (!baseUrl) throw new Error("[ChromaDBProvider] options.baseUrl is required");
|
|
2128
|
-
this.http =
|
|
2144
|
+
this.http = import_axios6.default.create({
|
|
2129
2145
|
baseURL: baseUrl,
|
|
2130
2146
|
headers: { "Content-Type": "application/json" }
|
|
2131
2147
|
});
|
|
@@ -2139,7 +2155,7 @@ var init_ChromaDBProvider = __esm({
|
|
|
2139
2155
|
const { data } = await this.http.get(`/api/v1/collections/${this.indexName}`);
|
|
2140
2156
|
this.collectionId = data.id;
|
|
2141
2157
|
} catch (err) {
|
|
2142
|
-
if (
|
|
2158
|
+
if (import_axios6.default.isAxiosError(err) && ((_a2 = err.response) == null ? void 0 : _a2.status) === 404) {
|
|
2143
2159
|
const { data } = await this.http.post("/api/v1/collections", {
|
|
2144
2160
|
name: this.indexName
|
|
2145
2161
|
});
|
|
@@ -2220,11 +2236,11 @@ var RedisProvider_exports = {};
|
|
|
2220
2236
|
__export(RedisProvider_exports, {
|
|
2221
2237
|
RedisProvider: () => RedisProvider
|
|
2222
2238
|
});
|
|
2223
|
-
var
|
|
2239
|
+
var import_axios7, RedisProvider;
|
|
2224
2240
|
var init_RedisProvider = __esm({
|
|
2225
2241
|
"src/providers/vectordb/RedisProvider.ts"() {
|
|
2226
2242
|
"use strict";
|
|
2227
|
-
|
|
2243
|
+
import_axios7 = __toESM(require("axios"));
|
|
2228
2244
|
init_BaseVectorProvider();
|
|
2229
2245
|
RedisProvider = class extends BaseVectorProvider {
|
|
2230
2246
|
constructor(config) {
|
|
@@ -2232,7 +2248,7 @@ var init_RedisProvider = __esm({
|
|
|
2232
2248
|
const opts = config.options;
|
|
2233
2249
|
const baseUrl = opts.baseUrl || opts.url || (opts.host ? `http://${opts.host}:${opts.port || 6379}` : void 0);
|
|
2234
2250
|
if (!baseUrl) throw new Error("[RedisProvider] options.baseUrl is required");
|
|
2235
|
-
this.http =
|
|
2251
|
+
this.http = import_axios7.default.create({
|
|
2236
2252
|
baseURL: baseUrl,
|
|
2237
2253
|
headers: __spreadValues({
|
|
2238
2254
|
"Content-Type": "application/json"
|
|
@@ -2302,11 +2318,11 @@ var WeaviateProvider_exports = {};
|
|
|
2302
2318
|
__export(WeaviateProvider_exports, {
|
|
2303
2319
|
WeaviateProvider: () => WeaviateProvider
|
|
2304
2320
|
});
|
|
2305
|
-
var
|
|
2321
|
+
var import_axios8, WeaviateProvider;
|
|
2306
2322
|
var init_WeaviateProvider = __esm({
|
|
2307
2323
|
"src/providers/vectordb/WeaviateProvider.ts"() {
|
|
2308
2324
|
"use strict";
|
|
2309
|
-
|
|
2325
|
+
import_axios8 = __toESM(require("axios"));
|
|
2310
2326
|
init_BaseVectorProvider();
|
|
2311
2327
|
WeaviateProvider = class extends BaseVectorProvider {
|
|
2312
2328
|
constructor(config) {
|
|
@@ -2314,7 +2330,7 @@ var init_WeaviateProvider = __esm({
|
|
|
2314
2330
|
const opts = config.options;
|
|
2315
2331
|
const baseUrl = opts.baseUrl || opts.url;
|
|
2316
2332
|
if (!baseUrl) throw new Error("[WeaviateProvider] options.baseUrl is required");
|
|
2317
|
-
this.http =
|
|
2333
|
+
this.http = import_axios8.default.create({
|
|
2318
2334
|
baseURL: baseUrl,
|
|
2319
2335
|
headers: __spreadValues(__spreadValues({
|
|
2320
2336
|
"Content-Type": "application/json"
|
|
@@ -2454,11 +2470,11 @@ var UniversalVectorProvider_exports = {};
|
|
|
2454
2470
|
__export(UniversalVectorProvider_exports, {
|
|
2455
2471
|
UniversalVectorProvider: () => UniversalVectorProvider
|
|
2456
2472
|
});
|
|
2457
|
-
var
|
|
2473
|
+
var import_axios9, UniversalVectorProvider;
|
|
2458
2474
|
var init_UniversalVectorProvider = __esm({
|
|
2459
2475
|
"src/providers/vectordb/UniversalVectorProvider.ts"() {
|
|
2460
2476
|
"use strict";
|
|
2461
|
-
|
|
2477
|
+
import_axios9 = __toESM(require("axios"));
|
|
2462
2478
|
init_BaseVectorProvider();
|
|
2463
2479
|
init_templateUtils();
|
|
2464
2480
|
UniversalVectorProvider = class extends BaseVectorProvider {
|
|
@@ -2471,7 +2487,7 @@ var init_UniversalVectorProvider = __esm({
|
|
|
2471
2487
|
}
|
|
2472
2488
|
async initialize() {
|
|
2473
2489
|
var _a2;
|
|
2474
|
-
this.http =
|
|
2490
|
+
this.http = import_axios9.default.create({
|
|
2475
2491
|
baseURL: this.opts.baseUrl,
|
|
2476
2492
|
headers: __spreadValues({
|
|
2477
2493
|
"Content-Type": "application/json"
|
|
@@ -2702,6 +2718,7 @@ __export(server_exports, {
|
|
|
2702
2718
|
ConfigResolver: () => ConfigResolver,
|
|
2703
2719
|
ConfigValidator: () => ConfigValidator,
|
|
2704
2720
|
ConfigurationException: () => ConfigurationException,
|
|
2721
|
+
CustomEmbeddingProvider: () => CustomEmbeddingProvider,
|
|
2705
2722
|
DocumentChunker: () => DocumentChunker,
|
|
2706
2723
|
DocumentParser: () => DocumentParser,
|
|
2707
2724
|
EmbeddingFailedException: () => EmbeddingFailedException,
|
|
@@ -3150,7 +3167,9 @@ var LLM_PROVIDERS = [
|
|
|
3150
3167
|
"qwen",
|
|
3151
3168
|
"rest",
|
|
3152
3169
|
"universal_rest",
|
|
3153
|
-
"custom"
|
|
3170
|
+
"custom",
|
|
3171
|
+
"custom_embedding",
|
|
3172
|
+
"local_embedding"
|
|
3154
3173
|
];
|
|
3155
3174
|
var EMBEDDING_PROVIDERS = [
|
|
3156
3175
|
"openai",
|
|
@@ -3159,7 +3178,9 @@ var EMBEDDING_PROVIDERS = [
|
|
|
3159
3178
|
"qwen",
|
|
3160
3179
|
"rest",
|
|
3161
3180
|
"universal_rest",
|
|
3162
|
-
"custom"
|
|
3181
|
+
"custom",
|
|
3182
|
+
"custom_embedding",
|
|
3183
|
+
"local_embedding"
|
|
3163
3184
|
];
|
|
3164
3185
|
var PROVIDERS_WITH_EMBEDDINGS = [
|
|
3165
3186
|
"openai",
|
|
@@ -3167,7 +3188,10 @@ var PROVIDERS_WITH_EMBEDDINGS = [
|
|
|
3167
3188
|
"gemini",
|
|
3168
3189
|
"qwen",
|
|
3169
3190
|
"rest",
|
|
3170
|
-
"universal_rest"
|
|
3191
|
+
"universal_rest",
|
|
3192
|
+
"custom",
|
|
3193
|
+
"custom_embedding",
|
|
3194
|
+
"local_embedding"
|
|
3171
3195
|
];
|
|
3172
3196
|
|
|
3173
3197
|
// src/config/serverConfig.ts
|
|
@@ -3913,8 +3937,8 @@ var OllamaProvider = class {
|
|
|
3913
3937
|
const baseUrl = config.baseUrl || "http://localhost:11434";
|
|
3914
3938
|
const modelName = config.model;
|
|
3915
3939
|
try {
|
|
3916
|
-
const
|
|
3917
|
-
const { data } = await
|
|
3940
|
+
const axios11 = (await import("axios")).default;
|
|
3941
|
+
const { data } = await axios11.get(`${baseUrl}/api/tags`);
|
|
3918
3942
|
const models = data.models || [];
|
|
3919
3943
|
const hasModel = models.some((m) => m.name === modelName || m.name.startsWith(`${modelName}:`));
|
|
3920
3944
|
return {
|
|
@@ -5031,6 +5055,158 @@ ${context != null ? context : "None"}` },
|
|
|
5031
5055
|
}
|
|
5032
5056
|
};
|
|
5033
5057
|
|
|
5058
|
+
// src/llm/providers/CustomEmbeddingProvider.ts
|
|
5059
|
+
var import_axios3 = __toESM(require("axios"));
|
|
5060
|
+
init_templateUtils();
|
|
5061
|
+
var CustomEmbeddingProvider = class {
|
|
5062
|
+
constructor(config) {
|
|
5063
|
+
var _a2, _b;
|
|
5064
|
+
this.model = config.model || "custom-embedding-model";
|
|
5065
|
+
this.apiKey = config.apiKey;
|
|
5066
|
+
const options = (_a2 = config.options) != null ? _a2 : {};
|
|
5067
|
+
this.opts = {
|
|
5068
|
+
baseUrl: config.baseUrl || options.baseUrl,
|
|
5069
|
+
embedPath: options.embedPath || "/embeddings",
|
|
5070
|
+
pingPath: options.pingPath || "/health",
|
|
5071
|
+
queryPrefix: options.queryPrefix || "",
|
|
5072
|
+
documentPrefix: options.documentPrefix || "",
|
|
5073
|
+
embedPayloadTemplate: options.embedPayloadTemplate,
|
|
5074
|
+
embedExtractPath: options.embedExtractPath,
|
|
5075
|
+
headers: options.headers || {},
|
|
5076
|
+
timeout: options.timeout || 3e4
|
|
5077
|
+
};
|
|
5078
|
+
this.baseUrl = (_b = this.opts.baseUrl) != null ? _b : "";
|
|
5079
|
+
if (!this.baseUrl) {
|
|
5080
|
+
throw new Error("[CustomEmbeddingProvider] baseUrl is required in config or config.options");
|
|
5081
|
+
}
|
|
5082
|
+
const headers = __spreadValues(__spreadValues({
|
|
5083
|
+
"Content-Type": "application/json"
|
|
5084
|
+
}, this.apiKey ? { Authorization: `Bearer ${this.apiKey}` } : {}), this.opts.headers || {});
|
|
5085
|
+
this.http = import_axios3.default.create({
|
|
5086
|
+
baseURL: this.baseUrl.replace(/\/$/, ""),
|
|
5087
|
+
headers,
|
|
5088
|
+
timeout: this.opts.timeout
|
|
5089
|
+
});
|
|
5090
|
+
}
|
|
5091
|
+
/**
|
|
5092
|
+
* Dummy chat implementation. CustomEmbeddingProvider is dedicated to embedding generation.
|
|
5093
|
+
*/
|
|
5094
|
+
async chat(_messages, _context, _options) {
|
|
5095
|
+
throw new Error("[CustomEmbeddingProvider] chat() is not supported on a dedicated embedding provider.");
|
|
5096
|
+
}
|
|
5097
|
+
/**
|
|
5098
|
+
* Generate vector embedding for a single string.
|
|
5099
|
+
*/
|
|
5100
|
+
async embed(text, options) {
|
|
5101
|
+
var _a2;
|
|
5102
|
+
const taskType = (_a2 = options == null ? void 0 : options.taskType) != null ? _a2 : "document";
|
|
5103
|
+
const prefix = taskType === "query" ? this.opts.queryPrefix : this.opts.documentPrefix;
|
|
5104
|
+
const formattedText = prefix ? `${prefix}${text}` : text;
|
|
5105
|
+
const modelToUse = (options == null ? void 0 : options.model) || this.model;
|
|
5106
|
+
const path2 = this.opts.embedPath || "/embeddings";
|
|
5107
|
+
let payload;
|
|
5108
|
+
if (this.opts.embedPayloadTemplate) {
|
|
5109
|
+
payload = buildPayload(this.opts.embedPayloadTemplate, {
|
|
5110
|
+
input: formattedText,
|
|
5111
|
+
model: modelToUse
|
|
5112
|
+
});
|
|
5113
|
+
} else {
|
|
5114
|
+
payload = {
|
|
5115
|
+
model: modelToUse,
|
|
5116
|
+
input: formattedText
|
|
5117
|
+
};
|
|
5118
|
+
}
|
|
5119
|
+
try {
|
|
5120
|
+
const { data } = await this.http.post(path2, payload);
|
|
5121
|
+
const vector = this.extractVector(data);
|
|
5122
|
+
if (vector) return vector;
|
|
5123
|
+
throw new Error(`[CustomEmbeddingProvider] Failed to extract embedding vector from response at ${path2}`);
|
|
5124
|
+
} catch (err) {
|
|
5125
|
+
console.error("[CustomEmbeddingProvider] Embedding request failed:", {
|
|
5126
|
+
baseUrl: this.baseUrl,
|
|
5127
|
+
path: path2,
|
|
5128
|
+
model: modelToUse,
|
|
5129
|
+
error: (err == null ? void 0 : err.message) || err
|
|
5130
|
+
});
|
|
5131
|
+
throw err;
|
|
5132
|
+
}
|
|
5133
|
+
}
|
|
5134
|
+
/**
|
|
5135
|
+
* Batch embedding generation for multiple texts.
|
|
5136
|
+
*/
|
|
5137
|
+
async batchEmbed(texts, options) {
|
|
5138
|
+
var _a2;
|
|
5139
|
+
if (!Array.isArray(texts) || texts.length === 0) return [];
|
|
5140
|
+
const taskType = (_a2 = options == null ? void 0 : options.taskType) != null ? _a2 : "document";
|
|
5141
|
+
const prefix = taskType === "query" ? this.opts.queryPrefix : this.opts.documentPrefix;
|
|
5142
|
+
const formattedTexts = prefix ? texts.map((t) => `${prefix}${t}`) : texts;
|
|
5143
|
+
const modelToUse = (options == null ? void 0 : options.model) || this.model;
|
|
5144
|
+
const path2 = this.opts.embedPath || "/embeddings";
|
|
5145
|
+
if (!this.opts.embedPayloadTemplate) {
|
|
5146
|
+
try {
|
|
5147
|
+
const payload = {
|
|
5148
|
+
model: modelToUse,
|
|
5149
|
+
input: formattedTexts
|
|
5150
|
+
};
|
|
5151
|
+
const { data } = await this.http.post(path2, payload);
|
|
5152
|
+
const batchVectors = this.extractBatchVectors(data);
|
|
5153
|
+
if (batchVectors && batchVectors.length === texts.length) {
|
|
5154
|
+
return batchVectors;
|
|
5155
|
+
}
|
|
5156
|
+
} catch (e) {
|
|
5157
|
+
}
|
|
5158
|
+
}
|
|
5159
|
+
return Promise.all(texts.map((text) => this.embed(text, options)));
|
|
5160
|
+
}
|
|
5161
|
+
/**
|
|
5162
|
+
* Ping provider endpoint for health check.
|
|
5163
|
+
*/
|
|
5164
|
+
async ping() {
|
|
5165
|
+
try {
|
|
5166
|
+
const pingPath = this.opts.pingPath || "/health";
|
|
5167
|
+
const res = await this.http.get(pingPath);
|
|
5168
|
+
return res.status >= 200 && res.status < 300;
|
|
5169
|
+
} catch (e) {
|
|
5170
|
+
try {
|
|
5171
|
+
const embedPath = this.opts.embedPath || "/embeddings";
|
|
5172
|
+
await this.http.post(embedPath, { input: "ping", model: this.model });
|
|
5173
|
+
return true;
|
|
5174
|
+
} catch (e2) {
|
|
5175
|
+
return false;
|
|
5176
|
+
}
|
|
5177
|
+
}
|
|
5178
|
+
}
|
|
5179
|
+
extractVector(data) {
|
|
5180
|
+
if (!data) return void 0;
|
|
5181
|
+
if (this.opts.embedExtractPath) {
|
|
5182
|
+
const extracted = resolvePath(data, this.opts.embedExtractPath);
|
|
5183
|
+
if (Array.isArray(extracted) && typeof extracted[0] === "number") {
|
|
5184
|
+
return extracted;
|
|
5185
|
+
}
|
|
5186
|
+
}
|
|
5187
|
+
const directVector = resolvePath(data, "data[0].embedding") || resolvePath(data, "embedding") || resolvePath(data, "embeddings[0]") || resolvePath(data, "data[0].vector") || resolvePath(data, "vector");
|
|
5188
|
+
if (Array.isArray(directVector) && typeof directVector[0] === "number") {
|
|
5189
|
+
return directVector;
|
|
5190
|
+
}
|
|
5191
|
+
if (Array.isArray(data) && typeof data[0] === "number") {
|
|
5192
|
+
return data;
|
|
5193
|
+
}
|
|
5194
|
+
return void 0;
|
|
5195
|
+
}
|
|
5196
|
+
extractBatchVectors(data) {
|
|
5197
|
+
if (!data) return void 0;
|
|
5198
|
+
if (typeof data === "object" && data !== null && Array.isArray(data.data)) {
|
|
5199
|
+
const list = data.data;
|
|
5200
|
+
const vectors = list.map((item) => (item == null ? void 0 : item.embedding) || (item == null ? void 0 : item.vector)).filter((v) => Array.isArray(v));
|
|
5201
|
+
if (vectors.length > 0) return vectors;
|
|
5202
|
+
}
|
|
5203
|
+
if (Array.isArray(data) && Array.isArray(data[0]) && typeof data[0][0] === "number") {
|
|
5204
|
+
return data;
|
|
5205
|
+
}
|
|
5206
|
+
return void 0;
|
|
5207
|
+
}
|
|
5208
|
+
};
|
|
5209
|
+
|
|
5034
5210
|
// src/llm/LLMFactory.ts
|
|
5035
5211
|
var customProviders = /* @__PURE__ */ new Map();
|
|
5036
5212
|
var LLMFactory = class _LLMFactory {
|
|
@@ -5073,6 +5249,8 @@ var LLMFactory = class _LLMFactory {
|
|
|
5073
5249
|
"rest",
|
|
5074
5250
|
"universal_rest",
|
|
5075
5251
|
"custom",
|
|
5252
|
+
"custom_embedding",
|
|
5253
|
+
"local_embedding",
|
|
5076
5254
|
...Array.from(customProviders.keys())
|
|
5077
5255
|
];
|
|
5078
5256
|
}
|
|
@@ -5091,6 +5269,9 @@ var LLMFactory = class _LLMFactory {
|
|
|
5091
5269
|
return new GroqProvider(llmConfig, embeddingConfig);
|
|
5092
5270
|
case "qwen":
|
|
5093
5271
|
return new QwenProvider(llmConfig, embeddingConfig);
|
|
5272
|
+
case "custom_embedding":
|
|
5273
|
+
case "local_embedding":
|
|
5274
|
+
return new CustomEmbeddingProvider(llmConfig);
|
|
5094
5275
|
case "rest":
|
|
5095
5276
|
case "universal_rest":
|
|
5096
5277
|
case "custom":
|
|
@@ -12376,6 +12557,8 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12376
12557
|
// 5-minute TTL for successful validation only
|
|
12377
12558
|
constructor() {
|
|
12378
12559
|
this.cache = /* @__PURE__ */ new Map();
|
|
12560
|
+
/** In-flight deduplication: concurrent calls for same key share one network request */
|
|
12561
|
+
this.inflight = /* @__PURE__ */ new Map();
|
|
12379
12562
|
}
|
|
12380
12563
|
/** @returns Singleton instance of the validator (shared cache across all consumers). */
|
|
12381
12564
|
static getInstance() {
|
|
@@ -12456,6 +12639,24 @@ var _LicenseValidator = class _LicenseValidator {
|
|
|
12456
12639
|
this.cache.delete(effectiveLicenseKey);
|
|
12457
12640
|
}
|
|
12458
12641
|
}
|
|
12642
|
+
const inflightPromise = this._doNetworkValidate(
|
|
12643
|
+
effectiveLicenseKey,
|
|
12644
|
+
effectiveProjectId,
|
|
12645
|
+
sdkVersion,
|
|
12646
|
+
sdk,
|
|
12647
|
+
platform,
|
|
12648
|
+
retrivoraApiBase,
|
|
12649
|
+
customHeaders
|
|
12650
|
+
);
|
|
12651
|
+
this.inflight.set(effectiveLicenseKey, inflightPromise);
|
|
12652
|
+
try {
|
|
12653
|
+
return await inflightPromise;
|
|
12654
|
+
} finally {
|
|
12655
|
+
this.inflight.delete(effectiveLicenseKey);
|
|
12656
|
+
}
|
|
12657
|
+
}
|
|
12658
|
+
/** Performs the actual network request. Called once; result shared by in-flight dedup. */
|
|
12659
|
+
async _doNetworkValidate(effectiveLicenseKey, effectiveProjectId, sdkVersion, sdk, platform, retrivoraApiBase, customHeaders) {
|
|
12459
12660
|
const base = retrivoraApiBase || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_API_BASE || process.env.RETRIVORA_API_BASE : "") || "https://www.retrivora.com/api";
|
|
12460
12661
|
const validateUrl = `${base.replace(/\/$/, "")}/v1/license/validate`;
|
|
12461
12662
|
let res = null;
|
|
@@ -12546,7 +12747,7 @@ _LicenseValidator.SUCCESS_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
|
12546
12747
|
var LicenseValidator = _LicenseValidator;
|
|
12547
12748
|
|
|
12548
12749
|
// src/config/LicenseConfigResolver.ts
|
|
12549
|
-
var
|
|
12750
|
+
var import_axios10 = __toESM(require("axios"));
|
|
12550
12751
|
var LicenseConfigResolver = class {
|
|
12551
12752
|
/**
|
|
12552
12753
|
* Validate and resolve configuration from license key
|
|
@@ -12570,7 +12771,7 @@ var LicenseConfigResolver = class {
|
|
|
12570
12771
|
*/
|
|
12571
12772
|
static async fetchTierConfig(licenseKey, projectId) {
|
|
12572
12773
|
try {
|
|
12573
|
-
const response = await
|
|
12774
|
+
const response = await import_axios10.default.post(
|
|
12574
12775
|
this.RETRIVORA_CONFIG_URL,
|
|
12575
12776
|
{ licenseKey, projectId },
|
|
12576
12777
|
{
|
|
@@ -12601,7 +12802,7 @@ var LicenseConfigResolver = class {
|
|
|
12601
12802
|
*/
|
|
12602
12803
|
static async fetchProviderCredentials(licenseKey, projectId) {
|
|
12603
12804
|
try {
|
|
12604
|
-
const response = await
|
|
12805
|
+
const response = await import_axios10.default.post(
|
|
12605
12806
|
this.RETRIVORA_CREDENTIALS_URL,
|
|
12606
12807
|
{ licenseKey, projectId },
|
|
12607
12808
|
{
|
|
@@ -12799,12 +13000,12 @@ var _TelemetryService = class _TelemetryService {
|
|
|
12799
13000
|
});
|
|
12800
13001
|
}
|
|
12801
13002
|
/**
|
|
12802
|
-
* Record query execution event
|
|
13003
|
+
* Record query execution event (PII-safe)
|
|
12803
13004
|
*/
|
|
12804
13005
|
recordQueryExecuted(data) {
|
|
12805
13006
|
this.recordEvent({
|
|
12806
13007
|
eventType: "query_executed" /* QUERY_EXECUTED */,
|
|
12807
|
-
|
|
13008
|
+
queryLength: data.queryLength,
|
|
12808
13009
|
resultCount: data.resultCount,
|
|
12809
13010
|
durationMs: data.durationMs,
|
|
12810
13011
|
operationId: data.operationId
|
|
@@ -13050,7 +13251,7 @@ var LicensedRetrivora = class {
|
|
|
13050
13251
|
const durationMs = Date.now() - startTime;
|
|
13051
13252
|
if (telemetry) {
|
|
13052
13253
|
telemetry.recordQueryExecuted({
|
|
13053
|
-
queryText,
|
|
13254
|
+
queryLength: queryText.length,
|
|
13054
13255
|
resultCount: ((_a2 = response.sources) == null ? void 0 : _a2.length) || 0,
|
|
13055
13256
|
durationMs,
|
|
13056
13257
|
operationId
|
|
@@ -13132,6 +13333,7 @@ async function createRetrivora(options) {
|
|
|
13132
13333
|
ConfigResolver,
|
|
13133
13334
|
ConfigValidator,
|
|
13134
13335
|
ConfigurationException,
|
|
13336
|
+
CustomEmbeddingProvider,
|
|
13135
13337
|
DocumentChunker,
|
|
13136
13338
|
DocumentParser,
|
|
13137
13339
|
EmbeddingFailedException,
|