@retrivora-ai/rag-engine 2.3.7 → 2.3.8
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.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.js +227 -117
- package/dist/handlers/index.mjs +229 -119
- package/dist/{index-ejOWsaqb.d.ts → index-BQd6Bax0.d.ts} +1 -1
- package/dist/{index-xxQOFx-u.d.mts → index-C7aHK7_g.d.mts} +1 -1
- package/dist/index.js +114 -87
- package/dist/index.mjs +114 -87
- package/dist/server.d.mts +12 -32
- package/dist/server.d.ts +12 -32
- package/dist/server.js +232 -121
- package/dist/server.mjs +234 -123
- package/package.json +1 -1
- package/src/components/ChatWidget.tsx +0 -1
- package/src/components/ConfigProvider.tsx +2 -1
- package/src/config/serverConfig.ts +1 -2
- package/src/core/ConfigFetcher.ts +36 -3
- package/src/core/DatabaseStorage.ts +13 -13
- package/src/core/LicenseValidator.ts +5 -3
- package/src/core/LicenseVerifier.ts +85 -120
- package/src/core/Retrivora.ts +1 -1
- package/src/core/VectorPlugin.ts +1 -1
- package/src/handlers/index.ts +23 -13
- package/src/providers/vectordb/PineconeProvider.ts +69 -2
|
@@ -12,6 +12,7 @@ import { ConfigFetcher } from '../../core/ConfigFetcher';
|
|
|
12
12
|
export class PineconeProvider extends BaseVectorProvider {
|
|
13
13
|
private client!: Pinecone;
|
|
14
14
|
private apiKey: string;
|
|
15
|
+
private licenseKey?: string;
|
|
15
16
|
|
|
16
17
|
constructor(config: VectorDBConfig) {
|
|
17
18
|
super(config);
|
|
@@ -19,6 +20,15 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
19
20
|
this.apiKey = opts.apiKey || process.env.PINECONE_API_KEY || '';
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
private getControlPlaneUrl(): string {
|
|
24
|
+
const urls = [
|
|
25
|
+
process.env.RETRIVORA_CONTROL_PLANE_URL,
|
|
26
|
+
process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
|
|
27
|
+
'https://www.retrivora.com'
|
|
28
|
+
].filter((url): url is string => Boolean(url));
|
|
29
|
+
return urls[0].replace(/\/$/, '');
|
|
30
|
+
}
|
|
31
|
+
|
|
22
32
|
static getValidator(): IProviderValidator {
|
|
23
33
|
return {
|
|
24
34
|
validate(config: Record<string, unknown>): ValidationError[] {
|
|
@@ -89,6 +99,7 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
89
99
|
|
|
90
100
|
if (!key) {
|
|
91
101
|
const licenseKey = process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
102
|
+
this.licenseKey = licenseKey;
|
|
92
103
|
const jwtProjectId = (() => {
|
|
93
104
|
if (!licenseKey) return undefined;
|
|
94
105
|
try {
|
|
@@ -102,6 +113,7 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
102
113
|
})();
|
|
103
114
|
|
|
104
115
|
const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || 'default';
|
|
116
|
+
this.projectId = projectId;
|
|
105
117
|
|
|
106
118
|
const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
|
|
107
119
|
|
|
@@ -158,6 +170,21 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
158
170
|
}
|
|
159
171
|
|
|
160
172
|
async upsert(doc: UpsertDocument, namespace?: string): Promise<void> {
|
|
173
|
+
if (!this.client) {
|
|
174
|
+
if (!this.licenseKey) throw new Error('[PineconeProvider] Cannot execute vector operation: Missing API key and License key.');
|
|
175
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
176
|
+
method: 'POST',
|
|
177
|
+
headers: { 'Content-Type': 'application/json', 'x-license-key': this.licenseKey },
|
|
178
|
+
body: JSON.stringify({
|
|
179
|
+
projectId: this.projectId,
|
|
180
|
+
indexName: this.indexName,
|
|
181
|
+
namespace: namespace || this.projectId,
|
|
182
|
+
records: [{ id: String(doc.id), values: doc.vector, metadata: { content: doc.content, ...(doc.metadata ?? {}) } }]
|
|
183
|
+
})
|
|
184
|
+
});
|
|
185
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy upsert failed: ${await res.text()}`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
161
188
|
const targetIdx = await this.getActiveIndex(namespace);
|
|
162
189
|
await targetIdx.upsert({
|
|
163
190
|
records: [{
|
|
@@ -169,8 +196,26 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
169
196
|
}
|
|
170
197
|
|
|
171
198
|
async batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void> {
|
|
172
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
173
199
|
const BATCH = 100;
|
|
200
|
+
if (!this.client) {
|
|
201
|
+
if (!this.licenseKey) throw new Error('[PineconeProvider] Cannot execute vector operation: Missing API key and License key.');
|
|
202
|
+
for (let i = 0; i < docs.length; i += BATCH) {
|
|
203
|
+
const records = docs.slice(i, i + BATCH).map((d) => ({
|
|
204
|
+
id: String(d.id), values: d.vector, metadata: { content: d.content, ...(d.metadata ?? {}) }
|
|
205
|
+
}));
|
|
206
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
|
|
207
|
+
method: 'POST',
|
|
208
|
+
headers: { 'Content-Type': 'application/json', 'x-license-key': this.licenseKey },
|
|
209
|
+
body: JSON.stringify({
|
|
210
|
+
projectId: this.projectId, indexName: this.indexName, namespace: namespace || this.projectId, records
|
|
211
|
+
})
|
|
212
|
+
});
|
|
213
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy batch upsert failed: ${await res.text()}`);
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
174
219
|
for (let i = 0; i < docs.length; i += BATCH) {
|
|
175
220
|
const records = docs.slice(i, i + BATCH).map((d) => ({
|
|
176
221
|
id: String(d.id),
|
|
@@ -187,8 +232,30 @@ export class PineconeProvider extends BaseVectorProvider {
|
|
|
187
232
|
namespace?: string,
|
|
188
233
|
filter?: Record<string, unknown>
|
|
189
234
|
): Promise<VectorMatch[]> {
|
|
190
|
-
const targetIdx = await this.getActiveIndex(namespace);
|
|
191
235
|
const pineconeFilter = this.sanitizeFilter(filter);
|
|
236
|
+
|
|
237
|
+
if (!this.client) {
|
|
238
|
+
if (!this.licenseKey) throw new Error('[PineconeProvider] Cannot execute vector operation: Missing API key and License key.');
|
|
239
|
+
const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
|
|
240
|
+
method: 'POST',
|
|
241
|
+
headers: { 'Content-Type': 'application/json', 'x-license-key': this.licenseKey },
|
|
242
|
+
body: JSON.stringify({
|
|
243
|
+
projectId: this.projectId,
|
|
244
|
+
indexName: this.indexName,
|
|
245
|
+
namespace: namespace || this.projectId,
|
|
246
|
+
vector,
|
|
247
|
+
topK,
|
|
248
|
+
filter: pineconeFilter
|
|
249
|
+
})
|
|
250
|
+
});
|
|
251
|
+
if (!res.ok) throw new Error(`[PineconeProvider] Proxy query failed: ${await res.text()}`);
|
|
252
|
+
const data = await res.json();
|
|
253
|
+
return (data.matches ?? []).map((m: any) => ({
|
|
254
|
+
id: m.id, score: m.score ?? 0, content: (m.metadata?.content || '') as string, metadata: m.metadata as Record<string, unknown>
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const targetIdx = await this.getActiveIndex(namespace);
|
|
192
259
|
const result = await targetIdx.query({
|
|
193
260
|
vector,
|
|
194
261
|
topK,
|