@retrivora-ai/rag-engine 2.3.9 → 2.4.1
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/README.md +1 -1
- package/dist/{BatchProcessor-C42_RVWO.d.ts → BatchProcessor-D42E706a.d.ts} +12 -1
- package/dist/{BatchProcessor-BhLczWj5.d.mts → BatchProcessor-zbQMaZHm.d.mts} +12 -1
- package/dist/{ILLMProvider-B8TAVx3j.d.mts → ILLMProvider-Y6aL5N8J.d.mts} +1 -0
- package/dist/{ILLMProvider-B8TAVx3j.d.ts → ILLMProvider-Y6aL5N8J.d.ts} +1 -0
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +26 -85
- package/dist/handlers/index.mjs +26 -85
- package/dist/{index-C7aHK7_g.d.mts → index-59CHg0V3.d.mts} +1 -1
- package/dist/{index-BQd6Bax0.d.ts → index-BgKRInpa.d.ts} +1 -1
- package/dist/index.css +83 -0
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +482 -260
- package/dist/index.mjs +494 -269
- package/dist/server.d.mts +9 -6
- package/dist/server.d.ts +9 -6
- package/dist/server.js +34 -118
- package/dist/server.mjs +34 -118
- package/package.json +1 -1
- package/src/LicensedRetrivora.ts +21 -16
- package/src/components/ChatWindow.tsx +296 -28
- package/src/components/ConfigProvider.tsx +10 -1
- package/src/components/DocumentUpload.tsx +28 -29
- package/src/components/UIDispatcher.tsx +1 -1
- package/src/config/LicenseConfigResolver.ts +14 -12
- package/src/config/RagConfig.ts +1 -0
- package/src/config/serverConfig.ts +31 -29
- package/src/config/uiConstants.ts +1 -0
- package/src/core/ConfigFetcher.ts +2 -2
- package/src/core/LLMRouter.ts +3 -3
- package/src/core/PluginManager.ts +5 -5
- package/src/core/mcp.ts +5 -5
- package/src/handlers/index.ts +11 -5
- package/src/hooks/useRagChat.ts +13 -13
- package/src/index.css +83 -0
- package/src/llm/LLMFactory.ts +1 -1
- package/src/llm/providers/UniversalLLMAdapter.ts +18 -18
- package/src/providers/graphdb/SimpleGraphProvider.ts +5 -5
- package/src/providers/vectordb/ChromaDBProvider.ts +4 -4
- package/src/providers/vectordb/MultiTablePostgresProvider.ts +32 -32
- package/src/providers/vectordb/QdrantProvider.ts +17 -17
- package/src/telemetry/TelemetryService.ts +12 -12
- package/src/types/props.ts +11 -0
- package/src/utils/SchemaMapper.ts +1 -1
- package/src/utils/UITransformer.ts +1 -1
|
@@ -70,12 +70,12 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
70
70
|
...(this.opts.headers || {}),
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
console.log('[UniversalLLMAdapter] Initialized with:', {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
73
|
+
// console.log('[UniversalLLMAdapter] Initialized with:', {
|
|
74
|
+
// model: this.model,
|
|
75
|
+
// baseUrl: this.baseUrl,
|
|
76
|
+
// hasApiKey: !!this.apiKey,
|
|
77
|
+
// apiKeyPrefix: this.apiKey ? `${this.apiKey.slice(0, 12)}...` : undefined,
|
|
78
|
+
// });
|
|
79
79
|
|
|
80
80
|
this.http = axios.create({
|
|
81
81
|
baseURL: this.baseUrl,
|
|
@@ -121,7 +121,7 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
121
121
|
console.debug(`[UniversalLLMAdapter] POST ${this.baseUrl}${path}`);
|
|
122
122
|
console.debug(`[UniversalLLMAdapter] Model: ${this.model}`);
|
|
123
123
|
console.debug(`[UniversalLLMAdapter] Auth: Bearer ${this.apiKey?.substring(0, 20) || 'none'}...`);
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
const { data } = await this.http.post(path, payload);
|
|
126
126
|
const extractPath = this.opts.responseExtractPath ?? 'choices[0].message.content';
|
|
127
127
|
const result = resolvePath(data, extractPath) ?? extractContent(data);
|
|
@@ -173,7 +173,7 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
173
173
|
* Streaming chat using native fetch + ReadableStream.
|
|
174
174
|
* Parses OpenAI-compatible SSE frames: `data: {...}\n\n`
|
|
175
175
|
*/
|
|
176
|
-
async *chatStream(messages: ChatMessage[], context?: string): AsyncIterable<string> {
|
|
176
|
+
async * chatStream(messages: ChatMessage[], context?: string): AsyncIterable<string> {
|
|
177
177
|
const path = this.opts.chatPath ?? '/chat/completions';
|
|
178
178
|
const url = `${this.baseUrl.replace(/\/$/, '')}${path}`;
|
|
179
179
|
const extractPath = (this.opts.responseExtractPath ?? 'choices[0].message.content')
|
|
@@ -325,18 +325,18 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
325
325
|
|
|
326
326
|
// First attempt: try HTTP call with fallback
|
|
327
327
|
try {
|
|
328
|
-
console.log(`[UniversalLLMAdapter] Posting to embedding endpoint: ${this.baseUrl}${path}`, {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
});
|
|
328
|
+
// console.log(`[UniversalLLMAdapter] Posting to embedding endpoint: ${this.baseUrl}${path}`, {
|
|
329
|
+
// model: this.model,
|
|
330
|
+
// inputLength: typeof text === 'string' ? text.length : 'unknown',
|
|
331
|
+
// });
|
|
332
332
|
const { data } = await this.http.post(path, payload);
|
|
333
333
|
const extractPath = this.opts.embedExtractPath ?? 'data[0].embedding';
|
|
334
334
|
const vector = resolvePath(data, extractPath) as number[] | undefined;
|
|
335
335
|
if (Array.isArray(vector)) {
|
|
336
|
-
console.log(`[UniversalLLMAdapter] Embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
336
|
+
//console.log(`[UniversalLLMAdapter] Embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
337
337
|
return vector;
|
|
338
338
|
}
|
|
339
|
-
|
|
339
|
+
|
|
340
340
|
// If we get here, the API succeeded but the response format was invalid
|
|
341
341
|
console.warn(
|
|
342
342
|
`[UniversalLLMAdapter] Embedding API returned unexpected format for path '${extractPath}'. Response:`,
|
|
@@ -347,7 +347,7 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
347
347
|
`[UniversalLLMAdapter] HTTP embedding request failed: ${err?.message || err}`,
|
|
348
348
|
{ path, model: this.model, response: err?.response?.data }
|
|
349
349
|
);
|
|
350
|
-
|
|
350
|
+
|
|
351
351
|
// In-process fallback for embeddings
|
|
352
352
|
const _g = globalThis as any;
|
|
353
353
|
const dispatchEmbed = _g.__retrivoraDispatchEmbedding;
|
|
@@ -366,16 +366,16 @@ export class UniversalLLMAdapter implements ILLMProvider {
|
|
|
366
366
|
|
|
367
367
|
// Second attempt: retry the HTTP call
|
|
368
368
|
try {
|
|
369
|
-
console.log(`[UniversalLLMAdapter] Retrying embedding request to: ${this.baseUrl}${path}`);
|
|
369
|
+
//console.log(`[UniversalLLMAdapter] Retrying embedding request to: ${this.baseUrl}${path}`);
|
|
370
370
|
const { data } = await this.http.post(path, payload);
|
|
371
371
|
const extractPath = this.opts.embedExtractPath ?? 'data[0].embedding';
|
|
372
372
|
const vector = resolvePath(data, extractPath) as number[] | undefined;
|
|
373
373
|
|
|
374
374
|
if (Array.isArray(vector)) {
|
|
375
|
-
console.log(`[UniversalLLMAdapter] Retry embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
375
|
+
//console.log(`[UniversalLLMAdapter] Retry embedding HTTP request successful. Vector size: ${vector.length}`);
|
|
376
376
|
return vector;
|
|
377
377
|
}
|
|
378
|
-
|
|
378
|
+
|
|
379
379
|
console.error(
|
|
380
380
|
`[UniversalLLMAdapter] Retry embedding failed: unexpected response format for path '${extractPath}'. Response:`,
|
|
381
381
|
data
|
|
@@ -9,7 +9,7 @@ export class SimpleGraphProvider extends BaseGraphProvider {
|
|
|
9
9
|
private edges: Edge[] = [];
|
|
10
10
|
|
|
11
11
|
async initialize(): Promise<void> {
|
|
12
|
-
console.log('[SimpleGraphProvider] Initialised in-memory graph store.');
|
|
12
|
+
//console.log('[SimpleGraphProvider] Initialised in-memory graph store.');
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async addNodes(nodes: GraphNode[]): Promise<void> {
|
|
@@ -24,16 +24,16 @@ export class SimpleGraphProvider extends BaseGraphProvider {
|
|
|
24
24
|
|
|
25
25
|
async query(queryText: string, limit = 5): Promise<GraphSearchResult> {
|
|
26
26
|
const q = queryText.toLowerCase();
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
// Simple keyword matching for demonstration
|
|
29
|
-
const matchedNodes = Array.from(this.nodes.values()).filter(node =>
|
|
30
|
-
node.id.toLowerCase().includes(q) ||
|
|
29
|
+
const matchedNodes = Array.from(this.nodes.values()).filter(node =>
|
|
30
|
+
node.id.toLowerCase().includes(q) ||
|
|
31
31
|
node.label.toLowerCase().includes(q) ||
|
|
32
32
|
JSON.stringify(node.properties).toLowerCase().includes(q)
|
|
33
33
|
).slice(0, limit);
|
|
34
34
|
|
|
35
35
|
const matchedNodeIds = new Set(matchedNodes.map(n => n.id));
|
|
36
|
-
const matchedEdges = this.edges.filter(edge =>
|
|
36
|
+
const matchedEdges = this.edges.filter(edge =>
|
|
37
37
|
matchedNodeIds.has(edge.source) || matchedNodeIds.has(edge.target)
|
|
38
38
|
);
|
|
39
39
|
|
|
@@ -37,16 +37,16 @@ export class ChromaDBProvider extends BaseVectorProvider {
|
|
|
37
37
|
try {
|
|
38
38
|
const { data } = await this.http.get(`/api/v1/collections/${this.indexName}`);
|
|
39
39
|
this.collectionId = data.id;
|
|
40
|
-
console.log(`[ChromaDBProvider] ✅ Collection "${this.indexName}" found (id: ${this.collectionId})`);
|
|
40
|
+
//console.log(`[ChromaDBProvider] ✅ Collection "${this.indexName}" found (id: ${this.collectionId})`);
|
|
41
41
|
} catch (err) {
|
|
42
42
|
if (axios.isAxiosError(err) && err.response?.status === 404) {
|
|
43
43
|
// Create the collection if it doesn't exist
|
|
44
|
-
console.log(`[ChromaDBProvider] ⏳ Collection "${this.indexName}" not found. Creating...`);
|
|
44
|
+
//console.log(`[ChromaDBProvider] ⏳ Collection "${this.indexName}" not found. Creating...`);
|
|
45
45
|
const { data } = await this.http.post('/api/v1/collections', {
|
|
46
46
|
name: this.indexName,
|
|
47
47
|
});
|
|
48
48
|
this.collectionId = data.id;
|
|
49
|
-
console.log(`[ChromaDBProvider] ✅ Created collection "${this.indexName}" (id: ${this.collectionId})`);
|
|
49
|
+
//console.log(`[ChromaDBProvider] ✅ Created collection "${this.indexName}" (id: ${this.collectionId})`);
|
|
50
50
|
} else {
|
|
51
51
|
throw err;
|
|
52
52
|
}
|
|
@@ -126,5 +126,5 @@ export class ChromaDBProvider extends BaseVectorProvider {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
async disconnect(): Promise<void> {}
|
|
129
|
+
async disconnect(): Promise<void> { }
|
|
130
130
|
}
|
|
@@ -56,7 +56,7 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
56
56
|
const client: PoolClient = await this.pool.connect();
|
|
57
57
|
try {
|
|
58
58
|
await client.query('CREATE EXTENSION IF NOT EXISTS vector');
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
// Ensure the upload table exists
|
|
61
61
|
await client.query(`
|
|
62
62
|
CREATE TABLE IF NOT EXISTS ${this.uploadTable} (
|
|
@@ -91,9 +91,9 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
91
91
|
if (this.tables.length === 0) {
|
|
92
92
|
console.warn('[MultiTablePostgresProvider] No tables with "embedding" columns found in the database.');
|
|
93
93
|
} else {
|
|
94
|
-
console.log(
|
|
95
|
-
|
|
96
|
-
);
|
|
94
|
+
// console.log(
|
|
95
|
+
// `[MultiTablePostgresProvider] Connected. Searching across ${this.tables.length} table(s): ${this.tables.join(', ')}`
|
|
96
|
+
// );
|
|
97
97
|
}
|
|
98
98
|
} finally {
|
|
99
99
|
client.release();
|
|
@@ -124,15 +124,15 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
124
124
|
const client = await this.pool.connect();
|
|
125
125
|
try {
|
|
126
126
|
await client.query('BEGIN');
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
for (const [fileName, fileDocs] of Object.entries(docsByFile)) {
|
|
129
129
|
// Sanitize table name (e.g., "jewelery.csv" -> "jewelery")
|
|
130
130
|
let tableName = fileName;
|
|
131
131
|
if (tableName.toLowerCase().endsWith('.csv')) {
|
|
132
|
-
|
|
132
|
+
tableName = tableName.slice(0, -4);
|
|
133
133
|
}
|
|
134
134
|
tableName = tableName.replace(/[^a-z0-9_]/gi, '_').toLowerCase() || this.uploadTable;
|
|
135
|
-
|
|
135
|
+
|
|
136
136
|
// Extract headers from the first doc's metadata
|
|
137
137
|
const firstMeta = fileDocs[0].metadata || {};
|
|
138
138
|
let csvHeaders: string[] = [];
|
|
@@ -142,7 +142,7 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
142
142
|
const systemKeys = ['fileName', 'fileSize', 'fileType', 'uploadedAt', 'dimension', 'chunkIndex', 'id', 'namespace', 'content', 'metadata', 'embedding', 'docId', 'docid', 'chunkId', 'chunkid', 'csvHeaders', 'csvheaders'];
|
|
143
143
|
csvHeaders = Object.keys(firstMeta).filter(k => !systemKeys.includes(k) && !systemKeys.includes(k.toLowerCase()));
|
|
144
144
|
}
|
|
145
|
-
|
|
145
|
+
|
|
146
146
|
// 1. Create Table Dynamically
|
|
147
147
|
const columnDefs = csvHeaders.map(h => `"${h}" TEXT`).join(',\n ');
|
|
148
148
|
const createTableSql = `
|
|
@@ -156,7 +156,7 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
156
156
|
)
|
|
157
157
|
`;
|
|
158
158
|
await client.query(createTableSql);
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
// Create Index
|
|
161
161
|
await client.query(`
|
|
162
162
|
CREATE INDEX IF NOT EXISTS "${tableName}_embedding_idx"
|
|
@@ -168,32 +168,32 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
168
168
|
ON "${tableName}"
|
|
169
169
|
USING gin (to_tsvector('english', content))
|
|
170
170
|
`);
|
|
171
|
-
|
|
171
|
+
|
|
172
172
|
// Ensure this new table is added to our search scope
|
|
173
173
|
if (!this.tables.includes(tableName)) {
|
|
174
174
|
this.tables.push(tableName);
|
|
175
175
|
}
|
|
176
|
-
|
|
176
|
+
|
|
177
177
|
// 2. Insert Data
|
|
178
178
|
const BATCH_SIZE = 50;
|
|
179
179
|
for (let i = 0; i < fileDocs.length; i += BATCH_SIZE) {
|
|
180
180
|
const batch = fileDocs.slice(i, i + BATCH_SIZE);
|
|
181
181
|
const values: unknown[] = [];
|
|
182
|
-
|
|
182
|
+
|
|
183
183
|
const headerColumns = csvHeaders.map(h => `"${h}"`).join(', ');
|
|
184
184
|
const allColumns = `id, ${headerColumns ? headerColumns + ', ' : ''}namespace, content, metadata, embedding`;
|
|
185
|
-
|
|
185
|
+
|
|
186
186
|
const valuePlaceholders = batch.map((doc, idx) => {
|
|
187
187
|
const offset = idx * (5 + csvHeaders.length);
|
|
188
|
-
|
|
188
|
+
|
|
189
189
|
values.push(doc.id);
|
|
190
190
|
// Push header values
|
|
191
191
|
for (const h of csvHeaders) {
|
|
192
192
|
values.push(String(doc.metadata?.[h] || ''));
|
|
193
193
|
}
|
|
194
|
-
|
|
194
|
+
|
|
195
195
|
values.push(namespace, doc.content, JSON.stringify(doc.metadata ?? {}), `[${doc.vector.join(',')}]`);
|
|
196
|
-
|
|
196
|
+
|
|
197
197
|
const docPlaceholders = [];
|
|
198
198
|
for (let j = 1; j <= 5 + csvHeaders.length; j++) {
|
|
199
199
|
if (j === 5 + csvHeaders.length) {
|
|
@@ -202,12 +202,12 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
202
202
|
docPlaceholders.push(`$${offset + j}`);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
|
-
|
|
205
|
+
|
|
206
206
|
return `(${docPlaceholders.join(', ')})`;
|
|
207
207
|
}).join(', ');
|
|
208
|
-
|
|
208
|
+
|
|
209
209
|
const conflictUpdates = csvHeaders.map(h => `"${h}" = EXCLUDED."${h}"`).join(',\n ');
|
|
210
|
-
|
|
210
|
+
|
|
211
211
|
const query = `
|
|
212
212
|
INSERT INTO "${tableName}" (${allColumns})
|
|
213
213
|
VALUES ${valuePlaceholders}
|
|
@@ -218,11 +218,11 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
218
218
|
metadata = EXCLUDED.metadata,
|
|
219
219
|
embedding = EXCLUDED.embedding
|
|
220
220
|
`;
|
|
221
|
-
|
|
221
|
+
|
|
222
222
|
await client.query(query, values);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
|
|
225
|
+
|
|
226
226
|
await client.query('COMMIT');
|
|
227
227
|
} catch (error) {
|
|
228
228
|
await client.query('ROLLBACK');
|
|
@@ -248,7 +248,7 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
248
248
|
const vectorLiteral = `[${vector.join(',')}]`;
|
|
249
249
|
const allResults: VectorMatch[] = [];
|
|
250
250
|
|
|
251
|
-
console.log(`[MultiTablePostgresProvider] --- Starting Multi-Table Search ---`);
|
|
251
|
+
//console.log(`[MultiTablePostgresProvider] --- Starting Multi-Table Search ---`);
|
|
252
252
|
|
|
253
253
|
const queryText = _filter?.queryText as string | undefined;
|
|
254
254
|
const entityHints = Array.isArray(_filter?.keywords)
|
|
@@ -257,8 +257,8 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
257
257
|
.filter(Boolean)
|
|
258
258
|
: [];
|
|
259
259
|
|
|
260
|
-
console.log(`[MultiTablePostgresProvider] queryText: "${queryText}"`);
|
|
261
|
-
console.log(`[MultiTablePostgresProvider] entityHints: [${entityHints.join(', ')}]`);
|
|
260
|
+
//console.log(`[MultiTablePostgresProvider] queryText: "${queryText}"`);
|
|
261
|
+
//console.log(`[MultiTablePostgresProvider] entityHints: [${entityHints.join(', ')}]`);
|
|
262
262
|
|
|
263
263
|
// Dynamic Keyword Search: Prioritize intelligently extracted hints over raw text
|
|
264
264
|
const getDynamicKeywordQuery = () => {
|
|
@@ -377,9 +377,9 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
377
377
|
const result = await this.pool.query(sqlQuery, params);
|
|
378
378
|
|
|
379
379
|
if (result.rowCount && result.rowCount > 0) {
|
|
380
|
-
console.log(` ✅ Table "${table}": Found ${result.rowCount} potential matches. Top score: ${result.rows[0].hybrid_score.toFixed(4)}`);
|
|
380
|
+
//console.log(` ✅ Table "${table}": Found ${result.rowCount} potential matches. Top score: ${result.rows[0].hybrid_score.toFixed(4)}`);
|
|
381
381
|
} else {
|
|
382
|
-
console.log(` ⚪ Table "${table}": No relevant matches found.`);
|
|
382
|
+
//console.log(` ⚪ Table "${table}": No relevant matches found.`);
|
|
383
383
|
}
|
|
384
384
|
|
|
385
385
|
const tableResults: VectorMatch[] = [];
|
|
@@ -425,22 +425,22 @@ export class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
425
425
|
|
|
426
426
|
// 2. Identify the "Active Table Context" from the absolute highest scoring match
|
|
427
427
|
const bestMatchTable = allResults[0].metadata?.source_table as string;
|
|
428
|
-
|
|
428
|
+
|
|
429
429
|
// 3. Filter out all results that don't belong to the active table to prevent cross-contamination
|
|
430
430
|
const finalSorted = allResults.filter(res => res.metadata?.source_table === bestMatchTable);
|
|
431
431
|
|
|
432
|
-
console.log(`[MultiTablePostgresProvider] --- Search Complete ---`);
|
|
433
|
-
console.log(`[MultiTablePostgresProvider] Final top match from "${bestMatchTable}" with score ${finalSorted[0].score.toFixed(4)}`);
|
|
434
|
-
console.log(`[MultiTablePostgresProvider] Restricting recommendations strictly to table: "${bestMatchTable}"`);
|
|
432
|
+
//console.log(`[MultiTablePostgresProvider] --- Search Complete ---`);
|
|
433
|
+
//console.log(`[MultiTablePostgresProvider] Final top match from "${bestMatchTable}" with score ${finalSorted[0].score.toFixed(4)}`);
|
|
434
|
+
//console.log(`[MultiTablePostgresProvider] Restricting recommendations strictly to table: "${bestMatchTable}"`);
|
|
435
435
|
|
|
436
436
|
return finalSorted.slice(0, Math.max(topK, 15));
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
-
|
|
439
|
+
async delete(_id: string | number, _namespace?: string): Promise<void> {
|
|
440
440
|
console.warn('[MultiTablePostgresProvider] delete() is a no-op for multi-table mode.');
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
-
|
|
443
|
+
async deleteNamespace(_namespace: string): Promise<void> {
|
|
444
444
|
console.warn('[MultiTablePostgresProvider] deleteNamespace() is a no-op for multi-table mode.');
|
|
445
445
|
}
|
|
446
446
|
|
|
@@ -37,22 +37,22 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
37
37
|
|
|
38
38
|
async initialize(): Promise<void> {
|
|
39
39
|
if (this.schemaDiscovered) return;
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
await this.ping();
|
|
42
42
|
await this.ensureCollection();
|
|
43
43
|
|
|
44
44
|
// 1. Discover schema from existing data
|
|
45
|
-
console.log(`[QdrantProvider] 🔍 Discovering schema for collection "${this.indexName}"...`);
|
|
45
|
+
//console.log(`[QdrantProvider] 🔍 Discovering schema for collection "${this.indexName}"...`);
|
|
46
46
|
const discoveredFields = await this.discoverSchema();
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
// 2. Add client-provided fields (if any) as fallback/override
|
|
49
49
|
const opts = this.config.options as Record<string, unknown>;
|
|
50
50
|
const configFields = (opts.filterableFields as string[]) || [];
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
const allFields = [...new Set([...discoveredFields, ...configFields])];
|
|
53
53
|
|
|
54
54
|
if (allFields.length > 0) {
|
|
55
|
-
console.log(`[QdrantProvider] 🛠 Ensuring indexes for ${allFields.length} discovered fields...`);
|
|
55
|
+
//console.log(`[QdrantProvider] 🛠 Ensuring indexes for ${allFields.length} discovered fields...`);
|
|
56
56
|
// Parallelize index creation for much faster startup
|
|
57
57
|
await Promise.all(
|
|
58
58
|
allFields.map(async (fieldInfo) => {
|
|
@@ -61,7 +61,7 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
61
61
|
})
|
|
62
62
|
);
|
|
63
63
|
} else {
|
|
64
|
-
console.log(`[QdrantProvider] ℹ️ No fields discovered for indexing.`);
|
|
64
|
+
//console.log(`[QdrantProvider] ℹ️ No fields discovered for indexing.`);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
this.schemaDiscovered = true;
|
|
@@ -84,7 +84,7 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
84
84
|
|
|
85
85
|
for (const point of points) {
|
|
86
86
|
const payload = point.payload || {};
|
|
87
|
-
|
|
87
|
+
|
|
88
88
|
// Extract root keys
|
|
89
89
|
Object.keys(payload).forEach(k => {
|
|
90
90
|
if (k !== 'namespace' && k !== this.contentField && k !== this.metadataField) {
|
|
@@ -114,20 +114,20 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
114
114
|
private async ensureCollection(): Promise<void> {
|
|
115
115
|
try {
|
|
116
116
|
await this.http.get(`/collections/${this.indexName}`);
|
|
117
|
-
console.log(`[QdrantProvider] ✅ Collection "${this.indexName}" already exists.`);
|
|
117
|
+
//console.log(`[QdrantProvider] ✅ Collection "${this.indexName}" already exists.`);
|
|
118
118
|
} catch (err) {
|
|
119
119
|
if (axios.isAxiosError(err) && err.response?.status === 404) {
|
|
120
120
|
const opts = this.config.options as Record<string, unknown>;
|
|
121
121
|
const dimensionsForCreate = (opts.dimensions as number) || 1536;
|
|
122
122
|
|
|
123
|
-
console.log(`[QdrantProvider] ⏳ Creating collection "${this.indexName}" (dimensions: ${dimensionsForCreate})...`);
|
|
123
|
+
//console.log(`[QdrantProvider] ⏳ Creating collection "${this.indexName}" (dimensions: ${dimensionsForCreate})...`);
|
|
124
124
|
await this.http.put(`/collections/${this.indexName}`, {
|
|
125
125
|
vectors: {
|
|
126
126
|
size: dimensionsForCreate,
|
|
127
127
|
distance: 'Cosine',
|
|
128
128
|
},
|
|
129
129
|
});
|
|
130
|
-
console.log(`[QdrantProvider] ✅ Created collection "${this.indexName}"`);
|
|
130
|
+
//console.log(`[QdrantProvider] ✅ Created collection "${this.indexName}"`);
|
|
131
131
|
} else {
|
|
132
132
|
throw err;
|
|
133
133
|
}
|
|
@@ -148,7 +148,7 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
148
148
|
field_name: fullPath,
|
|
149
149
|
field_schema: schema,
|
|
150
150
|
});
|
|
151
|
-
console.log(`[QdrantProvider] ✅ Ensured ${schema} index for "${fullPath}"`);
|
|
151
|
+
//console.log(`[QdrantProvider] ✅ Ensured ${schema} index for "${fullPath}"`);
|
|
152
152
|
} catch (err) {
|
|
153
153
|
let status: number | undefined;
|
|
154
154
|
if (axios.isAxiosError(err)) status = err.response?.status;
|
|
@@ -187,7 +187,7 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
187
187
|
|
|
188
188
|
async query(vector: number[], topK: number, namespace?: string, _filter?: Record<string, unknown>): Promise<VectorMatch[]> {
|
|
189
189
|
const must: Record<string, unknown>[] = [];
|
|
190
|
-
|
|
190
|
+
|
|
191
191
|
if (namespace) {
|
|
192
192
|
must.push({ key: 'namespace', match: { value: namespace } });
|
|
193
193
|
}
|
|
@@ -198,7 +198,7 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
198
198
|
if (!this.isFlatPayload && !key.includes('.') && key !== 'namespace' && key !== this.contentField) {
|
|
199
199
|
filterKey = `${this.metadataField}.${key}`;
|
|
200
200
|
}
|
|
201
|
-
|
|
201
|
+
|
|
202
202
|
if (Array.isArray(value)) {
|
|
203
203
|
must.push({ key: filterKey, match: { any: value } });
|
|
204
204
|
} else {
|
|
@@ -218,16 +218,16 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
218
218
|
};
|
|
219
219
|
|
|
220
220
|
const { data } = await this.http.post(`/collections/${this.indexName}/points/search`, payload);
|
|
221
|
-
|
|
221
|
+
|
|
222
222
|
const results = (data.result || []).map((res: Record<string, unknown>) => {
|
|
223
223
|
const p = (res.payload as Record<string, unknown>) || {};
|
|
224
224
|
let content = p[this.contentField] || '';
|
|
225
|
-
|
|
225
|
+
|
|
226
226
|
if (!content) {
|
|
227
227
|
const stringFields = Object.entries(p)
|
|
228
228
|
.filter(([, v]) => typeof v === 'string')
|
|
229
229
|
.map(([k, v]) => ({ key: k, val: v as string }));
|
|
230
|
-
|
|
230
|
+
|
|
231
231
|
if (stringFields.length > 0) {
|
|
232
232
|
const bestMatch = stringFields.sort((a, b) => b.val.length - a.val.length)[0];
|
|
233
233
|
content = bestMatch.val;
|
|
@@ -287,7 +287,7 @@ export class QdrantProvider extends BaseVectorProvider {
|
|
|
287
287
|
return `${hash.slice(0, 8)}-${hash.slice(8, 12)}-${hash.slice(12, 16)}-${hash.slice(16, 20)}-${hash.slice(20, 32)}`;
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
-
async disconnect(): Promise<void> {}
|
|
290
|
+
async disconnect(): Promise<void> { }
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
|
|
@@ -22,37 +22,37 @@ export interface TelemetryEvent {
|
|
|
22
22
|
eventType: EventType;
|
|
23
23
|
projectId: string;
|
|
24
24
|
timestamp: number;
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
// Operation details
|
|
27
27
|
operationId?: string; // Unique ID for correlating related events
|
|
28
28
|
durationMs?: number;
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
// LLM-specific
|
|
31
31
|
model?: string;
|
|
32
32
|
inputTokens?: number;
|
|
33
33
|
outputTokens?: number;
|
|
34
34
|
totalTokens?: number;
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
// Embedding-specific
|
|
37
37
|
embeddingModel?: string;
|
|
38
38
|
vectorDimensions?: number;
|
|
39
39
|
textLength?: number;
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
// Document ingestion
|
|
42
42
|
documentId?: string;
|
|
43
43
|
documentName?: string;
|
|
44
44
|
documentSize?: number;
|
|
45
45
|
chunksGenerated?: number;
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
// Query
|
|
48
48
|
queryText?: string;
|
|
49
49
|
resultCount?: number;
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
// Error tracking
|
|
52
52
|
errorCode?: string;
|
|
53
53
|
errorMessage?: string;
|
|
54
54
|
stackTrace?: string;
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
// Custom metadata
|
|
57
57
|
metadata?: Record<string, unknown>;
|
|
58
58
|
}
|
|
@@ -63,7 +63,7 @@ export interface TelemetryEvent {
|
|
|
63
63
|
export class TelemetryService {
|
|
64
64
|
private static readonly RETRIVORA_TELEMETRY_URL = 'https://www.retrivora.com/api/telemetry';
|
|
65
65
|
private static readonly USER_TELEMETRY_URL_ENV_KEY = 'TELEMETRY_URL';
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
private http: AxiosInstance;
|
|
68
68
|
private projectId: string;
|
|
69
69
|
private licenseKey: string;
|
|
@@ -219,7 +219,7 @@ export class TelemetryService {
|
|
|
219
219
|
if (this.eventQueue.length === 0) return;
|
|
220
220
|
|
|
221
221
|
const events = this.eventQueue.splice(0, this.batchSize);
|
|
222
|
-
|
|
222
|
+
|
|
223
223
|
// Create payload without license key (send only in headers)
|
|
224
224
|
const payload = {
|
|
225
225
|
events: events.map(e => {
|
|
@@ -232,7 +232,7 @@ export class TelemetryService {
|
|
|
232
232
|
// Send to Retrivora admin dashboard
|
|
233
233
|
try {
|
|
234
234
|
await this.http.post(TelemetryService.RETRIVORA_TELEMETRY_URL, payload);
|
|
235
|
-
console.log(`[TelemetryService] Flushed ${events.length} events to Retrivora`);
|
|
235
|
+
//console.log(`[TelemetryService] Flushed ${events.length} events to Retrivora`);
|
|
236
236
|
} catch (err: any) {
|
|
237
237
|
console.warn('[TelemetryService] Failed to send telemetry to Retrivora:', err.message);
|
|
238
238
|
// Re-queue events if send fails
|
|
@@ -249,7 +249,7 @@ export class TelemetryService {
|
|
|
249
249
|
'X-Project-ID': this.projectId,
|
|
250
250
|
},
|
|
251
251
|
});
|
|
252
|
-
console.log(`[TelemetryService] Flushed ${events.length} events to user telemetry`);
|
|
252
|
+
//console.log(`[TelemetryService] Flushed ${events.length} events to user telemetry`);
|
|
253
253
|
} catch (err: any) {
|
|
254
254
|
console.warn('[TelemetryService] Failed to send telemetry to user endpoint:', err.message);
|
|
255
255
|
}
|
|
@@ -315,7 +315,7 @@ export function getTelemetryService(): TelemetryService | null {
|
|
|
315
315
|
*/
|
|
316
316
|
export function initializeTelemetryService(projectId: string, licenseKey: string, userTelemetryUrl?: string): TelemetryService {
|
|
317
317
|
globalTelemetryService = new TelemetryService(projectId, licenseKey, userTelemetryUrl);
|
|
318
|
-
console.log('[TelemetryService] Initialized for project:', projectId);
|
|
318
|
+
//console.log('[TelemetryService] Initialized for project:', projectId);
|
|
319
319
|
return globalTelemetryService;
|
|
320
320
|
}
|
|
321
321
|
|
package/src/types/props.ts
CHANGED
|
@@ -66,6 +66,10 @@ export interface ChatWindowProps {
|
|
|
66
66
|
licenseKey?: string;
|
|
67
67
|
/** Optional custom headers to send with the chat request */
|
|
68
68
|
headers?: Record<string, string>;
|
|
69
|
+
/** Optional session ID to load conversation history from the server */
|
|
70
|
+
sessionId?: string;
|
|
71
|
+
/** Whether to show the ChatGPT-style sidebar history management and new chat controls */
|
|
72
|
+
showHistory?: boolean;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
export interface ChatWidgetProps {
|
|
@@ -153,6 +157,13 @@ export interface ConfigProviderProps {
|
|
|
153
157
|
retrivoraApiBase?: string;
|
|
154
158
|
projectSettings?: Partial<ProjectChatSettings>;
|
|
155
159
|
autoLoadProjectSettings?: boolean;
|
|
160
|
+
// Root-level flat mappings for developer convenience
|
|
161
|
+
primaryColor?: string;
|
|
162
|
+
secondaryColor?: string;
|
|
163
|
+
accentColor?: string;
|
|
164
|
+
theme?: 'light' | 'dark' | 'system';
|
|
165
|
+
borderRadius?: 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
166
|
+
visualStyle?: 'solid' | 'glass';
|
|
156
167
|
};
|
|
157
168
|
children: ReactNode;
|
|
158
169
|
}
|
|
@@ -68,7 +68,7 @@ export class SchemaMapper {
|
|
|
68
68
|
cacheKey: string,
|
|
69
69
|
keys: string[]
|
|
70
70
|
): Promise<SchemaMap> {
|
|
71
|
-
console.log(`[SchemaMapper] 🧠 Training on new schema keys: ${keys.join(', ')}`);
|
|
71
|
+
//console.log(`[SchemaMapper] 🧠 Training on new schema keys: ${keys.join(', ')}`);
|
|
72
72
|
|
|
73
73
|
const propertyList = Object.entries(this.TARGET_PROPERTIES)
|
|
74
74
|
.map(([prop, desc]) => `- ${prop} (${desc})`)
|
|
@@ -128,7 +128,7 @@ export class UITransformer {
|
|
|
128
128
|
return this.createTextResponse('No data available', 'No relevant data found for your query.');
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
// console.log('[UITransformer.transform] Processing retrievedData:', {
|
|
131
|
+
// //console.log('[UITransformer.transform] Processing retrievedData:', {
|
|
132
132
|
// userQuery,
|
|
133
133
|
// retrievedCount: retrievedData.length,
|
|
134
134
|
// sample: retrievedData.slice(0, 2).map((item) => ({
|