@retrivora-ai/rag-engine 0.1.3 → 0.1.4

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 (73) hide show
  1. package/dist/ChromaDBProvider-QNI7UCX4.mjs +8 -0
  2. package/dist/DocumentChunker-BQ5kQD7B.d.ts +155 -0
  3. package/dist/DocumentChunker-D9-fObJp.d.mts +155 -0
  4. package/dist/LLMFactory-XC55FTD2.mjs +7 -0
  5. package/dist/MilvusProvider-OO6QGZDZ.mjs +8 -0
  6. package/dist/MongoDBProvider-WWVJG3WT.mjs +8 -0
  7. package/dist/PineconeProvider-NJ675H7U.mjs +8 -0
  8. package/dist/{RAGPipeline-BmkIv1HD.d.mts → Pipeline-Bo6CUCox.d.mts} +76 -159
  9. package/dist/{RAGPipeline-BmkIv1HD.d.ts → Pipeline-Bo6CUCox.d.ts} +76 -159
  10. package/dist/PostgreSQLProvider-ISNMD3BE.mjs +8 -0
  11. package/dist/QdrantProvider-LJWOIGES.mjs +8 -0
  12. package/dist/RedisProvider-ASONNYBI.mjs +8 -0
  13. package/dist/WeaviateProvider-PSDCUGC7.mjs +8 -0
  14. package/dist/chunk-6FODXNUF.mjs +91 -0
  15. package/dist/chunk-7NXI6ZWX.mjs +89 -0
  16. package/dist/chunk-AALIF3AL.mjs +91 -0
  17. package/dist/chunk-AIAB2IEE.mjs +394 -0
  18. package/dist/chunk-FGGSVVSY.mjs +162 -0
  19. package/dist/chunk-GD3QJFNN.mjs +424 -0
  20. package/dist/chunk-HUGLYKD6.mjs +84 -0
  21. package/dist/chunk-I4E63NIC.mjs +24 -0
  22. package/dist/chunk-QEYVWVT5.mjs +102 -0
  23. package/dist/chunk-S5DRHETN.mjs +110 -0
  24. package/dist/chunk-V75V7BT2.mjs +117 -0
  25. package/dist/chunk-VOIWNO5O.mjs +11 -0
  26. package/dist/chunk-VPNRDXIA.mjs +74 -0
  27. package/dist/handlers/index.d.mts +9 -33
  28. package/dist/handlers/index.d.ts +9 -33
  29. package/dist/handlers/index.js +1477 -962
  30. package/dist/handlers/index.mjs +4 -2
  31. package/dist/index.d.mts +3 -3
  32. package/dist/index.d.ts +3 -3
  33. package/dist/index.js +1646 -19
  34. package/dist/index.mjs +14 -2
  35. package/dist/server.d.mts +93 -56
  36. package/dist/server.d.ts +93 -56
  37. package/dist/server.js +1531 -1099
  38. package/dist/server.mjs +56 -131
  39. package/package.json +1 -1
  40. package/src/app/page.tsx +1 -1
  41. package/src/components/MessageBubble.tsx +1 -1
  42. package/src/components/SourceCard.tsx +1 -1
  43. package/src/config/RagConfig.ts +1 -1
  44. package/src/config/serverConfig.ts +2 -2
  45. package/src/core/ConfigResolver.ts +69 -0
  46. package/src/core/Pipeline.ts +109 -0
  47. package/src/core/ProviderRegistry.ts +71 -0
  48. package/src/core/VectorPlugin.ts +51 -0
  49. package/src/handlers/index.ts +21 -100
  50. package/src/hooks/useRagChat.ts +1 -1
  51. package/src/index.ts +8 -6
  52. package/src/providers/vectordb/BaseVectorProvider.ts +61 -0
  53. package/src/providers/vectordb/ChromaDBProvider.ts +94 -0
  54. package/src/providers/vectordb/MilvusProvider.ts +100 -0
  55. package/src/providers/vectordb/MongoDBProvider.ts +118 -0
  56. package/src/{vectordb/adapters/PineconeAdapter.ts → providers/vectordb/PineconeProvider.ts} +21 -56
  57. package/src/{vectordb/adapters/PgVectorAdapter.ts → providers/vectordb/PostgreSQLProvider.ts} +23 -58
  58. package/src/providers/vectordb/QdrantProvider.ts +95 -0
  59. package/src/providers/vectordb/RedisProvider.ts +84 -0
  60. package/src/providers/vectordb/WeaviateProvider.ts +124 -0
  61. package/src/server.ts +16 -8
  62. package/src/test-refactor.ts +59 -0
  63. package/src/types/index.ts +13 -0
  64. package/src/utils/templateUtils.ts +6 -6
  65. package/dist/DocumentChunker-BUrIrcPk.d.mts +0 -43
  66. package/dist/DocumentChunker-BUrIrcPk.d.ts +0 -43
  67. package/dist/chunk-NVOMLHXW.mjs +0 -1259
  68. package/dist/chunk-ZPXLQR5Q.mjs +0 -67
  69. package/src/rag/RAGPipeline.ts +0 -200
  70. package/src/vectordb/IVectorDB.ts +0 -75
  71. package/src/vectordb/VectorDBFactory.ts +0 -41
  72. package/src/vectordb/adapters/MongoDbAdapter.ts +0 -175
  73. package/src/vectordb/adapters/UniversalVectorDBAdapter.ts +0 -177
@@ -0,0 +1,8 @@
1
+ import {
2
+ ChromaDBProvider
3
+ } from "./chunk-HUGLYKD6.mjs";
4
+ import "./chunk-VOIWNO5O.mjs";
5
+ import "./chunk-I4E63NIC.mjs";
6
+ export {
7
+ ChromaDBProvider
8
+ };
@@ -0,0 +1,155 @@
1
+ import { e as RagConfig, C as ChatMessage, b as ChatResponse, d as IngestDocument, g as VectorDBConfig, f as UpsertDocument, V as VectorMatch, L as LLMConfig, c as EmbeddingConfig, I as ILLMProvider } from './Pipeline-Bo6CUCox.js';
2
+
3
+ /**
4
+ * VectorPlugin — main orchestrator class.
5
+ * This is the primary interface for host applications.
6
+ */
7
+ declare class VectorPlugin {
8
+ private config;
9
+ private pipeline;
10
+ /**
11
+ * Initializes the plugin with the host configuration.
12
+ * @param hostConfig - Configuration object passed from the host application.
13
+ */
14
+ constructor(hostConfig?: Partial<RagConfig>);
15
+ /**
16
+ * Get the current resolved configuration.
17
+ */
18
+ getConfig(): RagConfig;
19
+ /**
20
+ * Run a chat query.
21
+ */
22
+ chat(message: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
23
+ /**
24
+ * Ingest documents into the vector database.
25
+ */
26
+ ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
27
+ docId: string;
28
+ chunksIngested: number;
29
+ }>>;
30
+ /**
31
+ * Check the health of the connected providers.
32
+ */
33
+ health(): Promise<Record<string, boolean>>;
34
+ }
35
+
36
+ /**
37
+ * ConfigResolver — validates and normalizes host configuration.
38
+ * It merges host-provided config with environment defaults.
39
+ */
40
+ declare class ConfigResolver {
41
+ /**
42
+ * Resolves the final configuration by merging host-provided config with defaults.
43
+ * @param hostConfig - Partial configuration passed from the host application.
44
+ */
45
+ static resolve(hostConfig?: Partial<RagConfig>): RagConfig;
46
+ /**
47
+ * Validates the configuration for required fields.
48
+ */
49
+ static validate(config: RagConfig): void;
50
+ }
51
+
52
+ /**
53
+ * BaseVectorProvider — Abstract base class for all vector database providers.
54
+ * Each provider (Pinecone, Milvus, Redis, etc.) must extend this class.
55
+ */
56
+ declare abstract class BaseVectorProvider {
57
+ protected readonly config: VectorDBConfig;
58
+ protected readonly indexName: string;
59
+ constructor(config: VectorDBConfig);
60
+ /**
61
+ * Initialise the connection (create tables, verify index, etc.)
62
+ */
63
+ abstract initialize(): Promise<void>;
64
+ /**
65
+ * Insert or update a single vector + content pair.
66
+ */
67
+ abstract upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
68
+ /**
69
+ * Batch upsert for efficient ingestion of many documents.
70
+ */
71
+ abstract batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
72
+ /**
73
+ * Find the top-K most similar vectors to the query vector.
74
+ */
75
+ abstract query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
76
+ /**
77
+ * Delete a stored vector by ID.
78
+ */
79
+ abstract delete(id: string, namespace?: string): Promise<void>;
80
+ /**
81
+ * Delete all vectors in a namespace (full data reset for a project).
82
+ */
83
+ abstract deleteNamespace(namespace: string): Promise<void>;
84
+ /**
85
+ * Check if the underlying DB is reachable.
86
+ */
87
+ abstract ping(): Promise<boolean>;
88
+ /**
89
+ * Gracefully close the connection.
90
+ */
91
+ abstract disconnect(): Promise<void>;
92
+ }
93
+
94
+ /**
95
+ * ProviderRegistry — dynamic provider loader for Vector DBs and LLMs.
96
+ */
97
+ declare class ProviderRegistry {
98
+ private static vectorProviders;
99
+ /**
100
+ * Register a custom vector provider.
101
+ */
102
+ static registerVectorProvider(name: string, providerClass: new (config: VectorDBConfig) => BaseVectorProvider): void;
103
+ /**
104
+ * Creates a vector database provider based on the configuration.
105
+ */
106
+ static createVectorProvider(config: VectorDBConfig): Promise<BaseVectorProvider>;
107
+ /**
108
+ * Creates an LLM provider based on the configuration.
109
+ */
110
+ static createLLMProvider(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig): ILLMProvider;
111
+ }
112
+
113
+ /**
114
+ * DocumentChunker — splits long text into overlapping chunks
115
+ * suitable for vector embedding and retrieval.
116
+ *
117
+ * Strategy: sentence-aware sliding window
118
+ * 1. Split on sentence boundaries
119
+ * 2. Accumulate sentences into chunks up to `chunkSize` characters
120
+ * 3. Carry over `chunkOverlap` characters from the previous chunk
121
+ */
122
+ interface Chunk {
123
+ id: string;
124
+ content: string;
125
+ metadata?: Record<string, unknown>;
126
+ }
127
+ interface ChunkOptions {
128
+ /** Target chunk size in characters (default 1000) */
129
+ chunkSize?: number;
130
+ /** Overlap between consecutive chunks in characters (default 200) */
131
+ chunkOverlap?: number;
132
+ /** Source document identifier used as ID prefix */
133
+ docId?: string;
134
+ /** Extra metadata to attach to every chunk */
135
+ metadata?: Record<string, unknown>;
136
+ }
137
+ declare class DocumentChunker {
138
+ private readonly chunkSize;
139
+ private readonly chunkOverlap;
140
+ constructor(chunkSize?: number, chunkOverlap?: number);
141
+ /**
142
+ * Split a single text string into overlapping chunks.
143
+ */
144
+ chunk(text: string, options?: ChunkOptions): Chunk[];
145
+ /**
146
+ * Chunk multiple documents at once.
147
+ */
148
+ chunkMany(documents: Array<{
149
+ content: string;
150
+ docId?: string;
151
+ metadata?: Record<string, unknown>;
152
+ }>): Chunk[];
153
+ }
154
+
155
+ export { BaseVectorProvider as B, type Chunk as C, DocumentChunker as D, ProviderRegistry as P, VectorPlugin as V, type ChunkOptions as a, ConfigResolver as b };
@@ -0,0 +1,155 @@
1
+ import { e as RagConfig, C as ChatMessage, b as ChatResponse, d as IngestDocument, g as VectorDBConfig, f as UpsertDocument, V as VectorMatch, L as LLMConfig, c as EmbeddingConfig, I as ILLMProvider } from './Pipeline-Bo6CUCox.mjs';
2
+
3
+ /**
4
+ * VectorPlugin — main orchestrator class.
5
+ * This is the primary interface for host applications.
6
+ */
7
+ declare class VectorPlugin {
8
+ private config;
9
+ private pipeline;
10
+ /**
11
+ * Initializes the plugin with the host configuration.
12
+ * @param hostConfig - Configuration object passed from the host application.
13
+ */
14
+ constructor(hostConfig?: Partial<RagConfig>);
15
+ /**
16
+ * Get the current resolved configuration.
17
+ */
18
+ getConfig(): RagConfig;
19
+ /**
20
+ * Run a chat query.
21
+ */
22
+ chat(message: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
23
+ /**
24
+ * Ingest documents into the vector database.
25
+ */
26
+ ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
27
+ docId: string;
28
+ chunksIngested: number;
29
+ }>>;
30
+ /**
31
+ * Check the health of the connected providers.
32
+ */
33
+ health(): Promise<Record<string, boolean>>;
34
+ }
35
+
36
+ /**
37
+ * ConfigResolver — validates and normalizes host configuration.
38
+ * It merges host-provided config with environment defaults.
39
+ */
40
+ declare class ConfigResolver {
41
+ /**
42
+ * Resolves the final configuration by merging host-provided config with defaults.
43
+ * @param hostConfig - Partial configuration passed from the host application.
44
+ */
45
+ static resolve(hostConfig?: Partial<RagConfig>): RagConfig;
46
+ /**
47
+ * Validates the configuration for required fields.
48
+ */
49
+ static validate(config: RagConfig): void;
50
+ }
51
+
52
+ /**
53
+ * BaseVectorProvider — Abstract base class for all vector database providers.
54
+ * Each provider (Pinecone, Milvus, Redis, etc.) must extend this class.
55
+ */
56
+ declare abstract class BaseVectorProvider {
57
+ protected readonly config: VectorDBConfig;
58
+ protected readonly indexName: string;
59
+ constructor(config: VectorDBConfig);
60
+ /**
61
+ * Initialise the connection (create tables, verify index, etc.)
62
+ */
63
+ abstract initialize(): Promise<void>;
64
+ /**
65
+ * Insert or update a single vector + content pair.
66
+ */
67
+ abstract upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
68
+ /**
69
+ * Batch upsert for efficient ingestion of many documents.
70
+ */
71
+ abstract batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
72
+ /**
73
+ * Find the top-K most similar vectors to the query vector.
74
+ */
75
+ abstract query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
76
+ /**
77
+ * Delete a stored vector by ID.
78
+ */
79
+ abstract delete(id: string, namespace?: string): Promise<void>;
80
+ /**
81
+ * Delete all vectors in a namespace (full data reset for a project).
82
+ */
83
+ abstract deleteNamespace(namespace: string): Promise<void>;
84
+ /**
85
+ * Check if the underlying DB is reachable.
86
+ */
87
+ abstract ping(): Promise<boolean>;
88
+ /**
89
+ * Gracefully close the connection.
90
+ */
91
+ abstract disconnect(): Promise<void>;
92
+ }
93
+
94
+ /**
95
+ * ProviderRegistry — dynamic provider loader for Vector DBs and LLMs.
96
+ */
97
+ declare class ProviderRegistry {
98
+ private static vectorProviders;
99
+ /**
100
+ * Register a custom vector provider.
101
+ */
102
+ static registerVectorProvider(name: string, providerClass: new (config: VectorDBConfig) => BaseVectorProvider): void;
103
+ /**
104
+ * Creates a vector database provider based on the configuration.
105
+ */
106
+ static createVectorProvider(config: VectorDBConfig): Promise<BaseVectorProvider>;
107
+ /**
108
+ * Creates an LLM provider based on the configuration.
109
+ */
110
+ static createLLMProvider(llmConfig: LLMConfig, embeddingConfig?: EmbeddingConfig): ILLMProvider;
111
+ }
112
+
113
+ /**
114
+ * DocumentChunker — splits long text into overlapping chunks
115
+ * suitable for vector embedding and retrieval.
116
+ *
117
+ * Strategy: sentence-aware sliding window
118
+ * 1. Split on sentence boundaries
119
+ * 2. Accumulate sentences into chunks up to `chunkSize` characters
120
+ * 3. Carry over `chunkOverlap` characters from the previous chunk
121
+ */
122
+ interface Chunk {
123
+ id: string;
124
+ content: string;
125
+ metadata?: Record<string, unknown>;
126
+ }
127
+ interface ChunkOptions {
128
+ /** Target chunk size in characters (default 1000) */
129
+ chunkSize?: number;
130
+ /** Overlap between consecutive chunks in characters (default 200) */
131
+ chunkOverlap?: number;
132
+ /** Source document identifier used as ID prefix */
133
+ docId?: string;
134
+ /** Extra metadata to attach to every chunk */
135
+ metadata?: Record<string, unknown>;
136
+ }
137
+ declare class DocumentChunker {
138
+ private readonly chunkSize;
139
+ private readonly chunkOverlap;
140
+ constructor(chunkSize?: number, chunkOverlap?: number);
141
+ /**
142
+ * Split a single text string into overlapping chunks.
143
+ */
144
+ chunk(text: string, options?: ChunkOptions): Chunk[];
145
+ /**
146
+ * Chunk multiple documents at once.
147
+ */
148
+ chunkMany(documents: Array<{
149
+ content: string;
150
+ docId?: string;
151
+ metadata?: Record<string, unknown>;
152
+ }>): Chunk[];
153
+ }
154
+
155
+ export { BaseVectorProvider as B, type Chunk as C, DocumentChunker as D, ProviderRegistry as P, VectorPlugin as V, type ChunkOptions as a, ConfigResolver as b };
@@ -0,0 +1,7 @@
1
+ import {
2
+ LLMFactory
3
+ } from "./chunk-GD3QJFNN.mjs";
4
+ import "./chunk-I4E63NIC.mjs";
5
+ export {
6
+ LLMFactory
7
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ MilvusProvider
3
+ } from "./chunk-7NXI6ZWX.mjs";
4
+ import "./chunk-VOIWNO5O.mjs";
5
+ import "./chunk-I4E63NIC.mjs";
6
+ export {
7
+ MilvusProvider
8
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ MongoDBProvider
3
+ } from "./chunk-QEYVWVT5.mjs";
4
+ import "./chunk-VOIWNO5O.mjs";
5
+ import "./chunk-I4E63NIC.mjs";
6
+ export {
7
+ MongoDBProvider
8
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ PineconeProvider
3
+ } from "./chunk-AALIF3AL.mjs";
4
+ import "./chunk-VOIWNO5O.mjs";
5
+ import "./chunk-I4E63NIC.mjs";
6
+ export {
7
+ PineconeProvider
8
+ };
@@ -1,120 +1,9 @@
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
- * Generic Vector Database interface.
53
- * Any adapter (Pinecone, pgVector, REST, Chroma, Qdrant, …) must implement this.
54
- */
55
- interface VectorMatch {
56
- /** Unique identifier of the stored chunk */
57
- id: string;
58
- /** Cosine or dot-product similarity score (0–1) */
59
- score: number;
60
- /** The original text content of the chunk */
61
- content: string;
62
- /** Arbitrary metadata attached at upsert time */
63
- metadata?: Record<string, unknown>;
64
- }
65
- interface UpsertDocument {
66
- id: string;
67
- vector: number[];
68
- content: string;
69
- metadata?: Record<string, unknown>;
70
- }
71
- interface IVectorDB {
72
- /**
73
- * Initialise the connection (create tables, verify index, etc.)
74
- * Called once during RAGPipeline construction.
75
- */
76
- initialize(): Promise<void>;
77
- /**
78
- * Insert or update a single vector + content pair.
79
- * @param namespace – optional project/tenant namespace
80
- */
81
- upsert(doc: UpsertDocument, namespace?: string): Promise<void>;
82
- /**
83
- * Batch upsert for efficient ingestion of many documents.
84
- */
85
- batchUpsert(docs: UpsertDocument[], namespace?: string): Promise<void>;
86
- /**
87
- * Find the top-K most similar vectors to the query vector.
88
- * @param vector – embedding of the user query
89
- * @param topK – number of results to return
90
- * @param namespace – optional project/tenant namespace
91
- * @param filter – optional metadata filter (provider-specific shape)
92
- */
93
- query(vector: number[], topK: number, namespace?: string, filter?: Record<string, unknown>): Promise<VectorMatch[]>;
94
- /**
95
- * Delete a stored vector by ID.
96
- */
97
- delete(id: string, namespace?: string): Promise<void>;
98
- /**
99
- * Delete all vectors in a namespace (full data reset for a project).
100
- */
101
- deleteNamespace(namespace: string): Promise<void>;
102
- /**
103
- * Check if the underlying DB is reachable.
104
- */
105
- ping(): Promise<boolean>;
106
- /**
107
- * Gracefully close the connection.
108
- */
109
- disconnect(): Promise<void>;
110
- }
111
-
112
1
  /**
113
2
  * Master configuration interface for Retrivora AI.
114
3
  * Each consuming project provides one RagConfig object to drive
115
4
  * vector DB selection, LLM selection, embedding, and UI branding.
116
5
  */
117
- type VectorDBProvider = 'pinecone' | 'pgvector' | 'mongodb' | 'rest' | 'universal_rest' | 'custom';
6
+ type VectorDBProvider = 'pinecone' | 'pgvector' | 'postgresql' | 'mongodb' | 'milvus' | 'qdrant' | 'chromadb' | 'redis' | 'weaviate' | 'rest' | 'universal_rest' | 'custom';
118
7
  interface VectorDBConfig {
119
8
  /** Which vector database to use */
120
9
  provider: VectorDBProvider;
@@ -232,67 +121,95 @@ interface RagConfig {
232
121
  }
233
122
 
234
123
  /**
235
- * RAGPipeline the central orchestrator for the RAG workflow.
236
- *
237
- * Responsibilities:
238
- * 1. INGEST: chunk → embed → upsert into vector DB
239
- * 2. ASK: embed query → retrieve top-K chunks → call LLM with context
240
- *
241
- * It is LLM-agnostic and vector-DB-agnostic; concrete implementations are
242
- * injected via ILLMProvider and IVectorDB.
124
+ * Generic LLM Provider interface.
125
+ * Covers both chat completion and embedding generation so a single
126
+ * provider can handle both responsibilities when appropriate.
243
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
+ }
244
185
 
245
186
  interface IngestDocument {
246
- /** Unique document ID (used as chunk ID prefix) */
247
187
  docId: string;
248
- /** Full text content of the document */
249
188
  content: string;
250
- /** Optional metadata stored alongside each chunk */
251
189
  metadata?: Record<string, unknown>;
252
190
  }
253
191
  interface ChatResponse {
254
- /** The LLM's answer */
255
192
  reply: string;
256
- /** Retrieved source chunks used to generate the answer */
257
193
  sources: VectorMatch[];
258
194
  }
259
- declare class RAGPipeline {
260
- private readonly vectorDB;
261
- private readonly llmProvider;
262
- private readonly embeddingProvider;
263
- private readonly chunker;
264
- private readonly config;
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;
265
204
  private initialised;
266
- constructor(config: RagConfig, adapters?: {
267
- vectorDB?: IVectorDB;
268
- llmProvider?: ILLMProvider;
269
- embeddingProvider?: ILLMProvider;
270
- });
271
- /** Lazily initialise the vector DB connection */
272
- init(): Promise<void>;
273
- /**
274
- * Ingest one or more documents into the vector DB.
275
- * Automatically chunks, embeds, and upserts each chunk.
276
- */
277
- ingest(documents: IngestDocument[], namespace?: string): Promise<{
205
+ constructor(config: RagConfig);
206
+ initialize(): Promise<void>;
207
+ ingest(documents: IngestDocument[], namespace?: string): Promise<Array<{
278
208
  docId: string;
279
209
  chunksIngested: number;
280
- }[]>;
281
- /**
282
- * Run a full RAG query:
283
- * 1. Embed the user question
284
- * 2. Retrieve top-K relevant chunks from the vector DB
285
- * 3. Filter by score threshold
286
- * 4. Build context string
287
- * 5. Call the LLM with chat history + context
288
- */
210
+ }>>;
289
211
  ask(question: string, history?: ChatMessage[], namespace?: string): Promise<ChatResponse>;
290
- health(): Promise<{
291
- vectorDB: boolean;
292
- llm: boolean;
293
- }>;
294
- deleteDocument(docId: string, namespace?: string): Promise<void>;
295
- deleteProject(namespace?: string): Promise<void>;
212
+ health(): Promise<Record<string, boolean>>;
296
213
  }
297
214
 
298
- export { type ChatMessage as C, type EmbedOptions as E, type ILLMProvider as I, type LLMConfig as L, 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 IVectorDB as d, type IngestDocument as e, type RagConfig as f, type UpsertDocument as g, type VectorDBConfig as h, RAGPipeline as i };
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 };