@retrivora-ai/rag-engine 2.4.2 → 2.4.5
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/dist/{BatchProcessor-zbQMaZHm.d.mts → BatchProcessor-Csy_K1qQ.d.mts} +2 -0
- package/dist/{BatchProcessor-D42E706a.d.ts → BatchProcessor-Dg18zZGk.d.ts} +2 -0
- package/dist/handlers/index.js +31 -5
- package/dist/handlers/index.mjs +31 -5
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +41 -21
- package/dist/index.min.css +2 -0
- package/dist/index.mjs +41 -21
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +32 -5
- package/dist/server.mjs +32 -5
- package/package.json +5 -4
- package/src/LicensedRetrivora.ts +0 -278
- package/src/app/api/chat/route.ts +0 -4
- package/src/app/api/health/route.ts +0 -5
- package/src/app/api/ingest/route.ts +0 -27
- package/src/app/api/suggestions/route.ts +0 -5
- package/src/app/api/upload/route.ts +0 -5
- package/src/app/constants.tsx +0 -270
- package/src/app/favicon.ico +0 -0
- package/src/app/globals.css +0 -449
- package/src/app/layout.tsx +0 -22
- package/src/app/page.tsx +0 -64
- package/src/app/types.ts +0 -30
- package/src/browser.tsx +0 -139
- package/src/components/ChatWidget.tsx +0 -393
- package/src/components/ChatWindow.tsx +0 -952
- package/src/components/CodeViewer.tsx +0 -56
- package/src/components/ConfigProvider.tsx +0 -123
- package/src/components/DocumentUpload.tsx +0 -354
- package/src/components/DynamicChart.tsx +0 -297
- package/src/components/HourglassLoader.tsx +0 -87
- package/src/components/MarkdownComponents.tsx +0 -186
- package/src/components/MessageBubble.tsx +0 -498
- package/src/components/ObservabilityPanel.tsx +0 -374
- package/src/components/ProductCard.tsx +0 -107
- package/src/components/ProductCarousel.tsx +0 -97
- package/src/components/SourceCard.tsx +0 -61
- package/src/components/ThemeProvider.tsx +0 -8
- package/src/components/ThemeToggle.tsx +0 -29
- package/src/components/ThinkingBlock.tsx +0 -75
- package/src/components/UIDispatcher.tsx +0 -342
- package/src/components/VisualizationRenderer.tsx +0 -621
- package/src/components/constants.tsx +0 -503
- package/src/config/ConfigBuilder.ts +0 -285
- package/src/config/EmbeddingStrategy.ts +0 -148
- package/src/config/LicenseConfigResolver.ts +0 -298
- package/src/config/RagConfig.ts +0 -328
- package/src/config/UniversalProfiles.ts +0 -82
- package/src/config/constants.ts +0 -64
- package/src/config/serverConfig.ts +0 -378
- package/src/config/uiConstants.ts +0 -47
- package/src/core/BatchProcessor.ts +0 -385
- package/src/core/CircuitBreaker.ts +0 -118
- package/src/core/ConfigFetcher.ts +0 -220
- package/src/core/ConfigResolver.ts +0 -165
- package/src/core/ConfigValidator.ts +0 -197
- package/src/core/DatabaseStorage.ts +0 -526
- package/src/core/FreeTierLimitsGuard.ts +0 -281
- package/src/core/LLMRouter.ts +0 -79
- package/src/core/LangChainAgent.ts +0 -132
- package/src/core/LicenseValidator.ts +0 -284
- package/src/core/LicenseVerifier.ts +0 -261
- package/src/core/MultiAgentCoordinator.ts +0 -239
- package/src/core/Pipeline.ts +0 -1279
- package/src/core/PluginManager.ts +0 -277
- package/src/core/ProjectSettings.ts +0 -247
- package/src/core/ProviderHealthCheck.ts +0 -133
- package/src/core/ProviderInterfaces.ts +0 -37
- package/src/core/ProviderRegistry.ts +0 -156
- package/src/core/QueryProcessor.ts +0 -399
- package/src/core/Retrivora.ts +0 -98
- package/src/core/VectorPlugin.ts +0 -193
- package/src/core/mcp.ts +0 -261
- package/src/exceptions/index.ts +0 -131
- package/src/handlers/index.ts +0 -1625
- package/src/hooks/useHydrated.ts +0 -13
- package/src/hooks/useProjectSettings.ts +0 -105
- package/src/hooks/useRagChat.ts +0 -436
- package/src/hooks/useStoredMessages.ts +0 -64
- package/src/index.css +0 -4269
- package/src/index.ts +0 -137
- package/src/lib/plugin.ts +0 -24
- package/src/llm/ILLMProvider.ts +0 -60
- package/src/llm/LLMFactory.ts +0 -141
- package/src/llm/providers/AnthropicProvider.ts +0 -215
- package/src/llm/providers/GeminiProvider.ts +0 -311
- package/src/llm/providers/GroqProvider.ts +0 -184
- package/src/llm/providers/OllamaProvider.ts +0 -232
- package/src/llm/providers/OpenAIProvider.ts +0 -188
- package/src/llm/providers/QwenProvider.ts +0 -199
- package/src/llm/providers/UniversalLLMAdapter.ts +0 -422
- package/src/llm/utils.ts +0 -46
- package/src/providers/graphdb/BaseGraphProvider.ts +0 -43
- package/src/providers/graphdb/SimpleGraphProvider.ts +0 -66
- package/src/providers/vectordb/BaseVectorProvider.ts +0 -98
- package/src/providers/vectordb/ChromaDBProvider.ts +0 -130
- package/src/providers/vectordb/MilvusProvider.ts +0 -134
- package/src/providers/vectordb/MongoDBProvider.ts +0 -250
- package/src/providers/vectordb/MultiTablePostgresProvider.ts +0 -461
- package/src/providers/vectordb/PineconeProvider.ts +0 -295
- package/src/providers/vectordb/PostgreSQLProvider.ts +0 -227
- package/src/providers/vectordb/QdrantProvider.ts +0 -294
- package/src/providers/vectordb/RedisProvider.ts +0 -105
- package/src/providers/vectordb/UniversalVectorProvider.ts +0 -221
- package/src/providers/vectordb/WeaviateProvider.ts +0 -172
- package/src/rag/DocumentChunker.ts +0 -144
- package/src/rag/EntityExtractor.ts +0 -90
- package/src/rag/LlamaIndexIngestor.ts +0 -60
- package/src/rag/Reranker.ts +0 -106
- package/src/rendering/IntentClassifier.ts +0 -167
- package/src/rendering/RendererRegistry.ts +0 -164
- package/src/rendering/RuleEngine.ts +0 -67
- package/src/rendering/VisualizationDecisionEngine.ts +0 -164
- package/src/rendering/__tests__/VisualizationDecisionEngine.test.ts +0 -237
- package/src/rendering/index.ts +0 -12
- package/src/rendering/rules/Rule1SpecificInfoRule.ts +0 -28
- package/src/rendering/rules/Rule2ComparisonRule.ts +0 -24
- package/src/rendering/rules/Rule3ProductDiscoveryRule.ts +0 -28
- package/src/rendering/rules/Rule4AnalyticalRule.ts +0 -38
- package/src/rendering/rules/Rule5MixedResponseRule.ts +0 -29
- package/src/rendering/rules/Rule6SmallResultSetRule.ts +0 -24
- package/src/rendering/rules/Rule7LargeTableRule.ts +0 -35
- package/src/rendering/types.ts +0 -96
- package/src/server.ts +0 -156
- package/src/tailwind.css +0 -194
- package/src/telemetry/TelemetryService.ts +0 -330
- package/src/types/chat.ts +0 -89
- package/src/types/index.ts +0 -278
- package/src/types/pdf-parse.d.ts +0 -13
- package/src/types/props.ts +0 -169
- package/src/utils/DocumentParser.ts +0 -111
- package/src/utils/ProductExtractor.ts +0 -350
- package/src/utils/SchemaMapper.ts +0 -176
- package/src/utils/UITransformer.ts +0 -1812
- package/src/utils/synonyms.ts +0 -80
- package/src/utils/templateUtils.ts +0 -78
- package/src/version.ts +0 -6
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LicenseConfigResolver — Resolves LLM and embedding configuration
|
|
3
|
-
* based on the user's license tier from Retrivora admin dashboard.
|
|
4
|
-
*
|
|
5
|
-
* The end-user SDK only needs:
|
|
6
|
-
* - licenseKey (JWT token from Retrivora)
|
|
7
|
-
* - projectId (workspace identifier)
|
|
8
|
-
*
|
|
9
|
-
* Configuration includes:
|
|
10
|
-
* 1. Tier-based model selection (/api/v1/config)
|
|
11
|
-
* 2. Provider API credentials (/api/v1/credentials)
|
|
12
|
-
* 3. Vector DB and rate limit settings
|
|
13
|
-
*
|
|
14
|
-
* All provider API keys (Gemini, Groq, Pinecone) are stored on Retrivora backend
|
|
15
|
-
* and never exposed to end-users directly.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import axios, { AxiosInstance } from 'axios';
|
|
19
|
-
import { LLMConfig, EmbeddingConfig, VectorDBConfig } from './RagConfig';
|
|
20
|
-
|
|
21
|
-
export interface ProviderCredentials {
|
|
22
|
-
geminiApiKey?: string;
|
|
23
|
-
groqApiKey?: string;
|
|
24
|
-
pineconeApiKey?: string;
|
|
25
|
-
textEmbeddingProvider?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface LicenseTierConfig {
|
|
29
|
-
tier: 'free_trial' | 'free' | 'hobby' | 'pro' | 'enterprise';
|
|
30
|
-
llmModel: string;
|
|
31
|
-
embeddingModel: string;
|
|
32
|
-
embeddingDimensions: number;
|
|
33
|
-
maxTokens: number;
|
|
34
|
-
chunkSize: number;
|
|
35
|
-
chunkOverlap: number;
|
|
36
|
-
topK: number;
|
|
37
|
-
vectorDb: {
|
|
38
|
-
provider: string;
|
|
39
|
-
indexName: string;
|
|
40
|
-
};
|
|
41
|
-
rateLimit?: {
|
|
42
|
-
requestsPerMinute: number;
|
|
43
|
-
tokensPerDay: number;
|
|
44
|
-
};
|
|
45
|
-
systemPrompt?: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface ProviderCredentials {
|
|
49
|
-
geminiApiKey?: string;
|
|
50
|
-
groqApiKey?: string;
|
|
51
|
-
pineconeApiKey?: string;
|
|
52
|
-
textEmbeddingProvider?: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface ConfigAPIResponse {
|
|
56
|
-
success: boolean;
|
|
57
|
-
config?: LicenseTierConfig;
|
|
58
|
-
error?: string;
|
|
59
|
-
message?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface CredentialsAPIResponse {
|
|
63
|
-
success: boolean;
|
|
64
|
-
credentials?: ProviderCredentials;
|
|
65
|
-
error?: string;
|
|
66
|
-
message?: string;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Resolver for license-based configuration.
|
|
71
|
-
* This is called by the end-user SDK after they instantiate with licenseKey + projectId.
|
|
72
|
-
*/
|
|
73
|
-
export class LicenseConfigResolver {
|
|
74
|
-
private static readonly RETRIVORA_CONFIG_URL = 'https://www.retrivora.com/api/v1/config';
|
|
75
|
-
private static readonly RETRIVORA_CREDENTIALS_URL = 'https://www.retrivora.com/api/v1/credentials';
|
|
76
|
-
private static readonly CACHE_TTL_MS = 3600000; // 1 hour
|
|
77
|
-
private static configCache = new Map<string, { config: LicenseTierConfig; credentials: ProviderCredentials; timestamp: number }>();
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Validate and resolve configuration from license key
|
|
81
|
-
* @param licenseKey JWT token from Retrivora (format: rtv_eyJ...)
|
|
82
|
-
* @param projectId Workspace identifier
|
|
83
|
-
* @returns Resolved LLM and embedding configs with provider credentials
|
|
84
|
-
*/
|
|
85
|
-
static async resolveFromLicense(
|
|
86
|
-
licenseKey: string,
|
|
87
|
-
projectId: string
|
|
88
|
-
): Promise<{
|
|
89
|
-
llmConfig: LLMConfig;
|
|
90
|
-
embeddingConfig: EmbeddingConfig;
|
|
91
|
-
vectorDbConfig: VectorDBConfig;
|
|
92
|
-
tierConfig: LicenseTierConfig;
|
|
93
|
-
credentials: ProviderCredentials;
|
|
94
|
-
}> {
|
|
95
|
-
// Check cache first
|
|
96
|
-
const cacheKey = `${licenseKey}:${projectId}`;
|
|
97
|
-
const cached = this.configCache.get(cacheKey);
|
|
98
|
-
if (cached && Date.now() - cached.timestamp < this.CACHE_TTL_MS) {
|
|
99
|
-
//console.log('[LicenseConfigResolver] Using cached config for', projectId);
|
|
100
|
-
return this.buildConfigs(cached.config, cached.credentials, licenseKey, projectId);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Fetch tier config from /api/v1/config
|
|
104
|
-
//console.log('[LicenseConfigResolver] Fetching tier config from Retrivora...');
|
|
105
|
-
const tierConfig = await this.fetchTierConfig(licenseKey, projectId);
|
|
106
|
-
|
|
107
|
-
// Fetch provider credentials from /api/v1/credentials
|
|
108
|
-
//console.log('[LicenseConfigResolver] Fetching provider credentials from Retrivora...');
|
|
109
|
-
const credentials = await this.fetchProviderCredentials(licenseKey, projectId);
|
|
110
|
-
|
|
111
|
-
// Cache both
|
|
112
|
-
this.configCache.set(cacheKey, { config: tierConfig, credentials, timestamp: Date.now() });
|
|
113
|
-
|
|
114
|
-
// console.log('[LicenseConfigResolver] ✅ Successfully resolved config from Retrivora:', {
|
|
115
|
-
// tier: tierConfig.tier,
|
|
116
|
-
// llmModel: tierConfig.llmModel,
|
|
117
|
-
// embeddingModel: tierConfig.embeddingModel,
|
|
118
|
-
// });
|
|
119
|
-
|
|
120
|
-
return this.buildConfigs(tierConfig, credentials, licenseKey, projectId);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Fetch tier configuration from Retrivora config API
|
|
125
|
-
*/
|
|
126
|
-
private static async fetchTierConfig(licenseKey: string, projectId: string): Promise<LicenseTierConfig> {
|
|
127
|
-
try {
|
|
128
|
-
const response = await axios.post<ConfigAPIResponse>(
|
|
129
|
-
this.RETRIVORA_CONFIG_URL,
|
|
130
|
-
{ licenseKey, projectId },
|
|
131
|
-
{
|
|
132
|
-
headers: {
|
|
133
|
-
'Content-Type': 'application/json',
|
|
134
|
-
Authorization: `Bearer ${licenseKey}`,
|
|
135
|
-
'X-License-Key': licenseKey,
|
|
136
|
-
'X-Project-ID': projectId,
|
|
137
|
-
},
|
|
138
|
-
timeout: 10000,
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
if (!response.data.success || !response.data.config) {
|
|
143
|
-
throw new Error(
|
|
144
|
-
`[LicenseConfigResolver] Config API returned error: ${response.data.error || response.data.message}`
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
//console.log(`[LicenseConfigResolver] Resolved tier: ${response.data.config.tier}`);
|
|
149
|
-
return response.data.config;
|
|
150
|
-
} catch (err: any) {
|
|
151
|
-
console.error('[LicenseConfigResolver] Failed to fetch config:', err.message);
|
|
152
|
-
throw new Error(
|
|
153
|
-
`[LicenseConfigResolver] Could not validate license key or fetch tier configuration: ${err.message}`
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Fetch provider credentials from Retrivora credentials API
|
|
160
|
-
*/
|
|
161
|
-
private static async fetchProviderCredentials(licenseKey: string, projectId: string): Promise<ProviderCredentials> {
|
|
162
|
-
try {
|
|
163
|
-
const response = await axios.post<CredentialsAPIResponse>(
|
|
164
|
-
this.RETRIVORA_CREDENTIALS_URL,
|
|
165
|
-
{ licenseKey, projectId },
|
|
166
|
-
{
|
|
167
|
-
headers: {
|
|
168
|
-
'Content-Type': 'application/json',
|
|
169
|
-
Authorization: `Bearer ${licenseKey}`,
|
|
170
|
-
'X-License-Key': licenseKey,
|
|
171
|
-
'X-Project-ID': projectId,
|
|
172
|
-
},
|
|
173
|
-
timeout: 10000,
|
|
174
|
-
}
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
if (!response.data.success || !response.data.credentials) {
|
|
178
|
-
throw new Error(
|
|
179
|
-
`[LicenseConfigResolver] Credentials API returned error: ${response.data.error || response.data.message}`
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
//console.log(`[LicenseConfigResolver] Retrieved provider credentials for project: ${projectId}`);
|
|
184
|
-
return response.data.credentials;
|
|
185
|
-
} catch (err: any) {
|
|
186
|
-
console.error('[LicenseConfigResolver] Failed to fetch credentials:', err.message);
|
|
187
|
-
throw new Error(
|
|
188
|
-
`[LicenseConfigResolver] Could not fetch provider credentials: ${err.message}`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Build LLM, embedding, and vector DB configs from tier and credentials
|
|
195
|
-
*/
|
|
196
|
-
private static buildConfigs(
|
|
197
|
-
tierConfig: LicenseTierConfig,
|
|
198
|
-
credentials: ProviderCredentials,
|
|
199
|
-
licenseKey: string,
|
|
200
|
-
projectId: string
|
|
201
|
-
): {
|
|
202
|
-
llmConfig: LLMConfig;
|
|
203
|
-
embeddingConfig: EmbeddingConfig;
|
|
204
|
-
vectorDbConfig: VectorDBConfig;
|
|
205
|
-
tierConfig: LicenseTierConfig;
|
|
206
|
-
credentials: ProviderCredentials;
|
|
207
|
-
} {
|
|
208
|
-
// Determine LLM provider and API key based on model
|
|
209
|
-
let llmProvider: 'gemini' | 'groq' | 'openai' = 'gemini';
|
|
210
|
-
let llmApiKey = credentials.geminiApiKey || licenseKey;
|
|
211
|
-
|
|
212
|
-
if (tierConfig.llmModel.includes('gpt')) {
|
|
213
|
-
llmProvider = 'openai';
|
|
214
|
-
} else if (tierConfig.llmModel.includes('groq') || tierConfig.llmModel.includes('llama')) {
|
|
215
|
-
llmProvider = 'groq';
|
|
216
|
-
llmApiKey = credentials.groqApiKey || licenseKey;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const llmConfig: LLMConfig = {
|
|
220
|
-
provider: llmProvider,
|
|
221
|
-
model: tierConfig.llmModel,
|
|
222
|
-
apiKey: llmApiKey,
|
|
223
|
-
maxTokens: tierConfig?.maxTokens,
|
|
224
|
-
temperature: 0.7,
|
|
225
|
-
systemPrompt: tierConfig?.systemPrompt,
|
|
226
|
-
options: {},
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
// Embedding config - use Gemini's embeddings
|
|
230
|
-
const embeddingConfig: EmbeddingConfig = {
|
|
231
|
-
provider: 'gemini',
|
|
232
|
-
model: tierConfig.embeddingModel,
|
|
233
|
-
apiKey: credentials.geminiApiKey || licenseKey,
|
|
234
|
-
dimensions: tierConfig.embeddingDimensions,
|
|
235
|
-
options: {},
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
// Vector DB config - determined by tier from Retrivora
|
|
239
|
-
const vectorDbConfig: VectorDBConfig = {
|
|
240
|
-
provider: tierConfig.vectorDb.provider as any,
|
|
241
|
-
indexName: tierConfig.vectorDb.indexName,
|
|
242
|
-
options: this.getVectorDbOptions(tierConfig.vectorDb.provider, projectId, credentials),
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
return { llmConfig, embeddingConfig, vectorDbConfig, tierConfig, credentials };
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Get provider-specific vector DB options
|
|
250
|
-
*/
|
|
251
|
-
private static getVectorDbOptions(
|
|
252
|
-
provider: string,
|
|
253
|
-
projectId: string,
|
|
254
|
-
credentials: ProviderCredentials
|
|
255
|
-
): Record<string, unknown> {
|
|
256
|
-
switch (provider) {
|
|
257
|
-
case 'pinecone':
|
|
258
|
-
return {
|
|
259
|
-
apiKey: credentials.pineconeApiKey,
|
|
260
|
-
indexName: `retrivora-${projectId}`,
|
|
261
|
-
};
|
|
262
|
-
case 'pgvector':
|
|
263
|
-
case 'postgresql':
|
|
264
|
-
return {
|
|
265
|
-
tables: [`documents_${projectId}`],
|
|
266
|
-
};
|
|
267
|
-
case 'mongodb':
|
|
268
|
-
return {
|
|
269
|
-
database: `retrivora_${projectId}`,
|
|
270
|
-
collection: `vectors_${projectId}`,
|
|
271
|
-
};
|
|
272
|
-
case 'qdrant':
|
|
273
|
-
return {
|
|
274
|
-
collection: `retrivora_${projectId}`,
|
|
275
|
-
};
|
|
276
|
-
default:
|
|
277
|
-
return {};
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Clear configuration cache (useful for testing or manual refresh)
|
|
283
|
-
*/
|
|
284
|
-
static clearCache(): void {
|
|
285
|
-
this.configCache.clear();
|
|
286
|
-
//console.log('[LicenseConfigResolver] Configuration cache cleared');
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Get cache stats for debugging
|
|
291
|
-
*/
|
|
292
|
-
static getCacheStats(): { size: number; entries: string[] } {
|
|
293
|
-
return {
|
|
294
|
-
size: this.configCache.size,
|
|
295
|
-
entries: Array.from(this.configCache.keys()),
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
}
|
package/src/config/RagConfig.ts
DELETED
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Master configuration interface for Retrivora AI.
|
|
3
|
-
* Each consuming project provides one RagConfig object to drive
|
|
4
|
-
* vector DB selection, LLM selection, embedding, and UI branding.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// ---------------------------------------------------------------------------
|
|
8
|
-
// Vector DB
|
|
9
|
-
// ---------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
VECTOR_DB_PROVIDERS,
|
|
13
|
-
LLM_PROVIDERS,
|
|
14
|
-
EMBEDDING_PROVIDERS,
|
|
15
|
-
GRAPH_DB_PROVIDERS,
|
|
16
|
-
} from './constants';
|
|
17
|
-
import type { ProjectChatSettings } from '../core/ProjectSettings';
|
|
18
|
-
|
|
19
|
-
export type VectorDBProvider = typeof VECTOR_DB_PROVIDERS[number];
|
|
20
|
-
|
|
21
|
-
export interface VectorDBConfig {
|
|
22
|
-
/** Which vector database to use */
|
|
23
|
-
provider: VectorDBProvider;
|
|
24
|
-
/** The index / table name to query */
|
|
25
|
-
indexName: string;
|
|
26
|
-
/** Provider-specific options (API keys, connection strings, etc.)
|
|
27
|
-
*
|
|
28
|
-
* For 'universal_rest', the following options are supported:
|
|
29
|
-
* - baseUrl: string
|
|
30
|
-
* - headers?: Record<string, string>
|
|
31
|
-
* - queryPath?: string
|
|
32
|
-
* - upsertPath?: string
|
|
33
|
-
* - queryPayloadTemplate?: string (e.g. '{"vector": {{vector}}, "limit": {{topK}}}')
|
|
34
|
-
* - upsertPayloadTemplate?: string (e.g. '{"id": "{{id}}", "vector": {{vector}}}')
|
|
35
|
-
* - responseExtractPath?: string (e.g. 'data.results')
|
|
36
|
-
* - idPath?: string (e.g. '_id')
|
|
37
|
-
* - scorePath?: string (e.g. 'similarity')
|
|
38
|
-
* - contentPath?: string (e.g. 'text')
|
|
39
|
-
*
|
|
40
|
-
* For 'mongodb', the following options are also supported:
|
|
41
|
-
* - numCandidates?: number // controls search recall depth
|
|
42
|
-
*
|
|
43
|
-
* For multi-table PostgreSQL search, the following options are also supported:
|
|
44
|
-
* - tables?: string[] | string
|
|
45
|
-
* - searchFields?: string[] | string // optional override for which columns receive exact-match boosts
|
|
46
|
-
*/
|
|
47
|
-
options: Record<string, unknown>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// ---------------------------------------------------------------------------
|
|
51
|
-
// Graph DB
|
|
52
|
-
// ---------------------------------------------------------------------------
|
|
53
|
-
|
|
54
|
-
export type GraphDBProvider = typeof GRAPH_DB_PROVIDERS[number];
|
|
55
|
-
|
|
56
|
-
export interface GraphDBConfig {
|
|
57
|
-
/** Which graph database to use */
|
|
58
|
-
provider: GraphDBProvider;
|
|
59
|
-
/** Provider-specific options (URI, credentials, etc.) */
|
|
60
|
-
options: Record<string, unknown>;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// ---------------------------------------------------------------------------
|
|
64
|
-
// LLM Provider
|
|
65
|
-
// ---------------------------------------------------------------------------
|
|
66
|
-
|
|
67
|
-
export type LLMProvider = typeof LLM_PROVIDERS[number];
|
|
68
|
-
|
|
69
|
-
export interface LLMConfig {
|
|
70
|
-
/** Which LLM provider to use */
|
|
71
|
-
provider: LLMProvider;
|
|
72
|
-
/** Model name, e.g. "gpt-4o", "claude-3-opus-20240229", "llama3" */
|
|
73
|
-
model: string;
|
|
74
|
-
/** API key for cloud providers */
|
|
75
|
-
apiKey?: string;
|
|
76
|
-
/** Base URL — required for Ollama or self-hosted endpoints */
|
|
77
|
-
baseUrl?: string;
|
|
78
|
-
/** Custom system prompt injected before every chat */
|
|
79
|
-
systemPrompt?: string;
|
|
80
|
-
/** Max tokens in the LLM response */
|
|
81
|
-
maxTokens?: number;
|
|
82
|
-
/** Sampling temperature (0–1) */
|
|
83
|
-
temperature?: number;
|
|
84
|
-
/** Provider-specific options
|
|
85
|
-
*
|
|
86
|
-
* For 'universal_rest', the following options are supported:
|
|
87
|
-
* - headers?: Record<string, string>
|
|
88
|
-
* - chatPath?: string
|
|
89
|
-
* - chatPayloadTemplate?: string (e.g. '{"prompt": "{{prompt}}", "max_tokens": {{maxTokens}}}')
|
|
90
|
-
* - responseExtractPath?: string (e.g. 'choices[0].text' or 'response')
|
|
91
|
-
*/
|
|
92
|
-
options?: Record<string, unknown>;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// ---------------------------------------------------------------------------
|
|
96
|
-
// Embedding
|
|
97
|
-
// ---------------------------------------------------------------------------
|
|
98
|
-
|
|
99
|
-
export type EmbeddingProvider = typeof EMBEDDING_PROVIDERS[number];
|
|
100
|
-
|
|
101
|
-
export interface EmbeddingConfig {
|
|
102
|
-
/** Which embedding provider to use */
|
|
103
|
-
provider: EmbeddingProvider;
|
|
104
|
-
/** Model name, e.g. "text-embedding-ada-002", "nomic-embed-text" */
|
|
105
|
-
model: string;
|
|
106
|
-
/** API key (if needed) */
|
|
107
|
-
apiKey?: string;
|
|
108
|
-
/** Base URL for custom / Ollama embedding endpoints */
|
|
109
|
-
baseUrl?: string;
|
|
110
|
-
/** Output vector dimension — must match the index dimension */
|
|
111
|
-
dimensions?: number;
|
|
112
|
-
/** Optional prefix to prepend to queries (for models like nomic-embed-text) */
|
|
113
|
-
queryPrefix?: string;
|
|
114
|
-
/** Optional prefix to prepend to documents during ingestion */
|
|
115
|
-
documentPrefix?: string;
|
|
116
|
-
/** Provider-specific options for custom adapters */
|
|
117
|
-
options?: Record<string, unknown>;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// ---------------------------------------------------------------------------
|
|
121
|
-
// UI Branding
|
|
122
|
-
// ---------------------------------------------------------------------------
|
|
123
|
-
|
|
124
|
-
export interface UIConfig {
|
|
125
|
-
/** Title shown in the chat header */
|
|
126
|
-
title?: string;
|
|
127
|
-
/** Subtitle / description below the title */
|
|
128
|
-
subtitle?: string;
|
|
129
|
-
/** Primary brand colour (CSS colour string) */
|
|
130
|
-
primaryColor?: string;
|
|
131
|
-
/** Accent colour for user message bubbles */
|
|
132
|
-
accentColor?: string;
|
|
133
|
-
/** URL to a logo image */
|
|
134
|
-
logoUrl?: string;
|
|
135
|
-
/** Input placeholder text */
|
|
136
|
-
placeholder?: string;
|
|
137
|
-
/** Show source cards after each answer */
|
|
138
|
-
showSources?: boolean;
|
|
139
|
-
/** Welcome message shown on first load */
|
|
140
|
-
welcomeMessage?: string;
|
|
141
|
-
/** Whether to show the floating chat widget. Defaults to true. */
|
|
142
|
-
showWidget?: boolean;
|
|
143
|
-
/** Custom 'Powered by' text shown in the header */
|
|
144
|
-
poweredBy?: string;
|
|
145
|
-
/** Visual style: 'glass' (default) or 'solid' */
|
|
146
|
-
visualStyle?: 'glass' | 'solid';
|
|
147
|
-
/** Border radius: 'none', 'sm', 'md', 'lg', 'xl', 'full' */
|
|
148
|
-
borderRadius?: 'none' | 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
149
|
-
/** Whether to allow file uploads directly from the UI */
|
|
150
|
-
allowUpload?: boolean;
|
|
151
|
-
/** Whether to allow manual resizing of the chat window. Defaults to true. */
|
|
152
|
-
allowResize?: boolean;
|
|
153
|
-
/** Whether to enable voice search input. Defaults to true. */
|
|
154
|
-
enableVoiceInput?: boolean;
|
|
155
|
-
theme?: 'light' | 'dark' | 'system';
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// ---------------------------------------------------------------------------
|
|
159
|
-
// RAG Pipeline Tuning
|
|
160
|
-
// ---------------------------------------------------------------------------
|
|
161
|
-
|
|
162
|
-
export interface CAGConfig {
|
|
163
|
-
/** Enable Cold RAG (Cache Augmented Generation) */
|
|
164
|
-
enabled?: boolean;
|
|
165
|
-
/** Namespace containing the cold data (e.g., static manuals/guides) */
|
|
166
|
-
coldNamespace?: string;
|
|
167
|
-
/** Limit of cold documents to retrieve at initialization and keep in cache/context */
|
|
168
|
-
coldLimit?: number;
|
|
169
|
-
/** Specific search query to retrieve the cold documents (e.g., "manual", "documentation") */
|
|
170
|
-
coldQuery?: string;
|
|
171
|
-
/** Specific document IDs to load as cold context */
|
|
172
|
-
coldDocumentIds?: string[];
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export interface RAGConfig {
|
|
176
|
-
/** Number of top-K chunks retrieved per query */
|
|
177
|
-
topK?: number;
|
|
178
|
-
/** Minimum similarity score to include a chunk (0–1) */
|
|
179
|
-
scoreThreshold?: number;
|
|
180
|
-
/** Target chunk size in tokens */
|
|
181
|
-
chunkSize?: number;
|
|
182
|
-
/** Overlap between adjacent chunks in tokens */
|
|
183
|
-
chunkOverlap?: number;
|
|
184
|
-
/** Characters used to split text, in order of priority */
|
|
185
|
-
separators?: string[];
|
|
186
|
-
/** Overall RAG architecture pattern */
|
|
187
|
-
architecture?: 'simple' | 'graph' | 'hybrid' | 'agentic' | 'naive' | 'retrieve-and-rerank' | 'multimodal' | 'agentic-router' | 'multi-agent';
|
|
188
|
-
/** Chunking strategy to use during ingestion */
|
|
189
|
-
chunkingStrategy?: 'recursive' | 'markdown' | 'semantic' | 'llamaindex';
|
|
190
|
-
/** Whether to use query transformation (e.g. HyDE) */
|
|
191
|
-
useQueryTransformation?: boolean;
|
|
192
|
-
/** Whether to use graph-based retrieval */
|
|
193
|
-
useGraphRetrieval?: boolean;
|
|
194
|
-
/** Whether to perform reranking on retrieved results */
|
|
195
|
-
useReranking?: boolean;
|
|
196
|
-
/** List of metadata fields that are valid for filtering.
|
|
197
|
-
* Used to dynamically extract hints from natural language queries.
|
|
198
|
-
*/
|
|
199
|
-
filterableFields?: string[];
|
|
200
|
-
/** Optional mapping from database metadata fields to standard UI properties.
|
|
201
|
-
* Useful for databases with custom schemas.
|
|
202
|
-
* e.g., { "name": "ProductName", "price": "SalesPrice", "image": "ThumbnailUrl" }
|
|
203
|
-
*/
|
|
204
|
-
uiMapping?: Record<string, string>;
|
|
205
|
-
/**
|
|
206
|
-
* Custom keywords that signal graph-based retrieval should be used.
|
|
207
|
-
* Defaults to built-in list (relationship, connect, hierarchy, etc.).
|
|
208
|
-
*/
|
|
209
|
-
graphKeywords?: string[];
|
|
210
|
-
/**
|
|
211
|
-
* Custom keywords that signal vector-based retrieval should be used.
|
|
212
|
-
* Defaults to built-in list (find, search, tell me about, etc.).
|
|
213
|
-
*/
|
|
214
|
-
vectorKeywords?: string[];
|
|
215
|
-
/** Cold RAG (Cache Augmented Generation) configuration */
|
|
216
|
-
cag?: CAGConfig;
|
|
217
|
-
/** Chat history configuration */
|
|
218
|
-
history?: {
|
|
219
|
-
enabled?: boolean;
|
|
220
|
-
tableName?: string;
|
|
221
|
-
};
|
|
222
|
-
/** User feedback configuration */
|
|
223
|
-
feedback?: {
|
|
224
|
-
enabled?: boolean;
|
|
225
|
-
tableName?: string;
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export interface RetrievalConfig {
|
|
230
|
-
/** Retrieval strategy selected by the host app. */
|
|
231
|
-
strategy?:
|
|
232
|
-
| 'vector'
|
|
233
|
-
| 'keyword'
|
|
234
|
-
| 'hybrid'
|
|
235
|
-
| 'multi-query'
|
|
236
|
-
| 'self-query'
|
|
237
|
-
| 'parent-document'
|
|
238
|
-
| 'contextual-compression'
|
|
239
|
-
| 'ensemble'
|
|
240
|
-
| 'recursive'
|
|
241
|
-
| 'agentic';
|
|
242
|
-
/** Number of documents/chunks retrieved per query. */
|
|
243
|
-
topK?: number;
|
|
244
|
-
/** Minimum similarity score to include a retrieved chunk. */
|
|
245
|
-
scoreThreshold?: number;
|
|
246
|
-
/** Whether to rerank retrieved chunks before generation. */
|
|
247
|
-
useReranking?: boolean;
|
|
248
|
-
/** Provider-specific retrieval options for future strategies. */
|
|
249
|
-
options?: Record<string, unknown>;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export interface WorkflowConfig {
|
|
253
|
-
/** High-level workflow selector from the SDK prompt. */
|
|
254
|
-
type?: 'simple-rag' | 'rag' | 'hybrid-rag' | 'graph-rag' | 'agentic-rag' | 'agentic' | 'naive-rag' | 'retrieve-and-rerank' | 'multimodal-rag' | 'agentic-router' | 'multi-agent-rag' | 'multi-agent';
|
|
255
|
-
/** Future workflow/provider-specific options. */
|
|
256
|
-
options?: Record<string, unknown>;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export interface MCPServerConfig {
|
|
260
|
-
name: string;
|
|
261
|
-
transport: 'stdio' | 'sse';
|
|
262
|
-
url?: string; // Required for SSE transport
|
|
263
|
-
command?: string; // Required for Stdio transport
|
|
264
|
-
args?: string[]; // Optional for Stdio transport
|
|
265
|
-
env?: Record<string, string>; // Optional env variables for Stdio child process
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// ---------------------------------------------------------------------------
|
|
269
|
-
// Root Config
|
|
270
|
-
// ---------------------------------------------------------------------------
|
|
271
|
-
|
|
272
|
-
export interface RagConfig {
|
|
273
|
-
/** License key for commercial production validation */
|
|
274
|
-
licenseKey?: string;
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Unique identifier for the consuming project.
|
|
278
|
-
* Used as the vector DB namespace to achieve multi-tenancy.
|
|
279
|
-
*/
|
|
280
|
-
projectId: string;
|
|
281
|
-
|
|
282
|
-
/** Vector database configuration */
|
|
283
|
-
vectorDb: VectorDBConfig;
|
|
284
|
-
|
|
285
|
-
/** LLM configuration */
|
|
286
|
-
llm: LLMConfig;
|
|
287
|
-
|
|
288
|
-
/** Embedding configuration */
|
|
289
|
-
embedding: EmbeddingConfig;
|
|
290
|
-
|
|
291
|
-
/** Optional UI branding overrides */
|
|
292
|
-
ui?: UIConfig;
|
|
293
|
-
|
|
294
|
-
/** Optional dashboard-managed project chat settings */
|
|
295
|
-
projectSettings?: ProjectChatSettings;
|
|
296
|
-
|
|
297
|
-
/** Optional RAG pipeline tuning knobs */
|
|
298
|
-
rag?: RAGConfig;
|
|
299
|
-
|
|
300
|
-
/** Optional Graph database configuration */
|
|
301
|
-
graphDb?: GraphDBConfig;
|
|
302
|
-
|
|
303
|
-
/** Optional Telemetry configuration for observability logging */
|
|
304
|
-
telemetry?: {
|
|
305
|
-
enabled?: boolean;
|
|
306
|
-
url?: string;
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
/** Optional Model Context Protocol (MCP) server configurations */
|
|
310
|
-
mcpServers?: MCPServerConfig[];
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Friendly SDK configuration accepted by the top-level Retrivora facade.
|
|
315
|
-
* It supports the prompt's `vectorDatabase`, `retrieval`, and `workflow`
|
|
316
|
-
* naming while normalizing to the internal RagConfig shape.
|
|
317
|
-
*/
|
|
318
|
-
export type UniversalRagConfig =
|
|
319
|
-
Partial<Omit<RagConfig, 'vectorDb' | 'rag' | 'llm' | 'embedding' | 'graphDb'>> & {
|
|
320
|
-
vectorDb?: Partial<VectorDBConfig>;
|
|
321
|
-
vectorDatabase?: Partial<VectorDBConfig>;
|
|
322
|
-
llm?: Partial<LLMConfig>;
|
|
323
|
-
embedding?: Partial<EmbeddingConfig>;
|
|
324
|
-
graphDb?: Partial<GraphDBConfig>;
|
|
325
|
-
retrieval?: RetrievalConfig;
|
|
326
|
-
rag?: RAGConfig;
|
|
327
|
-
workflow?: WorkflowConfig;
|
|
328
|
-
};
|