@retrivora-ai/rag-engine 2.2.0 → 2.2.2
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/handlers/index.js +93 -60
- package/dist/handlers/index.mjs +93 -60
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/server.d.mts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +93 -60
- package/dist/server.mjs +93 -60
- package/package.json +1 -1
- package/src/config/serverConfig.ts +21 -7
- package/src/core/ConfigFetcher.ts +7 -0
- package/src/core/LicenseVerifier.ts +8 -2
- package/src/core/Pipeline.ts +5 -7
- package/src/providers/vectordb/BaseVectorProvider.ts +1 -0
- package/src/providers/vectordb/PineconeProvider.ts +16 -1
package/dist/server.mjs
CHANGED
|
@@ -681,7 +681,7 @@ async function dispatchEmbedding(req, apiKeyOverride) {
|
|
|
681
681
|
}
|
|
682
682
|
}
|
|
683
683
|
const geminiKey = process.env.GEMINI_API_KEY || effectiveKey;
|
|
684
|
-
const isGeminiKeyValid = Boolean(geminiKey &&
|
|
684
|
+
const isGeminiKeyValid = Boolean(geminiKey && !geminiKey.startsWith("eyJ"));
|
|
685
685
|
if (isGeminiKeyValid) {
|
|
686
686
|
try {
|
|
687
687
|
return await handleGeminiEmbedding(req, effectiveKey);
|
|
@@ -799,7 +799,9 @@ var init_ConfigFetcher = __esm({
|
|
|
799
799
|
const controlPlaneUrls = [
|
|
800
800
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
801
801
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
802
|
+
"https://www.retrivora.com",
|
|
802
803
|
"https://retrivora.com",
|
|
804
|
+
"http://localhost:3001",
|
|
803
805
|
"http://localhost:3000"
|
|
804
806
|
].filter(Boolean);
|
|
805
807
|
for (const baseUrl of controlPlaneUrls) {
|
|
@@ -814,11 +816,14 @@ var init_ConfigFetcher = __esm({
|
|
|
814
816
|
if (res.ok) {
|
|
815
817
|
const data = await res.json();
|
|
816
818
|
if ((data == null ? void 0 : data.success) && ((_a2 = data == null ? void 0 : data.vectorDb) == null ? void 0 : _a2.apiKey)) {
|
|
819
|
+
const fetchedProjectId = data.projectId || projectId;
|
|
817
820
|
const config = {
|
|
821
|
+
projectId: fetchedProjectId,
|
|
818
822
|
vectorDb: {
|
|
819
823
|
apiKey: data.vectorDb.apiKey,
|
|
820
824
|
indexName: data.vectorDb.indexName || "retrivora-free",
|
|
821
|
-
provider: data.vectorDb.provider || "pinecone"
|
|
825
|
+
provider: data.vectorDb.provider || "pinecone",
|
|
826
|
+
projectId: fetchedProjectId
|
|
822
827
|
},
|
|
823
828
|
embedding: {
|
|
824
829
|
provider: ((_b = data.embedding) == null ? void 0 : _b.provider) || "universal_rest",
|
|
@@ -936,8 +941,20 @@ var init_PineconeProvider = __esm({
|
|
|
936
941
|
if (this.client) return;
|
|
937
942
|
let key = this.apiKey || process.env.PINECONE_API_KEY || "";
|
|
938
943
|
if (!key) {
|
|
939
|
-
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || "my-rag-app";
|
|
940
944
|
const licenseKey = process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
945
|
+
const jwtProjectId = (() => {
|
|
946
|
+
if (!licenseKey) return void 0;
|
|
947
|
+
try {
|
|
948
|
+
const parts = licenseKey.split(".");
|
|
949
|
+
if (parts.length >= 2) {
|
|
950
|
+
const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
951
|
+
return payload == null ? void 0 : payload.projectId;
|
|
952
|
+
}
|
|
953
|
+
} catch (e) {
|
|
954
|
+
}
|
|
955
|
+
return void 0;
|
|
956
|
+
})();
|
|
957
|
+
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
|
|
941
958
|
const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
|
|
942
959
|
if (remoteConfig == null ? void 0 : remoteConfig.apiKey) {
|
|
943
960
|
key = remoteConfig.apiKey;
|
|
@@ -945,6 +962,9 @@ var init_PineconeProvider = __esm({
|
|
|
945
962
|
if (remoteConfig.indexName) {
|
|
946
963
|
this.indexName = remoteConfig.indexName;
|
|
947
964
|
}
|
|
965
|
+
if (remoteConfig.projectId) {
|
|
966
|
+
this.projectId = remoteConfig.projectId;
|
|
967
|
+
}
|
|
948
968
|
}
|
|
949
969
|
}
|
|
950
970
|
if (!key) {
|
|
@@ -2924,7 +2944,8 @@ var LicenseVerifier = class {
|
|
|
2924
2944
|
};
|
|
2925
2945
|
}
|
|
2926
2946
|
try {
|
|
2927
|
-
const
|
|
2947
|
+
const rawToken = licenseKey.replace(/^rtv_/i, "").trim();
|
|
2948
|
+
const parts = rawToken.split(".");
|
|
2928
2949
|
if (parts.length !== 3) {
|
|
2929
2950
|
throw new Error("Malformed token structure (expected 3 parts).");
|
|
2930
2951
|
}
|
|
@@ -2948,7 +2969,8 @@ var LicenseVerifier = class {
|
|
|
2948
2969
|
if (!payload.projectId) {
|
|
2949
2970
|
throw new Error('License payload is missing "projectId".');
|
|
2950
2971
|
}
|
|
2951
|
-
|
|
2972
|
+
const isProjectMatch = payload.projectId === currentProjectId || payload.projectId === `retrivora-${currentProjectId}` || `retrivora-${payload.projectId}` === currentProjectId;
|
|
2973
|
+
if (!isProjectMatch) {
|
|
2952
2974
|
throw new Error(
|
|
2953
2975
|
`Project ID mismatch. License is bound to project namespace "${payload.projectId}" but configuration has "${currentProjectId}".`
|
|
2954
2976
|
);
|
|
@@ -3159,46 +3181,58 @@ function getRagConfig(baseConfig, env = process.env) {
|
|
|
3159
3181
|
return getEnvConfig(env, baseConfig);
|
|
3160
3182
|
}
|
|
3161
3183
|
function getEnvConfig(env = process.env, base) {
|
|
3162
|
-
var _a2, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb, _Ib;
|
|
3163
|
-
const
|
|
3164
|
-
const
|
|
3165
|
-
|
|
3184
|
+
var _a2, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa, _Ba, _Ca, _Da, _Ea, _Fa, _Ga, _Ha, _Ia, _Ja, _Ka, _La, _Ma, _Na, _Oa, _Pa, _Qa, _Ra, _Sa, _Ta, _Ua, _Va, _Wa, _Xa, _Ya, _Za, __a, _$a, _ab, _bb, _cb, _db, _eb, _fb, _gb, _hb, _ib, _jb, _kb, _lb, _mb, _nb, _ob, _pb, _qb, _rb, _sb, _tb, _ub, _vb, _wb, _xb, _yb, _zb, _Ab, _Bb, _Cb, _Db, _Eb, _Fb, _Gb, _Hb, _Ib, _Jb, _Kb;
|
|
3185
|
+
const licenseKey = (_d = (_c = (_b = (_a2 = readString(env, "RAG_LICENSE_KEY")) != null ? _a2 : readString(env, "RETRIVORA_LICENSE_KEY")) != null ? _b : readString(env, "NEXT_PUBLIC_RETRIVORA_LICENSE_KEY")) != null ? _c : readString(env, "LICENSE_KEY")) != null ? _d : base == null ? void 0 : base.licenseKey;
|
|
3186
|
+
const jwtProjectId = (() => {
|
|
3187
|
+
if (!licenseKey) return void 0;
|
|
3188
|
+
try {
|
|
3189
|
+
const parts = licenseKey.split(".");
|
|
3190
|
+
if (parts.length >= 2) {
|
|
3191
|
+
const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
3192
|
+
return payload == null ? void 0 : payload.projectId;
|
|
3193
|
+
}
|
|
3194
|
+
} catch (e) {
|
|
3195
|
+
}
|
|
3196
|
+
return void 0;
|
|
3197
|
+
})();
|
|
3198
|
+
const projectId = (_i = (_h = (_g2 = (_f = (_e = readString(env, "RAG_PROJECT_ID")) != null ? _e : readString(env, "NEXT_PUBLIC_RAG_PROJECT_ID")) != null ? _f : readString(env, "NEXT_PUBLIC_PROJECT_ID")) != null ? _g2 : base == null ? void 0 : base.projectId) != null ? _h : jwtProjectId) != null ? _i : "default";
|
|
3199
|
+
const telemetryEnabled = readString(env, "TELEMETRY_ENABLED") === "true" || readString(env, "NEXT_PUBLIC_TELEMETRY_ENABLED") === "true" || ((_j = base == null ? void 0 : base.telemetry) == null ? void 0 : _j.enabled) || Boolean(licenseKey);
|
|
3166
3200
|
const vectorProvider = readEnum(env, "VECTOR_DB_PROVIDER", "pinecone", VECTOR_DB_PROVIDERS);
|
|
3167
3201
|
const embeddingDimensions = readNumber(env, "EMBEDDING_DIMENSIONS", 768);
|
|
3168
3202
|
const vectorDbOptions = {};
|
|
3169
3203
|
if (vectorProvider === "pinecone") {
|
|
3170
|
-
vectorDbOptions.apiKey = (
|
|
3171
|
-
vectorDbOptions.indexName = (
|
|
3204
|
+
vectorDbOptions.apiKey = (_o = (_n = (_m = readString(env, "PINECONE_API_KEY")) != null ? _m : (_l = (_k = base == null ? void 0 : base.vectorDb) == null ? void 0 : _k.options) == null ? void 0 : _l.apiKey) != null ? _n : process.env.PINECONE_API_KEY) != null ? _o : "";
|
|
3205
|
+
vectorDbOptions.indexName = (_v = (_u = (_t = (_q = readString(env, "PINECONE_INDEX")) != null ? _q : (_p = base == null ? void 0 : base.vectorDb) == null ? void 0 : _p.indexName) != null ? _t : (_s = (_r = base == null ? void 0 : base.vectorDb) == null ? void 0 : _r.options) == null ? void 0 : _s.indexName) != null ? _u : process.env.PINECONE_INDEX) != null ? _v : "retrivora-free";
|
|
3172
3206
|
} else if (vectorProvider === "pgvector" || vectorProvider === "postgresql") {
|
|
3173
|
-
vectorDbOptions.connectionString = (
|
|
3174
|
-
vectorDbOptions.tables = (
|
|
3175
|
-
vectorDbOptions.searchFields = (
|
|
3207
|
+
vectorDbOptions.connectionString = (_A = (_z = (_w = readString(env, "PGVECTOR_CONNECTION_STRING")) != null ? _w : readString(env, "POSTGRES_URL")) != null ? _z : (_y = (_x = base == null ? void 0 : base.vectorDb) == null ? void 0 : _x.options) == null ? void 0 : _y.connectionString) != null ? _A : "";
|
|
3208
|
+
vectorDbOptions.tables = (_F = (_C = (_B = readString(env, "VECTOR_DB_TABLES")) != null ? _B : readString(env, "POSTGRES_TABLES")) == null ? void 0 : _C.split(",").map((t) => t.trim())) != null ? _F : (_E = (_D = base == null ? void 0 : base.vectorDb) == null ? void 0 : _D.options) == null ? void 0 : _E.tables;
|
|
3209
|
+
vectorDbOptions.searchFields = (_J = (_G = readString(env, "POSTGRES_SEARCH_FIELDS")) == null ? void 0 : _G.split(",").map((f) => f.trim())) != null ? _J : (_I = (_H = base == null ? void 0 : base.vectorDb) == null ? void 0 : _H.options) == null ? void 0 : _I.searchFields;
|
|
3176
3210
|
vectorDbOptions.dimensions = embeddingDimensions;
|
|
3177
3211
|
} else if (vectorProvider === "mongodb") {
|
|
3178
|
-
vectorDbOptions.uri = (
|
|
3179
|
-
vectorDbOptions.database = (
|
|
3180
|
-
vectorDbOptions.collection = (
|
|
3181
|
-
vectorDbOptions.indexName = (
|
|
3212
|
+
vectorDbOptions.uri = (_N = (_M = readString(env, "MONGODB_URI")) != null ? _M : (_L = (_K = base == null ? void 0 : base.vectorDb) == null ? void 0 : _K.options) == null ? void 0 : _L.uri) != null ? _N : "";
|
|
3213
|
+
vectorDbOptions.database = (_R = (_Q = readString(env, "MONGODB_DB")) != null ? _Q : (_P = (_O = base == null ? void 0 : base.vectorDb) == null ? void 0 : _O.options) == null ? void 0 : _P.database) != null ? _R : "";
|
|
3214
|
+
vectorDbOptions.collection = (_V = (_U = readString(env, "MONGODB_COLLECTION")) != null ? _U : (_T = (_S = base == null ? void 0 : base.vectorDb) == null ? void 0 : _S.options) == null ? void 0 : _T.collection) != null ? _V : "";
|
|
3215
|
+
vectorDbOptions.indexName = (_$ = (__ = (_X = readString(env, "MONGODB_INDEX_NAME")) != null ? _X : (_W = base == null ? void 0 : base.vectorDb) == null ? void 0 : _W.indexName) != null ? __ : (_Z = (_Y = base == null ? void 0 : base.vectorDb) == null ? void 0 : _Y.options) == null ? void 0 : _Z.indexName) != null ? _$ : "vector_index";
|
|
3182
3216
|
} else if (vectorProvider === "qdrant") {
|
|
3183
|
-
vectorDbOptions.baseUrl = (
|
|
3184
|
-
vectorDbOptions.apiKey = (
|
|
3217
|
+
vectorDbOptions.baseUrl = (_da = (_ca = readString(env, "QDRANT_URL")) != null ? _ca : (_ba = (_aa = base == null ? void 0 : base.vectorDb) == null ? void 0 : _aa.options) == null ? void 0 : _ba.baseUrl) != null ? _da : "http://localhost:6333";
|
|
3218
|
+
vectorDbOptions.apiKey = (_ga = readString(env, "QDRANT_API_KEY")) != null ? _ga : (_fa = (_ea = base == null ? void 0 : base.vectorDb) == null ? void 0 : _ea.options) == null ? void 0 : _fa.apiKey;
|
|
3185
3219
|
vectorDbOptions.dimensions = embeddingDimensions;
|
|
3186
3220
|
} else if (vectorProvider === "milvus") {
|
|
3187
|
-
vectorDbOptions.baseUrl = (
|
|
3221
|
+
vectorDbOptions.baseUrl = (_ha = readString(env, "MILVUS_URL")) != null ? _ha : "http://localhost:19530";
|
|
3188
3222
|
vectorDbOptions.apiKey = readString(env, "MILVUS_API_KEY");
|
|
3189
3223
|
} else if (vectorProvider === "chromadb") {
|
|
3190
|
-
vectorDbOptions.baseUrl = (
|
|
3224
|
+
vectorDbOptions.baseUrl = (_ia = readString(env, "CHROMADB_URL")) != null ? _ia : "http://localhost:8000";
|
|
3191
3225
|
} else if (vectorProvider === "weaviate") {
|
|
3192
|
-
vectorDbOptions.baseUrl = (
|
|
3226
|
+
vectorDbOptions.baseUrl = (_ja = readString(env, "WEAVIATE_URL")) != null ? _ja : "http://localhost:8080";
|
|
3193
3227
|
vectorDbOptions.apiKey = readString(env, "WEAVIATE_API_KEY");
|
|
3194
3228
|
} else if (vectorProvider === "redis") {
|
|
3195
|
-
vectorDbOptions.baseUrl = (
|
|
3229
|
+
vectorDbOptions.baseUrl = (_ka = readString(env, "REDIS_URL")) != null ? _ka : "";
|
|
3196
3230
|
vectorDbOptions.apiKey = readString(env, "REDIS_API_KEY");
|
|
3197
3231
|
} else if (vectorProvider === "rest") {
|
|
3198
|
-
vectorDbOptions.baseUrl = (
|
|
3232
|
+
vectorDbOptions.baseUrl = (_la = readString(env, "VECTOR_DB_REST_URL")) != null ? _la : "";
|
|
3199
3233
|
vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { "api-key": readString(env, "VECTOR_DB_REST_API_KEY") } : {};
|
|
3200
3234
|
} else if (vectorProvider === "universal_rest") {
|
|
3201
|
-
vectorDbOptions.baseUrl = (
|
|
3235
|
+
vectorDbOptions.baseUrl = (_na = (_ma = readString(env, "VECTOR_BASE_URL")) != null ? _ma : readString(env, "VECTOR_DB_REST_URL")) != null ? _na : "";
|
|
3202
3236
|
vectorDbOptions.profile = readString(env, "VECTOR_UNIVERSAL_PROFILE");
|
|
3203
3237
|
vectorDbOptions.headers = readString(env, "VECTOR_DB_REST_API_KEY") ? { Authorization: `Bearer ${readString(env, "VECTOR_DB_REST_API_KEY")}` } : {};
|
|
3204
3238
|
}
|
|
@@ -3217,8 +3251,8 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3217
3251
|
// Anthropic needs a separate embedding provider; key kept for completeness
|
|
3218
3252
|
gemini: readString(env, "GEMINI_API_KEY"),
|
|
3219
3253
|
ollama: void 0,
|
|
3220
|
-
universal_rest: (
|
|
3221
|
-
custom: (
|
|
3254
|
+
universal_rest: (_oa = readString(env, "EMBEDDING_API_KEY")) != null ? _oa : readString(env, "OPENAI_API_KEY"),
|
|
3255
|
+
custom: (_pa = readString(env, "EMBEDDING_API_KEY")) != null ? _pa : readString(env, "OPENAI_API_KEY")
|
|
3222
3256
|
};
|
|
3223
3257
|
const DEFAULT_MODEL_BY_PROVIDER = {
|
|
3224
3258
|
openai: "gpt-4o",
|
|
@@ -3239,25 +3273,25 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3239
3273
|
return true;
|
|
3240
3274
|
}
|
|
3241
3275
|
})();
|
|
3242
|
-
const defaultGatewayUrl = (
|
|
3276
|
+
const defaultGatewayUrl = (_ra = (_qa = readString(env, "LITELLM_BASE_URL")) != null ? _qa : readString(env, "LLM_BASE_URL")) != null ? _ra : "https://www.retrivora.com/api/v1";
|
|
3243
3277
|
const defaultLlmProvider = isFreeTier ? "universal_rest" : "universal_rest";
|
|
3244
|
-
const llmProvider = (
|
|
3245
|
-
const llmBaseUrl = (
|
|
3246
|
-
const llmModel = (
|
|
3247
|
-
const llmApiKey = (
|
|
3248
|
-
const llmProfile = (
|
|
3278
|
+
const llmProvider = (_ua = (_ta = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _ta : (_sa = base == null ? void 0 : base.llm) == null ? void 0 : _sa.provider) != null ? _ua : defaultLlmProvider;
|
|
3279
|
+
const llmBaseUrl = (_ya = (_xa = (_va = readString(env, "LITELLM_BASE_URL")) != null ? _va : readString(env, "LLM_BASE_URL")) != null ? _xa : (_wa = base == null ? void 0 : base.llm) == null ? void 0 : _wa.baseUrl) != null ? _ya : defaultGatewayUrl;
|
|
3280
|
+
const llmModel = (_Ca = (_Aa = readString(env, "LLM_MODEL")) != null ? _Aa : (_za = base == null ? void 0 : base.llm) == null ? void 0 : _za.model) != null ? _Ca : isFreeTier ? "llama-3.1-8b-instant" : (_Ba = DEFAULT_MODEL_BY_PROVIDER[llmProvider]) != null ? _Ba : "gpt-4o";
|
|
3281
|
+
const llmApiKey = (_Ia = (_Ha = (_Fa = (_Ea = (_Da = llmApiKeyByProvider[llmProvider]) != null ? _Da : readString(env, "LLM_API_KEY")) != null ? _Ea : readString(env, "LITELLM_MASTER_KEY")) != null ? _Fa : readString(env, "LITELLM_API_KEY")) != null ? _Ha : (_Ga = base == null ? void 0 : base.llm) == null ? void 0 : _Ga.apiKey) != null ? _Ia : licenseKey;
|
|
3282
|
+
const llmProfile = (_Ma = (_La = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _La : (_Ka = (_Ja = base == null ? void 0 : base.llm) == null ? void 0 : _Ja.options) == null ? void 0 : _Ka.profile) != null ? _Ma : "litellm";
|
|
3249
3283
|
const defaultEmbeddingProvider = isFreeTier ? "universal_rest" : "universal_rest";
|
|
3250
|
-
const embeddingProvider = (
|
|
3251
|
-
const embeddingBaseUrl = (
|
|
3252
|
-
const embeddingModel = (
|
|
3253
|
-
const embeddingApiKey = (
|
|
3254
|
-
const embeddingProfile = (
|
|
3284
|
+
const embeddingProvider = (_Pa = (_Oa = readEnum(env, "EMBEDDING_PROVIDER", defaultEmbeddingProvider, EMBEDDING_PROVIDERS)) != null ? _Oa : (_Na = base == null ? void 0 : base.embedding) == null ? void 0 : _Na.provider) != null ? _Pa : defaultEmbeddingProvider;
|
|
3285
|
+
const embeddingBaseUrl = (_Ua = (_Ta = (_Ra = (_Qa = readString(env, "LITELLM_BASE_URL")) != null ? _Qa : readString(env, "EMBEDDING_BASE_URL")) != null ? _Ra : readString(env, "LLM_BASE_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.embedding) == null ? void 0 : _Sa.baseUrl) != null ? _Ua : defaultGatewayUrl;
|
|
3286
|
+
const embeddingModel = (_Xa = (_Wa = readString(env, "EMBEDDING_MODEL")) != null ? _Wa : (_Va = base == null ? void 0 : base.embedding) == null ? void 0 : _Va.model) != null ? _Xa : "text-embedding-004";
|
|
3287
|
+
const embeddingApiKey = (_cb = (_bb = (_$a = (__a = (_Za = (_Ya = embeddingApiKeyByProvider[embeddingProvider]) != null ? _Ya : readString(env, "EMBEDDING_API_KEY")) != null ? _Za : readString(env, "LLM_API_KEY")) != null ? __a : readString(env, "LITELLM_MASTER_KEY")) != null ? _$a : readString(env, "LITELLM_API_KEY")) != null ? _bb : (_ab = base == null ? void 0 : base.embedding) == null ? void 0 : _ab.apiKey) != null ? _cb : licenseKey;
|
|
3288
|
+
const embeddingProfile = (_gb = (_fb = readString(env, "EMBEDDING_UNIVERSAL_PROFILE")) != null ? _fb : (_eb = (_db = base == null ? void 0 : base.embedding) == null ? void 0 : _db.options) == null ? void 0 : _eb.profile) != null ? _gb : "litellm";
|
|
3255
3289
|
return __spreadProps(__spreadValues({
|
|
3256
3290
|
projectId,
|
|
3257
3291
|
licenseKey,
|
|
3258
3292
|
vectorDb: {
|
|
3259
3293
|
provider: vectorProvider,
|
|
3260
|
-
indexName: (
|
|
3294
|
+
indexName: (_ib = (_hb = readString(env, "VECTOR_DB_INDEX")) != null ? _hb : vectorDbOptions.indexName) != null ? _ib : "rag-index",
|
|
3261
3295
|
options: vectorDbOptions
|
|
3262
3296
|
},
|
|
3263
3297
|
llm: {
|
|
@@ -3287,30 +3321,30 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3287
3321
|
}
|
|
3288
3322
|
},
|
|
3289
3323
|
ui: {
|
|
3290
|
-
title: (
|
|
3291
|
-
subtitle: (
|
|
3292
|
-
primaryColor: (
|
|
3293
|
-
accentColor: (
|
|
3294
|
-
logoUrl: (
|
|
3295
|
-
placeholder: (
|
|
3296
|
-
showSources: ((
|
|
3297
|
-
welcomeMessage: (
|
|
3298
|
-
visualStyle: (
|
|
3299
|
-
borderRadius: (
|
|
3300
|
-
allowUpload: ((
|
|
3324
|
+
title: (_kb = (_jb = readString(env, "NEXT_PUBLIC_UI_TITLE")) != null ? _jb : readString(env, "UI_TITLE")) != null ? _kb : "AI Assistant",
|
|
3325
|
+
subtitle: (_mb = (_lb = readString(env, "NEXT_PUBLIC_UI_SUBTITLE")) != null ? _lb : readString(env, "UI_SUBTITLE")) != null ? _mb : "Powered by RAG",
|
|
3326
|
+
primaryColor: (_ob = (_nb = readString(env, "NEXT_PUBLIC_PRIMARY_COLOR")) != null ? _nb : readString(env, "UI_PRIMARY_COLOR")) != null ? _ob : "#10b981",
|
|
3327
|
+
accentColor: (_qb = (_pb = readString(env, "NEXT_PUBLIC_ACCENT_COLOR")) != null ? _pb : readString(env, "UI_ACCENT_COLOR")) != null ? _qb : "#3b82f6",
|
|
3328
|
+
logoUrl: (_rb = readString(env, "NEXT_PUBLIC_LOGO_URL")) != null ? _rb : readString(env, "UI_LOGO_URL"),
|
|
3329
|
+
placeholder: (_tb = (_sb = readString(env, "NEXT_PUBLIC_PLACEHOLDER")) != null ? _sb : readString(env, "UI_PLACEHOLDER")) != null ? _tb : "Ask me anything\u2026",
|
|
3330
|
+
showSources: ((_vb = (_ub = readString(env, "NEXT_PUBLIC_SHOW_SOURCES")) != null ? _ub : readString(env, "UI_SHOW_SOURCES")) != null ? _vb : "true") !== "false",
|
|
3331
|
+
welcomeMessage: (_xb = (_wb = readString(env, "NEXT_PUBLIC_WELCOME_MESSAGE")) != null ? _wb : readString(env, "UI_WELCOME_MESSAGE")) != null ? _xb : "Hello! I'm your AI assistant. Ask me anything about your documents.",
|
|
3332
|
+
visualStyle: (_zb = (_yb = readString(env, "NEXT_PUBLIC_UI_VISUAL_STYLE")) != null ? _yb : readString(env, "UI_VISUAL_STYLE")) != null ? _zb : "glass",
|
|
3333
|
+
borderRadius: (_Bb = (_Ab = readString(env, "NEXT_PUBLIC_UI_BORDER_RADIUS")) != null ? _Ab : readString(env, "UI_BORDER_RADIUS")) != null ? _Bb : "xl",
|
|
3334
|
+
allowUpload: ((_Db = (_Cb = readString(env, "NEXT_PUBLIC_ALLOW_UPLOAD")) != null ? _Cb : readString(env, "UI_ALLOW_UPLOAD")) != null ? _Db : "false") === "true"
|
|
3301
3335
|
},
|
|
3302
3336
|
rag: {
|
|
3303
3337
|
topK: readNumber(env, "RAG_TOP_K", 5),
|
|
3304
3338
|
scoreThreshold: readNumber(env, "RAG_SCORE_THRESHOLD", 0),
|
|
3305
3339
|
chunkSize: readNumber(env, "RAG_CHUNK_SIZE", 1e3),
|
|
3306
3340
|
chunkOverlap: readNumber(env, "RAG_CHUNK_OVERLAP", 200),
|
|
3307
|
-
filterableFields: (
|
|
3341
|
+
filterableFields: (_Eb = readString(env, "RAG_FILTERABLE_FIELDS")) == null ? void 0 : _Eb.split(",").map((f) => f.trim()),
|
|
3308
3342
|
// Query pipeline toggles — read from .env.local
|
|
3309
3343
|
useQueryTransformation: readString(env, "RAG_USE_QUERY_TRANSFORMATION") === "true",
|
|
3310
3344
|
useReranking: readString(env, "RAG_USE_RERANKING") === "true",
|
|
3311
3345
|
useGraphRetrieval: readString(env, "RAG_USE_GRAPH_RETRIEVAL") === "true",
|
|
3312
|
-
architecture: (
|
|
3313
|
-
chunkingStrategy: (
|
|
3346
|
+
architecture: (_Fb = readString(env, "RAG_ARCHITECTURE")) != null ? _Fb : "simple",
|
|
3347
|
+
chunkingStrategy: (_Gb = readString(env, "RAG_CHUNKING_STRATEGY")) != null ? _Gb : "recursive",
|
|
3314
3348
|
uiMapping: (() => {
|
|
3315
3349
|
const raw = readString(env, "RAG_UI_MAPPING");
|
|
3316
3350
|
if (!raw) return void 0;
|
|
@@ -3323,7 +3357,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3323
3357
|
},
|
|
3324
3358
|
telemetry: {
|
|
3325
3359
|
enabled: telemetryEnabled,
|
|
3326
|
-
url: (
|
|
3360
|
+
url: (_Kb = (_Jb = (_Hb = readString(env, "TELEMETRY_URL")) != null ? _Hb : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Jb : (_Ib = base == null ? void 0 : base.telemetry) == null ? void 0 : _Ib.url) != null ? _Kb : process.env.NODE_ENV === "development" ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry"
|
|
3327
3361
|
}
|
|
3328
3362
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
3329
3363
|
graphDb: {
|
|
@@ -5365,7 +5399,7 @@ var ConfigValidator = class {
|
|
|
5365
5399
|
// package.json
|
|
5366
5400
|
var package_default = {
|
|
5367
5401
|
name: "@retrivora-ai/rag-engine",
|
|
5368
|
-
version: "2.
|
|
5402
|
+
version: "2.2.2",
|
|
5369
5403
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
5370
5404
|
author: "Abhinav Alkuchi",
|
|
5371
5405
|
license: "UNLICENSED",
|
|
@@ -9025,11 +9059,10 @@ SchemaMapper.TARGET_PROPERTIES = {
|
|
|
9025
9059
|
|
|
9026
9060
|
// src/core/Pipeline.ts
|
|
9027
9061
|
function formatNamespace(raw) {
|
|
9028
|
-
if (!raw || !raw.trim()) return "
|
|
9062
|
+
if (!raw || !raw.trim()) return "default";
|
|
9029
9063
|
const trimmed = raw.trim();
|
|
9030
|
-
|
|
9031
|
-
|
|
9032
|
-
return `retrivora-${sanitized}`;
|
|
9064
|
+
const sanitized = trimmed.replace(/[^a-zA-Z0-9_-]/g, "_").replace(/_+/g, "_").replace(/^_+|_+$/g, "");
|
|
9065
|
+
return sanitized || "default";
|
|
9033
9066
|
}
|
|
9034
9067
|
var LRUEmbeddingCache = class {
|
|
9035
9068
|
constructor(maxSize = 500) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retrivora-ai/rag-engine",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Retrivora AI is a plug-and-play AI engine for RAG chat experiences — generic vector DB + LLM provider, embeddable or standalone.",
|
|
5
5
|
"author": "Abhinav Alkuchi",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -59,12 +59,6 @@ export function getRagConfig(baseConfig?: Partial<RagConfig>, env: Record<string
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export function getEnvConfig(env: Record<string, string | undefined> = process.env, base?: Partial<RagConfig>): RagConfig {
|
|
62
|
-
const projectId =
|
|
63
|
-
readString(env, 'RAG_PROJECT_ID') ??
|
|
64
|
-
readString(env, 'NEXT_PUBLIC_PROJECT_ID') ??
|
|
65
|
-
base?.projectId ??
|
|
66
|
-
'__default__';
|
|
67
|
-
|
|
68
62
|
const licenseKey =
|
|
69
63
|
readString(env, 'RAG_LICENSE_KEY') ??
|
|
70
64
|
readString(env, 'RETRIVORA_LICENSE_KEY') ??
|
|
@@ -72,6 +66,26 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
|
|
|
72
66
|
readString(env, 'LICENSE_KEY') ??
|
|
73
67
|
base?.licenseKey;
|
|
74
68
|
|
|
69
|
+
const jwtProjectId = (() => {
|
|
70
|
+
if (!licenseKey) return undefined;
|
|
71
|
+
try {
|
|
72
|
+
const parts = licenseKey.split('.');
|
|
73
|
+
if (parts.length >= 2) {
|
|
74
|
+
const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
|
|
75
|
+
return payload?.projectId;
|
|
76
|
+
}
|
|
77
|
+
} catch { /* ignore */ }
|
|
78
|
+
return undefined;
|
|
79
|
+
})();
|
|
80
|
+
|
|
81
|
+
const projectId =
|
|
82
|
+
readString(env, 'RAG_PROJECT_ID') ??
|
|
83
|
+
readString(env, 'NEXT_PUBLIC_RAG_PROJECT_ID') ??
|
|
84
|
+
readString(env, 'NEXT_PUBLIC_PROJECT_ID') ??
|
|
85
|
+
base?.projectId ??
|
|
86
|
+
jwtProjectId ??
|
|
87
|
+
'default';
|
|
88
|
+
|
|
75
89
|
const telemetryEnabled =
|
|
76
90
|
readString(env, 'TELEMETRY_ENABLED') === 'true' ||
|
|
77
91
|
readString(env, 'NEXT_PUBLIC_TELEMETRY_ENABLED') === 'true' ||
|
|
@@ -174,7 +188,7 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
|
|
|
174
188
|
// Default gateway: retrivora.com/api/v1 acts as a secure proxy that validates the license key
|
|
175
189
|
// and forwards to llm.retrivora.com with LITELLM_MASTER_KEY (which end-users never need to know).
|
|
176
190
|
// Developers who self-host can override with LITELLM_BASE_URL.
|
|
177
|
-
const defaultGatewayUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? 'https://retrivora.com/api/v1';
|
|
191
|
+
const defaultGatewayUrl = readString(env, 'LITELLM_BASE_URL') ?? readString(env, 'LLM_BASE_URL') ?? 'https://www.retrivora.com/api/v1';
|
|
178
192
|
|
|
179
193
|
const defaultLlmProvider = isFreeTier ? 'universal_rest' : 'universal_rest';
|
|
180
194
|
const llmProvider = (readEnum(env, 'LLM_PROVIDER', defaultLlmProvider, LLM_PROVIDERS) ?? base?.llm?.provider ?? defaultLlmProvider) as LLMProvider;
|
|
@@ -7,6 +7,7 @@ export interface RemoteVectorConfig {
|
|
|
7
7
|
apiKey: string;
|
|
8
8
|
indexName: string;
|
|
9
9
|
provider: string;
|
|
10
|
+
projectId?: string;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
export interface RemoteEmbeddingConfig {
|
|
@@ -26,6 +27,7 @@ export interface RemoteLLMConfig {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export interface RemoteConfig {
|
|
30
|
+
projectId?: string;
|
|
29
31
|
vectorDb: RemoteVectorConfig;
|
|
30
32
|
embedding: RemoteEmbeddingConfig;
|
|
31
33
|
llm: RemoteLLMConfig;
|
|
@@ -53,7 +55,9 @@ export class ConfigFetcher {
|
|
|
53
55
|
const controlPlaneUrls = [
|
|
54
56
|
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
55
57
|
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
58
|
+
'https://www.retrivora.com',
|
|
56
59
|
'https://retrivora.com',
|
|
60
|
+
'http://localhost:3001',
|
|
57
61
|
'http://localhost:3000',
|
|
58
62
|
].filter(Boolean) as string[];
|
|
59
63
|
|
|
@@ -71,11 +75,14 @@ export class ConfigFetcher {
|
|
|
71
75
|
if (res.ok) {
|
|
72
76
|
const data = await res.json();
|
|
73
77
|
if (data?.success && data?.vectorDb?.apiKey) {
|
|
78
|
+
const fetchedProjectId = data.projectId || projectId;
|
|
74
79
|
const config: RemoteConfig = {
|
|
80
|
+
projectId: fetchedProjectId,
|
|
75
81
|
vectorDb: {
|
|
76
82
|
apiKey: data.vectorDb.apiKey,
|
|
77
83
|
indexName: data.vectorDb.indexName || 'retrivora-free',
|
|
78
84
|
provider: data.vectorDb.provider || 'pinecone',
|
|
85
|
+
projectId: fetchedProjectId,
|
|
79
86
|
},
|
|
80
87
|
embedding: {
|
|
81
88
|
provider: data.embedding?.provider || 'universal_rest',
|
|
@@ -80,7 +80,8 @@ MwIDAQAB
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
try {
|
|
83
|
-
const
|
|
83
|
+
const rawToken = licenseKey.replace(/^rtv_/i, '').trim();
|
|
84
|
+
const parts = rawToken.split('.');
|
|
84
85
|
if (parts.length !== 3) {
|
|
85
86
|
throw new Error('Malformed token structure (expected 3 parts).');
|
|
86
87
|
}
|
|
@@ -114,7 +115,12 @@ MwIDAQAB
|
|
|
114
115
|
throw new Error('License payload is missing "projectId".');
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
|
|
118
|
+
const isProjectMatch =
|
|
119
|
+
payload.projectId === currentProjectId ||
|
|
120
|
+
payload.projectId === `retrivora-${currentProjectId}` ||
|
|
121
|
+
`retrivora-${payload.projectId}` === currentProjectId;
|
|
122
|
+
|
|
123
|
+
if (!isProjectMatch) {
|
|
118
124
|
throw new Error(
|
|
119
125
|
`Project ID mismatch. License is bound to project namespace "${payload.projectId}" ` +
|
|
120
126
|
`but configuration has "${currentProjectId}".`
|
package/src/core/Pipeline.ts
CHANGED
|
@@ -28,19 +28,17 @@ import { SchemaMapper, SchemaMap } from '../utils/SchemaMapper';
|
|
|
28
28
|
// ─── Namespace Formatter ───────────────────────────────────────────────────────
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
* Clean & format namespace string to satisfy vector DB identifier rules
|
|
32
|
-
*
|
|
31
|
+
* Clean & format namespace string to satisfy vector DB identifier rules.
|
|
32
|
+
* Preserves the exact dynamic project ID passed by the user without forcing static prefixes.
|
|
33
33
|
*/
|
|
34
34
|
export function formatNamespace(raw?: string): string {
|
|
35
|
-
if (!raw || !raw.trim()) return '
|
|
35
|
+
if (!raw || !raw.trim()) return 'default';
|
|
36
36
|
const trimmed = raw.trim();
|
|
37
|
-
if (trimmed.startsWith('retrivora-')) return trimmed;
|
|
38
37
|
const sanitized = trimmed
|
|
39
|
-
.
|
|
40
|
-
.replace(/[^a-z0-9_-]/g, '_')
|
|
38
|
+
.replace(/[^a-zA-Z0-9_-]/g, '_')
|
|
41
39
|
.replace(/_+/g, '_')
|
|
42
40
|
.replace(/^_+|_+$/g, '');
|
|
43
|
-
return
|
|
41
|
+
return sanitized || 'default';
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
// ─── LRU Embedding Cache ───────────────────────────────────────────────────────
|
|
@@ -9,6 +9,7 @@ import { IProviderValidator, IProviderHealthChecker } from '../../core/ProviderI
|
|
|
9
9
|
export abstract class BaseVectorProvider {
|
|
10
10
|
protected readonly config: VectorDBConfig;
|
|
11
11
|
protected indexName: string;
|
|
12
|
+
protected projectId?: string;
|
|
12
13
|
|
|
13
14
|
constructor(config: VectorDBConfig) {
|
|
14
15
|
this.config = config;
|
|
@@ -88,8 +88,20 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
88
88
|
let key = this.apiKey || process.env.PINECONE_API_KEY || '';
|
|
89
89
|
|
|
90
90
|
if (!key) {
|
|
91
|
-
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || 'my-rag-app';
|
|
92
91
|
const licenseKey = process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
92
|
+
const jwtProjectId = (() => {
|
|
93
|
+
if (!licenseKey) return undefined;
|
|
94
|
+
try {
|
|
95
|
+
const parts = licenseKey.split('.');
|
|
96
|
+
if (parts.length >= 2) {
|
|
97
|
+
const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
|
|
98
|
+
return payload?.projectId;
|
|
99
|
+
}
|
|
100
|
+
} catch { /* ignore */ }
|
|
101
|
+
return undefined;
|
|
102
|
+
})();
|
|
103
|
+
|
|
104
|
+
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || 'default';
|
|
93
105
|
|
|
94
106
|
const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
|
|
95
107
|
if (remoteConfig?.apiKey) {
|
|
@@ -98,6 +110,9 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
98
110
|
if (remoteConfig.indexName) {
|
|
99
111
|
this.indexName = remoteConfig.indexName;
|
|
100
112
|
}
|
|
113
|
+
if (remoteConfig.projectId) {
|
|
114
|
+
this.projectId = remoteConfig.projectId;
|
|
115
|
+
}
|
|
101
116
|
}
|
|
102
117
|
}
|
|
103
118
|
|