@retrivora-ai/rag-engine 0.1.4 → 0.1.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 (50) hide show
  1. package/dist/DocumentChunker-BEyzadsv.d.mts +93 -0
  2. package/dist/DocumentChunker-BEyzadsv.d.ts +93 -0
  3. package/dist/{LLMFactory-XC55FTD2.mjs → LLMFactory-JFOY2V4X.mjs} +2 -1
  4. package/dist/{PineconeProvider-NJ675H7U.mjs → PineconeProvider-ZRAFNFEC.mjs} +1 -1
  5. package/dist/{PostgreSQLProvider-ISNMD3BE.mjs → PostgreSQLProvider-ZNXA67IM.mjs} +1 -1
  6. package/dist/{QdrantProvider-LJWOIGES.mjs → QdrantProvider-NYGHAA7C.mjs} +1 -1
  7. package/dist/{Pipeline-Bo6CUCox.d.mts → RagConfig-hBGXJmSx.d.mts} +23 -93
  8. package/dist/{Pipeline-Bo6CUCox.d.ts → RagConfig-hBGXJmSx.d.ts} +23 -93
  9. package/dist/{chunk-6FODXNUF.mjs → chunk-5K23H7JL.mjs} +27 -1
  10. package/dist/chunk-HSBXE2WV.mjs +1758 -0
  11. package/dist/{chunk-S5DRHETN.mjs → chunk-IUTAZ7QR.mjs} +31 -2
  12. package/dist/{chunk-GD3QJFNN.mjs → chunk-JI6VD5TJ.mjs} +4 -41
  13. package/dist/chunk-UKDXCXW7.mjs +49 -0
  14. package/dist/{chunk-AALIF3AL.mjs → chunk-ZM6TYIDH.mjs} +3 -3
  15. package/dist/handlers/index.d.mts +3 -44
  16. package/dist/handlers/index.d.ts +3 -44
  17. package/dist/handlers/index.js +1322 -57
  18. package/dist/handlers/index.mjs +3 -3
  19. package/dist/index-Bx182KKn.d.ts +64 -0
  20. package/dist/index-Ck2pt7-8.d.mts +64 -0
  21. package/dist/index.d.mts +4 -3
  22. package/dist/index.d.ts +4 -3
  23. package/dist/index.js +19 -1646
  24. package/dist/index.mjs +1 -11
  25. package/dist/server.d.mts +188 -11
  26. package/dist/server.d.ts +188 -11
  27. package/dist/server.js +1322 -57
  28. package/dist/server.mjs +10 -11
  29. package/package.json +20 -2
  30. package/src/config/serverConfig.ts +3 -0
  31. package/src/core/BatchProcessor.ts +347 -0
  32. package/src/core/ConfigValidator.ts +560 -0
  33. package/src/core/Pipeline.ts +91 -49
  34. package/src/core/ProviderHealthCheck.ts +565 -0
  35. package/src/core/VectorPlugin.ts +51 -9
  36. package/src/handlers/index.ts +2 -2
  37. package/src/index.ts +1 -7
  38. package/src/providers/vectordb/BaseVectorProvider.ts +1 -1
  39. package/src/providers/vectordb/MilvusProvider.ts +1 -1
  40. package/src/providers/vectordb/MongoDBProvider.ts +1 -1
  41. package/src/providers/vectordb/PineconeProvider.ts +4 -4
  42. package/src/providers/vectordb/PostgreSQLProvider.ts +35 -3
  43. package/src/providers/vectordb/QdrantProvider.ts +32 -2
  44. package/src/rag/DocumentChunker.ts +2 -2
  45. package/src/server.ts +1 -1
  46. package/src/types/index.ts +13 -2
  47. package/dist/DocumentChunker-BQ5kQD7B.d.ts +0 -155
  48. package/dist/DocumentChunker-D9-fObJp.d.mts +0 -155
  49. package/dist/chunk-AIAB2IEE.mjs +0 -394
  50. package/dist/chunk-FGGSVVSY.mjs +0 -162
@@ -0,0 +1,93 @@
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
+ }
22
+ interface ILLMProvider {
23
+ /**
24
+ * Send a chat completion request.
25
+ * @param messages – the full conversation history
26
+ * @param context – retrieved RAG context to inject
27
+ * @param options – optional per-call overrides
28
+ * @returns – the assistant's reply text
29
+ */
30
+ chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
31
+ /**
32
+ * Generate an embedding vector for the given text.
33
+ * @param text – text to embed
34
+ * @param options – optional overrides
35
+ * @returns – float array (the embedding)
36
+ */
37
+ embed(text: string, options?: EmbedOptions): Promise<number[]>;
38
+ /**
39
+ * Generate embedding vectors for multiple texts in a single batch.
40
+ * @param texts – array of texts to embed
41
+ * @param options – optional overrides
42
+ * @returns – array of float arrays
43
+ */
44
+ batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
45
+ /**
46
+ * Check if the provider endpoint is reachable.
47
+ */
48
+ ping(): Promise<boolean>;
49
+ }
50
+
51
+ /**
52
+ * DocumentChunker — splits long text into overlapping chunks
53
+ * suitable for vector embedding and retrieval.
54
+ *
55
+ * Strategy: sentence-aware sliding window
56
+ * 1. Split on sentence boundaries
57
+ * 2. Accumulate sentences into chunks up to `chunkSize` characters
58
+ * 3. Carry over `chunkOverlap` characters from the previous chunk
59
+ */
60
+ interface Chunk {
61
+ id: string;
62
+ content: string;
63
+ metadata?: Record<string, unknown>;
64
+ }
65
+ interface ChunkOptions {
66
+ /** Target chunk size in characters (default 1000) */
67
+ chunkSize?: number;
68
+ /** Overlap between consecutive chunks in characters (default 200) */
69
+ chunkOverlap?: number;
70
+ /** Source document identifier used as ID prefix */
71
+ docId?: string | number;
72
+ /** Extra metadata to attach to every chunk */
73
+ metadata?: Record<string, unknown>;
74
+ }
75
+ declare class DocumentChunker {
76
+ private readonly chunkSize;
77
+ private readonly chunkOverlap;
78
+ constructor(chunkSize?: number, chunkOverlap?: number);
79
+ /**
80
+ * Split a single text string into overlapping chunks.
81
+ */
82
+ chunk(text: string, options?: ChunkOptions): Chunk[];
83
+ /**
84
+ * Chunk multiple documents at once.
85
+ */
86
+ chunkMany(documents: Array<{
87
+ content: string;
88
+ docId?: string | number;
89
+ metadata?: Record<string, unknown>;
90
+ }>): Chunk[];
91
+ }
92
+
93
+ export { type ChatMessage as C, DocumentChunker as D, type EmbedOptions as E, type ILLMProvider as I, type ChatOptions as a, type Chunk as b, type ChunkOptions as c };
@@ -0,0 +1,93 @@
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
+ }
22
+ interface ILLMProvider {
23
+ /**
24
+ * Send a chat completion request.
25
+ * @param messages – the full conversation history
26
+ * @param context – retrieved RAG context to inject
27
+ * @param options – optional per-call overrides
28
+ * @returns – the assistant's reply text
29
+ */
30
+ chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
31
+ /**
32
+ * Generate an embedding vector for the given text.
33
+ * @param text – text to embed
34
+ * @param options – optional overrides
35
+ * @returns – float array (the embedding)
36
+ */
37
+ embed(text: string, options?: EmbedOptions): Promise<number[]>;
38
+ /**
39
+ * Generate embedding vectors for multiple texts in a single batch.
40
+ * @param texts – array of texts to embed
41
+ * @param options – optional overrides
42
+ * @returns – array of float arrays
43
+ */
44
+ batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
45
+ /**
46
+ * Check if the provider endpoint is reachable.
47
+ */
48
+ ping(): Promise<boolean>;
49
+ }
50
+
51
+ /**
52
+ * DocumentChunker — splits long text into overlapping chunks
53
+ * suitable for vector embedding and retrieval.
54
+ *
55
+ * Strategy: sentence-aware sliding window
56
+ * 1. Split on sentence boundaries
57
+ * 2. Accumulate sentences into chunks up to `chunkSize` characters
58
+ * 3. Carry over `chunkOverlap` characters from the previous chunk
59
+ */
60
+ interface Chunk {
61
+ id: string;
62
+ content: string;
63
+ metadata?: Record<string, unknown>;
64
+ }
65
+ interface ChunkOptions {
66
+ /** Target chunk size in characters (default 1000) */
67
+ chunkSize?: number;
68
+ /** Overlap between consecutive chunks in characters (default 200) */
69
+ chunkOverlap?: number;
70
+ /** Source document identifier used as ID prefix */
71
+ docId?: string | number;
72
+ /** Extra metadata to attach to every chunk */
73
+ metadata?: Record<string, unknown>;
74
+ }
75
+ declare class DocumentChunker {
76
+ private readonly chunkSize;
77
+ private readonly chunkOverlap;
78
+ constructor(chunkSize?: number, chunkOverlap?: number);
79
+ /**
80
+ * Split a single text string into overlapping chunks.
81
+ */
82
+ chunk(text: string, options?: ChunkOptions): Chunk[];
83
+ /**
84
+ * Chunk multiple documents at once.
85
+ */
86
+ chunkMany(documents: Array<{
87
+ content: string;
88
+ docId?: string | number;
89
+ metadata?: Record<string, unknown>;
90
+ }>): Chunk[];
91
+ }
92
+
93
+ export { type ChatMessage as C, DocumentChunker as D, type EmbedOptions as E, type ILLMProvider as I, type ChatOptions as a, type Chunk as b, type ChunkOptions as c };
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  LLMFactory
3
- } from "./chunk-GD3QJFNN.mjs";
3
+ } from "./chunk-JI6VD5TJ.mjs";
4
+ import "./chunk-UKDXCXW7.mjs";
4
5
  import "./chunk-I4E63NIC.mjs";
5
6
  export {
6
7
  LLMFactory
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PineconeProvider
3
- } from "./chunk-AALIF3AL.mjs";
3
+ } from "./chunk-ZM6TYIDH.mjs";
4
4
  import "./chunk-VOIWNO5O.mjs";
5
5
  import "./chunk-I4E63NIC.mjs";
6
6
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PostgreSQLProvider
3
- } from "./chunk-S5DRHETN.mjs";
3
+ } from "./chunk-IUTAZ7QR.mjs";
4
4
  import "./chunk-VOIWNO5O.mjs";
5
5
  import "./chunk-I4E63NIC.mjs";
6
6
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  QdrantProvider
3
- } from "./chunk-6FODXNUF.mjs";
3
+ } from "./chunk-5K23H7JL.mjs";
4
4
  import "./chunk-VOIWNO5O.mjs";
5
5
  import "./chunk-I4E63NIC.mjs";
6
6
  export {
@@ -1,3 +1,25 @@
1
+ interface VectorMatch {
2
+ id: string | number;
3
+ score: number;
4
+ content: string;
5
+ metadata?: Record<string, unknown>;
6
+ }
7
+ interface UpsertDocument {
8
+ id: string | number;
9
+ vector: number[];
10
+ content: string;
11
+ metadata?: Record<string, unknown>;
12
+ }
13
+ interface IngestDocument {
14
+ docId: string | number;
15
+ content: string;
16
+ metadata?: Record<string, unknown>;
17
+ }
18
+ interface ChatResponse {
19
+ reply: string;
20
+ sources: VectorMatch[];
21
+ }
22
+
1
23
  /**
2
24
  * Master configuration interface for Retrivora AI.
3
25
  * Each consuming project provides one RagConfig object to drive
@@ -120,96 +142,4 @@ interface RagConfig {
120
142
  rag?: RAGConfig;
121
143
  }
122
144
 
123
- /**
124
- * Generic LLM Provider interface.
125
- * Covers both chat completion and embedding generation so a single
126
- * provider can handle both responsibilities when appropriate.
127
- */
128
- interface ChatMessage {
129
- role: 'user' | 'assistant' | 'system';
130
- content: string;
131
- }
132
- interface ChatOptions {
133
- /** Override max tokens for this specific call */
134
- maxTokens?: number;
135
- /** Override temperature for this specific call */
136
- temperature?: number;
137
- /** Stop sequences */
138
- stop?: string[];
139
- }
140
- interface EmbedOptions {
141
- /** Override model for this specific embed call */
142
- model?: string;
143
- }
144
- interface ILLMProvider {
145
- /**
146
- * Send a chat completion request.
147
- * @param messages – the full conversation history
148
- * @param context – retrieved RAG context to inject
149
- * @param options – optional per-call overrides
150
- * @returns – the assistant's reply text
151
- */
152
- chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
153
- /**
154
- * Generate an embedding vector for the given text.
155
- * @param text – text to embed
156
- * @param options – optional overrides
157
- * @returns – float array (the embedding)
158
- */
159
- embed(text: string, options?: EmbedOptions): Promise<number[]>;
160
- /**
161
- * Generate embedding vectors for multiple texts in a single batch.
162
- * @param texts – array of texts to embed
163
- * @param options – optional overrides
164
- * @returns – array of float arrays
165
- */
166
- batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
167
- /**
168
- * Check if the provider endpoint is reachable.
169
- */
170
- ping(): Promise<boolean>;
171
- }
172
-
173
- interface VectorMatch {
174
- id: string;
175
- score: number;
176
- content: string;
177
- metadata?: Record<string, unknown>;
178
- }
179
- interface UpsertDocument {
180
- id: string;
181
- vector: number[];
182
- content: string;
183
- metadata?: Record<string, unknown>;
184
- }
185
-
186
- interface IngestDocument {
187
- docId: string;
188
- content: string;
189
- metadata?: Record<string, unknown>;
190
- }
191
- interface ChatResponse {
192
- reply: string;
193
- sources: VectorMatch[];
194
- }
195
- /**
196
- * Pipeline — orchestrates the RAG flow: Embed → Search → Augment → Generate.
197
- */
198
- declare class Pipeline {
199
- private vectorDB;
200
- private llmProvider;
201
- private embeddingProvider;
202
- private chunker;
203
- private config;
204
- private initialised;
205
- constructor(config: RagConfig);
206
- initialize(): Promise<void>;
207
- ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
208
- docId: string;
209
- chunksIngested: number;
210
- }>>;
211
- ask(question: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
212
- health(): Promise<Record<string, boolean>>;
213
- }
214
-
215
- export { type ChatMessage as C, type EmbedOptions as E, type ILLMProvider as I, type LLMConfig as L, Pipeline as P, type RAGConfig as R, type UIConfig as U, type VectorMatch as V, type ChatOptions as a, type ChatResponse as b, type EmbeddingConfig as c, type IngestDocument as d, type RagConfig as e, type UpsertDocument as f, type VectorDBConfig as g };
145
+ export type { ChatResponse as C, EmbeddingConfig as E, IngestDocument as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, RagConfig as a, UpsertDocument as b, VectorDBConfig as c };
@@ -1,3 +1,25 @@
1
+ interface VectorMatch {
2
+ id: string | number;
3
+ score: number;
4
+ content: string;
5
+ metadata?: Record<string, unknown>;
6
+ }
7
+ interface UpsertDocument {
8
+ id: string | number;
9
+ vector: number[];
10
+ content: string;
11
+ metadata?: Record<string, unknown>;
12
+ }
13
+ interface IngestDocument {
14
+ docId: string | number;
15
+ content: string;
16
+ metadata?: Record<string, unknown>;
17
+ }
18
+ interface ChatResponse {
19
+ reply: string;
20
+ sources: VectorMatch[];
21
+ }
22
+
1
23
  /**
2
24
  * Master configuration interface for Retrivora AI.
3
25
  * Each consuming project provides one RagConfig object to drive
@@ -120,96 +142,4 @@ interface RagConfig {
120
142
  rag?: RAGConfig;
121
143
  }
122
144
 
123
- /**
124
- * Generic LLM Provider interface.
125
- * Covers both chat completion and embedding generation so a single
126
- * provider can handle both responsibilities when appropriate.
127
- */
128
- interface ChatMessage {
129
- role: 'user' | 'assistant' | 'system';
130
- content: string;
131
- }
132
- interface ChatOptions {
133
- /** Override max tokens for this specific call */
134
- maxTokens?: number;
135
- /** Override temperature for this specific call */
136
- temperature?: number;
137
- /** Stop sequences */
138
- stop?: string[];
139
- }
140
- interface EmbedOptions {
141
- /** Override model for this specific embed call */
142
- model?: string;
143
- }
144
- interface ILLMProvider {
145
- /**
146
- * Send a chat completion request.
147
- * @param messages – the full conversation history
148
- * @param context – retrieved RAG context to inject
149
- * @param options – optional per-call overrides
150
- * @returns – the assistant's reply text
151
- */
152
- chat(messages: ChatMessage[], context: string, options?: ChatOptions): Promise<string>;
153
- /**
154
- * Generate an embedding vector for the given text.
155
- * @param text – text to embed
156
- * @param options – optional overrides
157
- * @returns – float array (the embedding)
158
- */
159
- embed(text: string, options?: EmbedOptions): Promise<number[]>;
160
- /**
161
- * Generate embedding vectors for multiple texts in a single batch.
162
- * @param texts – array of texts to embed
163
- * @param options – optional overrides
164
- * @returns – array of float arrays
165
- */
166
- batchEmbed(texts: string[], options?: EmbedOptions): Promise<number[][]>;
167
- /**
168
- * Check if the provider endpoint is reachable.
169
- */
170
- ping(): Promise<boolean>;
171
- }
172
-
173
- interface VectorMatch {
174
- id: string;
175
- score: number;
176
- content: string;
177
- metadata?: Record<string, unknown>;
178
- }
179
- interface UpsertDocument {
180
- id: string;
181
- vector: number[];
182
- content: string;
183
- metadata?: Record<string, unknown>;
184
- }
185
-
186
- interface IngestDocument {
187
- docId: string;
188
- content: string;
189
- metadata?: Record<string, unknown>;
190
- }
191
- interface ChatResponse {
192
- reply: string;
193
- sources: VectorMatch[];
194
- }
195
- /**
196
- * Pipeline — orchestrates the RAG flow: Embed → Search → Augment → Generate.
197
- */
198
- declare class Pipeline {
199
- private vectorDB;
200
- private llmProvider;
201
- private embeddingProvider;
202
- private chunker;
203
- private config;
204
- private initialised;
205
- constructor(config: RagConfig);
206
- initialize(): Promise<void>;
207
- ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
208
- docId: string;
209
- chunksIngested: number;
210
- }>>;
211
- ask(question: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
212
- health(): Promise<Record<string, boolean>>;
213
- }
214
-
215
- export { type ChatMessage as C, type EmbedOptions as E, type ILLMProvider as I, type LLMConfig as L, Pipeline as P, type RAGConfig as R, type UIConfig as U, type VectorMatch as V, type ChatOptions as a, type ChatResponse as b, type EmbeddingConfig as c, type IngestDocument as d, type RagConfig as e, type UpsertDocument as f, type VectorDBConfig as g };
145
+ export type { ChatResponse as C, EmbeddingConfig as E, IngestDocument as I, LLMConfig as L, RAGConfig as R, UIConfig as U, VectorMatch as V, RagConfig as a, UpsertDocument as b, VectorDBConfig as c };
@@ -22,6 +22,33 @@ var QdrantProvider = class extends BaseVectorProvider {
22
22
  }
23
23
  async initialize() {
24
24
  await this.ping();
25
+ await this.ensureIndex();
26
+ }
27
+ /**
28
+ * Ensures that the 'namespace' field has a keyword index for efficient filtering.
29
+ * Qdrant requires this for search filters to work in many configurations.
30
+ */
31
+ async ensureIndex() {
32
+ var _a, _b;
33
+ try {
34
+ await this.http.put(`/collections/${this.indexName}/index`, {
35
+ field_name: "namespace",
36
+ field_schema: "keyword"
37
+ });
38
+ console.log(`[QdrantProvider] \u2705 Ensured keyword index for "namespace" on collection "${this.indexName}"`);
39
+ } catch (err) {
40
+ let status;
41
+ let data;
42
+ if (axios.isAxiosError(err)) {
43
+ status = (_a = err.response) == null ? void 0 : _a.status;
44
+ data = (_b = err.response) == null ? void 0 : _b.data;
45
+ }
46
+ if (status === 409) {
47
+ return;
48
+ }
49
+ const errorMessage = err instanceof Error ? err.message : String(err);
50
+ console.warn(`[QdrantProvider] \u26A0\uFE0F Could not ensure namespace index (Status: ${status}):`, JSON.stringify(data || errorMessage));
51
+ }
25
52
  }
26
53
  async upsert(doc, namespace) {
27
54
  await this.batchUpsert([doc], namespace);
@@ -66,7 +93,6 @@ var QdrantProvider = class extends BaseVectorProvider {
66
93
  points: [id]
67
94
  });
68
95
  }
69
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
70
96
  async deleteNamespace(_namespace) {
71
97
  await this.http.post(`/collections/${this.indexName}/points/delete`, {
72
98
  filter: {