@retrivora-ai/rag-engine 1.4.8 → 1.4.9

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:
2265
+ ${CHART_MARKER}
2266
+ ### MASTER DATA VISUALIZATION PROTOCOL:
2267
+ You are an expert data analyst. When asked to visualize or compare data retrieved from the context:
2268
+ 1. DECIDE the best chart type: 'pie' (for parts-of-a-whole), 'bar' (for category comparisons), or 'line' (for trends).
2269
+ 2. TRANSFORM arbitrary metadata from the context into a FLAT list of objects. Extract relevant keys dynamically.
2270
+ 3. OUTPUT a \`\`\`chart\`\`\` code block using this JSON format:
2268
2271
  {
2269
2272
  "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
+ "xAxisKey": "key_for_labels",
2274
+ "dataKeys": ["key_for_values"],
2275
+ "data": [ { "key_for_labels": "Category A", "key_for_values": 100 }, ... ]
2273
2276
  }
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")) {
2277
+ 4. RULES: Valid JSON only. No math. No text-based charts. No markdown tables for graphs. If showing a chart, DO NOT output a "products" JSON carousel.`;
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:
3828
+ ${CHART_MARKER}
3829
+ ### MASTER DATA VISUALIZATION PROTOCOL:
3830
+ You are an expert data analyst. When asked to visualize or compare data retrieved from the context:
3831
+ 1. DECIDE the best chart type: 'pie' (for parts-of-a-whole), 'bar' (for category comparisons), or 'line' (for trends).
3832
+ 2. TRANSFORM arbitrary metadata from the context into a FLAT list of objects. Extract relevant keys dynamically.
3833
+ 3. OUTPUT a \`\`\`chart\`\`\` code block using this JSON format:
3831
3834
  {
3832
3835
  "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
+ "xAxisKey": "key_for_labels",
3837
+ "dataKeys": ["key_for_values"],
3838
+ "data": [ { "key_for_labels": "Category A", "key_for_values": 100 }, ... ]
3836
3839
  }
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")) {
3840
+ 4. RULES: Valid JSON only. No math. No text-based charts. No markdown tables for graphs. If showing a chart, DO NOT output a "products" JSON carousel.`;
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-FHNGNXXS.mjs";
13
13
  import "../chunk-YLTMFW4M.mjs";
14
14
  import "../chunk-X4TOT24V.mjs";
15
15
  export {
package/dist/index.js CHANGED
@@ -505,7 +505,8 @@ function MessageBubble({
505
505
  }, [sources, isUser]);
506
506
  const { productsFromContent, cleanContent } = import_react5.default.useMemo(() => {
507
507
  if (isUser) return { productsFromContent: [], cleanContent: message.content };
508
- if (message.content.includes("```chart")) {
508
+ const isVisualization = message.content.includes("```chart") || message.content.toLowerCase().includes("pie chart") || message.content.toLowerCase().includes("bar chart") || message.content.toLowerCase().includes("distribution");
509
+ if (isVisualization) {
509
510
  return { productsFromContent: [], cleanContent: message.content };
510
511
  }
511
512
  const jsonRegex = /```json\s*([\s\S]*?)\s*```/g;
package/dist/index.mjs CHANGED
@@ -468,7 +468,8 @@ function MessageBubble({
468
468
  }, [sources, isUser]);
469
469
  const { productsFromContent, cleanContent } = React5.useMemo(() => {
470
470
  if (isUser) return { productsFromContent: [], cleanContent: message.content };
471
- if (message.content.includes("```chart")) {
471
+ const isVisualization = message.content.includes("```chart") || message.content.toLowerCase().includes("pie chart") || message.content.toLowerCase().includes("bar chart") || message.content.toLowerCase().includes("distribution");
472
+ if (isVisualization) {
472
473
  return { productsFromContent: [], cleanContent: message.content };
473
474
  }
474
475
  const jsonRegex = /```json\s*([\s\S]*?)\s*```/g;
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:
3919
+ ${CHART_MARKER}
3920
+ ### MASTER DATA VISUALIZATION PROTOCOL:
3921
+ You are an expert data analyst. When asked to visualize or compare data retrieved from the context:
3922
+ 1. DECIDE the best chart type: 'pie' (for parts-of-a-whole), 'bar' (for category comparisons), or 'line' (for trends).
3923
+ 2. TRANSFORM arbitrary metadata from the context into a FLAT list of objects. Extract relevant keys dynamically.
3924
+ 3. OUTPUT a \`\`\`chart\`\`\` code block using this JSON format:
3922
3925
  {
3923
3926
  "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
+ "xAxisKey": "key_for_labels",
3928
+ "dataKeys": ["key_for_values"],
3929
+ "data": [ { "key_for_labels": "Category A", "key_for_values": 100 }, ... ]
3927
3930
  }
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")) {
3931
+ 4. RULES: Valid JSON only. No math. No text-based charts. No markdown tables for graphs. If showing a chart, DO NOT output a "products" JSON carousel.`;
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-FHNGNXXS.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.4.9",
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",
@@ -313,8 +313,14 @@ export function MessageBubble({
313
313
  const { productsFromContent, cleanContent } = React.useMemo(() => {
314
314
  if (isUser) return { productsFromContent: [] as Product[], cleanContent: message.content };
315
315
 
316
- // If the message contains a chart, suppress the product carousel to keep focus on visualization
317
- if (message.content.includes('```chart')) {
316
+ // If the message contains a chart or refers to visualization, suppress the product carousel
317
+ const isVisualization =
318
+ message.content.includes('```chart') ||
319
+ message.content.toLowerCase().includes('pie chart') ||
320
+ message.content.toLowerCase().includes('bar chart') ||
321
+ message.content.toLowerCase().includes('distribution');
322
+
323
+ if (isVisualization) {
318
324
  return { productsFromContent: [] as Product[], cleanContent: message.content };
319
325
  }
320
326
 
@@ -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:
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
+ ### MASTER DATA VISUALIZATION PROTOCOL:
107
+ You are an expert data analyst. When asked to visualize or compare data retrieved from the context:
108
+ 1. DECIDE the best chart type: 'pie' (for parts-of-a-whole), 'bar' (for category comparisons), or 'line' (for trends).
109
+ 2. TRANSFORM arbitrary metadata from the context into a FLAT list of objects. Extract relevant keys dynamically.
110
+ 3. OUTPUT a \`\`\`chart\`\`\` code block using this JSON format:
107
111
  {
108
112
  "type": "bar" | "line" | "pie",
109
- "xAxisKey": "property_for_label",
110
- "dataKeys": ["property_for_value"],
111
- "data": [{ "property_for_label": "A", "property_for_value": 10 }]
113
+ "xAxisKey": "key_for_labels",
114
+ "dataKeys": ["key_for_values"],
115
+ "data": [ { "key_for_labels": "Category A", "key_for_values": 100 }, ... ]
112
116
  }
113
- 3. RULES: Data objects MUST be FLAT (no nesting). No math expressions in JSON. NEVER draw charts with text or markdown tables.`;
117
+ 4. RULES: Valid JSON only. No math. No text-based charts. No markdown tables for graphs. If showing a chart, DO NOT output a "products" JSON carousel.`;
114
118
 
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')) {
119
+ if (!this.config.llm.systemPrompt?.includes(CHART_MARKER)) {
117
120
  this.config.llm.systemPrompt = (this.config.llm.systemPrompt || '') + chartInstruction;
118
121
  }
119
122