@retrivora-ai/rag-engine 2.4.2 → 2.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.
Files changed (140) hide show
  1. package/dist/{BatchProcessor-zbQMaZHm.d.mts → BatchProcessor-Csy_K1qQ.d.mts} +2 -0
  2. package/dist/{BatchProcessor-D42E706a.d.ts → BatchProcessor-Dg18zZGk.d.ts} +2 -0
  3. package/dist/handlers/index.js +31 -5
  4. package/dist/handlers/index.mjs +31 -5
  5. package/dist/index.d.mts +3 -3
  6. package/dist/index.d.ts +3 -3
  7. package/dist/index.js +41 -21
  8. package/dist/index.min.css +2 -0
  9. package/dist/index.mjs +41 -21
  10. package/dist/server.d.mts +2 -2
  11. package/dist/server.d.ts +2 -2
  12. package/dist/server.js +32 -5
  13. package/dist/server.mjs +32 -5
  14. package/package.json +5 -4
  15. package/src/LicensedRetrivora.ts +0 -278
  16. package/src/app/api/chat/route.ts +0 -4
  17. package/src/app/api/health/route.ts +0 -5
  18. package/src/app/api/ingest/route.ts +0 -27
  19. package/src/app/api/suggestions/route.ts +0 -5
  20. package/src/app/api/upload/route.ts +0 -5
  21. package/src/app/constants.tsx +0 -270
  22. package/src/app/favicon.ico +0 -0
  23. package/src/app/globals.css +0 -449
  24. package/src/app/layout.tsx +0 -22
  25. package/src/app/page.tsx +0 -64
  26. package/src/app/types.ts +0 -30
  27. package/src/browser.tsx +0 -139
  28. package/src/components/ChatWidget.tsx +0 -393
  29. package/src/components/ChatWindow.tsx +0 -952
  30. package/src/components/CodeViewer.tsx +0 -56
  31. package/src/components/ConfigProvider.tsx +0 -123
  32. package/src/components/DocumentUpload.tsx +0 -354
  33. package/src/components/DynamicChart.tsx +0 -297
  34. package/src/components/HourglassLoader.tsx +0 -87
  35. package/src/components/MarkdownComponents.tsx +0 -186
  36. package/src/components/MessageBubble.tsx +0 -498
  37. package/src/components/ObservabilityPanel.tsx +0 -374
  38. package/src/components/ProductCard.tsx +0 -107
  39. package/src/components/ProductCarousel.tsx +0 -97
  40. package/src/components/SourceCard.tsx +0 -61
  41. package/src/components/ThemeProvider.tsx +0 -8
  42. package/src/components/ThemeToggle.tsx +0 -29
  43. package/src/components/ThinkingBlock.tsx +0 -75
  44. package/src/components/UIDispatcher.tsx +0 -342
  45. package/src/components/VisualizationRenderer.tsx +0 -621
  46. package/src/components/constants.tsx +0 -503
  47. package/src/config/ConfigBuilder.ts +0 -285
  48. package/src/config/EmbeddingStrategy.ts +0 -148
  49. package/src/config/LicenseConfigResolver.ts +0 -298
  50. package/src/config/RagConfig.ts +0 -328
  51. package/src/config/UniversalProfiles.ts +0 -82
  52. package/src/config/constants.ts +0 -64
  53. package/src/config/serverConfig.ts +0 -378
  54. package/src/config/uiConstants.ts +0 -47
  55. package/src/core/BatchProcessor.ts +0 -385
  56. package/src/core/CircuitBreaker.ts +0 -118
  57. package/src/core/ConfigFetcher.ts +0 -220
  58. package/src/core/ConfigResolver.ts +0 -165
  59. package/src/core/ConfigValidator.ts +0 -197
  60. package/src/core/DatabaseStorage.ts +0 -526
  61. package/src/core/FreeTierLimitsGuard.ts +0 -281
  62. package/src/core/LLMRouter.ts +0 -79
  63. package/src/core/LangChainAgent.ts +0 -132
  64. package/src/core/LicenseValidator.ts +0 -284
  65. package/src/core/LicenseVerifier.ts +0 -261
  66. package/src/core/MultiAgentCoordinator.ts +0 -239
  67. package/src/core/Pipeline.ts +0 -1279
  68. package/src/core/PluginManager.ts +0 -277
  69. package/src/core/ProjectSettings.ts +0 -247
  70. package/src/core/ProviderHealthCheck.ts +0 -133
  71. package/src/core/ProviderInterfaces.ts +0 -37
  72. package/src/core/ProviderRegistry.ts +0 -156
  73. package/src/core/QueryProcessor.ts +0 -399
  74. package/src/core/Retrivora.ts +0 -98
  75. package/src/core/VectorPlugin.ts +0 -193
  76. package/src/core/mcp.ts +0 -261
  77. package/src/exceptions/index.ts +0 -131
  78. package/src/handlers/index.ts +0 -1625
  79. package/src/hooks/useHydrated.ts +0 -13
  80. package/src/hooks/useProjectSettings.ts +0 -105
  81. package/src/hooks/useRagChat.ts +0 -436
  82. package/src/hooks/useStoredMessages.ts +0 -64
  83. package/src/index.css +0 -4269
  84. package/src/index.ts +0 -137
  85. package/src/lib/plugin.ts +0 -24
  86. package/src/llm/ILLMProvider.ts +0 -60
  87. package/src/llm/LLMFactory.ts +0 -141
  88. package/src/llm/providers/AnthropicProvider.ts +0 -215
  89. package/src/llm/providers/GeminiProvider.ts +0 -311
  90. package/src/llm/providers/GroqProvider.ts +0 -184
  91. package/src/llm/providers/OllamaProvider.ts +0 -232
  92. package/src/llm/providers/OpenAIProvider.ts +0 -188
  93. package/src/llm/providers/QwenProvider.ts +0 -199
  94. package/src/llm/providers/UniversalLLMAdapter.ts +0 -422
  95. package/src/llm/utils.ts +0 -46
  96. package/src/providers/graphdb/BaseGraphProvider.ts +0 -43
  97. package/src/providers/graphdb/SimpleGraphProvider.ts +0 -66
  98. package/src/providers/vectordb/BaseVectorProvider.ts +0 -98
  99. package/src/providers/vectordb/ChromaDBProvider.ts +0 -130
  100. package/src/providers/vectordb/MilvusProvider.ts +0 -134
  101. package/src/providers/vectordb/MongoDBProvider.ts +0 -250
  102. package/src/providers/vectordb/MultiTablePostgresProvider.ts +0 -461
  103. package/src/providers/vectordb/PineconeProvider.ts +0 -295
  104. package/src/providers/vectordb/PostgreSQLProvider.ts +0 -227
  105. package/src/providers/vectordb/QdrantProvider.ts +0 -294
  106. package/src/providers/vectordb/RedisProvider.ts +0 -105
  107. package/src/providers/vectordb/UniversalVectorProvider.ts +0 -221
  108. package/src/providers/vectordb/WeaviateProvider.ts +0 -172
  109. package/src/rag/DocumentChunker.ts +0 -144
  110. package/src/rag/EntityExtractor.ts +0 -90
  111. package/src/rag/LlamaIndexIngestor.ts +0 -60
  112. package/src/rag/Reranker.ts +0 -106
  113. package/src/rendering/IntentClassifier.ts +0 -167
  114. package/src/rendering/RendererRegistry.ts +0 -164
  115. package/src/rendering/RuleEngine.ts +0 -67
  116. package/src/rendering/VisualizationDecisionEngine.ts +0 -164
  117. package/src/rendering/__tests__/VisualizationDecisionEngine.test.ts +0 -237
  118. package/src/rendering/index.ts +0 -12
  119. package/src/rendering/rules/Rule1SpecificInfoRule.ts +0 -28
  120. package/src/rendering/rules/Rule2ComparisonRule.ts +0 -24
  121. package/src/rendering/rules/Rule3ProductDiscoveryRule.ts +0 -28
  122. package/src/rendering/rules/Rule4AnalyticalRule.ts +0 -38
  123. package/src/rendering/rules/Rule5MixedResponseRule.ts +0 -29
  124. package/src/rendering/rules/Rule6SmallResultSetRule.ts +0 -24
  125. package/src/rendering/rules/Rule7LargeTableRule.ts +0 -35
  126. package/src/rendering/types.ts +0 -96
  127. package/src/server.ts +0 -156
  128. package/src/tailwind.css +0 -194
  129. package/src/telemetry/TelemetryService.ts +0 -330
  130. package/src/types/chat.ts +0 -89
  131. package/src/types/index.ts +0 -278
  132. package/src/types/pdf-parse.d.ts +0 -13
  133. package/src/types/props.ts +0 -169
  134. package/src/utils/DocumentParser.ts +0 -111
  135. package/src/utils/ProductExtractor.ts +0 -350
  136. package/src/utils/SchemaMapper.ts +0 -176
  137. package/src/utils/UITransformer.ts +0 -1812
  138. package/src/utils/synonyms.ts +0 -80
  139. package/src/utils/templateUtils.ts +0 -78
  140. package/src/version.ts +0 -6
@@ -1,237 +0,0 @@
1
- import { VisualizationDecisionEngine, decideVisualization } from '../VisualizationDecisionEngine';
2
- import { RendererRegistry } from '../RendererRegistry';
3
- import { IRendererStrategy, RenderDecision } from '../types';
4
- import { VectorMatch, UITransformationResponse } from '../../types';
5
-
6
- describe('VisualizationDecisionEngine Specification Tests', () => {
7
- beforeEach(() => {
8
- VisualizationDecisionEngine.clearCache();
9
- });
10
-
11
- // Mock retrieved documents helper
12
- const createMockDocs = (count: number, withNumeric = false): VectorMatch[] => {
13
- return Array.from({ length: count }, (_, i) => ({
14
- id: `doc-${i + 1}`,
15
- score: 0.95 - i * 0.05,
16
- content: `Item ${i + 1} content details`,
17
- metadata: {
18
- title: `Product ${i + 1}`,
19
- price: withNumeric ? 100 + i * 50 : undefined,
20
- sales: withNumeric ? 500 - i * 30 : undefined,
21
- category: `Category ${ (i % 3) + 1 }`,
22
- date: `2026-0${ (i % 9) + 1 }-01`,
23
- },
24
- }));
25
- };
26
-
27
- // ── Rule 1: Specific Information Requests ──────────────────────────────────
28
- describe('Rule 1: Specific Information Requests', () => {
29
-
30
- test('should render text for "What is Pinecone?"', () => {
31
- const decision = decideVisualization('What is Pinecone?', createMockDocs(4));
32
- expect(decision.renderType).toBe('text');
33
- expect(decision.confidence).toBeGreaterThanOrEqual(0.9);
34
- });
35
-
36
- test('should render text for "What is the price of iPhone 16?"', () => {
37
- const decision = decideVisualization('What is the price of iPhone 16?', createMockDocs(4, true));
38
- expect(decision.renderType).toBe('text');
39
- });
40
-
41
- test('should render text for "Explain RAG."', () => {
42
- const decision = decideVisualization('Explain RAG.', createMockDocs(3));
43
- expect(decision.renderType).toBe('text');
44
- });
45
-
46
- test('should render text for "Who is the CEO of OpenAI?"', () => {
47
- const decision = decideVisualization('Who is the CEO of OpenAI?', createMockDocs(4));
48
- expect(decision.renderType).toBe('text');
49
- });
50
-
51
- test('should render text for "What is namespace in Pinecone?"', () => {
52
- const decision = decideVisualization('What is namespace in Pinecone?', createMockDocs(5));
53
- expect(decision.renderType).toBe('text');
54
- });
55
- });
56
-
57
- // ── Rule 2: Comparison Queries ─────────────────────────────────────────────
58
- describe('Rule 2: Comparison Queries', () => {
59
-
60
- test('should render table for "Compare GPT-4 vs Claude"', () => {
61
- const decision = decideVisualization('Compare GPT-4 vs Claude', createMockDocs(4));
62
- expect(decision.renderType).toBe('table');
63
- expect(decision.confidence).toBeGreaterThanOrEqual(0.85);
64
- });
65
-
66
- test('should render table for "Compare iPhone vs Pixel"', () => {
67
- const decision = decideVisualization('Compare iPhone vs Pixel', createMockDocs(4));
68
- expect(decision.renderType).toBe('table');
69
- });
70
-
71
- test('should render table for "Difference between React and Vue"', () => {
72
- const decision = decideVisualization('Difference between React and Vue', createMockDocs(4));
73
- expect(decision.renderType).toBe('table');
74
- });
75
- });
76
-
77
- // ── Rule 3: Product Discovery ──────────────────────────────────────────────
78
- describe('Rule 3: Product Discovery', () => {
79
-
80
- test('should render carousel for "Best gaming laptops"', () => {
81
- const decision = decideVisualization('Best gaming laptops', createMockDocs(4, true));
82
- expect(decision.renderType).toBe('carousel');
83
- });
84
-
85
- test('should render carousel for "Recommend office chairs"', () => {
86
- const decision = decideVisualization('Recommend office chairs', createMockDocs(5, true));
87
- expect(decision.renderType).toBe('carousel');
88
- });
89
-
90
- test('should render carousel for "Best headphones under $200"', () => {
91
- const decision = decideVisualization('Best headphones under $200', createMockDocs(4, true));
92
- expect(decision.renderType).toBe('carousel');
93
- });
94
-
95
- test('should render carousel for "Show available Nike shoes"', () => {
96
- const decision = decideVisualization('Show available Nike shoes', createMockDocs(5, true));
97
- expect(decision.renderType).toBe('carousel');
98
- });
99
- });
100
-
101
- // ── Rule 4: Analytical Queries & Chart Types ───────────────────────────────
102
- describe('Rule 4: Analytical Queries', () => {
103
-
104
- test('should render line chart for "Monthly sales"', () => {
105
- const decision = decideVisualization('Monthly sales', createMockDocs(5, true));
106
- expect(decision.renderType).toBe('chart');
107
- expect(decision.chartType).toBe('line');
108
- });
109
-
110
- test('should render line chart for "Revenue growth"', () => {
111
- const decision = decideVisualization('Revenue growth', createMockDocs(5, true));
112
- expect(decision.renderType).toBe('chart');
113
- expect(decision.chartType).toBe('line');
114
- });
115
-
116
- test('should render bar chart for "Top performing products"', () => {
117
- const decision = decideVisualization('Top performing products', createMockDocs(4, true));
118
- expect(decision.renderType).toBe('chart');
119
- expect(decision.chartType).toBe('bar');
120
- });
121
-
122
- test('should render line chart for "Population trends"', () => {
123
- const decision = decideVisualization('Population trends', createMockDocs(5, true));
124
- expect(decision.renderType).toBe('chart');
125
- expect(decision.chartType).toBe('line');
126
- });
127
-
128
- test('should render bar chart for "Sales by region"', () => {
129
- const decision = decideVisualization('Sales by region', createMockDocs(4, true));
130
- expect(decision.renderType).toBe('chart');
131
- expect(decision.chartType).toBe('bar');
132
- });
133
-
134
- test('should render pie chart for "Percentage breakdown of categories"', () => {
135
- const decision = decideVisualization('Percentage breakdown of categories', createMockDocs(4, true));
136
- expect(decision.renderType).toBe('chart');
137
- expect(decision.chartType).toBe('pie');
138
- });
139
-
140
- test('should render scatter chart for "Correlation between price and rating"', () => {
141
- const decision = decideVisualization('Correlation between price and rating', createMockDocs(4, true));
142
- expect(decision.renderType).toBe('chart');
143
- expect(decision.chartType).toBe('scatter');
144
- });
145
- });
146
-
147
- // ── Rule 5: Mixed Responses ────────────────────────────────────────────────
148
- describe('Rule 5: Mixed Responses', () => {
149
-
150
- test('should render mixed sections for "Show top selling products this month"', () => {
151
- const decision = decideVisualization('Show top selling products this month.', createMockDocs(5, true));
152
- expect(decision.renderType).toBe('mixed');
153
- expect(decision.sections).toBeDefined();
154
- expect(decision.sections?.length).toBe(3);
155
-
156
- const sectionTypes = decision.sections?.map(s => s.type);
157
- expect(sectionTypes).toEqual(['text', 'carousel', 'chart']);
158
- });
159
- });
160
-
161
- // ── Rule 6: Small Result Sets (< 3 rows) ───────────────────────────────────
162
- describe('Rule 6: Small Result Sets', () => {
163
-
164
- test('should demote chart to text when result count is 2 (< 3 rows)', () => {
165
- const decision = decideVisualization('Monthly sales', createMockDocs(2, true));
166
- expect(decision.renderType).toBe('text'); // Demoted from chart to text
167
- expect(decision.reason).toContain('Rule 6');
168
- });
169
-
170
- test('should allow table for explicit comparison even with 2 rows', () => {
171
- const decision = decideVisualization('Compare GPT-4 vs Claude', createMockDocs(2));
172
- expect(decision.renderType).toBe('table');
173
- });
174
- });
175
-
176
- // ── Rule 7: Large Tables (> 5 rows) ────────────────────────────────────────
177
- describe('Rule 7: Large Tables', () => {
178
-
179
- test('should render table for generic non-analytical large dataset (> 5 rows)', () => {
180
- const decision = decideVisualization('List overall documents in system', createMockDocs(8));
181
- expect(decision.renderType).toBe('table');
182
- expect(decision.reason).toContain('Rule 7');
183
- });
184
-
185
- test('should render mixed table+chart for large analytical dataset (> 5 rows)', () => {
186
- const decision = decideVisualization('Regional sales statistics', createMockDocs(8, true));
187
- expect(decision.renderType).toBe('mixed');
188
- expect(decision.sections?.some(s => s.type === 'table')).toBe(true);
189
- expect(decision.sections?.some(s => s.type === 'chart')).toBe(true);
190
- });
191
- });
192
-
193
- // ── Strategy Registry & Extensibility ──────────────────────────────────────
194
- describe('Extensibility & Strategy Registry', () => {
195
-
196
- test('should support registering custom timeline renderer strategy', () => {
197
- class TimelineRendererStrategy implements IRendererStrategy {
198
- readonly type = 'timeline';
199
- render(data: unknown): UITransformationResponse {
200
- return {
201
- type: 'text',
202
- title: 'Timeline Events',
203
- data: { content: 'Rendered timeline' },
204
- };
205
- }
206
- }
207
-
208
- RendererRegistry.registerStrategy(new TimelineRendererStrategy());
209
- expect(RendererRegistry.hasStrategy('timeline')).toBe(true);
210
-
211
- const strategy = RendererRegistry.getStrategy('timeline');
212
- const res = strategy.render(createMockDocs(3));
213
- expect(res.title).toBe('Timeline Events');
214
- });
215
- });
216
-
217
- // ── Performance & LRU Decision Cache ──────────────────────────────────────
218
- describe('Performance & Caching', () => {
219
-
220
- test('should return cached decisions on repeated queries in < 1ms', () => {
221
- const query = 'What is namespace in Pinecone?';
222
- const docs = createMockDocs(4);
223
-
224
- const t0 = performance.now();
225
- const firstDecision = decideVisualization(query, docs);
226
- const t1 = performance.now();
227
-
228
- const t2 = performance.now();
229
- const secondDecision = decideVisualization(query, docs);
230
- const t3 = performance.now();
231
-
232
- expect(firstDecision.renderType).toBe(secondDecision.renderType);
233
- expect(t3 - t2).toBeLessThan(1.0); // Sub-millisecond execution
234
- expect(VisualizationDecisionEngine.getCacheSize()).toBeGreaterThan(0);
235
- });
236
- });
237
- });
@@ -1,12 +0,0 @@
1
- export * from './types';
2
- export { IntentClassifier } from './IntentClassifier';
3
- export { RuleEngine } from './RuleEngine';
4
- export { RendererRegistry, TextRendererStrategy, TableRendererStrategy, CarouselRendererStrategy, ChartRendererStrategy, MixedRendererStrategy } from './RendererRegistry';
5
- export { VisualizationDecisionEngine, decideVisualization } from './VisualizationDecisionEngine';
6
- export { Rule1SpecificInfoRule } from './rules/Rule1SpecificInfoRule';
7
- export { Rule2ComparisonRule } from './rules/Rule2ComparisonRule';
8
- export { Rule3ProductDiscoveryRule } from './rules/Rule3ProductDiscoveryRule';
9
- export { Rule4AnalyticalRule } from './rules/Rule4AnalyticalRule';
10
- export { Rule5MixedResponseRule } from './rules/Rule5MixedResponseRule';
11
- export { Rule6SmallResultSetRule } from './rules/Rule6SmallResultSetRule';
12
- export { Rule7LargeTableRule } from './rules/Rule7LargeTableRule';
@@ -1,28 +0,0 @@
1
- import { DecisionContext, IntentCategory, IRenderRule, RenderDecision } from '../types';
2
-
3
- export class Rule1SpecificInfoRule implements IRenderRule {
4
- readonly name = 'Rule1SpecificInfo';
5
- readonly priority = 100;
6
-
7
- evaluate(context: DecisionContext, intent: IntentCategory): RenderDecision | null {
8
- const q = (context.userQuery || '').toLowerCase().trim();
9
-
10
- // Check specific fact/definition/explanation indicators
11
- const isFactQuery =
12
- intent === 'information_lookup' ||
13
- /^(what|who|explain|explore|define|where|when|why|meaning of|tell me about|show details of|overview of|summarize)\s+/i.test(q) ||
14
- /^(what is the price of|price of|cost of)\b/i.test(q);
15
-
16
- const isNonVisual = !/\b(compare|versus|vs\.?|trend|monthly|revenue|best|top 10|chart|table|list|grid)\b/i.test(q);
17
-
18
- if (isFactQuery && isNonVisual) {
19
- return {
20
- renderType: 'text',
21
- confidence: 0.95,
22
- reason: 'Rule 1: Specific information request (fact, explanation, or definition) requires plain text rendering.',
23
- };
24
- }
25
-
26
- return null;
27
- }
28
- }
@@ -1,24 +0,0 @@
1
- import { DecisionContext, IntentCategory, IRenderRule, RenderDecision } from '../types';
2
-
3
- export class Rule2ComparisonRule implements IRenderRule {
4
- readonly name = 'Rule2Comparison';
5
- readonly priority = 90;
6
-
7
- evaluate(context: DecisionContext, intent: IntentCategory): RenderDecision | null {
8
- const q = (context.userQuery || '').toLowerCase().trim();
9
-
10
- const isComparison =
11
- intent === 'comparison' ||
12
- /\b(compare|comparison|vs\.?|versus|difference between|differ|contrast|against)\b/i.test(q);
13
-
14
- if (isComparison) {
15
- return {
16
- renderType: 'table',
17
- confidence: 0.90,
18
- reason: 'Rule 2: Comparison query contrasting multiple entities requires structured table rendering.',
19
- };
20
- }
21
-
22
- return null;
23
- }
24
- }
@@ -1,28 +0,0 @@
1
- import { DecisionContext, IntentCategory, IRenderRule, RenderDecision } from '../types';
2
-
3
- export class Rule3ProductDiscoveryRule implements IRenderRule {
4
- readonly name = 'Rule3ProductDiscovery';
5
- readonly priority = 85;
6
-
7
- evaluate(context: DecisionContext, intent: IntentCategory): RenderDecision | null {
8
- const q = (context.userQuery || '').toLowerCase().trim();
9
-
10
- const isDiscovery =
11
- intent === 'product_search' ||
12
- intent === 'recommendation' ||
13
- /\b(best|recommend|top|buy|shopping|under \$|cheap|shoes|laptops|chairs|headphones|sneakers|apparel|products|show available)\b/i.test(q);
14
-
15
- const isNotChart = !/\b(chart|sales|revenue|monthly|growth|trend|over time)\b/i.test(q);
16
- const isAnalyticalRanking = /\b(top performing|top selling|best performing|performing|sales|revenue|ranking)\b/i.test(q);
17
-
18
- if (isDiscovery && isNotChart && !isAnalyticalRanking) {
19
- return {
20
- renderType: 'carousel',
21
- confidence: 0.90,
22
- reason: 'Rule 3: Product discovery/recommendation query requires product carousel rendering.',
23
- };
24
- }
25
-
26
- return null;
27
- }
28
- }
@@ -1,38 +0,0 @@
1
- import { ChartType, DecisionContext, IntentCategory, IRenderRule, RenderDecision } from '../types';
2
-
3
- export class Rule4AnalyticalRule implements IRenderRule {
4
- readonly name = 'Rule4Analytical';
5
- readonly priority = 80;
6
-
7
- evaluate(context: DecisionContext, intent: IntentCategory): RenderDecision | null {
8
- const q = (context.userQuery || '').toLowerCase().trim();
9
-
10
- const isAnalytical =
11
- intent === 'analytics' ||
12
- intent === 'trend_analysis' ||
13
- intent === 'ranking' ||
14
- /\b(monthly sales|revenue growth|top performing|population trends|sales by|growth|distribution|share|percentage|breakdown|correlation|scatter|trend)\b/i.test(q);
15
-
16
- if (!isAnalytical) return null;
17
-
18
- // Determine specific chart type based on query intent signals
19
- let chartType: ChartType = 'bar'; // Default category comparison
20
-
21
- if (intent === 'trend_analysis' || /\b(monthly|yearly|weekly|growth|over time|trend|timeline|historical)\b/i.test(q)) {
22
- chartType = 'line';
23
- } else if (/\b(share|percentage|percent|breakup|breakdown|composition|pie|donut|proportion)\b/i.test(q)) {
24
- chartType = 'pie';
25
- } else if (/\b(correlation|scatter|relationship|relation|impact of|depends on)\b/i.test(q)) {
26
- chartType = 'scatter';
27
- } else {
28
- chartType = 'bar';
29
- }
30
-
31
- return {
32
- renderType: 'chart',
33
- chartType,
34
- confidence: 0.85,
35
- reason: `Rule 4: Analytical query with numerical insights selects ${chartType} chart.`,
36
- };
37
- }
38
- }
@@ -1,29 +0,0 @@
1
- import { DecisionContext, IntentCategory, IRenderRule, RenderDecision } from '../types';
2
-
3
- export class Rule5MixedResponseRule implements IRenderRule {
4
- readonly name = 'Rule5MixedResponse';
5
- readonly priority = 95;
6
-
7
- evaluate(context: DecisionContext, _intent: IntentCategory): RenderDecision | null {
8
- const q = (context.userQuery || '').toLowerCase().trim();
9
-
10
- // Specific mixed intent match: "top selling products this month" / multi-section requests
11
- const isTopSellingThisMonth = /\btop\s*(selling|performing)?\s*products?\s*(this|last)?\s*(month|year|week)\b/i.test(q);
12
- const hasMultipleSectionsRequest = /\b(summary|overview)\b/i.test(q) && /\b(carousel|products?|items?)\b/i.test(q) && /\b(chart|sales|trend|revenue)\b/i.test(q);
13
-
14
- if (isTopSellingThisMonth || hasMultipleSectionsRequest) {
15
- return {
16
- renderType: 'mixed',
17
- confidence: 0.95,
18
- reason: 'Rule 5: Mixed response query requires multi-section composition (text, carousel, chart).',
19
- sections: [
20
- { type: 'text', title: 'Summary' },
21
- { type: 'carousel', title: 'Top Products' },
22
- { type: 'chart', chartType: 'bar', title: 'Sales Performance' },
23
- ],
24
- };
25
- }
26
-
27
- return null;
28
- }
29
- }
@@ -1,24 +0,0 @@
1
- import { DecisionContext, IntentCategory, IRenderRule, RenderDecision } from '../types';
2
-
3
- export class Rule6SmallResultSetRule implements IRenderRule {
4
- readonly name = 'Rule6SmallResultSet';
5
- readonly priority = 110;
6
-
7
- evaluate(context: DecisionContext, _intent: IntentCategory): RenderDecision | null {
8
- const docs = context.retrievedDocuments || [];
9
-
10
- // Only apply if documents are present and fewer than 3
11
- if (docs.length > 0 && docs.length < 3) {
12
- const q = (context.userQuery || '').toLowerCase().trim();
13
- const isExplicitComparison = /\b(compare|versus|vs\.?)\b/i.test(q);
14
-
15
- return {
16
- renderType: isExplicitComparison ? 'table' : 'text',
17
- confidence: 0.98,
18
- reason: `Rule 6: Small result set (${docs.length} rows < 3). Charts avoided to prevent sparse or uninformative visualizations.`,
19
- };
20
- }
21
-
22
- return null;
23
- }
24
- }
@@ -1,35 +0,0 @@
1
- import { DecisionContext, IntentCategory, IRenderRule, RenderDecision } from '../types';
2
-
3
- export class Rule7LargeTableRule implements IRenderRule {
4
- readonly name = 'Rule7LargeTable';
5
- readonly priority = 75;
6
-
7
- evaluate(context: DecisionContext, intent: IntentCategory): RenderDecision | null {
8
- const docs = context.retrievedDocuments || [];
9
-
10
- if (docs.length > 5) {
11
- const q = (context.userQuery || '').toLowerCase().trim();
12
- const hasNumericAgg = intent === 'analytics' || intent === 'ranking' || /\b(sales|revenue|growth|count|total|average)\b/i.test(q);
13
-
14
- if (hasNumericAgg) {
15
- return {
16
- renderType: 'mixed',
17
- confidence: 0.88,
18
- reason: `Rule 7: Large result set (${docs.length} rows > 5) with numeric aggregation rendered as Table + Chart.`,
19
- sections: [
20
- { type: 'table', title: 'Detailed Data Table' },
21
- { type: 'chart', chartType: 'bar', title: 'Numerical Breakdown' },
22
- ],
23
- };
24
- }
25
-
26
- return {
27
- renderType: 'table',
28
- confidence: 0.85,
29
- reason: `Rule 7: Large result set (${docs.length} rows > 5) rendered as structured table for readability.`,
30
- };
31
- }
32
-
33
- return null;
34
- }
35
- }
@@ -1,96 +0,0 @@
1
- import { VectorMatch, UITransformationResponse } from '../types';
2
-
3
- /**
4
- * Primary rendering outcome types supported by the decision engine.
5
- */
6
- export type RenderType =
7
- | 'text'
8
- | 'table'
9
- | 'carousel'
10
- | 'chart'
11
- | 'mixed'
12
- | 'card'
13
- | 'none';
14
-
15
- /**
16
- * Chart sub-types available when renderType === 'chart'.
17
- */
18
- export type ChartType =
19
- | 'bar'
20
- | 'line'
21
- | 'pie'
22
- | 'scatter';
23
-
24
- /**
25
- * High-level intent classification categories.
26
- */
27
- export type IntentCategory =
28
- | 'information_lookup'
29
- | 'product_search'
30
- | 'recommendation'
31
- | 'comparison'
32
- | 'analytics'
33
- | 'trend_analysis'
34
- | 'ranking'
35
- | 'summarization';
36
-
37
- /**
38
- * Individual section specifier for multi-section (mixed) responses.
39
- */
40
- export interface RenderSectionDecision {
41
- type: RenderType;
42
- chartType?: ChartType;
43
- title?: string;
44
- }
45
-
46
- /**
47
- * Final decision produced by the Visualization Decision Engine.
48
- */
49
- export interface RenderDecision {
50
- /** Primary rendering format selected */
51
- renderType: RenderType;
52
- /** Specific chart sub-type if renderType === 'chart' */
53
- chartType?: ChartType;
54
- /** Confidence score between 0.0 and 1.0 */
55
- confidence: number;
56
- /** Human-readable explanation of why this decision was reached */
57
- reason: string;
58
- /** Sub-sections if renderType === 'mixed' */
59
- sections?: RenderSectionDecision[];
60
- }
61
-
62
- /**
63
- * Context provided to the intent classifier & decision engine rules.
64
- */
65
- export interface DecisionContext {
66
- /** Original user prompt/query string */
67
- userQuery: string;
68
- /** Vector DB retrieved documents / context records */
69
- retrievedDocuments?: VectorMatch[];
70
- /** Optional LLM text response if already available */
71
- llmResponse?: string;
72
- /** Additional custom metadata or config settings */
73
- metadata?: Record<string, unknown>;
74
- }
75
-
76
- /**
77
- * Interface implemented by rule strategies in the Rule Engine.
78
- */
79
- export interface IRenderRule {
80
- /** Unique name of the decision rule */
81
- name: string;
82
- /** Precedence score (higher priority rules run first) */
83
- priority: number;
84
- /** Evaluate the rule against current query context and classified intent */
85
- evaluate(context: DecisionContext, intent: IntentCategory): RenderDecision | null;
86
- }
87
-
88
- /**
89
- * Interface implemented by pluggable Renderer Strategies in RendererRegistry.
90
- */
91
- export interface IRendererStrategy {
92
- /** Render type identifier handled by this strategy */
93
- type: RenderType | string;
94
- /** Transform input data into a standardized UITransformationResponse payload */
95
- render(data: unknown, options?: Record<string, unknown>): UITransformationResponse;
96
- }