@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.
- package/README.md +59 -7
- package/dist/{ILLMProvider-Bw2A28nU.d.mts → ILLMProvider-Bhk6zJOK.d.mts} +43 -7
- package/dist/{ILLMProvider-Bw2A28nU.d.ts → ILLMProvider-Bhk6zJOK.d.ts} +43 -7
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +737 -237
- package/dist/handlers/index.mjs +736 -237
- package/dist/index-B9J_XEh0.d.ts +187 -0
- package/dist/index-BJ4cd-t5.d.mts +187 -0
- package/dist/{index-B70ZLkfG.d.mts → index-Bu7T6xgr.d.ts} +20 -3
- package/dist/{index-DVu-mkAM.d.ts → index-C3SVtPYg.d.mts} +20 -3
- package/dist/index.css +237 -10
- package/dist/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +365 -164
- package/dist/index.mjs +350 -158
- package/dist/server.d.mts +15 -94
- package/dist/server.d.ts +15 -94
- package/dist/server.js +850 -239
- package/dist/server.mjs +839 -238
- package/package.json +2 -4
- package/src/app/api/chat/route.ts +2 -2
- package/src/app/api/health/route.ts +3 -2
- package/src/app/api/ingest/route.ts +3 -2
- package/src/app/api/suggestions/route.ts +3 -2
- package/src/app/api/upload/route.ts +3 -2
- package/src/app/constants.tsx +168 -148
- package/src/app/layout.tsx +5 -18
- package/src/app/types.ts +17 -17
- package/src/components/ChatWidget.tsx +3 -1
- package/src/components/ChatWindow.tsx +5 -1
- package/src/components/DocViewer.tsx +71 -5
- package/src/components/Documentation.tsx +74 -11
- package/src/components/MessageBubble.tsx +39 -2
- package/src/components/ThinkingBlock.tsx +75 -0
- package/src/components/VisualizationRenderer.tsx +27 -1
- package/src/components/constants.tsx +275 -0
- package/src/config/RagConfig.ts +47 -0
- package/src/config/constants.ts +1 -0
- package/src/config/serverConfig.ts +25 -0
- package/src/core/ConfigResolver.ts +73 -22
- package/src/core/ConfigValidator.ts +2 -1
- package/src/core/Pipeline.ts +226 -68
- package/src/core/ProviderRegistry.ts +16 -7
- package/src/core/QueryProcessor.ts +38 -4
- package/src/core/Retrivora.ts +91 -0
- package/src/core/VectorPlugin.ts +62 -8
- package/src/exceptions/index.ts +111 -0
- package/src/handlers/index.ts +73 -0
- package/src/hooks/useRagChat.ts +30 -5
- package/src/index.ts +27 -1
- package/src/lib/plugin.ts +24 -0
- package/src/llm/LLMFactory.ts +8 -4
- package/src/llm/providers/AnthropicProvider.ts +70 -20
- package/src/llm/providers/GeminiProvider.ts +14 -15
- package/src/llm/providers/OllamaProvider.ts +13 -16
- package/src/llm/providers/OpenAIProvider.ts +9 -14
- package/src/llm/providers/UniversalLLMAdapter.ts +5 -5
- package/src/llm/utils.ts +46 -0
- package/src/providers/vectordb/MongoDBProvider.ts +9 -4
- package/src/providers/vectordb/MultiTablePostgresProvider.ts +45 -13
- package/src/rag/EntityExtractor.ts +2 -2
- package/src/rag/Reranker.ts +9 -16
- package/src/server.ts +30 -1
- package/src/types/chat.ts +9 -0
- package/src/types/props.ts +38 -1
- package/src/utils/UITransformer.ts +73 -4
- package/dist/DocumentChunker-Dh9TvmGG.d.mts +0 -45
- package/dist/DocumentChunker-Dh9TvmGG.d.ts +0 -45
package/src/config/RagConfig.ts
CHANGED
|
@@ -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
|
+
};
|
package/src/config/constants.ts
CHANGED
|
@@ -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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
194
|
+
throw new ConfigurationException(`[ConfigValidator] Configuration validation failed:\n ${message}`, errorItems);
|
|
194
195
|
}
|
|
195
196
|
}
|
|
196
197
|
}
|