@retrivora-ai/rag-engine 1.8.0 → 1.8.2

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 (71) hide show
  1. package/dist/DocumentChunker-Dh9TvmGG.d.mts +45 -0
  2. package/dist/DocumentChunker-Dh9TvmGG.d.ts +45 -0
  3. package/dist/{index-DPsQodME.d.mts → ILLMProvider-BOJFz3Na.d.mts} +104 -1
  4. package/dist/{index-DPsQodME.d.ts → ILLMProvider-BOJFz3Na.d.ts} +104 -1
  5. package/dist/MultiTablePostgresProvider-ZLGSKTJR.mjs +8 -0
  6. package/dist/chunk-ICKRMZQK.mjs +76 -0
  7. package/dist/{chunk-PV3MFHWU.mjs → chunk-LZVVLSDN.mjs} +977 -516
  8. package/dist/chunk-OZFBG4BA.mjs +291 -0
  9. package/dist/handlers/index.d.mts +2 -2
  10. package/dist/handlers/index.d.ts +2 -2
  11. package/dist/handlers/index.js +1269 -656
  12. package/dist/handlers/index.mjs +4 -1
  13. package/dist/{index-Bb2yEopi.d.mts → index-BwpcaziY.d.ts} +10 -2
  14. package/dist/{index-CkbTzj9J.d.ts → index-D3V9Et2M.d.mts} +10 -2
  15. package/dist/index.d.mts +24 -4
  16. package/dist/index.d.ts +24 -4
  17. package/dist/index.js +1354 -826
  18. package/dist/index.mjs +1284 -795
  19. package/dist/server.d.mts +47 -27
  20. package/dist/server.d.ts +47 -27
  21. package/dist/server.js +1417 -829
  22. package/dist/server.mjs +164 -176
  23. package/package.json +6 -2
  24. package/src/app/api/upload/route.ts +4 -0
  25. package/src/app/constants.tsx +2 -2
  26. package/src/app/page.tsx +12 -322
  27. package/src/components/AmbientBackground.tsx +29 -0
  28. package/src/components/ArchitectureCard.tsx +17 -0
  29. package/src/components/ArchitectureCardsSection.tsx +15 -0
  30. package/src/components/ChatWindow.tsx +32 -0
  31. package/src/components/CodeViewer.tsx +51 -0
  32. package/src/components/ConfigProvider.tsx +1 -0
  33. package/src/components/DocViewer.tsx +37 -0
  34. package/src/components/DocumentUpload.tsx +44 -1
  35. package/src/components/Documentation.tsx +58 -0
  36. package/src/components/DynamicChart.tsx +27 -2
  37. package/src/components/Hero.tsx +59 -0
  38. package/src/components/HourglassLoader.tsx +87 -0
  39. package/src/components/Lifecycle.tsx +37 -0
  40. package/src/components/MarkdownComponents.tsx +140 -0
  41. package/src/components/MessageBubble.tsx +124 -904
  42. package/src/components/Navbar.tsx +55 -0
  43. package/src/components/ObservabilityPanel.tsx +374 -0
  44. package/src/components/ProductCard.tsx +5 -3
  45. package/src/components/UIDispatcher.tsx +344 -0
  46. package/src/components/VisualizationRenderer.tsx +372 -250
  47. package/src/config/RagConfig.ts +5 -0
  48. package/src/config/serverConfig.ts +3 -1
  49. package/src/core/Pipeline.ts +240 -271
  50. package/src/core/ProviderRegistry.ts +2 -2
  51. package/src/core/VectorPlugin.ts +9 -0
  52. package/src/handlers/index.ts +91 -15
  53. package/src/hooks/useRagChat.ts +21 -11
  54. package/src/index.ts +9 -1
  55. package/src/llm/LLMFactory.ts +54 -2
  56. package/src/llm/providers/AnthropicProvider.ts +12 -8
  57. package/src/llm/providers/GeminiProvider.ts +188 -143
  58. package/src/llm/providers/OllamaProvider.ts +7 -3
  59. package/src/llm/providers/OpenAIProvider.ts +12 -8
  60. package/src/providers/vectordb/MultiTablePostgresProvider.ts +150 -64
  61. package/src/types/chat.ts +8 -0
  62. package/src/types/index.ts +132 -0
  63. package/src/types/props.ts +9 -1
  64. package/src/utils/ProductExtractor.ts +347 -0
  65. package/src/utils/SchemaMapper.ts +129 -0
  66. package/src/utils/UITransformer.ts +470 -209
  67. package/src/utils/synonyms.ts +78 -0
  68. package/dist/DocumentChunker-C1GEEosY.d.ts +0 -93
  69. package/dist/DocumentChunker-CFEiRopR.d.mts +0 -93
  70. package/dist/PostgreSQLProvider-BMOETDZA.mjs +0 -8
  71. package/dist/chunk-FLOSGE6A.mjs +0 -202
package/dist/server.d.mts CHANGED
@@ -1,8 +1,7 @@
1
- import { j as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, h as RagConfig, I as IngestDocument, C as ChatMessage, d as ChatResponse, l as RetrievalResult, i as UpsertDocument, V as VectorMatch, G as GraphDBConfig, m as GraphNode, n as Edge, o as GraphSearchResult, k as VectorDBProvider, f as LLMProvider, e as EmbeddingProvider, g as RAGConfig, U as UIConfig, c as ChatOptions } from './index-DPsQodME.mjs';
2
- import { I as ILLMProvider, E as EmbedOptions } from './DocumentChunker-CFEiRopR.mjs';
3
- export { C as Chunk, a as ChunkOptions, D as DocumentChunker } from './DocumentChunker-CFEiRopR.mjs';
4
- import { H as HealthCheckResult, I as IProviderValidator, a as IProviderHealthChecker } from './index-Bb2yEopi.mjs';
5
- export { C as ConfigValidator, V as ValidationError, b as VectorPlugin, c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from './index-Bb2yEopi.mjs';
1
+ import { n as VectorDBConfig, L as LLMConfig, e as EmbeddingConfig, k as RagConfig, I as ILLMProvider, g as IngestDocument, C as ChatMessage, d as ChatResponse, p as RetrievalResult, m as UpsertDocument, V as VectorMatch, G as GraphDBConfig, q as GraphNode, r as Edge, s as GraphSearchResult, o as VectorDBProvider, h as LLMProvider, f as EmbeddingProvider, j as RAGConfig, U as UIConfig, c as ChatOptions, E as EmbedOptions } from './ILLMProvider-BOJFz3Na.mjs';
2
+ export { C as Chunk, a as ChunkOptions, D as DocumentChunker } from './DocumentChunker-Dh9TvmGG.mjs';
3
+ import { H as HealthCheckResult, I as IProviderValidator, a as IProviderHealthChecker } from './index-D3V9Et2M.mjs';
4
+ export { C as ConfigValidator, V as ValidationError, b as VectorPlugin, c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from './index-D3V9Et2M.mjs';
6
5
  import 'next/server';
7
6
 
8
7
  /**
@@ -106,6 +105,7 @@ declare class ProviderHealthCheck {
106
105
  * - Error recovery for transient failures
107
106
  * - Multi-tenancy support via namespacing
108
107
  * - LRU-bounded embedding cache (max 500 entries, prevents memory leaks)
108
+ * - Full observability tracing (latency, tokens, hallucination scoring)
109
109
  */
110
110
  declare class Pipeline {
111
111
  private config;
@@ -122,54 +122,49 @@ declare class Pipeline {
122
122
  private embeddingCache;
123
123
  private initialised;
124
124
  constructor(config: RagConfig);
125
+ /**
126
+ * Expose the underlying LLM provider (set after initialize()).
127
+ * Used by the stream handler to pass to UITransformer.analyzeAndDecide().
128
+ */
129
+ getLLMProvider(): ILLMProvider | undefined;
125
130
  initialize(): Promise<void>;
126
131
  /**
127
132
  * Ingest documents with automatic chunking, embedding, and batch upsert.
128
- * Handles retries for transient failures.
129
133
  */
130
134
  ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
131
135
  docId: string | number;
132
136
  chunksIngested: number;
133
137
  }>>;
134
- /**
135
- * Step 1: Chunk the document content.
136
- */
138
+ /** Step 1: Chunk the document content. */
137
139
  private prepareChunks;
138
140
  /**
139
141
  * Step 2: Generate embeddings for chunks with retry logic.
140
142
  * Uses batchEmbed when available for efficiency; falls back to sequential embedding.
141
143
  */
142
144
  private processEmbeddings;
143
- /**
144
- * Step 3: Upsert chunks to vector database with retry logic.
145
- */
145
+ /** Step 3: Upsert chunks to vector database with retry logic. */
146
146
  private processUpserts;
147
- /**
148
- * Step 4: Optional graph-based entity extraction and ingestion.
149
- */
147
+ /** Step 4: Optional graph-based entity extraction and ingestion. */
150
148
  private processGraphIngestion;
151
149
  ask(question: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
152
150
  /**
153
151
  * High-performance streaming RAG flow.
154
- * Yields text chunks first, then the retrieval metadata at the end.
152
+ * Yields text chunks first, then the retrieval metadata + observability trace at the end.
155
153
  */
156
154
  askStream(question: string, history?: ChatMessage[], namespace?: string): AsyncIterable<string | ChatResponse>;
157
155
  /**
158
156
  * Universal retrieval method combining all enabled providers.
159
157
  * Uses an LRU-bounded embedding cache to avoid re-embedding the same query.
160
158
  */
159
+ private generateUiTransformation;
161
160
  retrieve(query: string, options: {
162
161
  namespace?: string;
163
162
  topK?: number;
164
163
  filter?: Record<string, unknown>;
165
164
  }): Promise<RetrievalResult>;
166
- /**
167
- * Rewrite the user query for better retrieval performance.
168
- */
165
+ /** Rewrite the user query for better retrieval performance. */
169
166
  private rewriteQuery;
170
- /**
171
- * Generate 3-5 short, relevant questions based on the vector database content.
172
- */
167
+ /** Generate 3-5 short, relevant questions based on the vector database content. */
173
168
  getSuggestions(query: string, namespace?: string): Promise<string[]>;
174
169
  }
175
170
 
@@ -659,17 +654,17 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
659
654
  private readonly connectionString;
660
655
  private tables;
661
656
  private searchFields;
657
+ private readonly uploadTable;
662
658
  constructor(config: VectorDBConfig);
663
659
  initialize(): Promise<void>;
664
660
  /**
665
- * Upsert is not supported for MultiTablePostgresProvider as it's designed for
666
- * searching across pre-existing tables with varying schemas.
661
+ * Upsert a document by dynamically provisioning a table and columns.
667
662
  */
668
- upsert(_doc: UpsertDocument, _namespace?: string): Promise<void>;
663
+ upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
669
664
  /**
670
- * Batch upsert is not supported for MultiTablePostgresProvider.
665
+ * Batch upsert documents by dynamically provisioning tables and columns based on CSV headers.
671
666
  */
672
- batchUpsert(_docs: UpsertDocument[], _namespace?: string): Promise<void>;
667
+ batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
673
668
  /**
674
669
  * Query all configured tables and merge results, sorted by cosine similarity score.
675
670
  */
@@ -871,6 +866,31 @@ declare class UniversalVectorProvider extends BaseVectorProvider {
871
866
  * LLMFactory — instantiates the correct ILLMProvider based on llmConfig.provider.
872
867
  */
873
868
  declare class LLMFactory {
869
+ /**
870
+ * Register a custom LLM provider factory at runtime.
871
+ *
872
+ * Use this to add support for any LLM backend (Azure OpenAI, Cohere, Mistral,
873
+ * Bedrock, etc.) without modifying this library's source code.
874
+ *
875
+ * @example
876
+ * // In your Next.js app initialization:
877
+ * import { LLMFactory } from '@retrivora-ai/rag-engine/server';
878
+ * import { MyCustomProvider } from './providers/MyCustomProvider';
879
+ *
880
+ * LLMFactory.register('my-provider', (config) => new MyCustomProvider(config));
881
+ *
882
+ * // Then set in your .env.local:
883
+ * // LLM_PROVIDER=my-provider
884
+ */
885
+ static register(name: string, factory: (config: LLMConfig) => ILLMProvider): void;
886
+ /**
887
+ * Unregister a previously registered custom provider.
888
+ */
889
+ static unregister(name: string): void;
890
+ /**
891
+ * List all registered provider names (built-in + custom).
892
+ */
893
+ static listProviders(): string[];
874
894
  static create(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig): ILLMProvider;
875
895
  static getValidator(provider: LLMProvider): IProviderValidator | null;
876
896
  static getHealthChecker(provider: LLMProvider): IProviderHealthChecker | null;
package/dist/server.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import { j as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, h as RagConfig, I as IngestDocument, C as ChatMessage, d as ChatResponse, l as RetrievalResult, i as UpsertDocument, V as VectorMatch, G as GraphDBConfig, m as GraphNode, n as Edge, o as GraphSearchResult, k as VectorDBProvider, f as LLMProvider, e as EmbeddingProvider, g as RAGConfig, U as UIConfig, c as ChatOptions } from './index-DPsQodME.js';
2
- import { I as ILLMProvider, E as EmbedOptions } from './DocumentChunker-C1GEEosY.js';
3
- export { C as Chunk, a as ChunkOptions, D as DocumentChunker } from './DocumentChunker-C1GEEosY.js';
4
- import { H as HealthCheckResult, I as IProviderValidator, a as IProviderHealthChecker } from './index-CkbTzj9J.js';
5
- export { C as ConfigValidator, V as ValidationError, b as VectorPlugin, c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from './index-CkbTzj9J.js';
1
+ import { n as VectorDBConfig, L as LLMConfig, e as EmbeddingConfig, k as RagConfig, I as ILLMProvider, g as IngestDocument, C as ChatMessage, d as ChatResponse, p as RetrievalResult, m as UpsertDocument, V as VectorMatch, G as GraphDBConfig, q as GraphNode, r as Edge, s as GraphSearchResult, o as VectorDBProvider, h as LLMProvider, f as EmbeddingProvider, j as RAGConfig, U as UIConfig, c as ChatOptions, E as EmbedOptions } from './ILLMProvider-BOJFz3Na.js';
2
+ export { C as Chunk, a as ChunkOptions, D as DocumentChunker } from './DocumentChunker-Dh9TvmGG.js';
3
+ import { H as HealthCheckResult, I as IProviderValidator, a as IProviderHealthChecker } from './index-BwpcaziY.js';
4
+ export { C as ConfigValidator, V as ValidationError, b as VectorPlugin, c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from './index-BwpcaziY.js';
6
5
  import 'next/server';
7
6
 
8
7
  /**
@@ -106,6 +105,7 @@ declare class ProviderHealthCheck {
106
105
  * - Error recovery for transient failures
107
106
  * - Multi-tenancy support via namespacing
108
107
  * - LRU-bounded embedding cache (max 500 entries, prevents memory leaks)
108
+ * - Full observability tracing (latency, tokens, hallucination scoring)
109
109
  */
110
110
  declare class Pipeline {
111
111
  private config;
@@ -122,54 +122,49 @@ declare class Pipeline {
122
122
  private embeddingCache;
123
123
  private initialised;
124
124
  constructor(config: RagConfig);
125
+ /**
126
+ * Expose the underlying LLM provider (set after initialize()).
127
+ * Used by the stream handler to pass to UITransformer.analyzeAndDecide().
128
+ */
129
+ getLLMProvider(): ILLMProvider | undefined;
125
130
  initialize(): Promise<void>;
126
131
  /**
127
132
  * Ingest documents with automatic chunking, embedding, and batch upsert.
128
- * Handles retries for transient failures.
129
133
  */
130
134
  ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
131
135
  docId: string | number;
132
136
  chunksIngested: number;
133
137
  }>>;
134
- /**
135
- * Step 1: Chunk the document content.
136
- */
138
+ /** Step 1: Chunk the document content. */
137
139
  private prepareChunks;
138
140
  /**
139
141
  * Step 2: Generate embeddings for chunks with retry logic.
140
142
  * Uses batchEmbed when available for efficiency; falls back to sequential embedding.
141
143
  */
142
144
  private processEmbeddings;
143
- /**
144
- * Step 3: Upsert chunks to vector database with retry logic.
145
- */
145
+ /** Step 3: Upsert chunks to vector database with retry logic. */
146
146
  private processUpserts;
147
- /**
148
- * Step 4: Optional graph-based entity extraction and ingestion.
149
- */
147
+ /** Step 4: Optional graph-based entity extraction and ingestion. */
150
148
  private processGraphIngestion;
151
149
  ask(question: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
152
150
  /**
153
151
  * High-performance streaming RAG flow.
154
- * Yields text chunks first, then the retrieval metadata at the end.
152
+ * Yields text chunks first, then the retrieval metadata + observability trace at the end.
155
153
  */
156
154
  askStream(question: string, history?: ChatMessage[], namespace?: string): AsyncIterable<string | ChatResponse>;
157
155
  /**
158
156
  * Universal retrieval method combining all enabled providers.
159
157
  * Uses an LRU-bounded embedding cache to avoid re-embedding the same query.
160
158
  */
159
+ private generateUiTransformation;
161
160
  retrieve(query: string, options: {
162
161
  namespace?: string;
163
162
  topK?: number;
164
163
  filter?: Record<string, unknown>;
165
164
  }): Promise<RetrievalResult>;
166
- /**
167
- * Rewrite the user query for better retrieval performance.
168
- */
165
+ /** Rewrite the user query for better retrieval performance. */
169
166
  private rewriteQuery;
170
- /**
171
- * Generate 3-5 short, relevant questions based on the vector database content.
172
- */
167
+ /** Generate 3-5 short, relevant questions based on the vector database content. */
173
168
  getSuggestions(query: string, namespace?: string): Promise<string[]>;
174
169
  }
175
170
 
@@ -659,17 +654,17 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
659
654
  private readonly connectionString;
660
655
  private tables;
661
656
  private searchFields;
657
+ private readonly uploadTable;
662
658
  constructor(config: VectorDBConfig);
663
659
  initialize(): Promise<void>;
664
660
  /**
665
- * Upsert is not supported for MultiTablePostgresProvider as it's designed for
666
- * searching across pre-existing tables with varying schemas.
661
+ * Upsert a document by dynamically provisioning a table and columns.
667
662
  */
668
- upsert(_doc: UpsertDocument, _namespace?: string): Promise<void>;
663
+ upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
669
664
  /**
670
- * Batch upsert is not supported for MultiTablePostgresProvider.
665
+ * Batch upsert documents by dynamically provisioning tables and columns based on CSV headers.
671
666
  */
672
- batchUpsert(_docs: UpsertDocument[], _namespace?: string): Promise<void>;
667
+ batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
673
668
  /**
674
669
  * Query all configured tables and merge results, sorted by cosine similarity score.
675
670
  */
@@ -871,6 +866,31 @@ declare class UniversalVectorProvider extends BaseVectorProvider {
871
866
  * LLMFactory — instantiates the correct ILLMProvider based on llmConfig.provider.
872
867
  */
873
868
  declare class LLMFactory {
869
+ /**
870
+ * Register a custom LLM provider factory at runtime.
871
+ *
872
+ * Use this to add support for any LLM backend (Azure OpenAI, Cohere, Mistral,
873
+ * Bedrock, etc.) without modifying this library's source code.
874
+ *
875
+ * @example
876
+ * // In your Next.js app initialization:
877
+ * import { LLMFactory } from '@retrivora-ai/rag-engine/server';
878
+ * import { MyCustomProvider } from './providers/MyCustomProvider';
879
+ *
880
+ * LLMFactory.register('my-provider', (config) => new MyCustomProvider(config));
881
+ *
882
+ * // Then set in your .env.local:
883
+ * // LLM_PROVIDER=my-provider
884
+ */
885
+ static register(name: string, factory: (config: LLMConfig) => ILLMProvider): void;
886
+ /**
887
+ * Unregister a previously registered custom provider.
888
+ */
889
+ static unregister(name: string): void;
890
+ /**
891
+ * List all registered provider names (built-in + custom).
892
+ */
893
+ static listProviders(): string[];
874
894
  static create(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig): ILLMProvider;
875
895
  static getValidator(provider: LLMProvider): IProviderValidator | null;
876
896
  static getHealthChecker(provider: LLMProvider): IProviderHealthChecker | null;