@retrivora-ai/rag-engine 1.0.4 → 1.0.6

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 (40) hide show
  1. package/dist/DocumentChunker-Dh9TvmGG.d.mts +45 -0
  2. package/dist/DocumentChunker-Dh9TvmGG.d.ts +45 -0
  3. package/dist/{RagConfig-DRJO4hGU.d.mts → RagConfig-BjC6zSTV.d.mts} +62 -1
  4. package/dist/{RagConfig-DRJO4hGU.d.ts → RagConfig-BjC6zSTV.d.ts} +62 -1
  5. package/dist/{chunk-6MLZHQZT.mjs → chunk-ZCDJSGUW.mjs} +237 -104
  6. package/dist/handlers/index.d.mts +2 -2
  7. package/dist/handlers/index.d.ts +2 -2
  8. package/dist/handlers/index.js +239 -106
  9. package/dist/handlers/index.mjs +11 -3
  10. package/dist/index-C3bLmWcR.d.ts +206 -0
  11. package/dist/index-CU_fQq__.d.mts +206 -0
  12. package/dist/index.d.mts +3 -4
  13. package/dist/index.d.ts +3 -4
  14. package/dist/index.js +103 -89
  15. package/dist/index.mjs +91 -95
  16. package/dist/server.d.mts +45 -97
  17. package/dist/server.d.ts +45 -97
  18. package/dist/server.js +319 -221
  19. package/dist/server.mjs +78 -167
  20. package/package.json +12 -10
  21. package/src/components/ChatWindow.tsx +2 -2
  22. package/src/components/ConfigProvider.tsx +2 -2
  23. package/src/components/MessageBubble.tsx +2 -2
  24. package/src/components/SourceCard.tsx +1 -1
  25. package/src/components/ThemeToggle.tsx +1 -1
  26. package/src/config/ConfigBuilder.ts +86 -211
  27. package/src/config/RagConfig.ts +4 -0
  28. package/src/config/uiConstants.ts +23 -0
  29. package/src/core/ConfigResolver.ts +57 -29
  30. package/src/core/LangChainAgent.ts +73 -40
  31. package/src/core/Pipeline.ts +64 -8
  32. package/src/core/ProviderRegistry.ts +2 -2
  33. package/src/core/QueryProcessor.ts +45 -12
  34. package/src/handlers/index.ts +138 -49
  35. package/src/hooks/useRagChat.ts +71 -32
  36. package/src/server.ts +12 -2
  37. package/dist/DocumentChunker-C-sCZPhi.d.mts +0 -102
  38. package/dist/DocumentChunker-C-sCZPhi.d.ts +0 -102
  39. package/dist/index-B2mutkgp.d.ts +0 -116
  40. package/dist/index-Bjy0es5a.d.mts +0 -116
@@ -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 };
@@ -1,3 +1,60 @@
1
+ /**
2
+ * Generic LLM Provider interface.
3
+ * Covers both chat completion and embedding generation so a single
4
+ * provider can handle both responsibilities when appropriate.
5
+ */
6
+ interface ChatMessage {
7
+ role: 'user' | 'assistant' | 'system';
8
+ content: string;
9
+ }
10
+ interface ChatOptions {
11
+ /** Override max tokens for this specific call */
12
+ maxTokens?: number;
13
+ /** Override temperature for this specific call */
14
+ temperature?: number;
15
+ /** Stop sequences */
16
+ stop?: string[];
17
+ }
18
+ interface EmbedOptions {
19
+ /** Override model for this specific embed call */
20
+ model?: string;
21
+ /** Specify the task type for models that require prefixes (e.g. nomic-embed-text) */
22
+ taskType?: 'query' | 'document';
23
+ }
24
+ interface ILLMProvider {
25
+ /**
26
+ * Send a chat completion request.
27
+ * @param messages – the full conversation history
28
+ * @param context – retrieved RAG context to inject
29
+ * @param options – optional per-call overrides
30
+ * @returns – the assistant's reply text
31
+ */
32
+ chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
33
+ /**
34
+ * Send a streaming chat completion request.
35
+ * @returns – an async iterable of text chunks
36
+ */
37
+ chatStream?(messages: ChatMessage[], context: string, options?: ChatOptions): AsyncIterable<string>;
38
+ /**
39
+ * Generate an embedding vector for the given text.
40
+ * @param text – text to embed
41
+ * @param options – optional overrides
42
+ * @returns – float array (the embedding)
43
+ */
44
+ embed(text: string, options?: EmbedOptions): Promise<number[]>;
45
+ /**
46
+ * Generate embedding vectors for multiple texts in a single batch.
47
+ * @param texts – array of texts to embed
48
+ * @param options – optional overrides
49
+ * @returns – array of float arrays
50
+ */
51
+ batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
52
+ /**
53
+ * Check if the provider endpoint is reachable.
54
+ */
55
+ ping(): Promise<boolean>;
56
+ }
57
+
1
58
  interface VectorMatch {
2
59
  id: string | number;
3
60
  score: number;
@@ -187,6 +244,10 @@ interface RAGConfig {
187
244
  useGraphRetrieval?: boolean;
188
245
  /** Whether to perform reranking on retrieved results */
189
246
  useReranking?: boolean;
247
+ /** List of metadata fields that are valid for filtering.
248
+ * Used to dynamically extract hints from natural language queries.
249
+ */
250
+ filterableFields?: string[];
190
251
  }
191
252
  interface RagConfig {
192
253
  /**
@@ -208,4 +269,4 @@ interface RagConfig {
208
269
  graphDb?: GraphDBConfig;
209
270
  }
210
271
 
211
- export type { ChatResponse as C, EmbeddingConfig as E, GraphDBConfig as G, IngestDocument as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, EmbeddingProvider as a, LLMProvider as b, RagConfig as c, UpsertDocument as d, VectorDBConfig as e, VectorDBProvider as f, RetrievalResult as g, GraphNode as h, Edge as i, GraphSearchResult as j };
272
+ export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, ChatOptions as a, ChatResponse as b, EmbeddingConfig as c, EmbeddingProvider as d, IngestDocument as e, LLMProvider as f, RagConfig as g, UpsertDocument as h, VectorDBConfig as i, VectorDBProvider as j, RetrievalResult as k, GraphNode as l, Edge as m, GraphSearchResult as n };
@@ -1,3 +1,60 @@
1
+ /**
2
+ * Generic LLM Provider interface.
3
+ * Covers both chat completion and embedding generation so a single
4
+ * provider can handle both responsibilities when appropriate.
5
+ */
6
+ interface ChatMessage {
7
+ role: 'user' | 'assistant' | 'system';
8
+ content: string;
9
+ }
10
+ interface ChatOptions {
11
+ /** Override max tokens for this specific call */
12
+ maxTokens?: number;
13
+ /** Override temperature for this specific call */
14
+ temperature?: number;
15
+ /** Stop sequences */
16
+ stop?: string[];
17
+ }
18
+ interface EmbedOptions {
19
+ /** Override model for this specific embed call */
20
+ model?: string;
21
+ /** Specify the task type for models that require prefixes (e.g. nomic-embed-text) */
22
+ taskType?: 'query' | 'document';
23
+ }
24
+ interface ILLMProvider {
25
+ /**
26
+ * Send a chat completion request.
27
+ * @param messages – the full conversation history
28
+ * @param context – retrieved RAG context to inject
29
+ * @param options – optional per-call overrides
30
+ * @returns – the assistant's reply text
31
+ */
32
+ chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
33
+ /**
34
+ * Send a streaming chat completion request.
35
+ * @returns – an async iterable of text chunks
36
+ */
37
+ chatStream?(messages: ChatMessage[], context: string, options?: ChatOptions): AsyncIterable<string>;
38
+ /**
39
+ * Generate an embedding vector for the given text.
40
+ * @param text – text to embed
41
+ * @param options – optional overrides
42
+ * @returns – float array (the embedding)
43
+ */
44
+ embed(text: string, options?: EmbedOptions): Promise<number[]>;
45
+ /**
46
+ * Generate embedding vectors for multiple texts in a single batch.
47
+ * @param texts – array of texts to embed
48
+ * @param options – optional overrides
49
+ * @returns – array of float arrays
50
+ */
51
+ batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
52
+ /**
53
+ * Check if the provider endpoint is reachable.
54
+ */
55
+ ping(): Promise<boolean>;
56
+ }
57
+
1
58
  interface VectorMatch {
2
59
  id: string | number;
3
60
  score: number;
@@ -187,6 +244,10 @@ interface RAGConfig {
187
244
  useGraphRetrieval?: boolean;
188
245
  /** Whether to perform reranking on retrieved results */
189
246
  useReranking?: boolean;
247
+ /** List of metadata fields that are valid for filtering.
248
+ * Used to dynamically extract hints from natural language queries.
249
+ */
250
+ filterableFields?: string[];
190
251
  }
191
252
  interface RagConfig {
192
253
  /**
@@ -208,4 +269,4 @@ interface RagConfig {
208
269
  graphDb?: GraphDBConfig;
209
270
  }
210
271
 
211
- export type { ChatResponse as C, EmbeddingConfig as E, GraphDBConfig as G, IngestDocument as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, EmbeddingProvider as a, LLMProvider as b, RagConfig as c, UpsertDocument as d, VectorDBConfig as e, VectorDBProvider as f, RetrievalResult as g, GraphNode as h, Edge as i, GraphSearchResult as j };
272
+ export type { ChatMessage as C, EmbedOptions as E, GraphDBConfig as G, ILLMProvider as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, ChatOptions as a, ChatResponse as b, EmbeddingConfig as c, EmbeddingProvider as d, IngestDocument as e, LLMProvider as f, RagConfig as g, UpsertDocument as h, VectorDBConfig as i, VectorDBProvider as j, RetrievalResult as k, GraphNode as l, Edge as m, GraphSearchResult as n };