@retrivora-ai/rag-engine 0.4.4 → 0.4.5

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MongoDBProvider
3
- } from "./chunk-IWHCAQEA.mjs";
3
+ } from "./chunk-PQKTC73Y.mjs";
4
4
  import "./chunk-IMP6FUCY.mjs";
5
5
  import "./chunk-FWCSY2DS.mjs";
6
6
  export {
@@ -77,7 +77,7 @@ var MongoDBProvider = class extends BaseVectorProvider {
77
77
  return results.map((res) => ({
78
78
  id: res._id,
79
79
  content: res[this.contentKey],
80
- metadata: res[this.metadataKey],
80
+ metadata: res[this.metadataKey] || {},
81
81
  score: res.score
82
82
  }));
83
83
  }
@@ -864,7 +864,7 @@ Output JSON:
864
864
  try {
865
865
  const cleanJson = response.replace(/```json\n?|\n?```/g, "").trim();
866
866
  return JSON.parse(cleanJson);
867
- } catch (error) {
867
+ } catch (e) {
868
868
  console.warn("[EntityExtractor] Failed to parse LLM response as JSON:", response);
869
869
  return { nodes: [], edges: [] };
870
870
  }
@@ -1443,7 +1443,7 @@ var ProviderRegistry = class {
1443
1443
  return new PostgreSQLProvider(config);
1444
1444
  }
1445
1445
  case "mongodb": {
1446
- const { MongoDBProvider } = await import("./MongoDBProvider-ZKW34AEL.mjs");
1446
+ const { MongoDBProvider } = await import("./MongoDBProvider-RE3Q5S5B.mjs");
1447
1447
  return new MongoDBProvider(config);
1448
1448
  }
1449
1449
  case "milvus": {
@@ -1998,12 +1998,28 @@ var Pipeline = class {
1998
1998
  chunksIngested: upsertResult.totalProcessed
1999
1999
  });
2000
2000
  if (this.graphDB && this.entityExtractor) {
2001
- console.log(`[Pipeline] Extracting entities for doc ${doc.docId}...`);
2002
- for (const chunk of chunks) {
2003
- const { nodes, edges } = await this.entityExtractor.extract(chunk.content);
2004
- if (nodes.length > 0) await this.graphDB.addNodes(nodes);
2005
- if (edges.length > 0) await this.graphDB.addEdges(edges);
2006
- }
2001
+ console.log(`[Pipeline] Extracting entities for doc ${doc.docId} (${chunks.length} chunks)...`);
2002
+ const extractionOptions = {
2003
+ batchSize: 2,
2004
+ // Low concurrency for LLM extraction
2005
+ maxRetries: 1,
2006
+ initialDelayMs: 500
2007
+ };
2008
+ await BatchProcessor.processBatch(
2009
+ chunks,
2010
+ async (batch) => {
2011
+ for (const chunk of batch) {
2012
+ try {
2013
+ const { nodes, edges } = await this.entityExtractor.extract(chunk.content);
2014
+ if (nodes.length > 0) await this.graphDB.addNodes(nodes);
2015
+ if (edges.length > 0) await this.graphDB.addEdges(edges);
2016
+ } catch (err) {
2017
+ console.warn(`[Pipeline] Entity extraction failed for chunk:`, err);
2018
+ }
2019
+ }
2020
+ },
2021
+ extractionOptions
2022
+ );
2007
2023
  }
2008
2024
  } catch (error) {
2009
2025
  console.error(`[Pipeline] Failed to ingest document ${doc.docId}:`, error);
@@ -2599,7 +2615,7 @@ var DocumentParser = class {
2599
2615
  }
2600
2616
  if (extension === "pdf" || mimeType === "application/pdf") {
2601
2617
  try {
2602
- const pdf = await import("pdf-parse/lib/pdf-parse.js");
2618
+ const pdf = await import("pdf-parse");
2603
2619
  const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
2604
2620
  const data = await pdf.default(buffer);
2605
2621
  return data.text;
@@ -445,7 +445,7 @@ var init_MongoDBProvider = __esm({
445
445
  return results.map((res) => ({
446
446
  id: res._id,
447
447
  content: res[this.contentKey],
448
- metadata: res[this.metadataKey],
448
+ metadata: res[this.metadataKey] || {},
449
449
  score: res.score
450
450
  }));
451
451
  }
@@ -2135,7 +2135,7 @@ Output JSON:
2135
2135
  try {
2136
2136
  const cleanJson = response.replace(/```json\n?|\n?```/g, "").trim();
2137
2137
  return JSON.parse(cleanJson);
2138
- } catch (error) {
2138
+ } catch (e) {
2139
2139
  console.warn("[EntityExtractor] Failed to parse LLM response as JSON:", response);
2140
2140
  return { nodes: [], edges: [] };
2141
2141
  }
@@ -3225,12 +3225,28 @@ var Pipeline = class {
3225
3225
  chunksIngested: upsertResult.totalProcessed
3226
3226
  });
3227
3227
  if (this.graphDB && this.entityExtractor) {
3228
- console.log(`[Pipeline] Extracting entities for doc ${doc.docId}...`);
3229
- for (const chunk of chunks) {
3230
- const { nodes, edges } = await this.entityExtractor.extract(chunk.content);
3231
- if (nodes.length > 0) await this.graphDB.addNodes(nodes);
3232
- if (edges.length > 0) await this.graphDB.addEdges(edges);
3233
- }
3228
+ console.log(`[Pipeline] Extracting entities for doc ${doc.docId} (${chunks.length} chunks)...`);
3229
+ const extractionOptions = {
3230
+ batchSize: 2,
3231
+ // Low concurrency for LLM extraction
3232
+ maxRetries: 1,
3233
+ initialDelayMs: 500
3234
+ };
3235
+ await BatchProcessor.processBatch(
3236
+ chunks,
3237
+ async (batch) => {
3238
+ for (const chunk of batch) {
3239
+ try {
3240
+ const { nodes, edges } = await this.entityExtractor.extract(chunk.content);
3241
+ if (nodes.length > 0) await this.graphDB.addNodes(nodes);
3242
+ if (edges.length > 0) await this.graphDB.addEdges(edges);
3243
+ } catch (err) {
3244
+ console.warn(`[Pipeline] Entity extraction failed for chunk:`, err);
3245
+ }
3246
+ }
3247
+ },
3248
+ extractionOptions
3249
+ );
3234
3250
  }
3235
3251
  } catch (error) {
3236
3252
  console.error(`[Pipeline] Failed to ingest document ${doc.docId}:`, error);
@@ -3826,7 +3842,7 @@ var DocumentParser = class {
3826
3842
  }
3827
3843
  if (extension === "pdf" || mimeType === "application/pdf") {
3828
3844
  try {
3829
- const pdf = await import("pdf-parse/lib/pdf-parse.js");
3845
+ const pdf = await import("pdf-parse");
3830
3846
  const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
3831
3847
  const data = await pdf.default(buffer);
3832
3848
  return data.text;
@@ -3,7 +3,7 @@ import {
3
3
  createHealthHandler,
4
4
  createIngestHandler,
5
5
  createUploadHandler
6
- } from "../chunk-OKY5P6RA.mjs";
6
+ } from "../chunk-PRC5CZIZ.mjs";
7
7
  import "../chunk-EDLTMSNY.mjs";
8
8
  import "../chunk-FWCSY2DS.mjs";
9
9
  export {
package/dist/index.d.mts CHANGED
@@ -27,7 +27,7 @@ interface DocumentUploadProps {
27
27
  /** Optional namespace for the upload */
28
28
  namespace?: string;
29
29
  /** Callback when upload completes */
30
- onUploadComplete?: (results: any) => void;
30
+ onUploadComplete?: (results: unknown) => void;
31
31
  /** Additional className */
32
32
  className?: string;
33
33
  }
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ interface DocumentUploadProps {
27
27
  /** Optional namespace for the upload */
28
28
  namespace?: string;
29
29
  /** Callback when upload completes */
30
- onUploadComplete?: (results: any) => void;
30
+ onUploadComplete?: (results: unknown) => void;
31
31
  /** Additional className */
32
32
  className?: string;
33
33
  }
package/dist/server.js CHANGED
@@ -457,7 +457,7 @@ var init_MongoDBProvider = __esm({
457
457
  return results.map((res) => ({
458
458
  id: res._id,
459
459
  content: res[this.contentKey],
460
- metadata: res[this.metadataKey],
460
+ metadata: res[this.metadataKey] || {},
461
461
  score: res.score
462
462
  }));
463
463
  }
@@ -2179,7 +2179,7 @@ Output JSON:
2179
2179
  try {
2180
2180
  const cleanJson = response.replace(/```json\n?|\n?```/g, "").trim();
2181
2181
  return JSON.parse(cleanJson);
2182
- } catch (error) {
2182
+ } catch (e) {
2183
2183
  console.warn("[EntityExtractor] Failed to parse LLM response as JSON:", response);
2184
2184
  return { nodes: [], edges: [] };
2185
2185
  }
@@ -3314,12 +3314,28 @@ var Pipeline = class {
3314
3314
  chunksIngested: upsertResult.totalProcessed
3315
3315
  });
3316
3316
  if (this.graphDB && this.entityExtractor) {
3317
- console.log(`[Pipeline] Extracting entities for doc ${doc.docId}...`);
3318
- for (const chunk of chunks) {
3319
- const { nodes, edges } = await this.entityExtractor.extract(chunk.content);
3320
- if (nodes.length > 0) await this.graphDB.addNodes(nodes);
3321
- if (edges.length > 0) await this.graphDB.addEdges(edges);
3322
- }
3317
+ console.log(`[Pipeline] Extracting entities for doc ${doc.docId} (${chunks.length} chunks)...`);
3318
+ const extractionOptions = {
3319
+ batchSize: 2,
3320
+ // Low concurrency for LLM extraction
3321
+ maxRetries: 1,
3322
+ initialDelayMs: 500
3323
+ };
3324
+ await BatchProcessor.processBatch(
3325
+ chunks,
3326
+ async (batch) => {
3327
+ for (const chunk of batch) {
3328
+ try {
3329
+ const { nodes, edges } = await this.entityExtractor.extract(chunk.content);
3330
+ if (nodes.length > 0) await this.graphDB.addNodes(nodes);
3331
+ if (edges.length > 0) await this.graphDB.addEdges(edges);
3332
+ } catch (err) {
3333
+ console.warn(`[Pipeline] Entity extraction failed for chunk:`, err);
3334
+ }
3335
+ }
3336
+ },
3337
+ extractionOptions
3338
+ );
3323
3339
  }
3324
3340
  } catch (error) {
3325
3341
  console.error(`[Pipeline] Failed to ingest document ${doc.docId}:`, error);
@@ -4188,7 +4204,7 @@ var DocumentParser = class {
4188
4204
  }
4189
4205
  if (extension === "pdf" || mimeType === "application/pdf") {
4190
4206
  try {
4191
- const pdf = await import("pdf-parse/lib/pdf-parse.js");
4207
+ const pdf = await import("pdf-parse");
4192
4208
  const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
4193
4209
  const data = await pdf.default(buffer);
4194
4210
  return data.text;
package/dist/server.mjs CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  createIngestHandler,
35
35
  createUploadHandler,
36
36
  getRagConfig
37
- } from "./chunk-OKY5P6RA.mjs";
37
+ } from "./chunk-PRC5CZIZ.mjs";
38
38
  import "./chunk-EDLTMSNY.mjs";
39
39
  import {
40
40
  PineconeProvider
@@ -44,7 +44,7 @@ import {
44
44
  } from "./chunk-LJWWPTWE.mjs";
45
45
  import {
46
46
  MongoDBProvider
47
- } from "./chunk-IWHCAQEA.mjs";
47
+ } from "./chunk-PQKTC73Y.mjs";
48
48
  import {
49
49
  MilvusProvider
50
50
  } from "./chunk-3QWAK3RZ.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "0.4.4",
3
+ "version": "0.4.5",
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": "MIT",
@@ -8,7 +8,7 @@ interface DocumentUploadProps {
8
8
  /** Optional namespace for the upload */
9
9
  namespace?: string;
10
10
  /** Callback when upload completes */
11
- onUploadComplete?: (results: any) => void;
11
+ onUploadComplete?: (results: unknown) => void;
12
12
  /** Additional className */
13
13
  className?: string;
14
14
  }
@@ -282,13 +282,31 @@ export class Pipeline {
282
282
  });
283
283
 
284
284
  // Graph ingestion
285
+ // Graph ingestion - Batched to prevent timeouts and LLM overload
285
286
  if (this.graphDB && this.entityExtractor) {
286
- console.log(`[Pipeline] Extracting entities for doc ${doc.docId}...`);
287
- for (const chunk of chunks) {
288
- const { nodes, edges } = await this.entityExtractor.extract(chunk.content);
289
- if (nodes.length > 0) await this.graphDB.addNodes(nodes);
290
- if (edges.length > 0) await this.graphDB.addEdges(edges);
291
- }
287
+ console.log(`[Pipeline] Extracting entities for doc ${doc.docId} (${chunks.length} chunks)...`);
288
+
289
+ const extractionOptions: BatchOptions = {
290
+ batchSize: 2, // Low concurrency for LLM extraction
291
+ maxRetries: 1,
292
+ initialDelayMs: 500,
293
+ };
294
+
295
+ await BatchProcessor.processBatch(
296
+ chunks,
297
+ async (batch) => {
298
+ for (const chunk of batch) {
299
+ try {
300
+ const { nodes, edges } = await this.entityExtractor!.extract(chunk.content);
301
+ if (nodes.length > 0) await this.graphDB!.addNodes(nodes);
302
+ if (edges.length > 0) await this.graphDB!.addEdges(edges);
303
+ } catch (err) {
304
+ console.warn(`[Pipeline] Entity extraction failed for chunk:`, err);
305
+ }
306
+ }
307
+ },
308
+ extractionOptions
309
+ );
292
310
  }
293
311
  } catch (error) {
294
312
  console.error(`[Pipeline] Failed to ingest document ${doc.docId}:`, error);
@@ -94,10 +94,10 @@ export class MongoDBProvider extends BaseVectorProvider {
94
94
 
95
95
  const results = await this.collection!.aggregate(pipeline).toArray();
96
96
 
97
- return results.map((res: any) => ({
97
+ return (results as unknown as Array<{ _id: string; score: number; [key: string]: unknown }>).map((res) => ({
98
98
  id: res._id,
99
- content: res[this.contentKey],
100
- metadata: res[this.metadataKey],
99
+ content: res[this.contentKey] as string,
100
+ metadata: (res[this.metadataKey] as Record<string, unknown>) || {},
101
101
  score: res.score,
102
102
  }));
103
103
  }
@@ -35,7 +35,7 @@ Output JSON:
35
35
  // Clean up LLM response (sometimes it adds markdown blocks)
36
36
  const cleanJson = response.replace(/```json\n?|\n?```/g, '').trim();
37
37
  return JSON.parse(cleanJson);
38
- } catch (error) {
38
+ } catch {
39
39
  console.warn('[EntityExtractor] Failed to parse LLM response as JSON:', response);
40
40
  return { nodes: [], edges: [] };
41
41
  }
@@ -35,7 +35,7 @@ export class DocumentParser {
35
35
  if (extension === 'pdf' || mimeType === 'application/pdf') {
36
36
  try {
37
37
  // Dynamic import to avoid errors if not installed
38
- const pdf = await import('pdf-parse/lib/pdf-parse.js');
38
+ const pdf = await import('pdf-parse');
39
39
  const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await (file as File).arrayBuffer());
40
40
  const data = await pdf.default(buffer);
41
41
  return data.text;