@retrivora-ai/rag-engine 1.8.1 → 1.8.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/{ILLMProvider-BfRgI1Xh.d.mts → ILLMProvider-BOJFz3Na.d.mts} +47 -1
- package/dist/{ILLMProvider-BfRgI1Xh.d.ts → ILLMProvider-BOJFz3Na.d.ts} +47 -1
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +509 -162
- package/dist/handlers/index.mjs +5849 -15
- package/dist/{index-1Z4GuYBi.d.ts → index-BwpcaziY.d.ts} +4 -2
- package/dist/{index-BV0z5mb6.d.mts → index-D3V9Et2M.d.mts} +4 -2
- package/dist/index.d.mts +30 -16
- package/dist/index.d.ts +30 -16
- package/dist/index.js +1999 -1210
- package/dist/index.mjs +2041 -1205
- package/dist/server.d.mts +21 -25
- package/dist/server.d.ts +21 -25
- package/dist/server.js +536 -163
- package/dist/server.mjs +5923 -67
- package/package.json +9 -7
- package/src/app/api/upload/route.ts +4 -0
- package/src/app/constants.tsx +2 -2
- package/src/app/globals.css +35 -11
- package/src/app/page.tsx +12 -321
- package/src/components/AmbientBackground.tsx +29 -0
- package/src/components/ArchitectureCard.tsx +17 -0
- package/src/components/ArchitectureCardsSection.tsx +15 -0
- package/src/components/ChatWidget.tsx +0 -1
- package/src/components/ChatWindow.tsx +32 -0
- package/src/components/CodeViewer.tsx +51 -0
- package/src/components/ConfigProvider.tsx +1 -0
- package/src/components/DocViewer.tsx +37 -0
- package/src/components/DocumentUpload.tsx +44 -1
- package/src/components/Documentation.tsx +58 -0
- package/src/components/DynamicChart.tsx +27 -2
- package/src/components/Hero.tsx +59 -0
- package/src/components/HourglassLoader.tsx +87 -0
- package/src/components/Lifecycle.tsx +37 -0
- package/src/components/MarkdownComponents.tsx +143 -0
- package/src/components/MessageBubble.tsx +91 -1012
- package/src/components/Navbar.tsx +55 -0
- package/src/components/ObservabilityPanel.tsx +374 -0
- package/src/components/ProductCard.tsx +3 -1
- package/src/components/UIDispatcher.tsx +341 -0
- package/src/components/VisualizationRenderer.tsx +48 -26
- package/src/config/ConfigBuilder.ts +38 -1
- package/src/core/LangChainAgent.ts +1 -4
- package/src/core/Pipeline.ts +209 -86
- package/src/core/QueryProcessor.ts +65 -0
- package/src/handlers/index.ts +72 -12
- package/src/hooks/useRagChat.ts +19 -9
- package/src/index.ts +9 -1
- package/src/providers/vectordb/MultiTablePostgresProvider.ts +150 -64
- package/src/rag/Reranker.ts +99 -6
- package/src/types/chat.ts +2 -0
- package/src/types/index.ts +52 -0
- package/src/types/props.ts +9 -1
- package/src/utils/ProductExtractor.ts +347 -0
- package/src/utils/UITransformer.ts +4 -53
- package/src/utils/synonyms.ts +78 -0
- package/dist/ChromaDBProvider-MIDOR4FW.mjs +0 -8
- package/dist/MilvusProvider-U7SKC27V.mjs +0 -8
- package/dist/MongoDBProvider-YNKC7EJ6.mjs +0 -8
- package/dist/MultiTablePostgresProvider-YY7LPNJK.mjs +0 -8
- package/dist/PineconeProvider-QZNRKTN2.mjs +0 -8
- package/dist/QdrantProvider-RLJTNGPY.mjs +0 -8
- package/dist/RedisProvider-SR65SCKV.mjs +0 -8
- package/dist/SimpleGraphProvider-SLOXO4M7.mjs +0 -62
- package/dist/UniversalVectorProvider-IN67OS56.mjs +0 -9
- package/dist/WeaviateProvider-5FWDFITI.mjs +0 -8
- package/dist/chunk-5AJ4XHLW.mjs +0 -201
- package/dist/chunk-5YGUXK7Z.mjs +0 -80
- package/dist/chunk-BFYLQYQU.mjs +0 -3985
- package/dist/chunk-CFVEZTBJ.mjs +0 -102
- package/dist/chunk-IMP6FUCY.mjs +0 -30
- package/dist/chunk-LR3VMDVK.mjs +0 -157
- package/dist/chunk-M6JSPGAR.mjs +0 -117
- package/dist/chunk-PSFPZXHX.mjs +0 -245
- package/dist/chunk-R3RGUMHE.mjs +0 -218
- package/dist/chunk-U55XRW3U.mjs +0 -96
- package/dist/chunk-VUQJVIJT.mjs +0 -148
- package/dist/chunk-X4TOT24V.mjs +0 -89
- package/dist/chunk-YLTMFW4M.mjs +0 -49
package/dist/chunk-R3RGUMHE.mjs
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseVectorProvider
|
|
3
|
-
} from "./chunk-IMP6FUCY.mjs";
|
|
4
|
-
import {
|
|
5
|
-
__objRest,
|
|
6
|
-
__spreadProps,
|
|
7
|
-
__spreadValues
|
|
8
|
-
} from "./chunk-X4TOT24V.mjs";
|
|
9
|
-
|
|
10
|
-
// src/providers/vectordb/MultiTablePostgresProvider.ts
|
|
11
|
-
import { Pool } from "pg";
|
|
12
|
-
var MultiTablePostgresProvider = class extends BaseVectorProvider {
|
|
13
|
-
constructor(config) {
|
|
14
|
-
var _a, _b, _c, _d, _e;
|
|
15
|
-
super(config);
|
|
16
|
-
const opts = config.options || {};
|
|
17
|
-
if (!opts.connectionString) {
|
|
18
|
-
throw new Error("[MultiTablePostgresProvider] options.connectionString is required");
|
|
19
|
-
}
|
|
20
|
-
this.connectionString = opts.connectionString;
|
|
21
|
-
this.dimensions = (_a = opts.dimensions) != null ? _a : 768;
|
|
22
|
-
const rawTables = (_c = (_b = opts.tables) != null ? _b : process.env.VECTOR_DB_TABLES) != null ? _c : "";
|
|
23
|
-
this.tables = typeof rawTables === "string" ? rawTables.split(",").map((t) => t.trim()).filter(Boolean) : rawTables;
|
|
24
|
-
if (this.tables.length === 0) {
|
|
25
|
-
console.warn(
|
|
26
|
-
"[MultiTablePostgresProvider] No tables configured. Set VECTOR_DB_TABLES as a comma-separated list of table names or pass options.tables."
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
const rawSearchFields = (_e = (_d = opts.searchFields) != null ? _d : process.env.VECTOR_DB_SEARCH_FIELDS) != null ? _e : ["name", "product_name", "productname", "title"];
|
|
30
|
-
this.searchFields = typeof rawSearchFields === "string" ? rawSearchFields.split(",").map((f) => f.trim()).filter(Boolean) : rawSearchFields;
|
|
31
|
-
}
|
|
32
|
-
async initialize() {
|
|
33
|
-
this.pool = new Pool({ connectionString: this.connectionString });
|
|
34
|
-
const client = await this.pool.connect();
|
|
35
|
-
try {
|
|
36
|
-
const res = await client.query(`
|
|
37
|
-
SELECT table_name
|
|
38
|
-
FROM information_schema.columns
|
|
39
|
-
WHERE column_name = 'embedding'
|
|
40
|
-
AND table_schema = 'public'
|
|
41
|
-
`);
|
|
42
|
-
const discoveredTables = res.rows.map((r) => r.table_name);
|
|
43
|
-
if (this.tables.length === 0) {
|
|
44
|
-
this.tables = discoveredTables;
|
|
45
|
-
} else {
|
|
46
|
-
const staticTables = [...this.tables];
|
|
47
|
-
this.tables = staticTables.filter((t) => discoveredTables.includes(t));
|
|
48
|
-
if (this.tables.length < staticTables.length) {
|
|
49
|
-
const missing = staticTables.filter((t) => !discoveredTables.includes(t));
|
|
50
|
-
console.warn(`[MultiTablePostgresProvider] Some configured tables were skipped (missing 'embedding' column): ${missing.join(", ")}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (this.tables.length === 0) {
|
|
54
|
-
console.warn('[MultiTablePostgresProvider] No tables with "embedding" columns found in the database.');
|
|
55
|
-
} else {
|
|
56
|
-
console.log(
|
|
57
|
-
`[MultiTablePostgresProvider] Connected. Searching across ${this.tables.length} table(s): ${this.tables.join(", ")}`
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
} finally {
|
|
61
|
-
client.release();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Upsert is not supported for MultiTablePostgresProvider as it's designed for
|
|
66
|
-
* searching across pre-existing tables with varying schemas.
|
|
67
|
-
*/
|
|
68
|
-
async upsert(_doc, _namespace) {
|
|
69
|
-
throw new Error(
|
|
70
|
-
"[MultiTablePostgresProvider] upsert() is not supported in multi-table mode. Please use the standard PostgreSQLProvider for single-table managed indices."
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Batch upsert is not supported for MultiTablePostgresProvider.
|
|
75
|
-
*/
|
|
76
|
-
async batchUpsert(_docs, _namespace) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
"[MultiTablePostgresProvider] batchUpsert() is not supported in multi-table mode."
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Query all configured tables and merge results, sorted by cosine similarity score.
|
|
83
|
-
*/
|
|
84
|
-
async query(vector, topK, _namespace, _filter) {
|
|
85
|
-
var _a, _b, _c;
|
|
86
|
-
if (!this.pool) {
|
|
87
|
-
throw new Error("[MultiTablePostgresProvider] Provider not initialized. Call initialize() first.");
|
|
88
|
-
}
|
|
89
|
-
const vectorLiteral = `[${vector.join(",")}]`;
|
|
90
|
-
const allResults = [];
|
|
91
|
-
console.log(`[MultiTablePostgresProvider] --- Starting Multi-Table Search ---`);
|
|
92
|
-
const queryText = _filter == null ? void 0 : _filter.queryText;
|
|
93
|
-
const entityHints = Array.isArray(_filter == null ? void 0 : _filter.__entityHints) ? _filter.__entityHints.filter(
|
|
94
|
-
(hint) => typeof hint === "object" && hint !== null && typeof hint.value === "string"
|
|
95
|
-
).map((hint) => hint.value.trim().toLowerCase()).filter(Boolean) : [];
|
|
96
|
-
console.log(`[MultiTablePostgresProvider] queryText: "${queryText}"`);
|
|
97
|
-
console.log(`[MultiTablePostgresProvider] entityHints: [${entityHints.join(", ")}]`);
|
|
98
|
-
const getDynamicKeywordQuery = () => {
|
|
99
|
-
if (entityHints.length > 0) {
|
|
100
|
-
return entityHints.map((h) => h.includes(" ") ? `"${h}"` : h).join(" & ");
|
|
101
|
-
}
|
|
102
|
-
if (queryText) {
|
|
103
|
-
return queryText.toLowerCase().replace(/\b(show|me|the|product[s]?|item[s]?|card[s]?|of|category|find|list|browse|what|are|display|all|under|for|in|with|about)\b/g, "").trim().replace(/\s+/g, " & ");
|
|
104
|
-
}
|
|
105
|
-
return "";
|
|
106
|
-
};
|
|
107
|
-
const dynamicKeywordQuery = getDynamicKeywordQuery();
|
|
108
|
-
const queryPromises = this.tables.map(async (table) => {
|
|
109
|
-
try {
|
|
110
|
-
let sqlQuery = "";
|
|
111
|
-
let params = [];
|
|
112
|
-
if (queryText) {
|
|
113
|
-
const hasEntityHints = entityHints.length > 0;
|
|
114
|
-
const exactNameScoreExpr = hasEntityHints ? `+ (
|
|
115
|
-
SELECT COALESCE(MAX(
|
|
116
|
-
CASE WHEN LOWER(val) IN (${entityHints.map((h) => `'${h.replace(/'/g, "''")}'`).join(", ")})
|
|
117
|
-
THEN 1.0 ELSE 0.0 END
|
|
118
|
-
), 0)
|
|
119
|
-
FROM jsonb_each_text(to_jsonb(t)) AS kv(key, val)
|
|
120
|
-
WHERE key IN (${this.searchFields.map((f) => `'${f}'`).join(", ")})
|
|
121
|
-
) * 3.0` : "";
|
|
122
|
-
sqlQuery = `
|
|
123
|
-
SELECT *,
|
|
124
|
-
(1 - (embedding <=> $1::vector)) AS vector_score,
|
|
125
|
-
COALESCE(ts_rank(to_tsvector('english', (to_jsonb(t) - 'embedding')::text), to_tsquery('english', $2)), 0) AS keyword_score,
|
|
126
|
-
((1 - (embedding <=> $1::vector)) + (COALESCE(ts_rank(to_tsvector('english', (to_jsonb(t) - 'embedding')::text), to_tsquery('english', $2)), 0) * 2.0) ${exactNameScoreExpr}) AS hybrid_score
|
|
127
|
-
FROM "${table}" t
|
|
128
|
-
ORDER BY hybrid_score DESC
|
|
129
|
-
LIMIT 50
|
|
130
|
-
`;
|
|
131
|
-
params = [vectorLiteral, dynamicKeywordQuery];
|
|
132
|
-
} else {
|
|
133
|
-
sqlQuery = `
|
|
134
|
-
SELECT *,
|
|
135
|
-
(1 - (embedding <=> $1::vector)) AS hybrid_score
|
|
136
|
-
FROM "${table}" t
|
|
137
|
-
ORDER BY hybrid_score DESC
|
|
138
|
-
LIMIT 50
|
|
139
|
-
`;
|
|
140
|
-
params = [vectorLiteral];
|
|
141
|
-
}
|
|
142
|
-
const result = await this.pool.query(sqlQuery, params);
|
|
143
|
-
if (result.rowCount && result.rowCount > 0) {
|
|
144
|
-
console.log(` \u2705 Table "${table}": Found ${result.rowCount} potential matches. Top score: ${result.rows[0].hybrid_score.toFixed(4)}`);
|
|
145
|
-
} else {
|
|
146
|
-
console.log(` \u26AA Table "${table}": No relevant matches found.`);
|
|
147
|
-
}
|
|
148
|
-
const tableResults = [];
|
|
149
|
-
for (const row of result.rows) {
|
|
150
|
-
const _a2 = row, { hybrid_score, id } = _a2, rest = __objRest(_a2, ["hybrid_score", "id"]);
|
|
151
|
-
delete rest.embedding;
|
|
152
|
-
delete rest.vector_score;
|
|
153
|
-
delete rest.keyword_score;
|
|
154
|
-
delete rest.exact_name_score;
|
|
155
|
-
const content = `[TYPE: ${table.replace(/s$/, "").toUpperCase()}]
|
|
156
|
-
` + Object.entries(rest).filter(([k, v]) => v !== null && typeof v !== "object" && k !== "id").map(([k, v]) => `${k}: ${v}`).join("\n");
|
|
157
|
-
tableResults.push({
|
|
158
|
-
id: `${table}-${id}`,
|
|
159
|
-
score: parseFloat(String(hybrid_score)),
|
|
160
|
-
content,
|
|
161
|
-
metadata: __spreadProps(__spreadValues({}, rest), { source_table: table })
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
return tableResults;
|
|
165
|
-
} catch (err) {
|
|
166
|
-
console.error(
|
|
167
|
-
`[MultiTablePostgresProvider] Error querying table "${table}":`,
|
|
168
|
-
err.message
|
|
169
|
-
);
|
|
170
|
-
return [];
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
const resultsArray = await Promise.all(queryPromises);
|
|
174
|
-
for (const tableResults of resultsArray) {
|
|
175
|
-
allResults.push(...tableResults);
|
|
176
|
-
}
|
|
177
|
-
const resultsByTable = {};
|
|
178
|
-
for (const res of allResults) {
|
|
179
|
-
const table = (_a = res.metadata) == null ? void 0 : _a.source_table;
|
|
180
|
-
if (!resultsByTable[table]) resultsByTable[table] = [];
|
|
181
|
-
resultsByTable[table].push(res);
|
|
182
|
-
}
|
|
183
|
-
const balancedResults = [];
|
|
184
|
-
const tables = Object.keys(resultsByTable);
|
|
185
|
-
for (const table of tables) {
|
|
186
|
-
balancedResults.push(...resultsByTable[table].slice(0, 3));
|
|
187
|
-
}
|
|
188
|
-
const finalSorted = balancedResults.sort((a, b) => b.score - a.score);
|
|
189
|
-
if (finalSorted.length > 0) {
|
|
190
|
-
console.log(`[MultiTablePostgresProvider] --- Search Complete ---`);
|
|
191
|
-
console.log(`[MultiTablePostgresProvider] Final top match from "${(_c = (_b = finalSorted[0].metadata) == null ? void 0 : _b.source_table) != null ? _c : "unknown"}" with score ${finalSorted[0].score.toFixed(4)}`);
|
|
192
|
-
}
|
|
193
|
-
return finalSorted.slice(0, Math.max(topK, 15));
|
|
194
|
-
}
|
|
195
|
-
async delete(_id, _namespace) {
|
|
196
|
-
console.warn("[MultiTablePostgresProvider] delete() is a no-op for multi-table mode.");
|
|
197
|
-
}
|
|
198
|
-
async deleteNamespace(_namespace) {
|
|
199
|
-
console.warn("[MultiTablePostgresProvider] deleteNamespace() is a no-op for multi-table mode.");
|
|
200
|
-
}
|
|
201
|
-
async ping() {
|
|
202
|
-
try {
|
|
203
|
-
await this.pool.query("SELECT 1");
|
|
204
|
-
return true;
|
|
205
|
-
} catch (e) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
async disconnect() {
|
|
210
|
-
if (this.pool) {
|
|
211
|
-
await this.pool.end();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
export {
|
|
217
|
-
MultiTablePostgresProvider
|
|
218
|
-
};
|
package/dist/chunk-U55XRW3U.mjs
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseVectorProvider
|
|
3
|
-
} from "./chunk-IMP6FUCY.mjs";
|
|
4
|
-
import {
|
|
5
|
-
__spreadValues
|
|
6
|
-
} from "./chunk-X4TOT24V.mjs";
|
|
7
|
-
|
|
8
|
-
// src/providers/vectordb/MilvusProvider.ts
|
|
9
|
-
import axios from "axios";
|
|
10
|
-
var MilvusProvider = class extends BaseVectorProvider {
|
|
11
|
-
constructor(config) {
|
|
12
|
-
super(config);
|
|
13
|
-
const opts = config.options;
|
|
14
|
-
const baseUrl = opts.baseUrl || opts.uri || (opts.host ? `http://${opts.host}:${opts.port || 19530}` : void 0);
|
|
15
|
-
if (!baseUrl) throw new Error("[MilvusProvider] options.baseUrl (or uri / host+port) is required");
|
|
16
|
-
this.http = axios.create({
|
|
17
|
-
baseURL: baseUrl,
|
|
18
|
-
headers: __spreadValues(__spreadValues({
|
|
19
|
-
"Content-Type": "application/json"
|
|
20
|
-
}, opts.headers || {}), opts.apiKey ? { Authorization: `Bearer ${opts.apiKey}` } : {})
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
async initialize() {
|
|
24
|
-
await this.ping();
|
|
25
|
-
}
|
|
26
|
-
async upsert(doc, namespace) {
|
|
27
|
-
const payload = {
|
|
28
|
-
collectionName: this.indexName,
|
|
29
|
-
data: [__spreadValues({
|
|
30
|
-
vector: doc.vector,
|
|
31
|
-
content: doc.content,
|
|
32
|
-
metadata: doc.metadata || {}
|
|
33
|
-
}, namespace ? { namespace } : {})]
|
|
34
|
-
};
|
|
35
|
-
await this.http.post("/v1/vector/upsert", payload);
|
|
36
|
-
}
|
|
37
|
-
async batchUpsert(docs, namespace) {
|
|
38
|
-
const payload = {
|
|
39
|
-
collectionName: this.indexName,
|
|
40
|
-
data: docs.map((doc) => __spreadValues({
|
|
41
|
-
vector: doc.vector,
|
|
42
|
-
content: doc.content,
|
|
43
|
-
metadata: doc.metadata || {}
|
|
44
|
-
}, namespace ? { namespace } : {}))
|
|
45
|
-
};
|
|
46
|
-
await this.http.post("/v1/vector/upsert", payload);
|
|
47
|
-
}
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
49
|
-
async query(vector, topK, namespace, _filter) {
|
|
50
|
-
const payload = {
|
|
51
|
-
collectionName: this.indexName,
|
|
52
|
-
vector,
|
|
53
|
-
limit: topK,
|
|
54
|
-
filter: namespace ? `namespace == "${namespace}"` : void 0,
|
|
55
|
-
outputFields: ["content", "metadata"],
|
|
56
|
-
searchParams: {
|
|
57
|
-
nprobe: this.config.options.nprobe || 16,
|
|
58
|
-
ef: this.config.options.efSearch || Math.max(topK * 10, 64)
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const { data } = await this.http.post("/v1/vector/search", payload);
|
|
62
|
-
return (data.data || []).map((res) => ({
|
|
63
|
-
id: String(res["id"]),
|
|
64
|
-
score: res["distance"],
|
|
65
|
-
content: res["content"],
|
|
66
|
-
metadata: res["metadata"] || {}
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
|
-
async delete(id, _namespace) {
|
|
71
|
-
await this.http.post("/v1/vector/delete", {
|
|
72
|
-
collectionName: this.indexName,
|
|
73
|
-
id
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
async deleteNamespace(namespace) {
|
|
77
|
-
await this.http.post("/v1/vector/delete", {
|
|
78
|
-
collectionName: this.indexName,
|
|
79
|
-
filter: `namespace == "${namespace}"`
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
async ping() {
|
|
83
|
-
try {
|
|
84
|
-
await this.http.get("/v1/health");
|
|
85
|
-
return true;
|
|
86
|
-
} catch (e) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async disconnect() {
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export {
|
|
95
|
-
MilvusProvider
|
|
96
|
-
};
|
package/dist/chunk-VUQJVIJT.mjs
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseVectorProvider
|
|
3
|
-
} from "./chunk-IMP6FUCY.mjs";
|
|
4
|
-
import {
|
|
5
|
-
__spreadValues
|
|
6
|
-
} from "./chunk-X4TOT24V.mjs";
|
|
7
|
-
|
|
8
|
-
// src/providers/vectordb/PineconeProvider.ts
|
|
9
|
-
import { Pinecone } from "@pinecone-database/pinecone";
|
|
10
|
-
var PineconeProvider = class extends BaseVectorProvider {
|
|
11
|
-
constructor(config) {
|
|
12
|
-
super(config);
|
|
13
|
-
const opts = config.options;
|
|
14
|
-
if (!opts.apiKey) throw new Error("[PineconeProvider] options.apiKey is required");
|
|
15
|
-
this.apiKey = opts.apiKey;
|
|
16
|
-
}
|
|
17
|
-
static getValidator() {
|
|
18
|
-
return {
|
|
19
|
-
validate(config) {
|
|
20
|
-
const errors = [];
|
|
21
|
-
const opts = config.options || {};
|
|
22
|
-
if (!opts.apiKey) {
|
|
23
|
-
errors.push({
|
|
24
|
-
field: "vectorDb.options.apiKey",
|
|
25
|
-
message: "Pinecone API key is required",
|
|
26
|
-
suggestion: "Set PINECONE_API_KEY environment variable",
|
|
27
|
-
severity: "error"
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
return errors;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
static getHealthChecker() {
|
|
35
|
-
return {
|
|
36
|
-
async check(config) {
|
|
37
|
-
var _a, _b;
|
|
38
|
-
const opts = config.options || {};
|
|
39
|
-
const indexName = config.indexName;
|
|
40
|
-
const timestamp = Date.now();
|
|
41
|
-
try {
|
|
42
|
-
const { Pinecone: Pinecone2 } = await import("@pinecone-database/pinecone");
|
|
43
|
-
const client = new Pinecone2({ apiKey: opts.apiKey });
|
|
44
|
-
const indexes = await client.listIndexes();
|
|
45
|
-
const indexNames = (_b = (_a = indexes.indexes) == null ? void 0 : _a.map((i) => i.name)) != null ? _b : [];
|
|
46
|
-
if (!indexNames.includes(indexName)) {
|
|
47
|
-
return {
|
|
48
|
-
healthy: false,
|
|
49
|
-
provider: "pinecone",
|
|
50
|
-
error: `Index "${indexName}" not found. Available: ${indexNames.join(", ")}`,
|
|
51
|
-
timestamp
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
healthy: true,
|
|
56
|
-
provider: "pinecone",
|
|
57
|
-
capabilities: { indexes: indexNames.length, targetIndex: indexName },
|
|
58
|
-
timestamp
|
|
59
|
-
};
|
|
60
|
-
} catch (error) {
|
|
61
|
-
return {
|
|
62
|
-
healthy: false,
|
|
63
|
-
provider: "pinecone",
|
|
64
|
-
error: `Connection failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
65
|
-
timestamp
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
async initialize() {
|
|
72
|
-
var _a, _b;
|
|
73
|
-
this.client = new Pinecone({ apiKey: this.apiKey });
|
|
74
|
-
const indexes = await this.client.listIndexes();
|
|
75
|
-
const names = (_b = (_a = indexes.indexes) == null ? void 0 : _a.map((i) => i.name)) != null ? _b : [];
|
|
76
|
-
if (!names.includes(this.indexName)) {
|
|
77
|
-
throw new Error(
|
|
78
|
-
`[PineconeProvider] Index "${this.indexName}" not found. Available: ${names.join(", ")}`
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
index(namespace) {
|
|
83
|
-
const idx = this.client.index(this.indexName);
|
|
84
|
-
return namespace ? idx.namespace(namespace) : idx.namespace("");
|
|
85
|
-
}
|
|
86
|
-
async upsert(doc, namespace) {
|
|
87
|
-
var _a;
|
|
88
|
-
await this.index(namespace).upsert({
|
|
89
|
-
records: [{
|
|
90
|
-
id: String(doc.id),
|
|
91
|
-
values: doc.vector,
|
|
92
|
-
metadata: __spreadValues({ content: doc.content }, (_a = doc.metadata) != null ? _a : {})
|
|
93
|
-
}]
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
async batchUpsert(docs, namespace) {
|
|
97
|
-
const BATCH = 100;
|
|
98
|
-
for (let i = 0; i < docs.length; i += BATCH) {
|
|
99
|
-
const records = docs.slice(i, i + BATCH).map((d) => {
|
|
100
|
-
var _a;
|
|
101
|
-
return {
|
|
102
|
-
id: String(d.id),
|
|
103
|
-
values: d.vector,
|
|
104
|
-
metadata: __spreadValues({ content: d.content }, (_a = d.metadata) != null ? _a : {})
|
|
105
|
-
};
|
|
106
|
-
});
|
|
107
|
-
await this.index(namespace).upsert({ records });
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
async query(vector, topK, namespace, filter) {
|
|
111
|
-
var _a;
|
|
112
|
-
const pineconeFilter = this.sanitizeFilter(filter);
|
|
113
|
-
const result = await this.index(namespace).query(__spreadValues({
|
|
114
|
-
vector,
|
|
115
|
-
topK,
|
|
116
|
-
includeMetadata: true
|
|
117
|
-
}, Object.keys(pineconeFilter).length > 0 ? { filter: pineconeFilter } : {}));
|
|
118
|
-
return ((_a = result.matches) != null ? _a : []).map((m) => {
|
|
119
|
-
var _a2, _b;
|
|
120
|
-
return {
|
|
121
|
-
id: m.id,
|
|
122
|
-
score: (_a2 = m.score) != null ? _a2 : 0,
|
|
123
|
-
content: ((_b = m.metadata) == null ? void 0 : _b.content) || "",
|
|
124
|
-
metadata: m.metadata
|
|
125
|
-
};
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
async delete(id, namespace) {
|
|
129
|
-
await this.index(namespace).deleteOne({ id: String(id) });
|
|
130
|
-
}
|
|
131
|
-
async deleteNamespace(namespace) {
|
|
132
|
-
await this.client.index(this.indexName).namespace(namespace).deleteAll();
|
|
133
|
-
}
|
|
134
|
-
async ping() {
|
|
135
|
-
try {
|
|
136
|
-
await this.client.listIndexes();
|
|
137
|
-
return true;
|
|
138
|
-
} catch (e) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
async disconnect() {
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export {
|
|
147
|
-
PineconeProvider
|
|
148
|
-
};
|
package/dist/chunk-X4TOT24V.mjs
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name);
|
|
8
|
-
var __typeError = (msg) => {
|
|
9
|
-
throw TypeError(msg);
|
|
10
|
-
};
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __objRest = (source, exclude) => {
|
|
25
|
-
var target = {};
|
|
26
|
-
for (var prop in source)
|
|
27
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
if (source != null && __getOwnPropSymbols)
|
|
30
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
-
target[prop] = source[prop];
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
|
-
var __await = function(promise, isYieldStar) {
|
|
37
|
-
this[0] = promise;
|
|
38
|
-
this[1] = isYieldStar;
|
|
39
|
-
};
|
|
40
|
-
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
41
|
-
var resume = (k, v, yes, no) => {
|
|
42
|
-
try {
|
|
43
|
-
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
44
|
-
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));
|
|
45
|
-
} catch (e) {
|
|
46
|
-
no(e);
|
|
47
|
-
}
|
|
48
|
-
}, 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 = {};
|
|
49
|
-
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
50
|
-
};
|
|
51
|
-
var __yieldStar = (value) => {
|
|
52
|
-
var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
|
|
53
|
-
if (obj == null) {
|
|
54
|
-
obj = value[__knownSymbol("iterator")]();
|
|
55
|
-
method = (k) => it[k] = (x) => obj[k](x);
|
|
56
|
-
} else {
|
|
57
|
-
obj = obj.call(value);
|
|
58
|
-
method = (k) => it[k] = (v) => {
|
|
59
|
-
if (isAwait) {
|
|
60
|
-
isAwait = false;
|
|
61
|
-
if (k === "throw") throw v;
|
|
62
|
-
return v;
|
|
63
|
-
}
|
|
64
|
-
isAwait = true;
|
|
65
|
-
return {
|
|
66
|
-
done: false,
|
|
67
|
-
value: new __await(new Promise((resolve) => {
|
|
68
|
-
var x = obj[k](v);
|
|
69
|
-
if (!(x instanceof Object)) __typeError("Object expected");
|
|
70
|
-
resolve(x);
|
|
71
|
-
}), 1)
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
|
|
76
|
-
throw x;
|
|
77
|
-
}, "return" in obj && method("return"), it;
|
|
78
|
-
};
|
|
79
|
-
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);
|
|
80
|
-
|
|
81
|
-
export {
|
|
82
|
-
__spreadValues,
|
|
83
|
-
__spreadProps,
|
|
84
|
-
__objRest,
|
|
85
|
-
__await,
|
|
86
|
-
__asyncGenerator,
|
|
87
|
-
__yieldStar,
|
|
88
|
-
__forAwait
|
|
89
|
-
};
|
package/dist/chunk-YLTMFW4M.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__spreadValues
|
|
3
|
-
} from "./chunk-X4TOT24V.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 (!isRecord(current) && !Array.isArray(current)) {
|
|
13
|
-
return void 0;
|
|
14
|
-
}
|
|
15
|
-
return current[segment];
|
|
16
|
-
}, obj);
|
|
17
|
-
}
|
|
18
|
-
function buildPayload(template, vars) {
|
|
19
|
-
let raw = template;
|
|
20
|
-
for (const [key, val] of Object.entries(vars)) {
|
|
21
|
-
const stringifiedVal = val === void 0 ? "null" : JSON.stringify(val);
|
|
22
|
-
raw = raw.replace(new RegExp(`"\\{\\{${key}\\}\\}"`, "g"), stringifiedVal);
|
|
23
|
-
raw = raw.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), stringifiedVal);
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
return JSON.parse(raw);
|
|
27
|
-
} catch (err) {
|
|
28
|
-
throw new Error(`Failed to parse payload template: ${err.message}
|
|
29
|
-
Raw payload: ${raw}`);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function mergeDefined(base, override) {
|
|
33
|
-
const merged = __spreadValues({}, base || {});
|
|
34
|
-
if (!override) {
|
|
35
|
-
return merged;
|
|
36
|
-
}
|
|
37
|
-
for (const [key, value] of Object.entries(override)) {
|
|
38
|
-
if (value !== void 0 && value !== null && value !== "") {
|
|
39
|
-
merged[key] = value;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return merged;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export {
|
|
46
|
-
resolvePath,
|
|
47
|
-
buildPayload,
|
|
48
|
-
mergeDefined
|
|
49
|
-
};
|