@retrivora-ai/rag-engine 2.0.2 → 2.0.4
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/FREE_TIER_ARCHITECTURE.md +232 -0
- package/README.md +9 -0
- package/dist/{ILLMProvider-DMxLyTdq.d.mts → ILLMProvider-0rRBYbVW.d.mts} +133 -1
- package/dist/{ILLMProvider-DMxLyTdq.d.ts → ILLMProvider-0rRBYbVW.d.ts} +133 -1
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +681 -17
- package/dist/handlers/index.mjs +681 -17
- package/dist/index-B1wGUlSL.d.mts +532 -0
- package/dist/{index-tzwc7UhY.d.ts → index-BIHHp_f6.d.ts} +1 -1
- package/dist/{index-DHsFLJXQ.d.mts → index-BvODr57d.d.mts} +1 -1
- package/dist/index-DcklhThn.d.ts +532 -0
- package/dist/index.css +51 -3
- package/dist/index.d.mts +6 -105
- package/dist/index.d.ts +6 -105
- package/dist/index.js +1918 -8
- package/dist/index.mjs +1913 -8
- package/dist/server.d.mts +51 -7
- package/dist/server.d.ts +51 -7
- package/dist/server.js +723 -17
- package/dist/server.mjs +706 -17
- package/package.json +9 -7
- package/src/app/page.tsx +54 -18
- package/src/components/ChatWindow.tsx +2 -2
- package/src/components/DocumentUpload.tsx +5 -4
- package/src/components/MessageBubble.tsx +2 -4
- package/src/core/DatabaseStorage.ts +5 -1
- package/src/core/LicenseVerifier.ts +1 -1
- package/src/core/Pipeline.ts +23 -5
- package/src/handlers/index.ts +48 -1
- package/src/index.ts +22 -4
- package/src/rendering/IntentClassifier.ts +167 -0
- package/src/rendering/RendererRegistry.ts +164 -0
- package/src/rendering/RuleEngine.ts +67 -0
- package/src/rendering/VisualizationDecisionEngine.ts +164 -0
- package/src/rendering/__tests__/VisualizationDecisionEngine.test.ts +237 -0
- package/src/rendering/index.ts +12 -0
- package/src/rendering/rules/Rule1SpecificInfoRule.ts +28 -0
- package/src/rendering/rules/Rule2ComparisonRule.ts +24 -0
- package/src/rendering/rules/Rule3ProductDiscoveryRule.ts +28 -0
- package/src/rendering/rules/Rule4AnalyticalRule.ts +38 -0
- package/src/rendering/rules/Rule5MixedResponseRule.ts +29 -0
- package/src/rendering/rules/Rule6SmallResultSetRule.ts +24 -0
- package/src/rendering/rules/Rule7LargeTableRule.ts +35 -0
- package/src/rendering/types.ts +96 -0
- package/src/server.ts +3 -2
- package/src/types/index.ts +48 -0
- package/src/utils/DocumentParser.ts +64 -28
- package/src/utils/UITransformer.ts +15 -4
- package/dist/index-CfkqZd2Y.d.ts +0 -197
- package/dist/index-xygonxpW.d.mts +0 -197
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import { CSSProperties, MouseEvent, ReactNode, ElementType } from 'react';
|
|
2
|
+
import { y as Product, m as UIConfig, j as RagMessage, q as VectorMatch, J as UITransformationResponse, i as RagConfig, I as ILLMProvider, f as IngestDocument, C as ChatMessage, c as ChatResponse, z as RetrievalResult, n as UniversalRagConfig } from './ILLMProvider-0rRBYbVW.js';
|
|
3
|
+
|
|
4
|
+
interface ArchitectureCardProps {
|
|
5
|
+
icon: ReactNode;
|
|
6
|
+
title: string;
|
|
7
|
+
description: string;
|
|
8
|
+
badge: string;
|
|
9
|
+
badgeColor: string;
|
|
10
|
+
}
|
|
11
|
+
interface Snippet {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
description: string;
|
|
15
|
+
code: string;
|
|
16
|
+
language: string;
|
|
17
|
+
}
|
|
18
|
+
interface PipelineStep {
|
|
19
|
+
step: string;
|
|
20
|
+
Icon: ElementType;
|
|
21
|
+
title: string;
|
|
22
|
+
desc: string;
|
|
23
|
+
colors: {
|
|
24
|
+
from: string;
|
|
25
|
+
to: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
interface ProviderPill {
|
|
29
|
+
Icon: ElementType;
|
|
30
|
+
label: string;
|
|
31
|
+
}
|
|
32
|
+
type ChatViewportSize = 'compact' | 'medium' | 'large';
|
|
33
|
+
interface ChatWindowProps {
|
|
34
|
+
/** Additional className for the wrapper div */
|
|
35
|
+
className?: string;
|
|
36
|
+
/** Inline styles for the wrapper div */
|
|
37
|
+
style?: CSSProperties;
|
|
38
|
+
/** Called when the close button is clicked (for widget mode) */
|
|
39
|
+
onClose?: () => void;
|
|
40
|
+
/** Whether to show a close (X) button in the header */
|
|
41
|
+
showClose?: boolean;
|
|
42
|
+
/** Called when the user starts dragging the resize handle */
|
|
43
|
+
onResizeStart?: (e: MouseEvent) => void;
|
|
44
|
+
/** Called when the user clicks the reset size button */
|
|
45
|
+
onResetResize?: () => void;
|
|
46
|
+
/** Whether the window has been resized from its default */
|
|
47
|
+
isResized?: boolean;
|
|
48
|
+
/** Called when the user clicks the maximize/minimize button */
|
|
49
|
+
onMaximize?: () => void;
|
|
50
|
+
/** Whether the window is currently maximized */
|
|
51
|
+
isMaximized?: boolean;
|
|
52
|
+
/** Called when the user clicks 'Add to Cart' on a product */
|
|
53
|
+
onAddToCart?: (product: Product) => void;
|
|
54
|
+
/** Optional custom API URL to send chat messages to */
|
|
55
|
+
apiUrl?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Base URL for Retrivora SDK history/feedback/sessions endpoints.
|
|
58
|
+
* Defaults to '/api/retrivora'. Set this to match your catch-all route location.
|
|
59
|
+
*/
|
|
60
|
+
retrivoraApiBase?: string;
|
|
61
|
+
/** Optional custom headers to send with the chat request */
|
|
62
|
+
headers?: Record<string, string>;
|
|
63
|
+
}
|
|
64
|
+
interface ChatWidgetProps {
|
|
65
|
+
/** Position of the floating button. Defaults to bottom-right. */
|
|
66
|
+
position?: 'bottom-right' | 'bottom-left';
|
|
67
|
+
/** Called when the user clicks 'Add to Cart' on a product */
|
|
68
|
+
onAddToCart?: (product: Product) => void;
|
|
69
|
+
/** Optional custom API URL to send chat messages to */
|
|
70
|
+
apiUrl?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Base URL for Retrivora SDK history/feedback/sessions endpoints.
|
|
73
|
+
* Defaults to '/api/retrivora'.
|
|
74
|
+
*/
|
|
75
|
+
retrivoraApiBase?: string;
|
|
76
|
+
/** Optional custom headers to send with the chat request */
|
|
77
|
+
headers?: Record<string, string>;
|
|
78
|
+
}
|
|
79
|
+
interface MessageBubbleProps {
|
|
80
|
+
message: RagMessage;
|
|
81
|
+
sources?: VectorMatch[];
|
|
82
|
+
isStreaming?: boolean;
|
|
83
|
+
primaryColor: string;
|
|
84
|
+
accentColor: string;
|
|
85
|
+
onAddToCart?: (product: Product) => void;
|
|
86
|
+
viewportSize?: ChatViewportSize;
|
|
87
|
+
/** Called when the user clicks thumbs up or thumbs down on an assistant message */
|
|
88
|
+
onFeedback?: (messageId: string, rating: 'thumbs_up' | 'thumbs_down') => void;
|
|
89
|
+
}
|
|
90
|
+
interface ProductCardProps {
|
|
91
|
+
product: Product;
|
|
92
|
+
primaryColor?: string;
|
|
93
|
+
onAddToCart?: (product: Product) => void;
|
|
94
|
+
}
|
|
95
|
+
interface ProductCarouselProps {
|
|
96
|
+
products: Product[];
|
|
97
|
+
primaryColor?: string;
|
|
98
|
+
onAddToCart?: (product: Product) => void;
|
|
99
|
+
}
|
|
100
|
+
interface DocumentUploadProps {
|
|
101
|
+
/** Optional namespace for the upload */
|
|
102
|
+
namespace?: string;
|
|
103
|
+
/** Callback when upload completes */
|
|
104
|
+
onUploadComplete?: (results: unknown) => void;
|
|
105
|
+
/** Additional className */
|
|
106
|
+
className?: string;
|
|
107
|
+
}
|
|
108
|
+
interface SourceCardProps {
|
|
109
|
+
source: VectorMatch;
|
|
110
|
+
index: number;
|
|
111
|
+
}
|
|
112
|
+
interface ClientConfig {
|
|
113
|
+
projectId: string;
|
|
114
|
+
ui: Required<UIConfig>;
|
|
115
|
+
embedding?: {
|
|
116
|
+
model?: string;
|
|
117
|
+
dimensions?: number;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
interface ConfigProviderProps {
|
|
121
|
+
config?: {
|
|
122
|
+
projectId?: string;
|
|
123
|
+
ui?: Partial<UIConfig>;
|
|
124
|
+
embedding?: {
|
|
125
|
+
model?: string;
|
|
126
|
+
dimensions?: number;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
children: ReactNode;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Primary rendering outcome types supported by the decision engine.
|
|
134
|
+
*/
|
|
135
|
+
type RenderType = 'text' | 'table' | 'carousel' | 'chart' | 'mixed' | 'card' | 'none';
|
|
136
|
+
/**
|
|
137
|
+
* Chart sub-types available when renderType === 'chart'.
|
|
138
|
+
*/
|
|
139
|
+
type ChartType = 'bar' | 'line' | 'pie' | 'scatter';
|
|
140
|
+
/**
|
|
141
|
+
* High-level intent classification categories.
|
|
142
|
+
*/
|
|
143
|
+
type IntentCategory = 'information_lookup' | 'product_search' | 'recommendation' | 'comparison' | 'analytics' | 'trend_analysis' | 'ranking' | 'summarization';
|
|
144
|
+
/**
|
|
145
|
+
* Individual section specifier for multi-section (mixed) responses.
|
|
146
|
+
*/
|
|
147
|
+
interface RenderSectionDecision {
|
|
148
|
+
type: RenderType;
|
|
149
|
+
chartType?: ChartType;
|
|
150
|
+
title?: string;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Final decision produced by the Visualization Decision Engine.
|
|
154
|
+
*/
|
|
155
|
+
interface RenderDecision {
|
|
156
|
+
/** Primary rendering format selected */
|
|
157
|
+
renderType: RenderType;
|
|
158
|
+
/** Specific chart sub-type if renderType === 'chart' */
|
|
159
|
+
chartType?: ChartType;
|
|
160
|
+
/** Confidence score between 0.0 and 1.0 */
|
|
161
|
+
confidence: number;
|
|
162
|
+
/** Human-readable explanation of why this decision was reached */
|
|
163
|
+
reason: string;
|
|
164
|
+
/** Sub-sections if renderType === 'mixed' */
|
|
165
|
+
sections?: RenderSectionDecision[];
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Context provided to the intent classifier & decision engine rules.
|
|
169
|
+
*/
|
|
170
|
+
interface DecisionContext {
|
|
171
|
+
/** Original user prompt/query string */
|
|
172
|
+
userQuery: string;
|
|
173
|
+
/** Vector DB retrieved documents / context records */
|
|
174
|
+
retrievedDocuments?: VectorMatch[];
|
|
175
|
+
/** Optional LLM text response if already available */
|
|
176
|
+
llmResponse?: string;
|
|
177
|
+
/** Additional custom metadata or config settings */
|
|
178
|
+
metadata?: Record<string, unknown>;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Interface implemented by rule strategies in the Rule Engine.
|
|
182
|
+
*/
|
|
183
|
+
interface IRenderRule {
|
|
184
|
+
/** Unique name of the decision rule */
|
|
185
|
+
name: string;
|
|
186
|
+
/** Precedence score (higher priority rules run first) */
|
|
187
|
+
priority: number;
|
|
188
|
+
/** Evaluate the rule against current query context and classified intent */
|
|
189
|
+
evaluate(context: DecisionContext, intent: IntentCategory): RenderDecision | null;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Interface implemented by pluggable Renderer Strategies in RendererRegistry.
|
|
193
|
+
*/
|
|
194
|
+
interface IRendererStrategy {
|
|
195
|
+
/** Render type identifier handled by this strategy */
|
|
196
|
+
type: RenderType | string;
|
|
197
|
+
/** Transform input data into a standardized UITransformationResponse payload */
|
|
198
|
+
render(data: unknown, options?: Record<string, unknown>): UITransformationResponse;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
interface DataSignals {
|
|
202
|
+
rowCount: number;
|
|
203
|
+
hasNumericFields: boolean;
|
|
204
|
+
hasDateFields: boolean;
|
|
205
|
+
hasCategoricalFields: boolean;
|
|
206
|
+
isProductLike: boolean;
|
|
207
|
+
numericFieldCount: number;
|
|
208
|
+
categoricalFieldCount: number;
|
|
209
|
+
}
|
|
210
|
+
declare class IntentClassifier {
|
|
211
|
+
/**
|
|
212
|
+
* Fast, zero-latency classifier that maps a user query and optional data context
|
|
213
|
+
* into a high-level IntentCategory.
|
|
214
|
+
*/
|
|
215
|
+
static classify(context: DecisionContext): {
|
|
216
|
+
intent: IntentCategory;
|
|
217
|
+
signals: DataSignals;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Extract key data structure signals from retrieved documents.
|
|
221
|
+
*/
|
|
222
|
+
static extractDataSignals(context: DecisionContext): DataSignals;
|
|
223
|
+
private static isInformationLookup;
|
|
224
|
+
private static isComparisonQuery;
|
|
225
|
+
private static isProductQuery;
|
|
226
|
+
private static isRecommendationQuery;
|
|
227
|
+
private static isTrendQuery;
|
|
228
|
+
private static isRankingQuery;
|
|
229
|
+
private static isAnalyticsQuery;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
declare class RuleEngine {
|
|
233
|
+
private rules;
|
|
234
|
+
constructor();
|
|
235
|
+
/**
|
|
236
|
+
* Register standard rules in priority order.
|
|
237
|
+
*/
|
|
238
|
+
private registerDefaultRules;
|
|
239
|
+
/**
|
|
240
|
+
* Add or replace a rule in the engine.
|
|
241
|
+
* Automatically keeps rules sorted by descending priority.
|
|
242
|
+
*/
|
|
243
|
+
registerRule(rule: IRenderRule): void;
|
|
244
|
+
/**
|
|
245
|
+
* Evaluate context against rules in descending priority order.
|
|
246
|
+
* Returns the first non-null RenderDecision.
|
|
247
|
+
*/
|
|
248
|
+
evaluate(context: DecisionContext, intent: IntentCategory): RenderDecision;
|
|
249
|
+
/**
|
|
250
|
+
* List all registered rules.
|
|
251
|
+
*/
|
|
252
|
+
getRegisteredRules(): Array<{
|
|
253
|
+
name: string;
|
|
254
|
+
priority: number;
|
|
255
|
+
}>;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
declare class TextRendererStrategy implements IRendererStrategy {
|
|
259
|
+
readonly type = "text";
|
|
260
|
+
render(data: unknown, options?: Record<string, unknown>): UITransformationResponse;
|
|
261
|
+
}
|
|
262
|
+
declare class TableRendererStrategy implements IRendererStrategy {
|
|
263
|
+
readonly type = "table";
|
|
264
|
+
render(data: unknown, options?: Record<string, unknown>): UITransformationResponse;
|
|
265
|
+
}
|
|
266
|
+
declare class CarouselRendererStrategy implements IRendererStrategy {
|
|
267
|
+
readonly type = "carousel";
|
|
268
|
+
render(data: unknown, options?: Record<string, unknown>): UITransformationResponse;
|
|
269
|
+
}
|
|
270
|
+
declare class ChartRendererStrategy implements IRendererStrategy {
|
|
271
|
+
readonly type = "chart";
|
|
272
|
+
render(data: unknown, options?: Record<string, unknown>): UITransformationResponse;
|
|
273
|
+
}
|
|
274
|
+
declare class MixedRendererStrategy implements IRendererStrategy {
|
|
275
|
+
readonly type = "mixed";
|
|
276
|
+
render(data: unknown, options?: Record<string, unknown>): UITransformationResponse;
|
|
277
|
+
}
|
|
278
|
+
declare class RendererRegistry {
|
|
279
|
+
private static strategies;
|
|
280
|
+
/**
|
|
281
|
+
* Register a new renderer strategy.
|
|
282
|
+
* Enables seamless addition of custom visualizers (Timeline, Maps, Flow Diagrams, etc.).
|
|
283
|
+
*/
|
|
284
|
+
static registerStrategy(strategy: IRendererStrategy): void;
|
|
285
|
+
/**
|
|
286
|
+
* Retrieve a registered renderer strategy by type string.
|
|
287
|
+
*/
|
|
288
|
+
static getStrategy(type: string): IRendererStrategy;
|
|
289
|
+
/**
|
|
290
|
+
* Check if a renderer strategy is registered.
|
|
291
|
+
*/
|
|
292
|
+
static hasStrategy(type: string): boolean;
|
|
293
|
+
/**
|
|
294
|
+
* List all registered strategy types.
|
|
295
|
+
*/
|
|
296
|
+
static getRegisteredTypes(): string[];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* High-Performance Visualization Decision Engine.
|
|
301
|
+
* Intelligently determines whether to render text, table, carousel, chart, or mixed sections
|
|
302
|
+
* BEFORE expensive visual generation or LLM visual calls execute.
|
|
303
|
+
*/
|
|
304
|
+
declare class VisualizationDecisionEngine {
|
|
305
|
+
private static ruleEngine;
|
|
306
|
+
private static cache;
|
|
307
|
+
/**
|
|
308
|
+
* Evaluate user query, documents, and context to produce a RenderDecision.
|
|
309
|
+
* Execution time is < 1ms for cached or rule-matched queries.
|
|
310
|
+
*/
|
|
311
|
+
static decideVisualization(userQuery: string, retrievedDocuments?: VectorMatch[], llmResponse?: string, metadata?: Record<string, unknown>): RenderDecision;
|
|
312
|
+
/**
|
|
313
|
+
* Convenience helper to decide AND render the data into a UITransformationResponse.
|
|
314
|
+
*/
|
|
315
|
+
static render(userQuery: string, retrievedDocuments?: VectorMatch[], llmResponse?: string, metadata?: Record<string, unknown>): UITransformationResponse;
|
|
316
|
+
/**
|
|
317
|
+
* Register a custom rule in the rule engine.
|
|
318
|
+
*/
|
|
319
|
+
static registerRule(rule: IRenderRule): void;
|
|
320
|
+
/**
|
|
321
|
+
* Register a custom renderer strategy.
|
|
322
|
+
*/
|
|
323
|
+
static registerRendererStrategy(strategy: IRendererStrategy): void;
|
|
324
|
+
/**
|
|
325
|
+
* Clear the decision cache.
|
|
326
|
+
*/
|
|
327
|
+
static clearCache(): void;
|
|
328
|
+
/**
|
|
329
|
+
* Get size of current decision cache.
|
|
330
|
+
*/
|
|
331
|
+
static getCacheSize(): number;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Top-level function export matching prompt specification.
|
|
335
|
+
*/
|
|
336
|
+
declare function decideVisualization(userQuery: string, retrievedDocuments?: VectorMatch[], llmResponse?: string, metadata?: Record<string, unknown>): RenderDecision;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* DocumentChunker — splits long text into overlapping chunks
|
|
340
|
+
* suitable for vector embedding and retrieval.
|
|
341
|
+
*
|
|
342
|
+
* Strategy: sentence-aware sliding window
|
|
343
|
+
* 1. Split on sentence boundaries
|
|
344
|
+
* 2. Accumulate sentences into chunks up to `chunkSize` characters
|
|
345
|
+
* 3. Carry over `chunkOverlap` characters from the previous chunk
|
|
346
|
+
*/
|
|
347
|
+
interface Chunk {
|
|
348
|
+
id: string;
|
|
349
|
+
content: string;
|
|
350
|
+
metadata?: Record<string, unknown>;
|
|
351
|
+
}
|
|
352
|
+
interface ChunkOptions {
|
|
353
|
+
/** Target chunk size in characters (default 1000) */
|
|
354
|
+
chunkSize?: number;
|
|
355
|
+
/** Overlap between consecutive chunks in characters (default 200) */
|
|
356
|
+
chunkOverlap?: number;
|
|
357
|
+
/** Source document identifier used as ID prefix */
|
|
358
|
+
docId?: string | number;
|
|
359
|
+
/** Extra metadata to attach to every chunk */
|
|
360
|
+
metadata?: Record<string, unknown>;
|
|
361
|
+
/** Characters used to split text, in order of priority */
|
|
362
|
+
separators?: string[];
|
|
363
|
+
}
|
|
364
|
+
declare class DocumentChunker {
|
|
365
|
+
private readonly chunkSize;
|
|
366
|
+
private readonly chunkOverlap;
|
|
367
|
+
private readonly separators;
|
|
368
|
+
constructor(chunkSize?: number, chunkOverlap?: number, separators?: string[]);
|
|
369
|
+
/**
|
|
370
|
+
* Split a single text string into overlapping chunks using a recursive strategy.
|
|
371
|
+
* Preserves structural boundaries (Markdown headers) where possible.
|
|
372
|
+
*/
|
|
373
|
+
chunk(text: string, options?: ChunkOptions): Chunk[];
|
|
374
|
+
private recursiveSplit;
|
|
375
|
+
chunkMany(documents: Array<{
|
|
376
|
+
content: string;
|
|
377
|
+
docId?: string | number;
|
|
378
|
+
metadata?: Record<string, unknown>;
|
|
379
|
+
}>): Chunk[];
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Pipeline — orchestrates the RAG flow: Embed → Search → Augment → Generate.
|
|
384
|
+
*
|
|
385
|
+
* Features:
|
|
386
|
+
* - Lazy initialization of providers
|
|
387
|
+
* - Batch processing with retry logic
|
|
388
|
+
* - Smart embedding strategy (integrated / separate / external)
|
|
389
|
+
* - Error recovery for transient failures
|
|
390
|
+
* - Multi-tenancy support via namespacing
|
|
391
|
+
* - LRU-bounded embedding cache (max 500 entries, prevents memory leaks)
|
|
392
|
+
* - Full observability tracing (latency, tokens, hallucination scoring)
|
|
393
|
+
*/
|
|
394
|
+
declare class Pipeline {
|
|
395
|
+
private config;
|
|
396
|
+
private vectorDB;
|
|
397
|
+
private graphDB?;
|
|
398
|
+
private llmProvider;
|
|
399
|
+
private embeddingProvider;
|
|
400
|
+
private llmRouter;
|
|
401
|
+
private chunker;
|
|
402
|
+
private llamaIngestor?;
|
|
403
|
+
private entityExtractor?;
|
|
404
|
+
private reranker;
|
|
405
|
+
private agent?;
|
|
406
|
+
private mcpRegistry?;
|
|
407
|
+
private multiAgentCoordinator?;
|
|
408
|
+
/** LRU-bounded cache: avoids re-embedding identical queries within the same process. */
|
|
409
|
+
private embeddingCache;
|
|
410
|
+
private initialised;
|
|
411
|
+
/** Namespace-specific static cold context cache for CAG */
|
|
412
|
+
private coldContexts;
|
|
413
|
+
constructor(config: RagConfig);
|
|
414
|
+
/**
|
|
415
|
+
* Expose the underlying LLM provider (set after initialize()).
|
|
416
|
+
* Used by the stream handler to pass to UITransformer.analyzeAndDecide().
|
|
417
|
+
*/
|
|
418
|
+
getLLMProvider(): ILLMProvider | undefined;
|
|
419
|
+
initialize(): Promise<void>;
|
|
420
|
+
private loadColdContext;
|
|
421
|
+
/**
|
|
422
|
+
* Ingest documents with automatic chunking, embedding, and batch upsert.
|
|
423
|
+
*/
|
|
424
|
+
ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
|
|
425
|
+
docId: string | number;
|
|
426
|
+
chunksIngested: number;
|
|
427
|
+
}>>;
|
|
428
|
+
/** Step 1: Chunk the document content. */
|
|
429
|
+
private prepareChunks;
|
|
430
|
+
/**
|
|
431
|
+
* Step 2: Generate embeddings for chunks with retry logic.
|
|
432
|
+
* Uses batchEmbed when available for efficiency; falls back to sequential embedding.
|
|
433
|
+
*/
|
|
434
|
+
private processEmbeddings;
|
|
435
|
+
/** Step 3: Upsert chunks to vector database with retry logic. */
|
|
436
|
+
private processUpserts;
|
|
437
|
+
/** Step 4: Optional graph-based entity extraction and ingestion. */
|
|
438
|
+
private processGraphIngestion;
|
|
439
|
+
runNormalQuery(question: string, history?: ChatMessage[], namespace?: string): Promise<{
|
|
440
|
+
reply: string;
|
|
441
|
+
sources: any[];
|
|
442
|
+
}>;
|
|
443
|
+
ask(question: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
|
|
444
|
+
askStream(question: string, history?: ChatMessage[], namespace?: string): AsyncIterable<string | ChatResponse>;
|
|
445
|
+
/**
|
|
446
|
+
* High-performance streaming RAG flow.
|
|
447
|
+
* Yields text chunks first, then the retrieval metadata + observability trace at the end.
|
|
448
|
+
*
|
|
449
|
+
* Latency optimizations:
|
|
450
|
+
* - Strategy classification runs in parallel with query embedding (saves ~400ms)
|
|
451
|
+
* - Hallucination scoring is fire-and-forget (doesn't block metadata yield)
|
|
452
|
+
* - UITransformation is computed after text streaming and emitted with metadata
|
|
453
|
+
* - SchemaMapper.train runs while answer generation streams
|
|
454
|
+
*/
|
|
455
|
+
askStreamInternal(question: string, history?: ChatMessage[], namespace?: string): AsyncIterable<string | ChatResponse>;
|
|
456
|
+
/**
|
|
457
|
+
* Universal retrieval method combining all enabled providers.
|
|
458
|
+
* Uses an LRU-bounded embedding cache to avoid re-embedding the same query.
|
|
459
|
+
*/
|
|
460
|
+
private generateUiTransformation;
|
|
461
|
+
private applyStructuredFilters;
|
|
462
|
+
private resolveNumericPredicateValue;
|
|
463
|
+
private extractNumericValueFromContent;
|
|
464
|
+
private matchesNumericPredicate;
|
|
465
|
+
private normalizeComparableField;
|
|
466
|
+
private fieldSimilarityScore;
|
|
467
|
+
private fieldTokens;
|
|
468
|
+
private toFiniteNumber;
|
|
469
|
+
retrieve(query: string, options: {
|
|
470
|
+
namespace?: string;
|
|
471
|
+
topK?: number;
|
|
472
|
+
filter?: Record<string, unknown>;
|
|
473
|
+
}): Promise<RetrievalResult>;
|
|
474
|
+
/** Rewrite the user query for better retrieval performance. */
|
|
475
|
+
private rewriteQuery;
|
|
476
|
+
/** Generate 3-5 short, relevant questions based on the vector database content. */
|
|
477
|
+
getSuggestions(query: string, namespace?: string): Promise<string[]>;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Public SDK facade matching the prompt-level Retrivora API.
|
|
482
|
+
*
|
|
483
|
+
* It keeps provider details behind configuration and delegates execution to the
|
|
484
|
+
* existing Pipeline implementation.
|
|
485
|
+
*/
|
|
486
|
+
declare class Retrivora {
|
|
487
|
+
private readonly pipeline;
|
|
488
|
+
readonly config: RagConfig;
|
|
489
|
+
constructor(config?: UniversalRagConfig);
|
|
490
|
+
initialize(): Promise<void>;
|
|
491
|
+
ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
|
|
492
|
+
docId: string | number;
|
|
493
|
+
chunksIngested: number;
|
|
494
|
+
}>>;
|
|
495
|
+
ask(question: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
|
|
496
|
+
askStream(question: string, history?: ChatMessage[], namespace?: string): AsyncIterable<string | ChatResponse>;
|
|
497
|
+
getPipeline(): Pipeline;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Named SDK exceptions make failures machine-readable for host applications.
|
|
502
|
+
*/
|
|
503
|
+
type RetrivoraErrorCode = 'PROVIDER_NOT_FOUND' | 'EMBEDDING_FAILED' | 'RETRIEVAL_FAILED' | 'RATE_LIMITED' | 'CONFIGURATION_ERROR' | 'AUTHENTICATION_ERROR';
|
|
504
|
+
declare class RetrivoraError extends Error {
|
|
505
|
+
readonly code: RetrivoraErrorCode;
|
|
506
|
+
readonly details?: unknown;
|
|
507
|
+
constructor(message: string, code: RetrivoraErrorCode, details?: unknown);
|
|
508
|
+
}
|
|
509
|
+
declare class ProviderNotFoundException extends RetrivoraError {
|
|
510
|
+
constructor(providerType: string, provider: string, details?: unknown);
|
|
511
|
+
}
|
|
512
|
+
declare class EmbeddingFailedException extends RetrivoraError {
|
|
513
|
+
constructor(message?: string, details?: unknown);
|
|
514
|
+
}
|
|
515
|
+
declare class RetrievalException extends RetrivoraError {
|
|
516
|
+
constructor(message?: string, details?: unknown);
|
|
517
|
+
}
|
|
518
|
+
declare class RateLimitException extends RetrivoraError {
|
|
519
|
+
constructor(message?: string, details?: unknown);
|
|
520
|
+
}
|
|
521
|
+
declare class ConfigurationException extends RetrivoraError {
|
|
522
|
+
constructor(message: string, details?: unknown);
|
|
523
|
+
}
|
|
524
|
+
declare class AuthenticationException extends RetrivoraError {
|
|
525
|
+
constructor(message?: string, details?: unknown);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Wraps any unknown error into an appropriate RetrivoraError subclass.
|
|
529
|
+
*/
|
|
530
|
+
declare function wrapError(err: unknown, defaultCode: RetrivoraErrorCode, defaultMessage?: string): RetrivoraError;
|
|
531
|
+
|
|
532
|
+
export { AuthenticationException as A, DocumentChunker as B, type ChatWidgetProps as C, type DocumentUploadProps as D, EmbeddingFailedException as E, MixedRendererStrategy as F, Pipeline as G, type PipelineStep as H, type IRenderRule as I, type ProviderPill as J, type RenderSectionDecision as K, type Snippet as L, type MessageBubbleProps as M, TextRendererStrategy as N, wrapError as O, type ProductCardProps as P, RateLimitException as R, type SourceCardProps as S, TableRendererStrategy as T, VisualizationDecisionEngine as V, type ChatWindowProps as a, type ConfigProviderProps as b, type ClientConfig as c, type ProductCarouselProps as d, type ChartType as e, type Chunk as f, type ChunkOptions as g, ConfigurationException as h, type DecisionContext as i, type IRendererStrategy as j, type IntentCategory as k, IntentClassifier as l, ProviderNotFoundException as m, type RenderDecision as n, type RenderType as o, RendererRegistry as p, RetrievalException as q, Retrivora as r, RetrivoraError as s, type RetrivoraErrorCode as t, RuleEngine as u, decideVisualization as v, type ArchitectureCardProps as w, CarouselRendererStrategy as x, ChartRendererStrategy as y, type ChatViewportSize as z };
|
package/dist/index.css
CHANGED
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
--color-blue-300: oklch(80.9% 0.105 251.813);
|
|
53
53
|
--color-blue-400: oklch(70.7% 0.165 254.624);
|
|
54
54
|
--color-blue-500: oklch(62.3% 0.214 259.815);
|
|
55
|
+
--color-blue-600: oklch(54.6% 0.245 262.881);
|
|
55
56
|
--color-blue-700: oklch(48.8% 0.243 264.376);
|
|
56
57
|
--color-blue-800: oklch(42.4% 0.199 265.638);
|
|
57
58
|
--color-blue-900: oklch(37.9% 0.146 265.522);
|
|
@@ -113,6 +114,7 @@
|
|
|
113
114
|
--container-xs: 20rem;
|
|
114
115
|
--container-md: 28rem;
|
|
115
116
|
--container-2xl: 42rem;
|
|
117
|
+
--container-4xl: 56rem;
|
|
116
118
|
--text-xs: 0.75rem;
|
|
117
119
|
--text-xs--line-height: calc(1 / 0.75);
|
|
118
120
|
--text-sm: 0.875rem;
|
|
@@ -126,6 +128,7 @@
|
|
|
126
128
|
--font-weight-medium: 500;
|
|
127
129
|
--font-weight-semibold: 600;
|
|
128
130
|
--font-weight-bold: 700;
|
|
131
|
+
--tracking-tight: -0.025em;
|
|
129
132
|
--tracking-wider: 0.05em;
|
|
130
133
|
--tracking-widest: 0.1em;
|
|
131
134
|
--leading-tight: 1.25;
|
|
@@ -618,6 +621,9 @@
|
|
|
618
621
|
.h-\[400\%\] {
|
|
619
622
|
height: 400%;
|
|
620
623
|
}
|
|
624
|
+
.h-\[600px\] {
|
|
625
|
+
height: 600px;
|
|
626
|
+
}
|
|
621
627
|
.h-full {
|
|
622
628
|
height: 100%;
|
|
623
629
|
}
|
|
@@ -729,6 +735,9 @@
|
|
|
729
735
|
.max-w-2xl {
|
|
730
736
|
max-width: var(--container-2xl);
|
|
731
737
|
}
|
|
738
|
+
.max-w-4xl {
|
|
739
|
+
max-width: var(--container-4xl);
|
|
740
|
+
}
|
|
732
741
|
.max-w-\[90\%\] {
|
|
733
742
|
max-width: 90%;
|
|
734
743
|
}
|
|
@@ -976,6 +985,13 @@
|
|
|
976
985
|
margin-block-end: calc(calc(var(--spacing) * 5) * calc(1 - var(--tw-space-y-reverse)));
|
|
977
986
|
}
|
|
978
987
|
}
|
|
988
|
+
.space-y-8 {
|
|
989
|
+
:where(& > :not(:last-child)) {
|
|
990
|
+
--tw-space-y-reverse: 0;
|
|
991
|
+
margin-block-start: calc(calc(var(--spacing) * 8) * var(--tw-space-y-reverse));
|
|
992
|
+
margin-block-end: calc(calc(var(--spacing) * 8) * calc(1 - var(--tw-space-y-reverse)));
|
|
993
|
+
}
|
|
994
|
+
}
|
|
979
995
|
.divide-y {
|
|
980
996
|
:where(& > :not(:last-child)) {
|
|
981
997
|
--tw-divide-y-reverse: 0;
|
|
@@ -1458,9 +1474,6 @@
|
|
|
1458
1474
|
.py-4 {
|
|
1459
1475
|
padding-block: calc(var(--spacing) * 4);
|
|
1460
1476
|
}
|
|
1461
|
-
.py-12 {
|
|
1462
|
-
padding-block: calc(var(--spacing) * 12);
|
|
1463
|
-
}
|
|
1464
1477
|
.pt-1 {
|
|
1465
1478
|
padding-top: calc(var(--spacing) * 1);
|
|
1466
1479
|
}
|
|
@@ -1476,6 +1489,9 @@
|
|
|
1476
1489
|
.pb-4 {
|
|
1477
1490
|
padding-bottom: calc(var(--spacing) * 4);
|
|
1478
1491
|
}
|
|
1492
|
+
.pb-6 {
|
|
1493
|
+
padding-bottom: calc(var(--spacing) * 6);
|
|
1494
|
+
}
|
|
1479
1495
|
.text-center {
|
|
1480
1496
|
text-align: center;
|
|
1481
1497
|
}
|
|
@@ -1543,6 +1559,10 @@
|
|
|
1543
1559
|
--tw-font-weight: var(--font-weight-semibold);
|
|
1544
1560
|
font-weight: var(--font-weight-semibold);
|
|
1545
1561
|
}
|
|
1562
|
+
.tracking-tight {
|
|
1563
|
+
--tw-tracking: var(--tracking-tight);
|
|
1564
|
+
letter-spacing: var(--tracking-tight);
|
|
1565
|
+
}
|
|
1546
1566
|
.tracking-wider {
|
|
1547
1567
|
--tw-tracking: var(--tracking-wider);
|
|
1548
1568
|
letter-spacing: var(--tracking-wider);
|
|
@@ -1587,6 +1607,9 @@
|
|
|
1587
1607
|
.text-amber-950 {
|
|
1588
1608
|
color: var(--color-amber-950);
|
|
1589
1609
|
}
|
|
1610
|
+
.text-blue-600 {
|
|
1611
|
+
color: var(--color-blue-600);
|
|
1612
|
+
}
|
|
1590
1613
|
.text-blue-700 {
|
|
1591
1614
|
color: var(--color-blue-700);
|
|
1592
1615
|
}
|
|
@@ -2213,6 +2236,11 @@
|
|
|
2213
2236
|
border-color: var(--color-emerald-500);
|
|
2214
2237
|
}
|
|
2215
2238
|
}
|
|
2239
|
+
.focus\:ring-blue-500 {
|
|
2240
|
+
&:focus {
|
|
2241
|
+
--tw-ring-color: var(--color-blue-500);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2216
2244
|
.active\:scale-95 {
|
|
2217
2245
|
&:active {
|
|
2218
2246
|
--tw-scale-x: 95%;
|
|
@@ -2268,6 +2296,11 @@
|
|
|
2268
2296
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
2269
2297
|
}
|
|
2270
2298
|
}
|
|
2299
|
+
.md\:p-12 {
|
|
2300
|
+
@media (width >= 48rem) {
|
|
2301
|
+
padding: calc(var(--spacing) * 12);
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2271
2304
|
.md\:opacity-0 {
|
|
2272
2305
|
@media (width >= 48rem) {
|
|
2273
2306
|
opacity: 0%;
|
|
@@ -2381,6 +2414,16 @@
|
|
|
2381
2414
|
}
|
|
2382
2415
|
}
|
|
2383
2416
|
}
|
|
2417
|
+
.dark\:border-slate-700 {
|
|
2418
|
+
@media (prefers-color-scheme: dark) {
|
|
2419
|
+
border-color: var(--color-slate-700);
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
.dark\:border-slate-800 {
|
|
2423
|
+
@media (prefers-color-scheme: dark) {
|
|
2424
|
+
border-color: var(--color-slate-800);
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2384
2427
|
.dark\:border-white\/5 {
|
|
2385
2428
|
@media (prefers-color-scheme: dark) {
|
|
2386
2429
|
border-color: color-mix(in srgb, #fff 5%, transparent);
|
|
@@ -2990,6 +3033,11 @@
|
|
|
2990
3033
|
color: var(--color-rose-400);
|
|
2991
3034
|
}
|
|
2992
3035
|
}
|
|
3036
|
+
.dark\:text-slate-100 {
|
|
3037
|
+
@media (prefers-color-scheme: dark) {
|
|
3038
|
+
color: var(--color-slate-100);
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
2993
3041
|
.dark\:text-slate-300 {
|
|
2994
3042
|
@media (prefers-color-scheme: dark) {
|
|
2995
3043
|
color: var(--color-slate-300);
|