@retrivora-ai/rag-engine 1.9.3 → 1.9.7

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 (69) hide show
  1. package/README.md +59 -7
  2. package/dist/{ILLMProvider-Bw2A28nU.d.mts → ILLMProvider-Bhk6zJOK.d.mts} +43 -7
  3. package/dist/{ILLMProvider-Bw2A28nU.d.ts → ILLMProvider-Bhk6zJOK.d.ts} +43 -7
  4. package/dist/handlers/index.d.mts +2 -2
  5. package/dist/handlers/index.d.ts +2 -2
  6. package/dist/handlers/index.js +737 -237
  7. package/dist/handlers/index.mjs +736 -237
  8. package/dist/index-B9J_XEh0.d.ts +187 -0
  9. package/dist/index-BJ4cd-t5.d.mts +187 -0
  10. package/dist/{index-B70ZLkfG.d.mts → index-Bu7T6xgr.d.ts} +20 -3
  11. package/dist/{index-DVu-mkAM.d.ts → index-C3SVtPYg.d.mts} +20 -3
  12. package/dist/index.css +237 -10
  13. package/dist/index.d.mts +13 -5
  14. package/dist/index.d.ts +13 -5
  15. package/dist/index.js +365 -164
  16. package/dist/index.mjs +350 -158
  17. package/dist/server.d.mts +15 -94
  18. package/dist/server.d.ts +15 -94
  19. package/dist/server.js +850 -239
  20. package/dist/server.mjs +839 -238
  21. package/package.json +2 -4
  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 +168 -148
  28. package/src/app/layout.tsx +5 -18
  29. package/src/app/types.ts +17 -17
  30. package/src/components/ChatWidget.tsx +3 -1
  31. package/src/components/ChatWindow.tsx +5 -1
  32. package/src/components/DocViewer.tsx +71 -5
  33. package/src/components/Documentation.tsx +74 -11
  34. package/src/components/MessageBubble.tsx +39 -2
  35. package/src/components/ThinkingBlock.tsx +75 -0
  36. package/src/components/VisualizationRenderer.tsx +27 -1
  37. package/src/components/constants.tsx +275 -0
  38. package/src/config/RagConfig.ts +47 -0
  39. package/src/config/constants.ts +1 -0
  40. package/src/config/serverConfig.ts +25 -0
  41. package/src/core/ConfigResolver.ts +73 -22
  42. package/src/core/ConfigValidator.ts +2 -1
  43. package/src/core/Pipeline.ts +226 -68
  44. package/src/core/ProviderRegistry.ts +16 -7
  45. package/src/core/QueryProcessor.ts +38 -4
  46. package/src/core/Retrivora.ts +91 -0
  47. package/src/core/VectorPlugin.ts +62 -8
  48. package/src/exceptions/index.ts +111 -0
  49. package/src/handlers/index.ts +73 -0
  50. package/src/hooks/useRagChat.ts +30 -5
  51. package/src/index.ts +27 -1
  52. package/src/lib/plugin.ts +24 -0
  53. package/src/llm/LLMFactory.ts +8 -4
  54. package/src/llm/providers/AnthropicProvider.ts +70 -20
  55. package/src/llm/providers/GeminiProvider.ts +14 -15
  56. package/src/llm/providers/OllamaProvider.ts +13 -16
  57. package/src/llm/providers/OpenAIProvider.ts +9 -14
  58. package/src/llm/providers/UniversalLLMAdapter.ts +5 -5
  59. package/src/llm/utils.ts +46 -0
  60. package/src/providers/vectordb/MongoDBProvider.ts +9 -4
  61. package/src/providers/vectordb/MultiTablePostgresProvider.ts +45 -13
  62. package/src/rag/EntityExtractor.ts +2 -2
  63. package/src/rag/Reranker.ts +9 -16
  64. package/src/server.ts +30 -1
  65. package/src/types/chat.ts +9 -0
  66. package/src/types/props.ts +38 -1
  67. package/src/utils/UITransformer.ts +73 -4
  68. package/dist/DocumentChunker-Dh9TvmGG.d.mts +0 -45
  69. package/dist/DocumentChunker-Dh9TvmGG.d.ts +0 -45
@@ -199,6 +199,36 @@ export interface RAGConfig {
199
199
  vectorKeywords?: string[];
200
200
  }
201
201
 
202
+ export interface RetrievalConfig {
203
+ /** Retrieval strategy selected by the host app. */
204
+ strategy?:
205
+ | 'vector'
206
+ | 'keyword'
207
+ | 'hybrid'
208
+ | 'multi-query'
209
+ | 'self-query'
210
+ | 'parent-document'
211
+ | 'contextual-compression'
212
+ | 'ensemble'
213
+ | 'recursive'
214
+ | 'agentic';
215
+ /** Number of documents/chunks retrieved per query. */
216
+ topK?: number;
217
+ /** Minimum similarity score to include a retrieved chunk. */
218
+ scoreThreshold?: number;
219
+ /** Whether to rerank retrieved chunks before generation. */
220
+ useReranking?: boolean;
221
+ /** Provider-specific retrieval options for future strategies. */
222
+ options?: Record<string, unknown>;
223
+ }
224
+
225
+ export interface WorkflowConfig {
226
+ /** High-level workflow selector from the SDK prompt. */
227
+ type?: 'simple-rag' | 'rag' | 'hybrid-rag' | 'graph-rag' | 'agentic-rag' | 'agentic';
228
+ /** Future workflow/provider-specific options. */
229
+ options?: Record<string, unknown>;
230
+ }
231
+
202
232
  // ---------------------------------------------------------------------------
203
233
  // Root Config
204
234
  // ---------------------------------------------------------------------------
@@ -228,3 +258,20 @@ export interface RagConfig {
228
258
  /** Optional Graph database configuration */
229
259
  graphDb?: GraphDBConfig;
230
260
  }
261
+
262
+ /**
263
+ * Friendly SDK configuration accepted by the top-level Retrivora facade.
264
+ * It supports the prompt's `vectorDatabase`, `retrieval`, and `workflow`
265
+ * naming while normalizing to the internal RagConfig shape.
266
+ */
267
+ export type UniversalRagConfig =
268
+ Partial<Omit<RagConfig, 'vectorDb' | 'rag' | 'llm' | 'embedding' | 'graphDb'>> & {
269
+ vectorDb?: Partial<VectorDBConfig>;
270
+ vectorDatabase?: Partial<VectorDBConfig>;
271
+ llm?: Partial<LLMConfig>;
272
+ embedding?: Partial<EmbeddingConfig>;
273
+ graphDb?: Partial<GraphDBConfig>;
274
+ retrieval?: RetrievalConfig;
275
+ rag?: RAGConfig;
276
+ workflow?: WorkflowConfig;
277
+ };
@@ -4,6 +4,7 @@
4
4
  * This file serves as the single source of truth for all statically supported
5
5
  * providers and stylistic options in the Retrivora AI RAG Engine.
6
6
  */
7
+ export const VERSION = '1.9.6';
7
8
 
8
9
  export const VECTOR_DB_PROVIDERS = [
9
10
  'pinecone',
@@ -167,6 +167,8 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
167
167
  temperature: readNumber(env, 'LLM_TEMPERATURE', 0.7),
168
168
  options: {
169
169
  profile: readString(env, 'LLM_UNIVERSAL_PROFILE'),
170
+ thinking: readString(env, 'LLM_THINKING') === 'true' || readString(env, 'LLM_THINKING') === 'enabled' ? true : (readString(env, 'LLM_THINKING') === 'false' ? false : undefined),
171
+ thinkingBudget: env.LLM_THINKING_BUDGET ? parseInt(env.LLM_THINKING_BUDGET, 10) : undefined,
170
172
  },
171
173
  },
172
174
  embedding: {
@@ -202,6 +204,29 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
202
204
  scoreThreshold: readNumber(env, 'RAG_SCORE_THRESHOLD', 0),
203
205
  chunkSize: readNumber(env, 'RAG_CHUNK_SIZE', 1000),
204
206
  chunkOverlap: readNumber(env, 'RAG_CHUNK_OVERLAP', 200),
207
+ filterableFields: readString(env, 'RAG_FILTERABLE_FIELDS')?.split(',').map(f => f.trim()),
208
+ // Query pipeline toggles — read from .env.local
209
+ useQueryTransformation: readString(env, 'RAG_USE_QUERY_TRANSFORMATION') === 'true',
210
+ useReranking: readString(env, 'RAG_USE_RERANKING') === 'true',
211
+ useGraphRetrieval: readString(env, 'RAG_USE_GRAPH_RETRIEVAL') === 'true',
212
+ architecture: (readString(env, 'RAG_ARCHITECTURE') ?? 'simple') as 'simple' | 'graph' | 'hybrid' | 'agentic',
213
+ chunkingStrategy: (readString(env, 'RAG_CHUNKING_STRATEGY') ?? 'recursive') as 'recursive' | 'markdown' | 'semantic' | 'llamaindex',
214
+ uiMapping: (() => {
215
+ const raw = readString(env, 'RAG_UI_MAPPING');
216
+ if (!raw) return undefined;
217
+ try { return JSON.parse(raw) as Record<string, string>; } catch { return undefined; }
218
+ })(),
205
219
  },
220
+ // Optional graph DB — driven by GRAPH_DB_PROVIDER env var
221
+ ...(readString(env, 'GRAPH_DB_PROVIDER') ? {
222
+ graphDb: {
223
+ provider: readString(env, 'GRAPH_DB_PROVIDER')! as 'neo4j' | 'memgraph' | 'simple' | 'custom',
224
+ options: {
225
+ uri: readString(env, 'GRAPH_DB_URI'),
226
+ username: readString(env, 'GRAPH_DB_USERNAME'),
227
+ password: readString(env, 'GRAPH_DB_PASSWORD'),
228
+ },
229
+ },
230
+ } : {}),
206
231
  };
207
232
  }
@@ -6,7 +6,7 @@
6
6
  * environment variables are only parsed once per process, avoiding
7
7
  * repeated work in serverless cold starts and per-request handler calls.
8
8
  */
9
- import { RagConfig } from '../config/RagConfig';
9
+ import { RagConfig, UniversalRagConfig, RAGConfig, RetrievalConfig, WorkflowConfig } from '../config/RagConfig';
10
10
  import { mergeDefined } from '../utils/templateUtils';
11
11
  import { getEnvConfig } from '../config/serverConfig';
12
12
 
@@ -31,39 +31,56 @@ export class ConfigResolver {
31
31
  projectId: hostConfig.projectId || envConfig.projectId,
32
32
  vectorDb: hostConfig.vectorDb
33
33
  ? {
34
- ...envConfig.vectorDb,
35
- ...hostConfig.vectorDb,
36
- options: {
37
- ...envConfig.vectorDb.options,
38
- ...(hostConfig.vectorDb.options || {}),
39
- },
40
- }
34
+ ...envConfig.vectorDb,
35
+ ...hostConfig.vectorDb,
36
+ options: {
37
+ ...envConfig.vectorDb.options,
38
+ ...(hostConfig.vectorDb.options || {}),
39
+ },
40
+ }
41
41
  : envConfig.vectorDb,
42
42
  llm: hostConfig.llm
43
43
  ? {
44
- ...envConfig.llm,
45
- ...hostConfig.llm,
46
- options: {
47
- ...(envConfig.llm.options || {}),
48
- ...(hostConfig.llm.options || {}),
49
- },
50
- }
44
+ ...envConfig.llm,
45
+ ...hostConfig.llm,
46
+ options: {
47
+ ...(envConfig.llm.options || {}),
48
+ ...(hostConfig.llm.options || {}),
49
+ },
50
+ }
51
51
  : envConfig.llm,
52
52
  embedding: hostConfig.embedding
53
53
  ? {
54
- ...envConfig.embedding,
55
- ...hostConfig.embedding,
56
- options: {
57
- ...(envConfig.embedding.options || {}),
58
- ...(hostConfig.embedding.options || {}),
59
- },
60
- }
54
+ ...envConfig.embedding,
55
+ ...hostConfig.embedding,
56
+ options: {
57
+ ...(envConfig.embedding.options || {}),
58
+ ...(hostConfig.embedding.options || {}),
59
+ },
60
+ }
61
61
  : envConfig.embedding,
62
62
  ui: hostConfig.ui ? mergeDefined(envConfig.ui, hostConfig.ui) : envConfig.ui,
63
63
  rag: hostConfig.rag ? { ...envConfig.rag, ...hostConfig.rag } : envConfig.rag,
64
64
  };
65
65
  }
66
66
 
67
+ /**
68
+ * Resolves the public SDK config shape used by `new Retrivora({...})`.
69
+ * Supports aliases from the product prompt while preserving existing env
70
+ * fallback behavior.
71
+ */
72
+ static resolveUniversal(hostConfig?: UniversalRagConfig, env: Record<string, string | undefined> = process.env): RagConfig {
73
+ if (!hostConfig) return this.resolve(undefined, env);
74
+
75
+ const normalized: Partial<RagConfig> = {
76
+ ...hostConfig,
77
+ vectorDb: hostConfig.vectorDb ?? hostConfig.vectorDatabase,
78
+ rag: this.mergeRetrievalWorkflow(hostConfig.rag, hostConfig.retrieval, hostConfig.workflow),
79
+ } as Partial<RagConfig>;
80
+
81
+ return this.resolve(normalized, env);
82
+ }
83
+
67
84
  /**
68
85
  * Validates the configuration for required fields.
69
86
  */
@@ -78,4 +95,38 @@ export class ConfigResolver {
78
95
  throw new Error('[ConfigResolver] llm.provider is required');
79
96
  }
80
97
  }
98
+
99
+ private static mergeRetrievalWorkflow(
100
+ rag?: RAGConfig,
101
+ retrieval?: RetrievalConfig,
102
+ workflow?: WorkflowConfig,
103
+ ): RAGConfig | undefined {
104
+ if (!rag && !retrieval && !workflow) return undefined;
105
+
106
+ const normalized: RAGConfig = { ...(rag ?? {}) };
107
+
108
+ if (retrieval) {
109
+ normalized.topK = retrieval.topK ?? normalized.topK;
110
+ normalized.scoreThreshold = retrieval.scoreThreshold ?? normalized.scoreThreshold;
111
+ normalized.useReranking = retrieval.useReranking ?? normalized.useReranking;
112
+
113
+ if (retrieval.strategy === 'hybrid') normalized.architecture = normalized.architecture ?? 'hybrid';
114
+ if (retrieval.strategy === 'agentic') normalized.architecture = 'agentic';
115
+ if (retrieval.strategy === 'contextual-compression') normalized.useReranking = true;
116
+ }
117
+
118
+ if (workflow?.type) {
119
+ const type = workflow.type;
120
+ if (type === 'agentic' || type === 'agentic-rag') normalized.architecture = 'agentic';
121
+ else if (type === 'hybrid-rag') normalized.architecture = 'hybrid';
122
+ else if (type === 'graph-rag') {
123
+ normalized.architecture = 'graph';
124
+ normalized.useGraphRetrieval = true;
125
+ } else if (type === 'simple-rag' || type === 'rag') {
126
+ normalized.architecture = normalized.architecture ?? 'simple';
127
+ }
128
+ }
129
+
130
+ return normalized;
131
+ }
81
132
  }
@@ -4,6 +4,7 @@ import {
4
4
  } from '../config/constants';
5
5
  import { ProviderRegistry } from './ProviderRegistry';
6
6
  import { LLMFactory } from '../llm/LLMFactory';
7
+ import { ConfigurationException } from '../exceptions';
7
8
 
8
9
  export interface ValidationError {
9
10
  field: string;
@@ -190,7 +191,7 @@ export class ConfigValidator {
190
191
  const message = errorItems
191
192
  .map((e) => `${e.field}: ${e.message}${e.suggestion ? ` (${e.suggestion})` : ''}`)
192
193
  .join('\n ');
193
- throw new Error(`[ConfigValidator] Configuration validation failed:\n ${message}`);
194
+ throw new ConfigurationException(`[ConfigValidator] Configuration validation failed:\n ${message}`, errorItems);
194
195
  }
195
196
  }
196
197
  }