@retrivora-ai/rag-engine 1.9.2 → 1.9.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.
Files changed (60) hide show
  1. package/README.md +27 -0
  2. package/dist/{ILLMProvider-Bw2A28nU.d.mts → ILLMProvider-DNhyOYoK.d.mts} +41 -1
  3. package/dist/{ILLMProvider-Bw2A28nU.d.ts → ILLMProvider-DNhyOYoK.d.ts} +41 -1
  4. package/dist/handlers/index.d.mts +2 -2
  5. package/dist/handlers/index.d.ts +2 -2
  6. package/dist/handlers/index.js +563 -205
  7. package/dist/handlers/index.mjs +563 -205
  8. package/dist/index-C9v7-tWd.d.mts +183 -0
  9. package/dist/{index-B70ZLkfG.d.mts → index-CHL1jdYm.d.mts} +1 -1
  10. package/dist/index-CjQdL0cX.d.ts +183 -0
  11. package/dist/{index-DVu-mkAM.d.ts → index-Hgbwl9X4.d.ts} +1 -1
  12. package/dist/index.css +40 -0
  13. package/dist/index.d.mts +3 -3
  14. package/dist/index.d.ts +3 -3
  15. package/dist/index.js +326 -158
  16. package/dist/index.mjs +312 -151
  17. package/dist/server.d.mts +15 -94
  18. package/dist/server.d.ts +15 -94
  19. package/dist/server.js +623 -205
  20. package/dist/server.mjs +615 -205
  21. package/package.json +1 -1
  22. package/src/app/api/chat/route.ts +2 -2
  23. package/src/app/api/health/route.ts +3 -2
  24. package/src/app/api/ingest/route.ts +3 -2
  25. package/src/app/api/suggestions/route.ts +3 -2
  26. package/src/app/api/upload/route.ts +3 -2
  27. package/src/app/constants.tsx +85 -30
  28. package/src/app/layout.tsx +18 -7
  29. package/src/components/MessageBubble.tsx +39 -2
  30. package/src/components/ThinkingBlock.tsx +75 -0
  31. package/src/components/VisualizationRenderer.tsx +27 -1
  32. package/src/config/RagConfig.ts +47 -0
  33. package/src/config/serverConfig.ts +25 -0
  34. package/src/core/ConfigResolver.ts +56 -4
  35. package/src/core/ConfigValidator.ts +2 -1
  36. package/src/core/Pipeline.ts +226 -68
  37. package/src/core/ProviderRegistry.ts +11 -2
  38. package/src/core/QueryProcessor.ts +38 -4
  39. package/src/core/Retrivora.ts +51 -0
  40. package/src/exceptions/index.ts +59 -0
  41. package/src/handlers/index.ts +2 -0
  42. package/src/hooks/useRagChat.ts +26 -4
  43. package/src/index.ts +25 -1
  44. package/src/lib/plugin.ts +24 -0
  45. package/src/llm/LLMFactory.ts +4 -1
  46. package/src/llm/providers/AnthropicProvider.ts +70 -20
  47. package/src/llm/providers/GeminiProvider.ts +14 -15
  48. package/src/llm/providers/OllamaProvider.ts +13 -16
  49. package/src/llm/providers/OpenAIProvider.ts +9 -14
  50. package/src/llm/providers/UniversalLLMAdapter.ts +5 -5
  51. package/src/llm/utils.ts +46 -0
  52. package/src/providers/vectordb/MongoDBProvider.ts +19 -7
  53. package/src/providers/vectordb/MultiTablePostgresProvider.ts +45 -13
  54. package/src/rag/EntityExtractor.ts +2 -2
  55. package/src/rag/Reranker.ts +9 -16
  56. package/src/server.ts +27 -1
  57. package/src/types/chat.ts +7 -0
  58. package/src/utils/UITransformer.ts +73 -4
  59. package/dist/DocumentChunker-Dh9TvmGG.d.mts +0 -45
  60. package/dist/DocumentChunker-Dh9TvmGG.d.ts +0 -45
package/README.md CHANGED
@@ -103,6 +103,33 @@ await pipeline.ingest([{ docId: 'readme', content: 'Your document text here' }])
103
103
  const { reply, sources } = await pipeline.ask('What is the refund policy?');
104
104
  ```
105
105
 
106
+ ### 4. Use the Retrivora SDK facade
107
+
108
+ ```ts
109
+ import { Retrivora } from '@retrivora-ai/rag-engine/server';
110
+
111
+ const ai = new Retrivora({
112
+ llm: {
113
+ provider: 'openai',
114
+ model: 'gpt-5',
115
+ },
116
+ embedding: {
117
+ provider: 'openai',
118
+ },
119
+ vectorDatabase: {
120
+ provider: 'pinecone',
121
+ },
122
+ retrieval: {
123
+ strategy: 'hybrid',
124
+ },
125
+ workflow: {
126
+ type: 'agentic-rag',
127
+ },
128
+ });
129
+
130
+ const { reply, sources } = await ai.ask('What is the refund policy?');
131
+ ```
132
+
106
133
  ---
107
134
 
108
135
  ## Configuration Reference
@@ -10,6 +10,13 @@ interface RagMessage extends ChatMessage {
10
10
  /** Full observability trace emitted by the backend. Only present on assistant messages. */
11
11
  trace?: ObservabilityTrace;
12
12
  createdAt: string;
13
+ /**
14
+ * Chain-of-thought reasoning from the LLM.
15
+ * Populated by native Anthropic extended thinking or simulated <think> tag stripping.
16
+ */
17
+ thinking?: string;
18
+ /** Wall-clock ms the model spent in the thinking phase. */
19
+ thinkingMs?: number;
13
20
  }
14
21
  interface ChatOptions {
15
22
  /** Override max tokens for this specific call */
@@ -227,6 +234,24 @@ interface RAGConfig {
227
234
  */
228
235
  vectorKeywords?: string[];
229
236
  }
237
+ interface RetrievalConfig {
238
+ /** Retrieval strategy selected by the host app. */
239
+ strategy?: 'vector' | 'keyword' | 'hybrid' | 'multi-query' | 'self-query' | 'parent-document' | 'contextual-compression' | 'ensemble' | 'recursive' | 'agentic';
240
+ /** Number of documents/chunks retrieved per query. */
241
+ topK?: number;
242
+ /** Minimum similarity score to include a retrieved chunk. */
243
+ scoreThreshold?: number;
244
+ /** Whether to rerank retrieved chunks before generation. */
245
+ useReranking?: boolean;
246
+ /** Provider-specific retrieval options for future strategies. */
247
+ options?: Record<string, unknown>;
248
+ }
249
+ interface WorkflowConfig {
250
+ /** High-level workflow selector from the SDK prompt. */
251
+ type?: 'simple-rag' | 'rag' | 'hybrid-rag' | 'graph-rag' | 'agentic-rag' | 'agentic';
252
+ /** Future workflow/provider-specific options. */
253
+ options?: Record<string, unknown>;
254
+ }
230
255
  interface RagConfig {
231
256
  /**
232
257
  * Unique identifier for the consuming project.
@@ -246,6 +271,21 @@ interface RagConfig {
246
271
  /** Optional Graph database configuration */
247
272
  graphDb?: GraphDBConfig;
248
273
  }
274
+ /**
275
+ * Friendly SDK configuration accepted by the top-level Retrivora facade.
276
+ * It supports the prompt's `vectorDatabase`, `retrieval`, and `workflow`
277
+ * naming while normalizing to the internal RagConfig shape.
278
+ */
279
+ type UniversalRagConfig = Partial<Omit<RagConfig, 'vectorDb' | 'rag' | 'llm' | 'embedding' | 'graphDb'>> & {
280
+ vectorDb?: Partial<VectorDBConfig>;
281
+ vectorDatabase?: Partial<VectorDBConfig>;
282
+ llm?: Partial<LLMConfig>;
283
+ embedding?: Partial<EmbeddingConfig>;
284
+ graphDb?: Partial<GraphDBConfig>;
285
+ retrieval?: RetrievalConfig;
286
+ rag?: RAGConfig;
287
+ workflow?: WorkflowConfig;
288
+ };
249
289
 
250
290
  /** Per-stage latency breakdown for a single RAG request. */
251
291
  interface LatencyBreakdown {
@@ -389,4 +429,4 @@ interface ILLMProvider {
389
429
  ping(): Promise<boolean>;
390
430
  }
391
431
 
392
- 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 };
432
+ 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, WorkflowConfig as W, 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, RetrievalConfig as l, RetrievedChunk as m, UniversalRagConfig as n, UpsertDocument as o, VectorDBConfig as p, VectorDBProvider as q, GraphNode as r, Edge as s, GraphSearchResult as t, RetrievalResult as u };
@@ -10,6 +10,13 @@ interface RagMessage extends ChatMessage {
10
10
  /** Full observability trace emitted by the backend. Only present on assistant messages. */
11
11
  trace?: ObservabilityTrace;
12
12
  createdAt: string;
13
+ /**
14
+ * Chain-of-thought reasoning from the LLM.
15
+ * Populated by native Anthropic extended thinking or simulated <think> tag stripping.
16
+ */
17
+ thinking?: string;
18
+ /** Wall-clock ms the model spent in the thinking phase. */
19
+ thinkingMs?: number;
13
20
  }
14
21
  interface ChatOptions {
15
22
  /** Override max tokens for this specific call */
@@ -227,6 +234,24 @@ interface RAGConfig {
227
234
  */
228
235
  vectorKeywords?: string[];
229
236
  }
237
+ interface RetrievalConfig {
238
+ /** Retrieval strategy selected by the host app. */
239
+ strategy?: 'vector' | 'keyword' | 'hybrid' | 'multi-query' | 'self-query' | 'parent-document' | 'contextual-compression' | 'ensemble' | 'recursive' | 'agentic';
240
+ /** Number of documents/chunks retrieved per query. */
241
+ topK?: number;
242
+ /** Minimum similarity score to include a retrieved chunk. */
243
+ scoreThreshold?: number;
244
+ /** Whether to rerank retrieved chunks before generation. */
245
+ useReranking?: boolean;
246
+ /** Provider-specific retrieval options for future strategies. */
247
+ options?: Record<string, unknown>;
248
+ }
249
+ interface WorkflowConfig {
250
+ /** High-level workflow selector from the SDK prompt. */
251
+ type?: 'simple-rag' | 'rag' | 'hybrid-rag' | 'graph-rag' | 'agentic-rag' | 'agentic';
252
+ /** Future workflow/provider-specific options. */
253
+ options?: Record<string, unknown>;
254
+ }
230
255
  interface RagConfig {
231
256
  /**
232
257
  * Unique identifier for the consuming project.
@@ -246,6 +271,21 @@ interface RagConfig {
246
271
  /** Optional Graph database configuration */
247
272
  graphDb?: GraphDBConfig;
248
273
  }
274
+ /**
275
+ * Friendly SDK configuration accepted by the top-level Retrivora facade.
276
+ * It supports the prompt's `vectorDatabase`, `retrieval`, and `workflow`
277
+ * naming while normalizing to the internal RagConfig shape.
278
+ */
279
+ type UniversalRagConfig = Partial<Omit<RagConfig, 'vectorDb' | 'rag' | 'llm' | 'embedding' | 'graphDb'>> & {
280
+ vectorDb?: Partial<VectorDBConfig>;
281
+ vectorDatabase?: Partial<VectorDBConfig>;
282
+ llm?: Partial<LLMConfig>;
283
+ embedding?: Partial<EmbeddingConfig>;
284
+ graphDb?: Partial<GraphDBConfig>;
285
+ retrieval?: RetrievalConfig;
286
+ rag?: RAGConfig;
287
+ workflow?: WorkflowConfig;
288
+ };
249
289
 
250
290
  /** Per-stage latency breakdown for a single RAG request. */
251
291
  interface LatencyBreakdown {
@@ -389,4 +429,4 @@ interface ILLMProvider {
389
429
  ping(): Promise<boolean>;
390
430
  }
391
431
 
392
- 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 };
432
+ 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, WorkflowConfig as W, 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, RetrievalConfig as l, RetrievedChunk as m, UniversalRagConfig as n, UpsertDocument as o, VectorDBConfig as p, VectorDBProvider as q, GraphNode as r, Edge as s, GraphSearchResult as t, RetrievalResult as u };
@@ -1,3 +1,3 @@
1
- import '../ILLMProvider-Bw2A28nU.mjs';
2
- export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, k as createSuggestionsHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, l as sseObservabilityFrame, j as sseTextFrame, m as sseUIFrame } from '../index-B70ZLkfG.mjs';
1
+ import '../ILLMProvider-DNhyOYoK.mjs';
2
+ export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, k as createSuggestionsHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, l as sseObservabilityFrame, j as sseTextFrame, m as sseUIFrame } from '../index-CHL1jdYm.mjs';
3
3
  import 'next/server';
@@ -1,3 +1,3 @@
1
- import '../ILLMProvider-Bw2A28nU.js';
2
- export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, k as createSuggestionsHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, l as sseObservabilityFrame, j as sseTextFrame, m as sseUIFrame } from '../index-DVu-mkAM.js';
1
+ import '../ILLMProvider-DNhyOYoK.js';
2
+ export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, k as createSuggestionsHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, l as sseObservabilityFrame, j as sseTextFrame, m as sseUIFrame } from '../index-Hgbwl9X4.js';
3
3
  import 'next/server';