@retrivora-ai/rag-engine 2.6.2 → 2.6.3
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/ChromaDBProvider-NDA2IBOH.mjs +8 -0
- package/dist/MilvusProvider-H6GGL5FQ.mjs +8 -0
- package/dist/MongoDBProvider-KC3GF3FH.mjs +8 -0
- package/dist/MultiTablePostgresProvider-6LJBFZL2.mjs +9 -0
- package/dist/PineconeProvider-22RF2QPF.mjs +10 -0
- package/dist/PineconeProvider-HBBIXLT3.mjs +10 -0
- package/dist/PostgreSQLProvider-VWFL4OIP.mjs +8 -0
- package/dist/QdrantProvider-UU7RGXBI.mjs +8 -0
- package/dist/RedisProvider-MIIPSAAE.mjs +8 -0
- package/dist/SimpleGraphProvider-HJIS4S7Y.mjs +70 -0
- package/dist/UniversalVectorProvider-NO3L255G.mjs +9 -0
- package/dist/WeaviateProvider-YRZDZFAC.mjs +8 -0
- package/dist/chunk-23PFNEBF.mjs +107 -0
- package/dist/chunk-3E4GZGDX.mjs +10851 -0
- package/dist/chunk-3SQ4DODU.mjs +238 -0
- package/dist/chunk-AHMMUZ4W.mjs +152 -0
- package/dist/chunk-ASBNNEVI.mjs +81 -0
- package/dist/chunk-AT4TFUQN.mjs +219 -0
- package/dist/chunk-BEPLYQBS.mjs +89 -0
- package/dist/chunk-G7MJRFCO.mjs +340 -0
- package/dist/chunk-IHWKVAUR.mjs +112 -0
- package/dist/chunk-IMP6FUCY.mjs +30 -0
- package/dist/chunk-LFNV6DEL.mjs +281 -0
- package/dist/chunk-MAXMVO7B.mjs +211 -0
- package/dist/chunk-MGJ6V2IT.mjs +203 -0
- package/dist/chunk-N3TI27LG.mjs +334 -0
- package/dist/chunk-NWYE4Q7B.mjs +334 -0
- package/dist/chunk-OJMAT4EG.mjs +219 -0
- package/dist/chunk-QKZM3RSJ.mjs +10851 -0
- package/dist/chunk-QUY3E6HJ.mjs +168 -0
- package/dist/chunk-SG6XYLQE.mjs +53 -0
- package/dist/chunk-UT6SZZEC.mjs +69 -0
- package/dist/chunk-VW3U4MMX.mjs +157 -0
- package/dist/chunk-WOJCOTXI.mjs +281 -0
- package/dist/chunk-XP6NJMX4.mjs +168 -0
- package/dist/chunk-XYBKDJDW.mjs +696 -0
- package/dist/handlers/index.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +56 -23
- package/dist/handlers/index.mjs +24 -14027
- package/dist/{index-D7FuQRSb.d.mts → index-BBbt5A2y.d.mts} +3 -1
- package/dist/{index-CFl4KrKq.d.ts → index-BZ_rR6V8.d.ts} +3 -1
- package/dist/index.js +12 -4
- package/dist/index.mjs +46 -1461
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +56 -23
- package/dist/server.mjs +377 -14573
- package/package.json +1 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var package_default = {
|
|
3
|
+
name: "@retrivora-ai/rag-engine",
|
|
4
|
+
version: "2.6.2",
|
|
5
|
+
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
6
|
+
author: "Abhinav Alkuchi",
|
|
7
|
+
license: "UNLICENSED",
|
|
8
|
+
keywords: [
|
|
9
|
+
"rag",
|
|
10
|
+
"retrieval-augmented-generation",
|
|
11
|
+
"chatbot",
|
|
12
|
+
"vector-database",
|
|
13
|
+
"pinecone",
|
|
14
|
+
"pgvector",
|
|
15
|
+
"postgresql",
|
|
16
|
+
"milvus",
|
|
17
|
+
"qdrant",
|
|
18
|
+
"chromadb",
|
|
19
|
+
"redis",
|
|
20
|
+
"weaviate",
|
|
21
|
+
"mongodb",
|
|
22
|
+
"openai",
|
|
23
|
+
"anthropic",
|
|
24
|
+
"ollama",
|
|
25
|
+
"nextjs",
|
|
26
|
+
"react",
|
|
27
|
+
"ai",
|
|
28
|
+
"llm",
|
|
29
|
+
"embeddings"
|
|
30
|
+
],
|
|
31
|
+
main: "dist/index.js",
|
|
32
|
+
module: "dist/index.mjs",
|
|
33
|
+
types: "dist/index.d.ts",
|
|
34
|
+
exports: {
|
|
35
|
+
".": {
|
|
36
|
+
types: "./dist/index.d.ts",
|
|
37
|
+
require: "./dist/index.js",
|
|
38
|
+
import: "./dist/index.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./style.css": "./dist/index.css",
|
|
41
|
+
"./style.min.css": "./dist/index.min.css",
|
|
42
|
+
"./index.css": "./dist/index.css",
|
|
43
|
+
"./index.min.css": "./dist/index.min.css",
|
|
44
|
+
"./styles.css": "./dist/index.css",
|
|
45
|
+
"./styles.min.css": "./dist/index.min.css",
|
|
46
|
+
"./handlers": {
|
|
47
|
+
types: "./dist/handlers/index.d.ts",
|
|
48
|
+
require: "./dist/handlers/index.js",
|
|
49
|
+
import: "./dist/handlers/index.mjs"
|
|
50
|
+
},
|
|
51
|
+
"./server": {
|
|
52
|
+
types: "./dist/server.d.ts",
|
|
53
|
+
require: "./dist/server.js",
|
|
54
|
+
import: "./dist/server.mjs"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
browser: {
|
|
58
|
+
child_process: false,
|
|
59
|
+
fs: false,
|
|
60
|
+
net: false,
|
|
61
|
+
tls: false,
|
|
62
|
+
crypto: false,
|
|
63
|
+
os: false,
|
|
64
|
+
path: false,
|
|
65
|
+
stream: false,
|
|
66
|
+
http: false,
|
|
67
|
+
https: false,
|
|
68
|
+
zlib: false,
|
|
69
|
+
mongodb: false,
|
|
70
|
+
pg: false,
|
|
71
|
+
"pdf-parse": false,
|
|
72
|
+
mammoth: false
|
|
73
|
+
},
|
|
74
|
+
files: [
|
|
75
|
+
"dist",
|
|
76
|
+
"README.md",
|
|
77
|
+
"FREE_TIER_ARCHITECTURE.md"
|
|
78
|
+
],
|
|
79
|
+
scripts: {
|
|
80
|
+
dev: "npx @tailwindcss/cli -i src/tailwind.css -o src/index.css && tsup src/index.ts src/handlers/index.ts src/server.ts --format cjs,esm --watch --tsconfig tsconfig.build.json --external react,react-dom,next,mongodb,pg,openai,@anthropic-ai/sdk,@pinecone-database/pinecone,axios,lucide-react,mammoth,pdf-parse,xlsx,react-markdown,remark-gfm,next-themes,langchain,@langchain/core,@langchain/openai,llamaindex --inject-style",
|
|
81
|
+
build: "npm run build:pkg",
|
|
82
|
+
"build:pkg": "npx @tailwindcss/cli -i src/tailwind.css -o src/index.css && tsup src/index.ts src/handlers/index.ts src/server.ts --format cjs,esm --dts --clean --no-splitting --tsconfig tsconfig.build.json --external react,react-dom,next,mongodb,pg,openai,@anthropic-ai/sdk,@pinecone-database/pinecone,axios,lucide-react,mammoth,pdf-parse,xlsx,react-markdown,remark-gfm,next-themes,langchain,@langchain/core,@langchain/openai,llamaindex --inject-style && npx @tailwindcss/cli -i src/tailwind.css -o dist/index.css && npx @tailwindcss/cli -i src/tailwind.css -o dist/index.min.css --minify",
|
|
83
|
+
lint: "eslint",
|
|
84
|
+
typecheck: "tsc --noEmit -p tsconfig.build.json",
|
|
85
|
+
test: "jest",
|
|
86
|
+
clean: `node -e "require('fs').rmSync('dist', { recursive: true, force: true })"`
|
|
87
|
+
},
|
|
88
|
+
peerDependencies: {
|
|
89
|
+
axios: ">=1.0.0",
|
|
90
|
+
next: ">=15.0.0",
|
|
91
|
+
react: ">=18.0.0",
|
|
92
|
+
"react-dom": ">=18.0.0"
|
|
93
|
+
},
|
|
94
|
+
peerDependenciesMeta: {
|
|
95
|
+
axios: {
|
|
96
|
+
optional: true
|
|
97
|
+
},
|
|
98
|
+
next: {
|
|
99
|
+
optional: true
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
dependencies: {
|
|
103
|
+
"@anthropic-ai/sdk": "^0.95.1",
|
|
104
|
+
"@google/genai": "^0.8.0",
|
|
105
|
+
"@google/generative-ai": "^0.24.1",
|
|
106
|
+
"@pinecone-database/pinecone": "^7.2.0",
|
|
107
|
+
"@retrivora-ai/billing-guards": "file:../billing-guards",
|
|
108
|
+
"@types/papaparse": "^5.5.2",
|
|
109
|
+
exceljs: "^4.4.0",
|
|
110
|
+
"framer-motion": "^13.1.0",
|
|
111
|
+
jszip: "^3.10.1",
|
|
112
|
+
katex: "^0.18.4",
|
|
113
|
+
"lucide-react": "^1.8.0",
|
|
114
|
+
"next-themes": "^0.4.6",
|
|
115
|
+
openai: "^6.34.0",
|
|
116
|
+
papaparse: "^5.5.3",
|
|
117
|
+
"react-is": "^18.3.1",
|
|
118
|
+
"react-markdown": "^10.1.0",
|
|
119
|
+
"react-syntax-highlighter": "^16.1.1",
|
|
120
|
+
recharts: "^3.8.1",
|
|
121
|
+
"rehype-katex": "^7.0.1",
|
|
122
|
+
"remark-gfm": "^4.0.1",
|
|
123
|
+
"remark-math": "^6.0.0",
|
|
124
|
+
xlsx: "^0.18.5",
|
|
125
|
+
zod: "^4.4.3"
|
|
126
|
+
},
|
|
127
|
+
optionalDependencies: {
|
|
128
|
+
"@langchain/core": "^1.1.42",
|
|
129
|
+
"@langchain/openai": "^1.4.5",
|
|
130
|
+
langchain: "^1.3.5",
|
|
131
|
+
llamaindex: "^0.11.9",
|
|
132
|
+
mammoth: "^1.8.0",
|
|
133
|
+
mongodb: "^7.1.1",
|
|
134
|
+
"pdf-parse": "^1.1.1",
|
|
135
|
+
pg: "^8.20.0"
|
|
136
|
+
},
|
|
137
|
+
devDependencies: {
|
|
138
|
+
"@tailwindcss/cli": "^4",
|
|
139
|
+
"@tailwindcss/postcss": "^4",
|
|
140
|
+
"@types/estree": "^1.0.9",
|
|
141
|
+
"@types/jest": "^30.0.0",
|
|
142
|
+
"@types/jszip": "^3.4.1",
|
|
143
|
+
"@types/katex": "^0.16.8",
|
|
144
|
+
"@types/node": "^20",
|
|
145
|
+
"@types/pdf-parse": "^1.1.5",
|
|
146
|
+
"@types/pg": "^8.20.0",
|
|
147
|
+
"@types/react": "^19.2.14",
|
|
148
|
+
"@types/react-dom": "^19.2.3",
|
|
149
|
+
"@types/react-syntax-highlighter": "^15.5.13",
|
|
150
|
+
axios: "^1.15.0",
|
|
151
|
+
dotenv: "^17.4.2",
|
|
152
|
+
eslint: "^9",
|
|
153
|
+
"eslint-config-next": "16.3.2",
|
|
154
|
+
jest: "^30.4.2",
|
|
155
|
+
next: "^16.3.2",
|
|
156
|
+
tailwindcss: "^4",
|
|
157
|
+
"ts-jest": "^29.4.12",
|
|
158
|
+
tsup: "^8.5.1",
|
|
159
|
+
typescript: "^5"
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// src/version.ts
|
|
164
|
+
var SDK_VERSION = package_default.version || "2.1.3";
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
SDK_VERSION
|
|
168
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadValues
|
|
3
|
+
} from "./chunk-UT6SZZEC.mjs";
|
|
4
|
+
|
|
5
|
+
// src/utils/templateUtils.ts
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null;
|
|
8
|
+
}
|
|
9
|
+
function resolvePath(obj, path) {
|
|
10
|
+
if (!path || !obj) return void 0;
|
|
11
|
+
return path.replace(/\[(\w+)\]/g, ".$1").replace(/^\./, "").split(".").reduce((current, segment) => {
|
|
12
|
+
if (segment === "__proto__" || segment === "constructor" || segment === "prototype") {
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
if (!isRecord(current) && !Array.isArray(current)) {
|
|
16
|
+
return void 0;
|
|
17
|
+
}
|
|
18
|
+
return current[segment];
|
|
19
|
+
}, obj);
|
|
20
|
+
}
|
|
21
|
+
function buildPayload(template, vars) {
|
|
22
|
+
let raw = template;
|
|
23
|
+
for (const [key, val] of Object.entries(vars)) {
|
|
24
|
+
const stringifiedVal = val === void 0 ? "null" : JSON.stringify(val);
|
|
25
|
+
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
26
|
+
raw = raw.replace(new RegExp(`"\\{\\{${escapedKey}\\}\\}"`, "g"), () => stringifiedVal);
|
|
27
|
+
raw = raw.replace(new RegExp(`\\{\\{${escapedKey}\\}\\}`, "g"), () => stringifiedVal);
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(raw);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
throw new Error(`Failed to parse payload template: ${err.message}
|
|
33
|
+
Raw payload: ${raw}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function mergeDefined(base, override) {
|
|
37
|
+
const merged = __spreadValues({}, base || {});
|
|
38
|
+
if (!override) {
|
|
39
|
+
return merged;
|
|
40
|
+
}
|
|
41
|
+
for (const [key, value] of Object.entries(override)) {
|
|
42
|
+
if (value !== void 0 && value !== null && value !== "") {
|
|
43
|
+
merged[key] = value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return merged;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export {
|
|
50
|
+
resolvePath,
|
|
51
|
+
buildPayload,
|
|
52
|
+
mergeDefined
|
|
53
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
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 __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
35
|
+
var __copyProps = (to, from, except, desc) => {
|
|
36
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
37
|
+
for (let key of __getOwnPropNames(from))
|
|
38
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
39
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
40
|
+
}
|
|
41
|
+
return to;
|
|
42
|
+
};
|
|
43
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
44
|
+
var __await = function(promise, isYieldStar) {
|
|
45
|
+
this[0] = promise;
|
|
46
|
+
this[1] = isYieldStar;
|
|
47
|
+
};
|
|
48
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
49
|
+
var resume = (k, v, yes, no) => {
|
|
50
|
+
try {
|
|
51
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
52
|
+
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));
|
|
53
|
+
} catch (e) {
|
|
54
|
+
no(e);
|
|
55
|
+
}
|
|
56
|
+
}, 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 = {};
|
|
57
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
58
|
+
};
|
|
59
|
+
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);
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
__spreadValues,
|
|
63
|
+
__spreadProps,
|
|
64
|
+
__objRest,
|
|
65
|
+
__reExport,
|
|
66
|
+
__await,
|
|
67
|
+
__asyncGenerator,
|
|
68
|
+
__forAwait
|
|
69
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildPayload,
|
|
3
|
+
resolvePath
|
|
4
|
+
} from "./chunk-SG6XYLQE.mjs";
|
|
5
|
+
import {
|
|
6
|
+
BaseVectorProvider
|
|
7
|
+
} from "./chunk-IMP6FUCY.mjs";
|
|
8
|
+
import {
|
|
9
|
+
__spreadValues
|
|
10
|
+
} from "./chunk-UT6SZZEC.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
|
+
};
|