@retrivora-ai/rag-engine 1.4.8 → 1.5.0

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.
@@ -2257,22 +2257,25 @@ var Pipeline = class {
2257
2257
  this.reranker = new Reranker();
2258
2258
  }
2259
2259
  async initialize() {
2260
- var _a;
2260
+ var _a, _b;
2261
2261
  if (this.initialised) return;
2262
+ const CHART_MARKER = "<!-- VIZ_PROTOCOL_V1 -->";
2262
2263
  const chartInstruction = `
2263
2264
 
2264
- ### VISUALIZATION PROTOCOL:
2265
- When requested to show data visually (charts, graphs, or comparisons), you MUST use this format:
2266
- 1. Wrap the data in a fenced code block with the language 'chart'.
2267
- 2. Use ONLY valid JSON matching this schema:
2268
- {
2269
- "type": "bar" | "line" | "pie",
2270
- "xAxisKey": "property_for_label",
2271
- "dataKeys": ["property_for_value"],
2272
- "data": [{ "property_for_label": "A", "property_for_value": 10 }]
2273
- }
2274
- 3. RULES: Data objects MUST be FLAT (no nesting). No math expressions in JSON. NEVER draw charts with text or markdown tables.`;
2275
- if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes("chart")) {
2265
+ ${CHART_MARKER}
2266
+ ### MANDATORY CHART PROTOCOL:
2267
+ If asked for a chart (pie, bar, line), you MUST output exactly ONE block using this structure:
2268
+ \`\`\`chart
2269
+ {
2270
+ "type": "pie",
2271
+ "data": [ { "label": "Item A", "value": 10 }, { "label": "Item B", "value": 20 } ]
2272
+ }
2273
+ \`\`\`
2274
+ - RULES:
2275
+ 1. You MUST include the \`\`\`chart and \`\`\` markers. Naked JSON will NOT render.
2276
+ 2. Output ONLY the chart block. No Python snippets. No "here is the data" text.
2277
+ 3. Data objects MUST be FLAT. No math (e.g. use 10, NOT 5+5).`;
2278
+ if (!((_a = this.config.llm.systemPrompt) == null ? void 0 : _a.includes(CHART_MARKER))) {
2276
2279
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
2277
2280
  }
2278
2281
  console.log(`[Pipeline] Initializing with provider: ${this.config.vectorDb.provider}...`);
@@ -2289,7 +2292,7 @@ When requested to show data visually (charts, graphs, or comparisons), you MUST
2289
2292
  this.entityExtractor = new EntityExtractor(this.llmProvider);
2290
2293
  }
2291
2294
  await this.vectorDB.initialize();
2292
- if (((_a = this.config.rag) == null ? void 0 : _a.architecture) === "agentic") {
2295
+ if (((_b = this.config.rag) == null ? void 0 : _b.architecture) === "agentic") {
2293
2296
  this.agent = new LangChainAgent(this, this.config);
2294
2297
  await this.agent.initialize(this.llmProvider);
2295
2298
  }
@@ -3820,22 +3820,25 @@ var Pipeline = class {
3820
3820
  this.reranker = new Reranker();
3821
3821
  }
3822
3822
  async initialize() {
3823
- var _a;
3823
+ var _a, _b;
3824
3824
  if (this.initialised) return;
3825
+ const CHART_MARKER = "<!-- VIZ_PROTOCOL_V1 -->";
3825
3826
  const chartInstruction = `
3826
3827
 
3827
- ### VISUALIZATION PROTOCOL:
3828
- When requested to show data visually (charts, graphs, or comparisons), you MUST use this format:
3829
- 1. Wrap the data in a fenced code block with the language 'chart'.
3830
- 2. Use ONLY valid JSON matching this schema:
3831
- {
3832
- "type": "bar" | "line" | "pie",
3833
- "xAxisKey": "property_for_label",
3834
- "dataKeys": ["property_for_value"],
3835
- "data": [{ "property_for_label": "A", "property_for_value": 10 }]
3836
- }
3837
- 3. RULES: Data objects MUST be FLAT (no nesting). No math expressions in JSON. NEVER draw charts with text or markdown tables.`;
3838
- if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes("chart")) {
3828
+ ${CHART_MARKER}
3829
+ ### MANDATORY CHART PROTOCOL:
3830
+ If asked for a chart (pie, bar, line), you MUST output exactly ONE block using this structure:
3831
+ \`\`\`chart
3832
+ {
3833
+ "type": "pie",
3834
+ "data": [ { "label": "Item A", "value": 10 }, { "label": "Item B", "value": 20 } ]
3835
+ }
3836
+ \`\`\`
3837
+ - RULES:
3838
+ 1. You MUST include the \`\`\`chart and \`\`\` markers. Naked JSON will NOT render.
3839
+ 2. Output ONLY the chart block. No Python snippets. No "here is the data" text.
3840
+ 3. Data objects MUST be FLAT. No math (e.g. use 10, NOT 5+5).`;
3841
+ if (!((_a = this.config.llm.systemPrompt) == null ? void 0 : _a.includes(CHART_MARKER))) {
3839
3842
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
3840
3843
  }
3841
3844
  console.log(`[Pipeline] Initializing with provider: ${this.config.vectorDb.provider}...`);
@@ -3852,7 +3855,7 @@ When requested to show data visually (charts, graphs, or comparisons), you MUST
3852
3855
  this.entityExtractor = new EntityExtractor(this.llmProvider);
3853
3856
  }
3854
3857
  await this.vectorDB.initialize();
3855
- if (((_a = this.config.rag) == null ? void 0 : _a.architecture) === "agentic") {
3858
+ if (((_b = this.config.rag) == null ? void 0 : _b.architecture) === "agentic") {
3856
3859
  this.agent = new LangChainAgent(this, this.config);
3857
3860
  await this.agent.initialize(this.llmProvider);
3858
3861
  }
@@ -9,7 +9,7 @@ import {
9
9
  sseFrame,
10
10
  sseMetaFrame,
11
11
  sseTextFrame
12
- } from "../chunk-YCL23GST.mjs";
12
+ } from "../chunk-YTL3SLQU.mjs";
13
13
  import "../chunk-YLTMFW4M.mjs";
14
14
  import "../chunk-X4TOT24V.mjs";
15
15
  export {
package/dist/index.js CHANGED
@@ -503,9 +503,13 @@ function MessageBubble({
503
503
  };
504
504
  });
505
505
  }, [sources, isUser]);
506
+ const isVisualizationRequested = import_react5.default.useMemo(() => {
507
+ if (isUser) return false;
508
+ const text = message.content.toLowerCase();
509
+ return message.content.includes("```chart") || text.includes("pie chart") || text.includes("bar chart") || text.includes("line chart") || text.includes("distribution across");
510
+ }, [message.content, isUser]);
506
511
  const { productsFromContent, cleanContent } = import_react5.default.useMemo(() => {
507
- if (isUser) return { productsFromContent: [], cleanContent: message.content };
508
- if (message.content.includes("```chart")) {
512
+ if (isUser || isVisualizationRequested) {
509
513
  return { productsFromContent: [], cleanContent: message.content };
510
514
  }
511
515
  const jsonRegex = /```json\s*([\s\S]*?)\s*```/g;
@@ -531,7 +535,7 @@ function MessageBubble({
531
535
  }
532
536
  }
533
537
  return { productsFromContent: products, cleanContent: content.trim() };
534
- }, [message.content, isUser]);
538
+ }, [message.content, isUser, isVisualizationRequested]);
535
539
  const allProducts = import_react5.default.useMemo(() => {
536
540
  if (productsFromContent.length > 0) return productsFromContent;
537
541
  const seen = /* @__PURE__ */ new Set();
package/dist/index.mjs CHANGED
@@ -466,9 +466,13 @@ function MessageBubble({
466
466
  };
467
467
  });
468
468
  }, [sources, isUser]);
469
+ const isVisualizationRequested = React5.useMemo(() => {
470
+ if (isUser) return false;
471
+ const text = message.content.toLowerCase();
472
+ return message.content.includes("```chart") || text.includes("pie chart") || text.includes("bar chart") || text.includes("line chart") || text.includes("distribution across");
473
+ }, [message.content, isUser]);
469
474
  const { productsFromContent, cleanContent } = React5.useMemo(() => {
470
- if (isUser) return { productsFromContent: [], cleanContent: message.content };
471
- if (message.content.includes("```chart")) {
475
+ if (isUser || isVisualizationRequested) {
472
476
  return { productsFromContent: [], cleanContent: message.content };
473
477
  }
474
478
  const jsonRegex = /```json\s*([\s\S]*?)\s*```/g;
@@ -494,7 +498,7 @@ function MessageBubble({
494
498
  }
495
499
  }
496
500
  return { productsFromContent: products, cleanContent: content.trim() };
497
- }, [message.content, isUser]);
501
+ }, [message.content, isUser, isVisualizationRequested]);
498
502
  const allProducts = React5.useMemo(() => {
499
503
  if (productsFromContent.length > 0) return productsFromContent;
500
504
  const seen = /* @__PURE__ */ new Set();
package/dist/server.js CHANGED
@@ -3911,22 +3911,25 @@ var Pipeline = class {
3911
3911
  this.reranker = new Reranker();
3912
3912
  }
3913
3913
  async initialize() {
3914
- var _a;
3914
+ var _a, _b;
3915
3915
  if (this.initialised) return;
3916
+ const CHART_MARKER = "<!-- VIZ_PROTOCOL_V1 -->";
3916
3917
  const chartInstruction = `
3917
3918
 
3918
- ### VISUALIZATION PROTOCOL:
3919
- When requested to show data visually (charts, graphs, or comparisons), you MUST use this format:
3920
- 1. Wrap the data in a fenced code block with the language 'chart'.
3921
- 2. Use ONLY valid JSON matching this schema:
3922
- {
3923
- "type": "bar" | "line" | "pie",
3924
- "xAxisKey": "property_for_label",
3925
- "dataKeys": ["property_for_value"],
3926
- "data": [{ "property_for_label": "A", "property_for_value": 10 }]
3927
- }
3928
- 3. RULES: Data objects MUST be FLAT (no nesting). No math expressions in JSON. NEVER draw charts with text or markdown tables.`;
3929
- if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes("chart")) {
3919
+ ${CHART_MARKER}
3920
+ ### MANDATORY CHART PROTOCOL:
3921
+ If asked for a chart (pie, bar, line), you MUST output exactly ONE block using this structure:
3922
+ \`\`\`chart
3923
+ {
3924
+ "type": "pie",
3925
+ "data": [ { "label": "Item A", "value": 10 }, { "label": "Item B", "value": 20 } ]
3926
+ }
3927
+ \`\`\`
3928
+ - RULES:
3929
+ 1. You MUST include the \`\`\`chart and \`\`\` markers. Naked JSON will NOT render.
3930
+ 2. Output ONLY the chart block. No Python snippets. No "here is the data" text.
3931
+ 3. Data objects MUST be FLAT. No math (e.g. use 10, NOT 5+5).`;
3932
+ if (!((_a = this.config.llm.systemPrompt) == null ? void 0 : _a.includes(CHART_MARKER))) {
3930
3933
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || "") + chartInstruction;
3931
3934
  }
3932
3935
  console.log(`[Pipeline] Initializing with provider: ${this.config.vectorDb.provider}...`);
@@ -3943,7 +3946,7 @@ When requested to show data visually (charts, graphs, or comparisons), you MUST
3943
3946
  this.entityExtractor = new EntityExtractor(this.llmProvider);
3944
3947
  }
3945
3948
  await this.vectorDB.initialize();
3946
- if (((_a = this.config.rag) == null ? void 0 : _a.architecture) === "agentic") {
3949
+ if (((_b = this.config.rag) == null ? void 0 : _b.architecture) === "agentic") {
3947
3950
  this.agent = new LangChainAgent(this, this.config);
3948
3951
  await this.agent.initialize(this.llmProvider);
3949
3952
  }
package/dist/server.mjs CHANGED
@@ -39,7 +39,7 @@ import {
39
39
  sseFrame,
40
40
  sseMetaFrame,
41
41
  sseTextFrame
42
- } from "./chunk-YCL23GST.mjs";
42
+ } from "./chunk-YTL3SLQU.mjs";
43
43
  import "./chunk-YLTMFW4M.mjs";
44
44
  import {
45
45
  PineconeProvider
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "1.4.8",
3
+ "version": "1.5.0",
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",
@@ -309,12 +309,23 @@ export function MessageBubble({
309
309
  });
310
310
  }, [sources, isUser]);
311
311
 
312
+ // ── Visualization Intent Detection ────────────────────────────────────────
313
+ // Robust detection to prevent UI clutter and ensure atomic rendering.
314
+ const isVisualizationRequested = React.useMemo(() => {
315
+ if (isUser) return false;
316
+ const text = message.content.toLowerCase();
317
+ return (
318
+ message.content.includes('```chart') ||
319
+ text.includes('pie chart') ||
320
+ text.includes('bar chart') ||
321
+ text.includes('line chart') ||
322
+ text.includes('distribution across')
323
+ );
324
+ }, [message.content, isUser]);
325
+
312
326
  // ── Products + cleaned content from structured JSON blocks in the message ──
313
327
  const { productsFromContent, cleanContent } = React.useMemo(() => {
314
- if (isUser) return { productsFromContent: [] as Product[], cleanContent: message.content };
315
-
316
- // If the message contains a chart, suppress the product carousel to keep focus on visualization
317
- if (message.content.includes('```chart')) {
328
+ if (isUser || isVisualizationRequested) {
318
329
  return { productsFromContent: [] as Product[], cleanContent: message.content };
319
330
  }
320
331
 
@@ -342,7 +353,7 @@ export function MessageBubble({
342
353
  }
343
354
 
344
355
  return { productsFromContent: products, cleanContent: content.trim() };
345
- }, [message.content, isUser]);
356
+ }, [message.content, isUser, isVisualizationRequested]);
346
357
 
347
358
  // ── Merge & deduplicate products ───────────────────────────────────────────
348
359
  const allProducts = React.useMemo<Product[]>(() => {
@@ -100,20 +100,23 @@ export class Pipeline {
100
100
  if (this.initialised) return;
101
101
 
102
102
  // Augment system prompt with a Universal Visualization Protocol
103
- const chartInstruction = `\n\n### VISUALIZATION PROTOCOL:
104
- When requested to show data visually (charts, graphs, or comparisons), you MUST use this format:
105
- 1. Wrap the data in a fenced code block with the language 'chart'.
106
- 2. Use ONLY valid JSON matching this schema:
107
- {
108
- "type": "bar" | "line" | "pie",
109
- "xAxisKey": "property_for_label",
110
- "dataKeys": ["property_for_value"],
111
- "data": [{ "property_for_label": "A", "property_for_value": 10 }]
112
- }
113
- 3. RULES: Data objects MUST be FLAT (no nesting). No math expressions in JSON. NEVER draw charts with text or markdown tables.`;
114
-
115
- // Inject chart instructions if not already present (including when systemPrompt is undefined)
116
- if (!this.config.llm.systemPrompt || !this.config.llm.systemPrompt.includes('chart')) {
103
+ // We use a unique marker to ensure this is only injected once but is ALWAYS present.
104
+ const CHART_MARKER = '<!-- VIZ_PROTOCOL_V1 -->';
105
+ const chartInstruction = `\n\n${CHART_MARKER}
106
+ ### MANDATORY CHART PROTOCOL:
107
+ If asked for a chart (pie, bar, line), you MUST output exactly ONE block using this structure:
108
+ \`\`\`chart
109
+ {
110
+ "type": "pie",
111
+ "data": [ { "label": "Item A", "value": 10 }, { "label": "Item B", "value": 20 } ]
112
+ }
113
+ \`\`\`
114
+ - RULES:
115
+ 1. You MUST include the \`\`\`chart and \`\`\` markers. Naked JSON will NOT render.
116
+ 2. Output ONLY the chart block. No Python snippets. No "here is the data" text.
117
+ 3. Data objects MUST be FLAT. No math (e.g. use 10, NOT 5+5).`;
118
+
119
+ if (!this.config.llm.systemPrompt?.includes(CHART_MARKER)) {
117
120
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || '') + chartInstruction;
118
121
  }
119
122