@retrivora-ai/rag-engine 1.8.0 → 1.8.1

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 (46) 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-BfRgI1Xh.d.mts} +58 -1
  4. package/dist/{index-DPsQodME.d.ts → ILLMProvider-BfRgI1Xh.d.ts} +58 -1
  5. package/dist/MultiTablePostgresProvider-YY7LPNJK.mjs +8 -0
  6. package/dist/{chunk-PV3MFHWU.mjs → chunk-BFYLQYQU.mjs} +808 -439
  7. package/dist/chunk-R3RGUMHE.mjs +218 -0
  8. package/dist/handlers/index.d.mts +2 -2
  9. package/dist/handlers/index.d.ts +2 -2
  10. package/dist/handlers/index.js +995 -603
  11. package/dist/handlers/index.mjs +1 -1
  12. package/dist/{index-Bb2yEopi.d.mts → index-1Z4GuYBi.d.ts} +7 -1
  13. package/dist/{index-CkbTzj9J.d.ts → index-BV0z5mb6.d.mts} +7 -1
  14. package/dist/index.d.mts +3 -3
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +491 -316
  17. package/dist/index.mjs +411 -217
  18. package/dist/server.d.mts +35 -5
  19. package/dist/server.d.ts +35 -5
  20. package/dist/server.js +1146 -777
  21. package/dist/server.mjs +163 -176
  22. package/package.json +4 -2
  23. package/src/app/page.tsx +1 -2
  24. package/src/components/MessageBubble.tsx +211 -69
  25. package/src/components/ProductCard.tsx +2 -2
  26. package/src/components/VisualizationRenderer.tsx +347 -247
  27. package/src/config/RagConfig.ts +5 -0
  28. package/src/config/serverConfig.ts +3 -1
  29. package/src/core/Pipeline.ts +65 -206
  30. package/src/core/ProviderRegistry.ts +2 -2
  31. package/src/core/VectorPlugin.ts +9 -0
  32. package/src/handlers/index.ts +23 -7
  33. package/src/hooks/useRagChat.ts +2 -2
  34. package/src/llm/LLMFactory.ts +54 -2
  35. package/src/llm/providers/AnthropicProvider.ts +12 -8
  36. package/src/llm/providers/GeminiProvider.ts +188 -143
  37. package/src/llm/providers/OllamaProvider.ts +7 -3
  38. package/src/llm/providers/OpenAIProvider.ts +12 -8
  39. package/src/types/chat.ts +6 -0
  40. package/src/types/index.ts +80 -0
  41. package/src/utils/SchemaMapper.ts +129 -0
  42. package/src/utils/UITransformer.ts +491 -181
  43. package/dist/DocumentChunker-C1GEEosY.d.ts +0 -93
  44. package/dist/DocumentChunker-CFEiRopR.d.mts +0 -93
  45. package/dist/PostgreSQLProvider-BMOETDZA.mjs +0 -8
  46. package/dist/chunk-FLOSGE6A.mjs +0 -202
@@ -0,0 +1,45 @@
1
+ /**
2
+ * DocumentChunker — splits long text into overlapping chunks
3
+ * suitable for vector embedding and retrieval.
4
+ *
5
+ * Strategy: sentence-aware sliding window
6
+ * 1. Split on sentence boundaries
7
+ * 2. Accumulate sentences into chunks up to `chunkSize` characters
8
+ * 3. Carry over `chunkOverlap` characters from the previous chunk
9
+ */
10
+ interface Chunk {
11
+ id: string;
12
+ content: string;
13
+ metadata?: Record<string, unknown>;
14
+ }
15
+ interface ChunkOptions {
16
+ /** Target chunk size in characters (default 1000) */
17
+ chunkSize?: number;
18
+ /** Overlap between consecutive chunks in characters (default 200) */
19
+ chunkOverlap?: number;
20
+ /** Source document identifier used as ID prefix */
21
+ docId?: string | number;
22
+ /** Extra metadata to attach to every chunk */
23
+ metadata?: Record<string, unknown>;
24
+ /** Characters used to split text, in order of priority */
25
+ separators?: string[];
26
+ }
27
+ declare class DocumentChunker {
28
+ private readonly chunkSize;
29
+ private readonly chunkOverlap;
30
+ private readonly separators;
31
+ constructor(chunkSize?: number, chunkOverlap?: number, separators?: string[]);
32
+ /**
33
+ * Split a single text string into overlapping chunks using a recursive strategy.
34
+ * Preserves structural boundaries (Markdown headers) where possible.
35
+ */
36
+ chunk(text: string, options?: ChunkOptions): Chunk[];
37
+ private recursiveSplit;
38
+ chunkMany(documents: Array<{
39
+ content: string;
40
+ docId?: string | number;
41
+ metadata?: Record<string, unknown>;
42
+ }>): Chunk[];
43
+ }
44
+
45
+ export { type Chunk as C, DocumentChunker as D, type ChunkOptions as a };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * DocumentChunker — splits long text into overlapping chunks
3
+ * suitable for vector embedding and retrieval.
4
+ *
5
+ * Strategy: sentence-aware sliding window
6
+ * 1. Split on sentence boundaries
7
+ * 2. Accumulate sentences into chunks up to `chunkSize` characters
8
+ * 3. Carry over `chunkOverlap` characters from the previous chunk
9
+ */
10
+ interface Chunk {
11
+ id: string;
12
+ content: string;
13
+ metadata?: Record<string, unknown>;
14
+ }
15
+ interface ChunkOptions {
16
+ /** Target chunk size in characters (default 1000) */
17
+ chunkSize?: number;
18
+ /** Overlap between consecutive chunks in characters (default 200) */
19
+ chunkOverlap?: number;
20
+ /** Source document identifier used as ID prefix */
21
+ docId?: string | number;
22
+ /** Extra metadata to attach to every chunk */
23
+ metadata?: Record<string, unknown>;
24
+ /** Characters used to split text, in order of priority */
25
+ separators?: string[];
26
+ }
27
+ declare class DocumentChunker {
28
+ private readonly chunkSize;
29
+ private readonly chunkOverlap;
30
+ private readonly separators;
31
+ constructor(chunkSize?: number, chunkOverlap?: number, separators?: string[]);
32
+ /**
33
+ * Split a single text string into overlapping chunks using a recursive strategy.
34
+ * Preserves structural boundaries (Markdown headers) where possible.
35
+ */
36
+ chunk(text: string, options?: ChunkOptions): Chunk[];
37
+ private recursiveSplit;
38
+ chunkMany(documents: Array<{
39
+ content: string;
40
+ docId?: string | number;
41
+ metadata?: Record<string, unknown>;
42
+ }>): Chunk[];
43
+ }
44
+
45
+ export { type Chunk as C, DocumentChunker as D, type ChunkOptions as a };
@@ -16,6 +16,12 @@ interface ChatOptions {
16
16
  temperature?: number;
17
17
  /** Stop sequences */
18
18
  stop?: string[];
19
+ /**
20
+ * Per-call system prompt override. When provided, providers should use this
21
+ * instead of (or in addition to) their configured llmConfig.systemPrompt.
22
+ * Useful for one-off analytical calls (e.g. UITransformer.analyzeAndDecide).
23
+ */
24
+ systemPrompt?: string;
19
25
  }
20
26
  interface UseRagChatOptions {
21
27
  /** Override the chat API endpoint (default: /api/chat) */
@@ -201,6 +207,11 @@ interface RAGConfig {
201
207
  * Used to dynamically extract hints from natural language queries.
202
208
  */
203
209
  filterableFields?: string[];
210
+ /** Optional mapping from database metadata fields to standard UI properties.
211
+ * Useful for databases with custom schemas.
212
+ * e.g., { "name": "ProductName", "price": "SalesPrice", "image": "ThumbnailUrl" }
213
+ */
214
+ uiMapping?: Record<string, string>;
204
215
  }
205
216
  interface RagConfig {
206
217
  /**
@@ -274,4 +285,50 @@ interface Product {
274
285
  description?: string;
275
286
  }
276
287
 
277
- export type { ChatMessage as C, EmbeddingConfig as E, GraphDBConfig as G, IngestDocument as I, LLMConfig as L, Product as P, RagMessage as R, UIConfig as U, VectorMatch as V, UseRagChatOptions as a, UseRagChatReturn as b, ChatOptions as c, ChatResponse as d, EmbeddingProvider as e, LLMProvider as f, RAGConfig as g, RagConfig as h, UpsertDocument as i, VectorDBConfig as j, VectorDBProvider as k, RetrievalResult as l, GraphNode as m, Edge as n, GraphSearchResult as o };
288
+ /**
289
+ * Generic LLM Provider interface.
290
+ * Covers both chat completion and embedding generation so a single
291
+ * provider can handle both responsibilities when appropriate.
292
+ */
293
+
294
+ interface EmbedOptions {
295
+ /** Override model for this specific embed call */
296
+ model?: string;
297
+ /** Specify the task type for models that require prefixes (e.g. nomic-embed-text) */
298
+ taskType?: 'query' | 'document';
299
+ }
300
+ interface ILLMProvider {
301
+ /**
302
+ * Send a chat completion request.
303
+ * @param messages – the full conversation history
304
+ * @param context – retrieved RAG context to inject
305
+ * @param options – optional per-call overrides
306
+ * @returns – the assistant's reply text
307
+ */
308
+ chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
309
+ /**
310
+ * Send a streaming chat completion request.
311
+ * @returns – an async iterable of text chunks
312
+ */
313
+ chatStream?(messages: ChatMessage[], context: string, options?: ChatOptions): AsyncIterable<string>;
314
+ /**
315
+ * Generate an embedding vector for the given text.
316
+ * @param text – text to embed
317
+ * @param options – optional overrides
318
+ * @returns – float array (the embedding)
319
+ */
320
+ embed(text: string, options?: EmbedOptions): Promise<number[]>;
321
+ /**
322
+ * Generate embedding vectors for multiple texts in a single batch.
323
+ * @param texts – array of texts to embed
324
+ * @param options – optional overrides
325
+ * @returns – array of float arrays
326
+ */
327
+ batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
328
+ /**
329
+ * Check if the provider endpoint is reachable.
330
+ */
331
+ ping(): Promise<boolean>;
332
+ }
333
+
334
+ export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, Product as P, RagMessage as R, 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, RAGConfig as i, RagConfig as j, UpsertDocument as k, VectorDBConfig as l, VectorDBProvider as m, RetrievalResult as n, GraphNode as o, Edge as p, GraphSearchResult as q };
@@ -16,6 +16,12 @@ interface ChatOptions {
16
16
  temperature?: number;
17
17
  /** Stop sequences */
18
18
  stop?: string[];
19
+ /**
20
+ * Per-call system prompt override. When provided, providers should use this
21
+ * instead of (or in addition to) their configured llmConfig.systemPrompt.
22
+ * Useful for one-off analytical calls (e.g. UITransformer.analyzeAndDecide).
23
+ */
24
+ systemPrompt?: string;
19
25
  }
20
26
  interface UseRagChatOptions {
21
27
  /** Override the chat API endpoint (default: /api/chat) */
@@ -201,6 +207,11 @@ interface RAGConfig {
201
207
  * Used to dynamically extract hints from natural language queries.
202
208
  */
203
209
  filterableFields?: string[];
210
+ /** Optional mapping from database metadata fields to standard UI properties.
211
+ * Useful for databases with custom schemas.
212
+ * e.g., { "name": "ProductName", "price": "SalesPrice", "image": "ThumbnailUrl" }
213
+ */
214
+ uiMapping?: Record<string, string>;
204
215
  }
205
216
  interface RagConfig {
206
217
  /**
@@ -274,4 +285,50 @@ interface Product {
274
285
  description?: string;
275
286
  }
276
287
 
277
- export type { ChatMessage as C, EmbeddingConfig as E, GraphDBConfig as G, IngestDocument as I, LLMConfig as L, Product as P, RagMessage as R, UIConfig as U, VectorMatch as V, UseRagChatOptions as a, UseRagChatReturn as b, ChatOptions as c, ChatResponse as d, EmbeddingProvider as e, LLMProvider as f, RAGConfig as g, RagConfig as h, UpsertDocument as i, VectorDBConfig as j, VectorDBProvider as k, RetrievalResult as l, GraphNode as m, Edge as n, GraphSearchResult as o };
288
+ /**
289
+ * Generic LLM Provider interface.
290
+ * Covers both chat completion and embedding generation so a single
291
+ * provider can handle both responsibilities when appropriate.
292
+ */
293
+
294
+ interface EmbedOptions {
295
+ /** Override model for this specific embed call */
296
+ model?: string;
297
+ /** Specify the task type for models that require prefixes (e.g. nomic-embed-text) */
298
+ taskType?: 'query' | 'document';
299
+ }
300
+ interface ILLMProvider {
301
+ /**
302
+ * Send a chat completion request.
303
+ * @param messages – the full conversation history
304
+ * @param context – retrieved RAG context to inject
305
+ * @param options – optional per-call overrides
306
+ * @returns – the assistant's reply text
307
+ */
308
+ chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
309
+ /**
310
+ * Send a streaming chat completion request.
311
+ * @returns – an async iterable of text chunks
312
+ */
313
+ chatStream?(messages: ChatMessage[], context: string, options?: ChatOptions): AsyncIterable<string>;
314
+ /**
315
+ * Generate an embedding vector for the given text.
316
+ * @param text – text to embed
317
+ * @param options – optional overrides
318
+ * @returns – float array (the embedding)
319
+ */
320
+ embed(text: string, options?: EmbedOptions): Promise<number[]>;
321
+ /**
322
+ * Generate embedding vectors for multiple texts in a single batch.
323
+ * @param texts – array of texts to embed
324
+ * @param options – optional overrides
325
+ * @returns – array of float arrays
326
+ */
327
+ batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
328
+ /**
329
+ * Check if the provider endpoint is reachable.
330
+ */
331
+ ping(): Promise<boolean>;
332
+ }
333
+
334
+ export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, Product as P, RagMessage as R, 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, RAGConfig as i, RagConfig as j, UpsertDocument as k, VectorDBConfig as l, VectorDBProvider as m, RetrievalResult as n, GraphNode as o, Edge as p, GraphSearchResult as q };
@@ -0,0 +1,8 @@
1
+ import {
2
+ MultiTablePostgresProvider
3
+ } from "./chunk-R3RGUMHE.mjs";
4
+ import "./chunk-IMP6FUCY.mjs";
5
+ import "./chunk-X4TOT24V.mjs";
6
+ export {
7
+ MultiTablePostgresProvider
8
+ };