@retrivora-ai/rag-engine 2.6.5 → 2.6.6
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/dist/{ILLMProvider-Csukdic7.d.mts → ILLMProvider-BQXlVWNn.d.mts} +7 -0
- package/dist/{ILLMProvider-Csukdic7.d.ts → ILLMProvider-BQXlVWNn.d.ts} +7 -0
- package/dist/{PineconeProvider-RDXBD3PE.mjs → PineconeProvider-S7AV7FKC.mjs} +3 -3
- package/dist/{chunk-SYI7TYRP.mjs → chunk-2GDW6W5C.mjs} +1 -1
- package/dist/{chunk-PLODIWBN.mjs → chunk-557UWRCG.mjs} +1 -1
- package/dist/{chunk-7PVV4TV2.mjs → chunk-F656WHWF.mjs} +77 -41
- package/dist/{chunk-UB4IVERI.mjs → chunk-JNPVVOIF.mjs} +1 -1
- package/dist/{chunk-4NRSH3VX.mjs → chunk-Q4MVJ7NW.mjs} +1 -1
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +76 -40
- package/dist/handlers/index.mjs +2 -2
- package/dist/{index-CAN5ZTWN.d.ts → index-BVNd1Ii7.d.ts} +1 -1
- package/dist/{index-Bzpu_Ujt.d.mts → index-BmbFZGyv.d.mts} +5 -1
- package/dist/{index-CYhWkWaX.d.mts → index-C2ONv-uf.d.mts} +1 -1
- package/dist/{index-DYgeV_V5.d.ts → index-CBlH1Kvs.d.ts} +5 -1
- package/dist/index.css +209 -0
- package/dist/index.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +1291 -732
- package/dist/index.min.css +1 -1
- package/dist/index.mjs +1240 -681
- package/dist/server.d.mts +11 -6
- package/dist/server.d.ts +11 -6
- package/dist/server.js +76 -40
- package/dist/server.mjs +5 -5
- package/package.json +1 -1
package/dist/server.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { b as RagConfig, f as UniversalRagConfig, h as VectorDBConfig, y as UpsertDocument, V as VectorMatch, H as GraphDBConfig, J as GraphNode, K as Edge, M as GraphSearchResult, L as LLMConfig, E as EmbeddingConfig, I as ILLMProvider, z as VectorDBProvider, n as LLMProvider, m as EmbeddingProvider, u as RAGConfig, U as UIConfig, C as ChatMessage, g as UITransformationResponse, k as ChatOptions, l as EmbedOptions, c as IngestDocument, d as ChatResponse } from './ILLMProvider-
|
|
2
|
-
export { A as AuthMode, N as BarChartData, Q as CarouselProduct, S as IRetriever, o as LatencyBreakdown, X as LineChartDataPoint, Y as MessageRole, Z as MetricCardData, O as ObservabilityTrace, _ as PieChartData, P as Product, p as ProjectAiSettings, q as ProjectAuthSettings, r as ProjectBrandingSettings, a as ProjectChatSettings, s as ProjectTelemetrySettings, t as ProjectWidgetSettings, R as RagMessage, v as RetrievalConfig, e as RetrievalResult, w as RetrievedChunk, $ as RetrivoraChunkMetadata, a0 as RetrivoraIngestedDocument, a1 as ScatterPlotDataPoint, a2 as SuggestionsResponse, a3 as TableData, T as ThemeMode, x as TokenUsage, i as UseRagChatOptions, j as UseRagChatReturn, a4 as VisualizationType, W as WidgetPosition, B as WorkflowConfig, D as createDefaultProjectSettings, F as normalizeProjectSettings, G as projectSettingsToUiConfig } from './ILLMProvider-
|
|
3
|
-
import { V as Pipeline, o as DecisionContext, q as IntentCategory, I as IRenderRule, G as RenderDecision, p as IRendererStrategy } from './index-
|
|
4
|
-
export { W as ArchitectureCardProps, A as AuthenticationException, B as BatchOptions, f as BatchProcessor, g as BatchResult, h as ChartType, e as ChatViewportSize, C as ChatWidgetProps, a as ChatWindowProps, i as Chunk, j as ChunkOptions, c as ClientConfig, m as ConfigFetcher, b as ConfigProviderProps, n as ConfigurationException, X as DocumentChunker, D as DocumentUploadProps, E as EmbeddingFailedException, Y as LicenseConfigResolver, L as LicenseTierConfig, r as LicenseValidationError, s as LicenseValidationRequest, t as LicenseValidationResponse, u as LicenseValidator, M as MessageBubbleProps, Z as PipelineStep, P as ProductCardProps, d as ProductCarouselProps, v as ProviderCredentials, w as ProviderNotFoundException, _ as ProviderPill, x as RateLimitException, R as RemoteConfig, y as RemoteEmbeddingConfig, z as RemoteLLMConfig, F as RemoteVectorConfig, $ as RenderSectionDecision, H as RenderType, J as RetrievalException, K as Retrivora, N as RetrivoraError, O as RetrivoraErrorCode, Q as SDKVersionUnsupportedError, T as SDK_VERSION, a0 as Snippet, S as SourceCardProps, a1 as wrapError } from './index-
|
|
5
|
-
import { I as IProviderValidator, a as IProviderHealthChecker, H as HealthCheckResult } from './index-
|
|
6
|
-
export { C as ConfigValidator, b as HandlerOptions, V as ValidationError, c as VectorPlugin, d as createChatHandler, e as createFeedbackHandler, f as createHealthHandler, g as createHistoryHandler, h as createIngestHandler, i as createLicenseHandler, j as createRagHandler, k as createSessionsHandler, l as createStreamHandler, m as createSuggestionsHandler, n as createUploadHandler, s as sseErrorFrame, o as sseFrame, p as sseMetaFrame, q as sseObservabilityFrame, r as sseTextFrame, t as sseUIFrame } from './index-
|
|
1
|
+
import { b as RagConfig, f as UniversalRagConfig, h as VectorDBConfig, y as UpsertDocument, V as VectorMatch, H as GraphDBConfig, J as GraphNode, K as Edge, M as GraphSearchResult, L as LLMConfig, E as EmbeddingConfig, I as ILLMProvider, z as VectorDBProvider, n as LLMProvider, m as EmbeddingProvider, u as RAGConfig, U as UIConfig, C as ChatMessage, g as UITransformationResponse, k as ChatOptions, l as EmbedOptions, c as IngestDocument, d as ChatResponse } from './ILLMProvider-BQXlVWNn.mjs';
|
|
2
|
+
export { A as AuthMode, N as BarChartData, Q as CarouselProduct, S as IRetriever, o as LatencyBreakdown, X as LineChartDataPoint, Y as MessageRole, Z as MetricCardData, O as ObservabilityTrace, _ as PieChartData, P as Product, p as ProjectAiSettings, q as ProjectAuthSettings, r as ProjectBrandingSettings, a as ProjectChatSettings, s as ProjectTelemetrySettings, t as ProjectWidgetSettings, R as RagMessage, v as RetrievalConfig, e as RetrievalResult, w as RetrievedChunk, $ as RetrivoraChunkMetadata, a0 as RetrivoraIngestedDocument, a1 as ScatterPlotDataPoint, a2 as SuggestionsResponse, a3 as TableData, T as ThemeMode, x as TokenUsage, i as UseRagChatOptions, j as UseRagChatReturn, a4 as VisualizationType, W as WidgetPosition, B as WorkflowConfig, D as createDefaultProjectSettings, F as normalizeProjectSettings, G as projectSettingsToUiConfig } from './ILLMProvider-BQXlVWNn.mjs';
|
|
3
|
+
import { V as Pipeline, o as DecisionContext, q as IntentCategory, I as IRenderRule, G as RenderDecision, p as IRendererStrategy } from './index-BmbFZGyv.mjs';
|
|
4
|
+
export { W as ArchitectureCardProps, A as AuthenticationException, B as BatchOptions, f as BatchProcessor, g as BatchResult, h as ChartType, e as ChatViewportSize, C as ChatWidgetProps, a as ChatWindowProps, i as Chunk, j as ChunkOptions, c as ClientConfig, m as ConfigFetcher, b as ConfigProviderProps, n as ConfigurationException, X as DocumentChunker, D as DocumentUploadProps, E as EmbeddingFailedException, Y as LicenseConfigResolver, L as LicenseTierConfig, r as LicenseValidationError, s as LicenseValidationRequest, t as LicenseValidationResponse, u as LicenseValidator, M as MessageBubbleProps, Z as PipelineStep, P as ProductCardProps, d as ProductCarouselProps, v as ProviderCredentials, w as ProviderNotFoundException, _ as ProviderPill, x as RateLimitException, R as RemoteConfig, y as RemoteEmbeddingConfig, z as RemoteLLMConfig, F as RemoteVectorConfig, $ as RenderSectionDecision, H as RenderType, J as RetrievalException, K as Retrivora, N as RetrivoraError, O as RetrivoraErrorCode, Q as SDKVersionUnsupportedError, T as SDK_VERSION, a0 as Snippet, S as SourceCardProps, a1 as wrapError } from './index-BmbFZGyv.mjs';
|
|
5
|
+
import { I as IProviderValidator, a as IProviderHealthChecker, H as HealthCheckResult } from './index-C2ONv-uf.mjs';
|
|
6
|
+
export { C as ConfigValidator, b as HandlerOptions, V as ValidationError, c as VectorPlugin, d as createChatHandler, e as createFeedbackHandler, f as createHealthHandler, g as createHistoryHandler, h as createIngestHandler, i as createLicenseHandler, j as createRagHandler, k as createSessionsHandler, l as createStreamHandler, m as createSuggestionsHandler, n as createUploadHandler, s as sseErrorFrame, o as sseFrame, p as sseMetaFrame, q as sseObservabilityFrame, r as sseTextFrame, t as sseUIFrame } from './index-C2ONv-uf.mjs';
|
|
7
7
|
import 'react';
|
|
8
8
|
import 'next/server';
|
|
9
9
|
|
|
@@ -1207,6 +1207,11 @@ declare class VisualizationDecisionEngine {
|
|
|
1207
1207
|
/**
|
|
1208
1208
|
* Clear the decision cache.
|
|
1209
1209
|
*/
|
|
1210
|
+
/**
|
|
1211
|
+
* Returns true when the generated chat response indicates there is no relevant
|
|
1212
|
+
* data or the assistant could not answer the query.
|
|
1213
|
+
*/
|
|
1214
|
+
static isNegativeResponse(response?: string): boolean;
|
|
1210
1215
|
static clearCache(): void;
|
|
1211
1216
|
/**
|
|
1212
1217
|
* Get size of current decision cache.
|
package/dist/server.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { b as RagConfig, f as UniversalRagConfig, h as VectorDBConfig, y as UpsertDocument, V as VectorMatch, H as GraphDBConfig, J as GraphNode, K as Edge, M as GraphSearchResult, L as LLMConfig, E as EmbeddingConfig, I as ILLMProvider, z as VectorDBProvider, n as LLMProvider, m as EmbeddingProvider, u as RAGConfig, U as UIConfig, C as ChatMessage, g as UITransformationResponse, k as ChatOptions, l as EmbedOptions, c as IngestDocument, d as ChatResponse } from './ILLMProvider-
|
|
2
|
-
export { A as AuthMode, N as BarChartData, Q as CarouselProduct, S as IRetriever, o as LatencyBreakdown, X as LineChartDataPoint, Y as MessageRole, Z as MetricCardData, O as ObservabilityTrace, _ as PieChartData, P as Product, p as ProjectAiSettings, q as ProjectAuthSettings, r as ProjectBrandingSettings, a as ProjectChatSettings, s as ProjectTelemetrySettings, t as ProjectWidgetSettings, R as RagMessage, v as RetrievalConfig, e as RetrievalResult, w as RetrievedChunk, $ as RetrivoraChunkMetadata, a0 as RetrivoraIngestedDocument, a1 as ScatterPlotDataPoint, a2 as SuggestionsResponse, a3 as TableData, T as ThemeMode, x as TokenUsage, i as UseRagChatOptions, j as UseRagChatReturn, a4 as VisualizationType, W as WidgetPosition, B as WorkflowConfig, D as createDefaultProjectSettings, F as normalizeProjectSettings, G as projectSettingsToUiConfig } from './ILLMProvider-
|
|
3
|
-
import { V as Pipeline, o as DecisionContext, q as IntentCategory, I as IRenderRule, G as RenderDecision, p as IRendererStrategy } from './index-
|
|
4
|
-
export { W as ArchitectureCardProps, A as AuthenticationException, B as BatchOptions, f as BatchProcessor, g as BatchResult, h as ChartType, e as ChatViewportSize, C as ChatWidgetProps, a as ChatWindowProps, i as Chunk, j as ChunkOptions, c as ClientConfig, m as ConfigFetcher, b as ConfigProviderProps, n as ConfigurationException, X as DocumentChunker, D as DocumentUploadProps, E as EmbeddingFailedException, Y as LicenseConfigResolver, L as LicenseTierConfig, r as LicenseValidationError, s as LicenseValidationRequest, t as LicenseValidationResponse, u as LicenseValidator, M as MessageBubbleProps, Z as PipelineStep, P as ProductCardProps, d as ProductCarouselProps, v as ProviderCredentials, w as ProviderNotFoundException, _ as ProviderPill, x as RateLimitException, R as RemoteConfig, y as RemoteEmbeddingConfig, z as RemoteLLMConfig, F as RemoteVectorConfig, $ as RenderSectionDecision, H as RenderType, J as RetrievalException, K as Retrivora, N as RetrivoraError, O as RetrivoraErrorCode, Q as SDKVersionUnsupportedError, T as SDK_VERSION, a0 as Snippet, S as SourceCardProps, a1 as wrapError } from './index-
|
|
5
|
-
import { I as IProviderValidator, a as IProviderHealthChecker, H as HealthCheckResult } from './index-
|
|
6
|
-
export { C as ConfigValidator, b as HandlerOptions, V as ValidationError, c as VectorPlugin, d as createChatHandler, e as createFeedbackHandler, f as createHealthHandler, g as createHistoryHandler, h as createIngestHandler, i as createLicenseHandler, j as createRagHandler, k as createSessionsHandler, l as createStreamHandler, m as createSuggestionsHandler, n as createUploadHandler, s as sseErrorFrame, o as sseFrame, p as sseMetaFrame, q as sseObservabilityFrame, r as sseTextFrame, t as sseUIFrame } from './index-
|
|
1
|
+
import { b as RagConfig, f as UniversalRagConfig, h as VectorDBConfig, y as UpsertDocument, V as VectorMatch, H as GraphDBConfig, J as GraphNode, K as Edge, M as GraphSearchResult, L as LLMConfig, E as EmbeddingConfig, I as ILLMProvider, z as VectorDBProvider, n as LLMProvider, m as EmbeddingProvider, u as RAGConfig, U as UIConfig, C as ChatMessage, g as UITransformationResponse, k as ChatOptions, l as EmbedOptions, c as IngestDocument, d as ChatResponse } from './ILLMProvider-BQXlVWNn.js';
|
|
2
|
+
export { A as AuthMode, N as BarChartData, Q as CarouselProduct, S as IRetriever, o as LatencyBreakdown, X as LineChartDataPoint, Y as MessageRole, Z as MetricCardData, O as ObservabilityTrace, _ as PieChartData, P as Product, p as ProjectAiSettings, q as ProjectAuthSettings, r as ProjectBrandingSettings, a as ProjectChatSettings, s as ProjectTelemetrySettings, t as ProjectWidgetSettings, R as RagMessage, v as RetrievalConfig, e as RetrievalResult, w as RetrievedChunk, $ as RetrivoraChunkMetadata, a0 as RetrivoraIngestedDocument, a1 as ScatterPlotDataPoint, a2 as SuggestionsResponse, a3 as TableData, T as ThemeMode, x as TokenUsage, i as UseRagChatOptions, j as UseRagChatReturn, a4 as VisualizationType, W as WidgetPosition, B as WorkflowConfig, D as createDefaultProjectSettings, F as normalizeProjectSettings, G as projectSettingsToUiConfig } from './ILLMProvider-BQXlVWNn.js';
|
|
3
|
+
import { V as Pipeline, o as DecisionContext, q as IntentCategory, I as IRenderRule, G as RenderDecision, p as IRendererStrategy } from './index-CBlH1Kvs.js';
|
|
4
|
+
export { W as ArchitectureCardProps, A as AuthenticationException, B as BatchOptions, f as BatchProcessor, g as BatchResult, h as ChartType, e as ChatViewportSize, C as ChatWidgetProps, a as ChatWindowProps, i as Chunk, j as ChunkOptions, c as ClientConfig, m as ConfigFetcher, b as ConfigProviderProps, n as ConfigurationException, X as DocumentChunker, D as DocumentUploadProps, E as EmbeddingFailedException, Y as LicenseConfigResolver, L as LicenseTierConfig, r as LicenseValidationError, s as LicenseValidationRequest, t as LicenseValidationResponse, u as LicenseValidator, M as MessageBubbleProps, Z as PipelineStep, P as ProductCardProps, d as ProductCarouselProps, v as ProviderCredentials, w as ProviderNotFoundException, _ as ProviderPill, x as RateLimitException, R as RemoteConfig, y as RemoteEmbeddingConfig, z as RemoteLLMConfig, F as RemoteVectorConfig, $ as RenderSectionDecision, H as RenderType, J as RetrievalException, K as Retrivora, N as RetrivoraError, O as RetrivoraErrorCode, Q as SDKVersionUnsupportedError, T as SDK_VERSION, a0 as Snippet, S as SourceCardProps, a1 as wrapError } from './index-CBlH1Kvs.js';
|
|
5
|
+
import { I as IProviderValidator, a as IProviderHealthChecker, H as HealthCheckResult } from './index-BVNd1Ii7.js';
|
|
6
|
+
export { C as ConfigValidator, b as HandlerOptions, V as ValidationError, c as VectorPlugin, d as createChatHandler, e as createFeedbackHandler, f as createHealthHandler, g as createHistoryHandler, h as createIngestHandler, i as createLicenseHandler, j as createRagHandler, k as createSessionsHandler, l as createStreamHandler, m as createSuggestionsHandler, n as createUploadHandler, s as sseErrorFrame, o as sseFrame, p as sseMetaFrame, q as sseObservabilityFrame, r as sseTextFrame, t as sseUIFrame } from './index-BVNd1Ii7.js';
|
|
7
7
|
import 'react';
|
|
8
8
|
import 'next/server';
|
|
9
9
|
|
|
@@ -1207,6 +1207,11 @@ declare class VisualizationDecisionEngine {
|
|
|
1207
1207
|
/**
|
|
1208
1208
|
* Clear the decision cache.
|
|
1209
1209
|
*/
|
|
1210
|
+
/**
|
|
1211
|
+
* Returns true when the generated chat response indicates there is no relevant
|
|
1212
|
+
* data or the assistant could not answer the query.
|
|
1213
|
+
*/
|
|
1214
|
+
static isNegativeResponse(response?: string): boolean;
|
|
1210
1215
|
static clearCache(): void;
|
|
1211
1216
|
/**
|
|
1212
1217
|
* Get size of current decision cache.
|
package/dist/server.js
CHANGED
|
@@ -336,7 +336,7 @@ var init_package = __esm({
|
|
|
336
336
|
"package.json"() {
|
|
337
337
|
package_default = {
|
|
338
338
|
name: "@retrivora-ai/rag-engine",
|
|
339
|
-
version: "2.6.
|
|
339
|
+
version: "2.6.6",
|
|
340
340
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
341
341
|
author: "Abhinav Alkuchi",
|
|
342
342
|
license: "UNLICENSED",
|
|
@@ -9075,7 +9075,9 @@ var LRUDecisionCache = class {
|
|
|
9075
9075
|
var _a2, _b;
|
|
9076
9076
|
const q = (context.userQuery || "").toLowerCase().trim();
|
|
9077
9077
|
const docCount = (_b = (_a2 = context.retrievedDocuments) == null ? void 0 : _a2.length) != null ? _b : 0;
|
|
9078
|
-
|
|
9078
|
+
const resp = context.llmResponse ? context.llmResponse.trim() : "";
|
|
9079
|
+
const respKey = resp ? `::resp:${resp.length}:${resp.slice(0, 32)}:${resp.slice(-32)}` : "";
|
|
9080
|
+
return `${q}::docs:${docCount}${respKey}`;
|
|
9079
9081
|
}
|
|
9080
9082
|
get(context) {
|
|
9081
9083
|
const key = this.generateKey(context);
|
|
@@ -9116,6 +9118,13 @@ var VisualizationDecisionEngine = class {
|
|
|
9116
9118
|
llmResponse,
|
|
9117
9119
|
metadata
|
|
9118
9120
|
};
|
|
9121
|
+
if (this.isNegativeResponse(llmResponse)) {
|
|
9122
|
+
return {
|
|
9123
|
+
renderType: "text",
|
|
9124
|
+
confidence: 0.99,
|
|
9125
|
+
reason: "Chat response indicates no relevant data or inability to answer; suppressing visualization."
|
|
9126
|
+
};
|
|
9127
|
+
}
|
|
9119
9128
|
const cached = this.cache.get(context);
|
|
9120
9129
|
if (cached) {
|
|
9121
9130
|
return cached;
|
|
@@ -9153,6 +9162,16 @@ var VisualizationDecisionEngine = class {
|
|
|
9153
9162
|
/**
|
|
9154
9163
|
* Clear the decision cache.
|
|
9155
9164
|
*/
|
|
9165
|
+
/**
|
|
9166
|
+
* Returns true when the generated chat response indicates there is no relevant
|
|
9167
|
+
* data or the assistant could not answer the query.
|
|
9168
|
+
*/
|
|
9169
|
+
static isNegativeResponse(response) {
|
|
9170
|
+
if (!response) return false;
|
|
9171
|
+
const text = response.trim().toLowerCase();
|
|
9172
|
+
if (!text) return false;
|
|
9173
|
+
return text.includes("cannot answer") || text.includes("can't answer") || text.includes("no relevant data") || text.includes("no data available") || text.includes("no matching data") || text.includes("don't have enough information") || text.includes("do not have enough information") || text.includes("couldn't find any") || text.includes("could not find any") || text.includes("unable to find");
|
|
9174
|
+
}
|
|
9156
9175
|
static clearCache() {
|
|
9157
9176
|
this.cache.clear();
|
|
9158
9177
|
}
|
|
@@ -9182,11 +9201,20 @@ var UITransformer = class _UITransformer {
|
|
|
9182
9201
|
* Uses the lightweight heuristic intent detector as a fallback.
|
|
9183
9202
|
* Prefer `analyzeAndDecide()` in production.
|
|
9184
9203
|
*/
|
|
9185
|
-
static transform(userQuery, retrievedData, config, trainedSchema, intent) {
|
|
9204
|
+
static transform(userQuery, retrievedData, config, trainedSchema, intent, chatResponse) {
|
|
9186
9205
|
var _a2, _b, _c;
|
|
9187
9206
|
if (!retrievedData || retrievedData.length === 0) {
|
|
9188
9207
|
return this.createTextResponse("No data available", "No relevant data found for your query.");
|
|
9189
9208
|
}
|
|
9209
|
+
if (VisualizationDecisionEngine.isNegativeResponse(chatResponse)) {
|
|
9210
|
+
return this.transformToText(retrievedData);
|
|
9211
|
+
}
|
|
9212
|
+
if (!intent && chatResponse) {
|
|
9213
|
+
const decision = VisualizationDecisionEngine.decideVisualization(userQuery, retrievedData, chatResponse);
|
|
9214
|
+
if (decision.renderType === "text") {
|
|
9215
|
+
return this.transformToText(retrievedData);
|
|
9216
|
+
}
|
|
9217
|
+
}
|
|
9190
9218
|
const resolvedIntent = intent != null ? intent : this.detectIntentHeuristic(userQuery);
|
|
9191
9219
|
const filteredData = resolvedIntent.filterInStockOnly ? retrievedData.filter((item) => this.determineStockStatus(item)) : retrievedData;
|
|
9192
9220
|
const profile = this.profileData(filteredData);
|
|
@@ -9237,15 +9265,15 @@ var UITransformer = class _UITransformer {
|
|
|
9237
9265
|
* Step 2 — Pass the intent + data to the visualization-selection prompt.
|
|
9238
9266
|
* Step 3 — Fall back to the heuristic `transform()` if either LLM call fails.
|
|
9239
9267
|
*/
|
|
9240
|
-
static async analyzeAndDecide(query, sources, llm) {
|
|
9241
|
-
const decision = VisualizationDecisionEngine.decideVisualization(query, sources);
|
|
9268
|
+
static async analyzeAndDecide(query, sources, llm, chatResponse) {
|
|
9269
|
+
const decision = VisualizationDecisionEngine.decideVisualization(query, sources, chatResponse);
|
|
9242
9270
|
if (decision.renderType === "text") {
|
|
9243
9271
|
console.debug("[UITransformer] Decision Engine selected plain text rendering \u2014 skipping visual LLM calls.");
|
|
9244
9272
|
return this.transformToText(sources);
|
|
9245
9273
|
}
|
|
9246
9274
|
let intent;
|
|
9247
9275
|
try {
|
|
9248
|
-
intent = await this.detectIntent(query, llm, sources);
|
|
9276
|
+
intent = await this.detectIntent(query, llm, sources, chatResponse);
|
|
9249
9277
|
console.debug("[UITransformer] Detected intent:", intent);
|
|
9250
9278
|
} catch (err) {
|
|
9251
9279
|
console.warn("[UITransformer] Intent detection failed; using heuristic.", err);
|
|
@@ -9274,6 +9302,8 @@ RETRIEVED DATA SCHEMA:
|
|
|
9274
9302
|
`;
|
|
9275
9303
|
const userPrompt = [
|
|
9276
9304
|
`USER QUESTION: ${query}`,
|
|
9305
|
+
...chatResponse ? ["", `CHAT RESPONSE (RESULT):
|
|
9306
|
+
${chatResponse.slice(0, 2e3)}`] : [],
|
|
9277
9307
|
"",
|
|
9278
9308
|
`DETECTED INTENT (JSON): ${JSON.stringify(intent)}`,
|
|
9279
9309
|
"",
|
|
@@ -9302,17 +9332,17 @@ RETRIEVED DATA SCHEMA:
|
|
|
9302
9332
|
}
|
|
9303
9333
|
if (!isCompatible) {
|
|
9304
9334
|
console.warn(`[UITransformer] LLM chose incompatible visualization type "${parsed.type}" for retrieved schema. Falling back to heuristic.`);
|
|
9305
|
-
return this.transform(query, sources, void 0, void 0, intent);
|
|
9335
|
+
return this.transform(query, sources, void 0, void 0, intent, chatResponse);
|
|
9306
9336
|
}
|
|
9307
9337
|
const intentAllowsTable = intent.wantsExplicitTable || ["tabular", "table", "geographic"].includes(intent.visualizationHint);
|
|
9308
9338
|
const intentWantsPieLikeChart = ["pie_chart", "donut_chart"].includes(intent.recommendedChart) || ["composition", "category_breakdown"].includes(intent.visualizationHint);
|
|
9309
9339
|
if (parsed.type === "table" && !intentAllowsTable) {
|
|
9310
9340
|
console.debug("[UITransformer] LLM chose table but intent says no. Falling back to text.");
|
|
9311
|
-
return this.transform(query, sources, void 0, void 0, intent);
|
|
9341
|
+
return this.transform(query, sources, void 0, void 0, intent, chatResponse);
|
|
9312
9342
|
}
|
|
9313
9343
|
if (intentWantsPieLikeChart && parsed.type !== "pie_chart" && this.detectCategories(sources).length > 1) {
|
|
9314
9344
|
console.debug("[UITransformer] LLM ignored pie/composition intent. Using deterministic pie chart.");
|
|
9315
|
-
return this.transform(query, sources, void 0, void 0, intent);
|
|
9345
|
+
return this.transform(query, sources, void 0, void 0, intent, chatResponse);
|
|
9316
9346
|
}
|
|
9317
9347
|
console.debug("[UITransformer] LLM chose visualization type:", parsed.type);
|
|
9318
9348
|
return parsed;
|
|
@@ -9321,7 +9351,7 @@ RETRIEVED DATA SCHEMA:
|
|
|
9321
9351
|
} catch (err) {
|
|
9322
9352
|
console.warn("[UITransformer] analyzeAndDecide LLM call failed; falling back to heuristic.", err);
|
|
9323
9353
|
}
|
|
9324
|
-
return this.transform(query, sources, void 0, void 0, intent);
|
|
9354
|
+
return this.transform(query, sources, void 0, void 0, intent, chatResponse);
|
|
9325
9355
|
}
|
|
9326
9356
|
// ─── Dynamic Intent Detection ─────────────────────────────────────────────
|
|
9327
9357
|
/**
|
|
@@ -9333,7 +9363,7 @@ RETRIEVED DATA SCHEMA:
|
|
|
9333
9363
|
* - The intent object can be reused across both the heuristic and LLM paths.
|
|
9334
9364
|
* - It is easy to unit-test intent detection in isolation.
|
|
9335
9365
|
*/
|
|
9336
|
-
static async detectIntent(query, llm, sources) {
|
|
9366
|
+
static async detectIntent(query, llm, sources, chatResponse) {
|
|
9337
9367
|
let schemaProfileText = "";
|
|
9338
9368
|
if (sources && sources.length > 0) {
|
|
9339
9369
|
const profile = this.profileData(sources);
|
|
@@ -9388,7 +9418,10 @@ RULES:
|
|
|
9388
9418
|
- isTemporal: true if time words appear (trend, historical, over time, last year, monthly, etc.)
|
|
9389
9419
|
- isComparison: true if user compares, ranks, or contrasts entities or categories.
|
|
9390
9420
|
- language: detect from the query text itself; default "en" if uncertain.`;
|
|
9391
|
-
const userPrompt = `QUERY: ${query}${
|
|
9421
|
+
const userPrompt = `QUERY: ${query}${chatResponse ? `
|
|
9422
|
+
|
|
9423
|
+
CHAT RESPONSE (RESULT):
|
|
9424
|
+
${chatResponse.slice(0, 1500)}` : ""}${schemaProfileText ? `
|
|
9392
9425
|
|
|
9393
9426
|
${schemaProfileText}` : ""}`;
|
|
9394
9427
|
const rawResponse = await llm.chat(
|
|
@@ -10472,8 +10505,8 @@ ${schemaProfileText}` : ""}`;
|
|
|
10472
10505
|
// ─── Visualization Prompt ─────────────────────────────────────────────────
|
|
10473
10506
|
static buildVisualizationSystemPrompt() {
|
|
10474
10507
|
return `You are a data visualization expert embedded in a RAG chat system.
|
|
10475
|
-
You will receive a user question, a pre-computed INTENT object, and structured data from a vector database.
|
|
10476
|
-
Your ONLY job is to return a single JSON object describing how to visualize the data.
|
|
10508
|
+
You will receive a user question, the generated chat response (result), a pre-computed INTENT object, and structured data from a vector database.
|
|
10509
|
+
Your ONLY job is to return a single JSON object describing how to visualize the result and data after the chat response (or "text" if no visualization is needed).
|
|
10477
10510
|
The INTENT object is authoritative \u2014 honor it. For example:
|
|
10478
10511
|
- If intent.wantsExplicitTable is false, never return type "table".
|
|
10479
10512
|
- If intent.isTemporal is true, prefer line_chart.
|
|
@@ -11362,24 +11395,6 @@ ${context}`;
|
|
|
11362
11395
|
SchemaMapper.train(this.llmProvider, ns, allMetadataKeys).catch(() => {
|
|
11363
11396
|
});
|
|
11364
11397
|
}
|
|
11365
|
-
const isProductQ = UITransformer.isProductQueryPublic(effectiveQuestion);
|
|
11366
|
-
const uiTransformationPromise = isProductQ ? Promise.resolve(
|
|
11367
|
-
UITransformer.transform(
|
|
11368
|
-
effectiveQuestion,
|
|
11369
|
-
sources,
|
|
11370
|
-
this.config,
|
|
11371
|
-
cachedSchema,
|
|
11372
|
-
{ visualizationHint: "product_browse", recommendedChart: "text", filterInStockOnly: false, wantsExplicitTable: false, isTemporal: false, isComparison: false, language: "en" }
|
|
11373
|
-
)
|
|
11374
|
-
) : this.generateUiTransformation(
|
|
11375
|
-
effectiveQuestion,
|
|
11376
|
-
sources,
|
|
11377
|
-
cachedSchema,
|
|
11378
|
-
hasNumericPredicates
|
|
11379
|
-
).catch((uiError) => {
|
|
11380
|
-
Logger.warn("[Pipeline] UI transformation failed concurrently", { error: String(uiError) });
|
|
11381
|
-
return UITransformer.transform(effectiveQuestion, sources, this.config, cachedSchema);
|
|
11382
|
-
});
|
|
11383
11398
|
let hallucinationScoringPromise = Promise.resolve(void 0);
|
|
11384
11399
|
const restrictionSuffix = "\n\n(IMPORTANT: Format your response beautifully using rich Markdown! Use bolding for emphasis, headings (##) for structure, bullet points for lists, and proper line breaks between paragraphs to make it highly readable. However, NEVER generate Markdown tables, HTML figures, or text charts (the UI renders requested charts separately, so NEVER say you cannot create, display, draw, render, or provide a chart/visualization). If listing products, use simple markdown bullet points or comma-separated names. NEVER use plus signs (+) to separate product names, category names, or list items. For product description/detail questions, provide customer-facing prose only and do NOT list internal catalog fields such as Handle, Body (HTML), Vendor, Type, Tags, Published, Option, Variant, SKU, or raw metadata labels. You CAN use numbers for years/counts like 2006 or 5800, but NEVER put a dollar sign ($) before them.)";
|
|
11385
11400
|
const isClaude37 = this.config.llm.model.includes("claude-3-7-sonnet");
|
|
@@ -11527,6 +11542,26 @@ ${context}`;
|
|
|
11527
11542
|
estimatedCostUsd: estimateCostUsd(promptTokens, completionTokens, this.config.llm.model)
|
|
11528
11543
|
};
|
|
11529
11544
|
const awaitHallucination = ((_E = this.config.llm.options) == null ? void 0 : _E.awaitHallucination) === true;
|
|
11545
|
+
const isProductQ = UITransformer.isProductQueryPublic(effectiveQuestion);
|
|
11546
|
+
const uiTransformationPromise = isProductQ ? Promise.resolve(
|
|
11547
|
+
UITransformer.transform(
|
|
11548
|
+
effectiveQuestion,
|
|
11549
|
+
sources,
|
|
11550
|
+
this.config,
|
|
11551
|
+
cachedSchema,
|
|
11552
|
+
{ visualizationHint: "product_browse", recommendedChart: "text", filterInStockOnly: false, wantsExplicitTable: false, isTemporal: false, isComparison: false, language: "en" },
|
|
11553
|
+
fullReply
|
|
11554
|
+
)
|
|
11555
|
+
) : this.generateUiTransformation(
|
|
11556
|
+
effectiveQuestion,
|
|
11557
|
+
sources,
|
|
11558
|
+
fullReply,
|
|
11559
|
+
cachedSchema,
|
|
11560
|
+
hasNumericPredicates
|
|
11561
|
+
).catch((uiError) => {
|
|
11562
|
+
Logger.warn("[Pipeline] UI transformation failed after generation", { error: String(uiError) });
|
|
11563
|
+
return UITransformer.transform(effectiveQuestion, sources, this.config, cachedSchema, void 0, fullReply);
|
|
11564
|
+
});
|
|
11530
11565
|
const [uiTransformation, hallucinationResult] = yield new __await(Promise.all([
|
|
11531
11566
|
uiTransformationPromise,
|
|
11532
11567
|
awaitHallucination ? hallucinationScoringPromise : Promise.resolve(void 0)
|
|
@@ -11594,10 +11629,10 @@ ${context}`;
|
|
|
11594
11629
|
* Universal retrieval method combining all enabled providers.
|
|
11595
11630
|
* Uses an LRU-bounded embedding cache to avoid re-embedding the same query.
|
|
11596
11631
|
*/
|
|
11597
|
-
async generateUiTransformation(question, sources, cachedSchema, forceDeterministic = false) {
|
|
11632
|
+
async generateUiTransformation(question, sources, chatResponse, cachedSchema, forceDeterministic = false) {
|
|
11598
11633
|
var _a2;
|
|
11599
11634
|
if (!sources || sources.length === 0) {
|
|
11600
|
-
return UITransformer.transform(question, sources, this.config, cachedSchema);
|
|
11635
|
+
return UITransformer.transform(question, sources, this.config, cachedSchema, void 0, chatResponse);
|
|
11601
11636
|
}
|
|
11602
11637
|
if (UITransformer.isProductQueryPublic(question)) {
|
|
11603
11638
|
return UITransformer.transform(
|
|
@@ -11605,18 +11640,19 @@ ${context}`;
|
|
|
11605
11640
|
sources,
|
|
11606
11641
|
this.config,
|
|
11607
11642
|
cachedSchema,
|
|
11608
|
-
{ visualizationHint: "product_browse", recommendedChart: "text", filterInStockOnly: false, wantsExplicitTable: false, isTemporal: false, isComparison: false, language: "en" }
|
|
11643
|
+
{ visualizationHint: "product_browse", recommendedChart: "text", filterInStockOnly: false, wantsExplicitTable: false, isTemporal: false, isComparison: false, language: "en" },
|
|
11644
|
+
chatResponse
|
|
11609
11645
|
);
|
|
11610
11646
|
}
|
|
11611
11647
|
const enableLlmUiTransform = ((_a2 = this.config.llm.options) == null ? void 0 : _a2.enableLlmUiTransform) === true;
|
|
11612
11648
|
if (forceDeterministic || !enableLlmUiTransform) {
|
|
11613
|
-
return UITransformer.transform(question, sources, this.config, cachedSchema);
|
|
11649
|
+
return UITransformer.transform(question, sources, this.config, cachedSchema, void 0, chatResponse);
|
|
11614
11650
|
}
|
|
11615
11651
|
try {
|
|
11616
|
-
return await UITransformer.analyzeAndDecide(question, sources, this.llmRouter.get("fast"));
|
|
11652
|
+
return await UITransformer.analyzeAndDecide(question, sources, this.llmRouter.get("fast"), chatResponse);
|
|
11617
11653
|
} catch (err) {
|
|
11618
11654
|
Logger.warn("[Pipeline] generateUiTransformation failed, using heuristic fallback", { error: String(err) });
|
|
11619
|
-
return UITransformer.transform(question, sources, this.config, cachedSchema);
|
|
11655
|
+
return UITransformer.transform(question, sources, this.config, cachedSchema, void 0, chatResponse);
|
|
11620
11656
|
}
|
|
11621
11657
|
}
|
|
11622
11658
|
applyStructuredFilters(sources, filter) {
|
|
@@ -14287,14 +14323,14 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
14287
14323
|
let uiTransformation = responseChunk == null ? void 0 : responseChunk.ui_transformation;
|
|
14288
14324
|
if (sources.length > 0) {
|
|
14289
14325
|
try {
|
|
14290
|
-
uiTransformation = (_a3 = responseChunk == null ? void 0 : responseChunk.ui_transformation) != null ? _a3 : UITransformer.transform(message, sources, plugin.getConfig());
|
|
14326
|
+
uiTransformation = (_a3 = responseChunk == null ? void 0 : responseChunk.ui_transformation) != null ? _a3 : UITransformer.transform(message, sources, plugin.getConfig(), void 0, void 0, fullReply);
|
|
14291
14327
|
if (uiTransformation) {
|
|
14292
14328
|
enqueue(sseUIFrame(uiTransformation));
|
|
14293
14329
|
}
|
|
14294
14330
|
} catch (transformError) {
|
|
14295
14331
|
console.warn("[createStreamHandler] UI transformation warning:", transformError);
|
|
14296
14332
|
try {
|
|
14297
|
-
const fallback = UITransformer.transform(message, sources, plugin.getConfig());
|
|
14333
|
+
const fallback = UITransformer.transform(message, sources, plugin.getConfig(), void 0, void 0, fullReply);
|
|
14298
14334
|
if (fallback) {
|
|
14299
14335
|
uiTransformation = fallback;
|
|
14300
14336
|
enqueue(sseUIFrame(fallback));
|
package/dist/server.mjs
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from "./chunk-VW3U4MMX.mjs";
|
|
16
16
|
import {
|
|
17
17
|
LicenseValidator
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-2GDW6W5C.mjs";
|
|
19
19
|
import {
|
|
20
20
|
AnthropicProvider,
|
|
21
21
|
CarouselRendererStrategy,
|
|
@@ -96,7 +96,7 @@ import {
|
|
|
96
96
|
sseUIFrame,
|
|
97
97
|
validateCitations,
|
|
98
98
|
wrapUntrustedSources
|
|
99
|
-
} from "./chunk-
|
|
99
|
+
} from "./chunk-F656WHWF.mjs";
|
|
100
100
|
import {
|
|
101
101
|
AuthenticationException,
|
|
102
102
|
BatchProcessor,
|
|
@@ -114,16 +114,16 @@ import {
|
|
|
114
114
|
import "./chunk-SG6XYLQE.mjs";
|
|
115
115
|
import {
|
|
116
116
|
PineconeProvider
|
|
117
|
-
} from "./chunk-
|
|
117
|
+
} from "./chunk-JNPVVOIF.mjs";
|
|
118
118
|
import {
|
|
119
119
|
ConfigFetcher,
|
|
120
120
|
createDefaultProjectSettings,
|
|
121
121
|
normalizeProjectSettings,
|
|
122
122
|
projectSettingsToUiConfig
|
|
123
|
-
} from "./chunk-
|
|
123
|
+
} from "./chunk-557UWRCG.mjs";
|
|
124
124
|
import {
|
|
125
125
|
SDK_VERSION
|
|
126
|
-
} from "./chunk-
|
|
126
|
+
} from "./chunk-Q4MVJ7NW.mjs";
|
|
127
127
|
import {
|
|
128
128
|
PostgreSQLProvider
|
|
129
129
|
} from "./chunk-MGJ6V2IT.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retrivora-ai/rag-engine",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.6",
|
|
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": "UNLICENSED",
|