@retrivora-ai/rag-engine 1.8.1 → 1.8.2

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 (55) hide show
  1. package/dist/{ILLMProvider-BfRgI1Xh.d.mts → ILLMProvider-BOJFz3Na.d.mts} +47 -1
  2. package/dist/{ILLMProvider-BfRgI1Xh.d.ts → ILLMProvider-BOJFz3Na.d.ts} +47 -1
  3. package/dist/{MultiTablePostgresProvider-YY7LPNJK.mjs → MultiTablePostgresProvider-ZLGSKTJR.mjs} +1 -1
  4. package/dist/chunk-ICKRMZQK.mjs +76 -0
  5. package/dist/{chunk-BFYLQYQU.mjs → chunk-LZVVLSDN.mjs} +192 -100
  6. package/dist/{chunk-R3RGUMHE.mjs → chunk-OZFBG4BA.mjs} +121 -48
  7. package/dist/handlers/index.d.mts +2 -2
  8. package/dist/handlers/index.d.ts +2 -2
  9. package/dist/handlers/index.js +368 -147
  10. package/dist/handlers/index.mjs +4 -1
  11. package/dist/{index-BV0z5mb6.d.mts → index-BwpcaziY.d.ts} +4 -2
  12. package/dist/{index-1Z4GuYBi.d.ts → index-D3V9Et2M.d.mts} +4 -2
  13. package/dist/index.d.mts +23 -3
  14. package/dist/index.d.ts +23 -3
  15. package/dist/index.js +1143 -790
  16. package/dist/index.mjs +1065 -770
  17. package/dist/server.d.mts +15 -25
  18. package/dist/server.d.ts +15 -25
  19. package/dist/server.js +366 -147
  20. package/dist/server.mjs +3 -2
  21. package/package.json +4 -2
  22. package/src/app/api/upload/route.ts +4 -0
  23. package/src/app/constants.tsx +2 -2
  24. package/src/app/page.tsx +12 -321
  25. package/src/components/AmbientBackground.tsx +29 -0
  26. package/src/components/ArchitectureCard.tsx +17 -0
  27. package/src/components/ArchitectureCardsSection.tsx +15 -0
  28. package/src/components/ChatWindow.tsx +32 -0
  29. package/src/components/CodeViewer.tsx +51 -0
  30. package/src/components/ConfigProvider.tsx +1 -0
  31. package/src/components/DocViewer.tsx +37 -0
  32. package/src/components/DocumentUpload.tsx +44 -1
  33. package/src/components/Documentation.tsx +58 -0
  34. package/src/components/DynamicChart.tsx +27 -2
  35. package/src/components/Hero.tsx +59 -0
  36. package/src/components/HourglassLoader.tsx +87 -0
  37. package/src/components/Lifecycle.tsx +37 -0
  38. package/src/components/MarkdownComponents.tsx +140 -0
  39. package/src/components/MessageBubble.tsx +88 -1010
  40. package/src/components/Navbar.tsx +55 -0
  41. package/src/components/ObservabilityPanel.tsx +374 -0
  42. package/src/components/ProductCard.tsx +3 -1
  43. package/src/components/UIDispatcher.tsx +344 -0
  44. package/src/components/VisualizationRenderer.tsx +48 -26
  45. package/src/core/Pipeline.ts +186 -76
  46. package/src/handlers/index.ts +72 -12
  47. package/src/hooks/useRagChat.ts +19 -9
  48. package/src/index.ts +9 -1
  49. package/src/providers/vectordb/MultiTablePostgresProvider.ts +150 -64
  50. package/src/types/chat.ts +2 -0
  51. package/src/types/index.ts +52 -0
  52. package/src/types/props.ts +9 -1
  53. package/src/utils/ProductExtractor.ts +347 -0
  54. package/src/utils/UITransformer.ts +4 -53
  55. package/src/utils/synonyms.ts +78 -0
@@ -7,6 +7,8 @@ interface RagMessage extends ChatMessage {
7
7
  id: string;
8
8
  sources?: VectorMatch[];
9
9
  uiTransformation?: unknown;
10
+ /** Full observability trace emitted by the backend. Only present on assistant messages. */
11
+ trace?: ObservabilityTrace;
10
12
  createdAt: string;
11
13
  }
12
14
  interface ChatOptions {
@@ -233,6 +235,48 @@ interface RagConfig {
233
235
  graphDb?: GraphDBConfig;
234
236
  }
235
237
 
238
+ /** Per-stage latency breakdown for a single RAG request. */
239
+ interface LatencyBreakdown {
240
+ embedMs: number;
241
+ retrieveMs: number;
242
+ rerankMs?: number;
243
+ generateMs: number;
244
+ totalMs: number;
245
+ }
246
+ /** Token usage reported by the LLM (or estimated when the provider doesn't expose it). */
247
+ interface TokenUsage {
248
+ promptTokens: number;
249
+ completionTokens: number;
250
+ totalTokens: number;
251
+ /** Rough cost in USD — estimated from token counts and model pricing. */
252
+ estimatedCostUsd?: number;
253
+ }
254
+ /** A single retrieved chunk annotated with its retrieval context. */
255
+ interface RetrievedChunk {
256
+ id: string | number;
257
+ score: number;
258
+ content: string;
259
+ metadata: Record<string, unknown>;
260
+ namespace: string;
261
+ }
262
+ /**
263
+ * Full observability trace for one RAG request.
264
+ * Emitted by the backend as an SSE frame and stored on each RagMessage.
265
+ */
266
+ interface ObservabilityTrace {
267
+ requestId: string;
268
+ query: string;
269
+ rewrittenQuery?: string;
270
+ systemPrompt: string;
271
+ userPrompt: string;
272
+ chunks: RetrievedChunk[];
273
+ latency: LatencyBreakdown;
274
+ tokens?: TokenUsage;
275
+ /** 0 = fully grounded, 1 = likely hallucinated. */
276
+ hallucinationScore?: number;
277
+ hallucinationReason?: string;
278
+ timestamp: string;
279
+ }
236
280
  interface VectorMatch {
237
281
  id: string | number;
238
282
  score: number;
@@ -255,6 +299,8 @@ interface ChatResponse {
255
299
  sources: VectorMatch[];
256
300
  graphData?: GraphSearchResult;
257
301
  ui_transformation?: unknown;
302
+ /** Observability trace — populated by the instrumented Pipeline. */
303
+ trace?: ObservabilityTrace;
258
304
  }
259
305
  interface GraphNode {
260
306
  id: string;
@@ -331,4 +377,4 @@ interface ILLMProvider {
331
377
  ping(): Promise<boolean>;
332
378
  }
333
379
 
334
- export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, Product as P, RagMessage as R, UIConfig as U, VectorMatch as V, UseRagChatOptions as a, UseRagChatReturn as b, ChatOptions as c, ChatResponse as d, EmbeddingConfig as e, EmbeddingProvider as f, IngestDocument as g, LLMProvider as h, RAGConfig as i, RagConfig as j, UpsertDocument as k, VectorDBConfig as l, VectorDBProvider as m, RetrievalResult as n, GraphNode as o, Edge as p, GraphSearchResult as q };
380
+ export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, ObservabilityTrace as O, Product as P, RagMessage as R, TokenUsage as T, UIConfig as U, VectorMatch as V, UseRagChatOptions as a, UseRagChatReturn as b, ChatOptions as c, ChatResponse as d, EmbeddingConfig as e, EmbeddingProvider as f, IngestDocument as g, LLMProvider as h, LatencyBreakdown as i, RAGConfig as j, RagConfig as k, RetrievedChunk as l, UpsertDocument as m, VectorDBConfig as n, VectorDBProvider as o, RetrievalResult as p, GraphNode as q, Edge as r, GraphSearchResult as s };
@@ -7,6 +7,8 @@ interface RagMessage extends ChatMessage {
7
7
  id: string;
8
8
  sources?: VectorMatch[];
9
9
  uiTransformation?: unknown;
10
+ /** Full observability trace emitted by the backend. Only present on assistant messages. */
11
+ trace?: ObservabilityTrace;
10
12
  createdAt: string;
11
13
  }
12
14
  interface ChatOptions {
@@ -233,6 +235,48 @@ interface RagConfig {
233
235
  graphDb?: GraphDBConfig;
234
236
  }
235
237
 
238
+ /** Per-stage latency breakdown for a single RAG request. */
239
+ interface LatencyBreakdown {
240
+ embedMs: number;
241
+ retrieveMs: number;
242
+ rerankMs?: number;
243
+ generateMs: number;
244
+ totalMs: number;
245
+ }
246
+ /** Token usage reported by the LLM (or estimated when the provider doesn't expose it). */
247
+ interface TokenUsage {
248
+ promptTokens: number;
249
+ completionTokens: number;
250
+ totalTokens: number;
251
+ /** Rough cost in USD — estimated from token counts and model pricing. */
252
+ estimatedCostUsd?: number;
253
+ }
254
+ /** A single retrieved chunk annotated with its retrieval context. */
255
+ interface RetrievedChunk {
256
+ id: string | number;
257
+ score: number;
258
+ content: string;
259
+ metadata: Record<string, unknown>;
260
+ namespace: string;
261
+ }
262
+ /**
263
+ * Full observability trace for one RAG request.
264
+ * Emitted by the backend as an SSE frame and stored on each RagMessage.
265
+ */
266
+ interface ObservabilityTrace {
267
+ requestId: string;
268
+ query: string;
269
+ rewrittenQuery?: string;
270
+ systemPrompt: string;
271
+ userPrompt: string;
272
+ chunks: RetrievedChunk[];
273
+ latency: LatencyBreakdown;
274
+ tokens?: TokenUsage;
275
+ /** 0 = fully grounded, 1 = likely hallucinated. */
276
+ hallucinationScore?: number;
277
+ hallucinationReason?: string;
278
+ timestamp: string;
279
+ }
236
280
  interface VectorMatch {
237
281
  id: string | number;
238
282
  score: number;
@@ -255,6 +299,8 @@ interface ChatResponse {
255
299
  sources: VectorMatch[];
256
300
  graphData?: GraphSearchResult;
257
301
  ui_transformation?: unknown;
302
+ /** Observability trace — populated by the instrumented Pipeline. */
303
+ trace?: ObservabilityTrace;
258
304
  }
259
305
  interface GraphNode {
260
306
  id: string;
@@ -331,4 +377,4 @@ interface ILLMProvider {
331
377
  ping(): Promise<boolean>;
332
378
  }
333
379
 
334
- export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, Product as P, RagMessage as R, UIConfig as U, VectorMatch as V, UseRagChatOptions as a, UseRagChatReturn as b, ChatOptions as c, ChatResponse as d, EmbeddingConfig as e, EmbeddingProvider as f, IngestDocument as g, LLMProvider as h, RAGConfig as i, RagConfig as j, UpsertDocument as k, VectorDBConfig as l, VectorDBProvider as m, RetrievalResult as n, GraphNode as o, Edge as p, GraphSearchResult as q };
380
+ export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, ObservabilityTrace as O, Product as P, RagMessage as R, TokenUsage as T, UIConfig as U, VectorMatch as V, UseRagChatOptions as a, UseRagChatReturn as b, ChatOptions as c, ChatResponse as d, EmbeddingConfig as e, EmbeddingProvider as f, IngestDocument as g, LLMProvider as h, LatencyBreakdown as i, RAGConfig as j, RagConfig as k, RetrievedChunk as l, UpsertDocument as m, VectorDBConfig as n, VectorDBProvider as o, RetrievalResult as p, GraphNode as q, Edge as r, GraphSearchResult as s };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MultiTablePostgresProvider
3
- } from "./chunk-R3RGUMHE.mjs";
3
+ } from "./chunk-OZFBG4BA.mjs";
4
4
  import "./chunk-IMP6FUCY.mjs";
5
5
  import "./chunk-X4TOT24V.mjs";
6
6
  export {
@@ -0,0 +1,76 @@
1
+ // src/utils/synonyms.ts
2
+ var FIELD_SYNONYMS = {
3
+ name: ["product", "item", "title", "label", "heading", "subject", "product name", "item name"],
4
+ price: ["cost", "amount", "msrp", "price", "rate", "value", "price_usd"],
5
+ brand: ["manufacturer", "vendor", "make", "company", "brand_name", "supplier"],
6
+ image: [
7
+ "imageUrl",
8
+ "thumbnail",
9
+ "img",
10
+ "url",
11
+ "photo",
12
+ "picture",
13
+ "media",
14
+ "image_url",
15
+ "main_image",
16
+ "product_image",
17
+ "thumb"
18
+ ],
19
+ stock: [
20
+ "inventory",
21
+ "quantity",
22
+ "count",
23
+ "availability",
24
+ "stock_level",
25
+ "inStock",
26
+ "is_available",
27
+ "in stock",
28
+ "status"
29
+ ],
30
+ description: ["summary", "content", "body", "text", "info", "details"],
31
+ link: ["url", "href", "product_url", "page_url", "link"]
32
+ };
33
+ function addSynonyms(customSynonyms) {
34
+ for (const [key, aliases] of Object.entries(customSynonyms)) {
35
+ if (!FIELD_SYNONYMS[key]) {
36
+ FIELD_SYNONYMS[key] = [];
37
+ }
38
+ const existing = new Set(FIELD_SYNONYMS[key].map((s) => s.toLowerCase()));
39
+ for (const alias of aliases) {
40
+ if (!existing.has(alias.toLowerCase())) {
41
+ FIELD_SYNONYMS[key].push(alias);
42
+ existing.add(alias.toLowerCase());
43
+ }
44
+ }
45
+ }
46
+ }
47
+ function resolveMetadataValue(meta, uiKey) {
48
+ var _a;
49
+ const synonyms = (_a = FIELD_SYNONYMS[uiKey]) != null ? _a : [];
50
+ const keys = Object.keys(meta);
51
+ const systemKeys = ["namespace", "filename", "filesize", "filetype", "docid", "uploadedat", "dimension", "chunkindex"];
52
+ let match = keys.find((k) => k.toLowerCase() === uiKey.toLowerCase());
53
+ if (match !== void 0) return meta[match];
54
+ match = keys.find((k) => synonyms.map((s) => s.toLowerCase()).includes(k.toLowerCase()));
55
+ if (match !== void 0) return meta[match];
56
+ const isBlacklisted = (kl) => {
57
+ return systemKeys.includes(kl) || kl.startsWith("option1") || kl.startsWith("option2") || kl.startsWith("option3");
58
+ };
59
+ match = keys.find((k) => {
60
+ const kl = k.toLowerCase();
61
+ if (isBlacklisted(kl)) return false;
62
+ return kl.includes(uiKey.toLowerCase());
63
+ });
64
+ if (match !== void 0) return meta[match];
65
+ match = keys.find((k) => {
66
+ const kl = k.toLowerCase();
67
+ if (isBlacklisted(kl)) return false;
68
+ return synonyms.some((sk) => kl.includes(sk.toLowerCase()) || sk.toLowerCase().includes(kl));
69
+ });
70
+ return match !== void 0 ? meta[match] : void 0;
71
+ }
72
+
73
+ export {
74
+ addSynonyms,
75
+ resolveMetadataValue
76
+ };