@retrivora-ai/rag-engine 0.1.4 → 0.1.5
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.
- package/dist/DocumentChunker-cfaMidtA.d.mts +93 -0
- package/dist/DocumentChunker-cfaMidtA.d.ts +93 -0
- package/dist/{LLMFactory-XC55FTD2.mjs → LLMFactory-JFOY2V4X.mjs} +2 -1
- package/dist/{Pipeline-Bo6CUCox.d.ts → RagConfig-DG_0f8ka.d.mts} +23 -93
- package/dist/{Pipeline-Bo6CUCox.d.mts → RagConfig-DG_0f8ka.d.ts} +23 -93
- package/dist/{chunk-AIAB2IEE.mjs → chunk-BP4U4TT5.mjs} +158 -4
- package/dist/{chunk-GD3QJFNN.mjs → chunk-JI6VD5TJ.mjs} +4 -41
- package/dist/chunk-UKDXCXW7.mjs +49 -0
- package/dist/handlers/index.d.mts +1 -1
- package/dist/handlers/index.d.ts +1 -1
- package/dist/handlers/index.mjs +3 -3
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +19 -1646
- package/dist/index.mjs +1 -11
- package/dist/server.d.mts +135 -5
- package/dist/server.d.ts +135 -5
- package/dist/server.mjs +7 -8
- package/package.json +19 -2
- package/src/core/Pipeline.ts +2 -10
- package/src/core/VectorPlugin.ts +2 -1
- package/src/index.ts +1 -7
- package/src/server.ts +1 -1
- package/src/types/index.ts +11 -0
- package/dist/DocumentChunker-BQ5kQD7B.d.ts +0 -155
- package/dist/DocumentChunker-D9-fObJp.d.mts +0 -155
- 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;
|
|
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;
|
|
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;
|
|
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;
|
|
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,3 +1,25 @@
|
|
|
1
|
+
interface VectorMatch {
|
|
2
|
+
id: string;
|
|
3
|
+
score: number;
|
|
4
|
+
content: string;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
interface UpsertDocument {
|
|
8
|
+
id: string;
|
|
9
|
+
vector: number[];
|
|
10
|
+
content: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface IngestDocument {
|
|
14
|
+
docId: string;
|
|
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;
|
|
3
|
+
score: number;
|
|
4
|
+
content: string;
|
|
5
|
+
metadata?: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
interface UpsertDocument {
|
|
8
|
+
id: string;
|
|
9
|
+
vector: number[];
|
|
10
|
+
content: string;
|
|
11
|
+
metadata?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
interface IngestDocument {
|
|
14
|
+
docId: string;
|
|
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,12 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LLMFactory
|
|
2
|
+
LLMFactory
|
|
3
|
+
} from "./chunk-JI6VD5TJ.mjs";
|
|
4
|
+
import {
|
|
3
5
|
mergeDefined
|
|
4
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-UKDXCXW7.mjs";
|
|
5
7
|
import {
|
|
6
8
|
__spreadProps,
|
|
7
9
|
__spreadValues
|
|
8
10
|
} from "./chunk-I4E63NIC.mjs";
|
|
9
11
|
|
|
12
|
+
// src/handlers/index.ts
|
|
13
|
+
import { NextResponse } from "next/server";
|
|
14
|
+
|
|
10
15
|
// src/config/serverConfig.ts
|
|
11
16
|
var VECTOR_DB_PROVIDERS = ["pinecone", "pgvector", "postgresql", "mongodb", "milvus", "qdrant", "chromadb", "redis", "weaviate", "rest", "universal_rest", "custom"];
|
|
12
17
|
var LLM_PROVIDERS = ["openai", "anthropic", "ollama", "rest", "universal_rest", "custom"];
|
|
@@ -293,7 +298,7 @@ var Pipeline = class {
|
|
|
293
298
|
this.vectorDB = await ProviderRegistry.createVectorProvider(this.config.vectorDb);
|
|
294
299
|
this.llmProvider = ProviderRegistry.createLLMProvider(this.config.llm, this.config.embedding);
|
|
295
300
|
if (this.config.llm.provider === "anthropic") {
|
|
296
|
-
const { LLMFactory: LLMFactory2 } = await import("./LLMFactory-
|
|
301
|
+
const { LLMFactory: LLMFactory2 } = await import("./LLMFactory-JFOY2V4X.mjs");
|
|
297
302
|
this.embeddingProvider = LLMFactory2.createEmbeddingProvider(this.config.embedding);
|
|
298
303
|
} else {
|
|
299
304
|
this.embeddingProvider = this.llmProvider;
|
|
@@ -384,11 +389,160 @@ var VectorPlugin = class {
|
|
|
384
389
|
}
|
|
385
390
|
};
|
|
386
391
|
|
|
392
|
+
// src/utils/DocumentParser.ts
|
|
393
|
+
var DocumentParser = class {
|
|
394
|
+
/**
|
|
395
|
+
* Extract text from a File or Buffer based on its type.
|
|
396
|
+
*/
|
|
397
|
+
static async parse(file, fileName, mimeType) {
|
|
398
|
+
var _a;
|
|
399
|
+
const extension = (_a = fileName.split(".").pop()) == null ? void 0 : _a.toLowerCase();
|
|
400
|
+
if (extension === "txt" || extension === "md" || mimeType === "text/plain" || mimeType === "text/markdown") {
|
|
401
|
+
return this.readAsText(file);
|
|
402
|
+
}
|
|
403
|
+
if (extension === "json" || mimeType === "application/json") {
|
|
404
|
+
const text = await this.readAsText(file);
|
|
405
|
+
try {
|
|
406
|
+
const obj = JSON.parse(text);
|
|
407
|
+
return JSON.stringify(obj, null, 2);
|
|
408
|
+
} catch (e) {
|
|
409
|
+
return text;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (extension === "csv" || mimeType === "text/csv") {
|
|
413
|
+
return this.readAsText(file);
|
|
414
|
+
}
|
|
415
|
+
if (extension === "pdf" || mimeType === "application/pdf") {
|
|
416
|
+
try {
|
|
417
|
+
const pdf = await import("pdf-parse/lib/pdf-parse.js");
|
|
418
|
+
const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
|
|
419
|
+
const data = await pdf.default(buffer);
|
|
420
|
+
return data.text;
|
|
421
|
+
} catch (err) {
|
|
422
|
+
console.warn('[DocumentParser] PDF parsing failed. Make sure "pdf-parse" is installed.', err);
|
|
423
|
+
return `[PDF Parsing Error for ${fileName}]`;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
if (extension === "docx" || mimeType === "application/vnd.openxmlformats-officedocument.wordprocessingml.document") {
|
|
427
|
+
try {
|
|
428
|
+
const mammoth = await import("mammoth");
|
|
429
|
+
const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
|
|
430
|
+
const result = await mammoth.extractRawText({ buffer });
|
|
431
|
+
return result.value;
|
|
432
|
+
} catch (err) {
|
|
433
|
+
console.warn('[DocumentParser] DOCX parsing failed. Make sure "mammoth" is installed.', err);
|
|
434
|
+
return `[DOCX Parsing Error for ${fileName}]`;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
try {
|
|
438
|
+
return await this.readAsText(file);
|
|
439
|
+
} catch (e) {
|
|
440
|
+
throw new Error(`[DocumentParser] Unsupported file format: ${fileName} (${mimeType})`);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
static async readAsText(file) {
|
|
444
|
+
if (Buffer.isBuffer(file)) {
|
|
445
|
+
return file.toString("utf-8");
|
|
446
|
+
}
|
|
447
|
+
return await file.text();
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// src/handlers/index.ts
|
|
452
|
+
function createChatHandler(config) {
|
|
453
|
+
const plugin = new VectorPlugin(config);
|
|
454
|
+
return async function POST(req) {
|
|
455
|
+
try {
|
|
456
|
+
const body = await req.json();
|
|
457
|
+
const { message, history = [], namespace } = body;
|
|
458
|
+
if (!(message == null ? void 0 : message.trim())) {
|
|
459
|
+
return NextResponse.json({ error: "message is required" }, { status: 400 });
|
|
460
|
+
}
|
|
461
|
+
const result = await plugin.chat(message, history, namespace);
|
|
462
|
+
return NextResponse.json(result);
|
|
463
|
+
} catch (err) {
|
|
464
|
+
const message = err instanceof Error ? err.message : "Internal server error";
|
|
465
|
+
return NextResponse.json({ error: message }, { status: 500 });
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function createIngestHandler(config) {
|
|
470
|
+
const plugin = new VectorPlugin(config);
|
|
471
|
+
return async function POST(req) {
|
|
472
|
+
try {
|
|
473
|
+
const body = await req.json();
|
|
474
|
+
const { documents, namespace } = body;
|
|
475
|
+
if (!Array.isArray(documents) || documents.length === 0) {
|
|
476
|
+
return NextResponse.json({ error: "documents array is required" }, { status: 400 });
|
|
477
|
+
}
|
|
478
|
+
const results = await plugin.ingest(documents, namespace);
|
|
479
|
+
return NextResponse.json({ results });
|
|
480
|
+
} catch (err) {
|
|
481
|
+
const message = err instanceof Error ? err.message : "Internal server error";
|
|
482
|
+
return NextResponse.json({ error: message }, { status: 500 });
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
function createHealthHandler(config) {
|
|
487
|
+
const plugin = new VectorPlugin(config);
|
|
488
|
+
return async function GET() {
|
|
489
|
+
try {
|
|
490
|
+
const health = await plugin.health();
|
|
491
|
+
const status = health.vectorDB && health.llm ? "ok" : "degraded";
|
|
492
|
+
return NextResponse.json(__spreadProps(__spreadValues({
|
|
493
|
+
status
|
|
494
|
+
}, health), {
|
|
495
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
496
|
+
}));
|
|
497
|
+
} catch (err) {
|
|
498
|
+
const message = err instanceof Error ? err.message : "Unknown error";
|
|
499
|
+
return NextResponse.json({ status: "error", error: message }, { status: 500 });
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function createUploadHandler(config) {
|
|
504
|
+
const plugin = new VectorPlugin(config);
|
|
505
|
+
return async function POST(req) {
|
|
506
|
+
try {
|
|
507
|
+
const formData = await req.formData();
|
|
508
|
+
const files = formData.getAll("files");
|
|
509
|
+
const namespace = formData.get("namespace") || void 0;
|
|
510
|
+
if (!files || files.length === 0) {
|
|
511
|
+
return NextResponse.json({ error: "No files provided" }, { status: 400 });
|
|
512
|
+
}
|
|
513
|
+
const documents = await Promise.all(
|
|
514
|
+
files.map(async (file) => {
|
|
515
|
+
const content = await DocumentParser.parse(file, file.name, file.type);
|
|
516
|
+
return {
|
|
517
|
+
docId: file.name,
|
|
518
|
+
content,
|
|
519
|
+
metadata: {
|
|
520
|
+
fileName: file.name,
|
|
521
|
+
fileSize: file.size,
|
|
522
|
+
fileType: file.type,
|
|
523
|
+
uploadedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
})
|
|
527
|
+
);
|
|
528
|
+
const results = await plugin.ingest(documents, namespace);
|
|
529
|
+
return NextResponse.json({ message: "Upload successful", results });
|
|
530
|
+
} catch (err) {
|
|
531
|
+
const message = err instanceof Error ? err.message : "Upload failed";
|
|
532
|
+
return NextResponse.json({ error: message }, { status: 500 });
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
|
|
387
537
|
export {
|
|
388
538
|
getRagConfig,
|
|
389
539
|
ConfigResolver,
|
|
390
540
|
DocumentChunker,
|
|
391
541
|
ProviderRegistry,
|
|
392
542
|
Pipeline,
|
|
393
|
-
VectorPlugin
|
|
543
|
+
VectorPlugin,
|
|
544
|
+
createChatHandler,
|
|
545
|
+
createIngestHandler,
|
|
546
|
+
createHealthHandler,
|
|
547
|
+
createUploadHandler
|
|
394
548
|
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildPayload,
|
|
3
|
+
resolvePath
|
|
4
|
+
} from "./chunk-UKDXCXW7.mjs";
|
|
1
5
|
import {
|
|
2
6
|
__spreadProps,
|
|
3
7
|
__spreadValues
|
|
@@ -192,46 +196,6 @@ ${context}`;
|
|
|
192
196
|
// src/llm/providers/UniversalLLMAdapter.ts
|
|
193
197
|
import axios2 from "axios";
|
|
194
198
|
|
|
195
|
-
// src/utils/templateUtils.ts
|
|
196
|
-
function isRecord(value) {
|
|
197
|
-
return typeof value === "object" && value !== null;
|
|
198
|
-
}
|
|
199
|
-
function resolvePath(obj, path) {
|
|
200
|
-
if (!path || !obj) return void 0;
|
|
201
|
-
return path.replace(/\[(\w+)\]/g, ".$1").replace(/^\./, "").split(".").reduce((current, segment) => {
|
|
202
|
-
if (!isRecord(current) && !Array.isArray(current)) {
|
|
203
|
-
return void 0;
|
|
204
|
-
}
|
|
205
|
-
return current[segment];
|
|
206
|
-
}, obj);
|
|
207
|
-
}
|
|
208
|
-
function buildPayload(template, vars) {
|
|
209
|
-
let raw = template;
|
|
210
|
-
for (const [key, val] of Object.entries(vars)) {
|
|
211
|
-
const stringifiedVal = val === void 0 ? "null" : JSON.stringify(val);
|
|
212
|
-
raw = raw.replace(new RegExp(`"\\{\\{${key}\\}\\}"`, "g"), stringifiedVal);
|
|
213
|
-
raw = raw.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), stringifiedVal);
|
|
214
|
-
}
|
|
215
|
-
try {
|
|
216
|
-
return JSON.parse(raw);
|
|
217
|
-
} catch (err) {
|
|
218
|
-
throw new Error(`Failed to parse payload template: ${err.message}
|
|
219
|
-
Raw payload: ${raw}`);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
function mergeDefined(base, override) {
|
|
223
|
-
const merged = __spreadValues({}, base || {});
|
|
224
|
-
if (!override) {
|
|
225
|
-
return merged;
|
|
226
|
-
}
|
|
227
|
-
for (const [key, value] of Object.entries(override)) {
|
|
228
|
-
if (value !== void 0 && value !== null && value !== "") {
|
|
229
|
-
merged[key] = value;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
return merged;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
199
|
// src/config/UniversalProfiles.ts
|
|
236
200
|
var OPENAI_BASE = {
|
|
237
201
|
chatPath: "/chat/completions",
|
|
@@ -416,7 +380,6 @@ var LLMFactory = class _LLMFactory {
|
|
|
416
380
|
};
|
|
417
381
|
|
|
418
382
|
export {
|
|
419
|
-
mergeDefined,
|
|
420
383
|
OpenAIProvider,
|
|
421
384
|
AnthropicProvider,
|
|
422
385
|
OllamaProvider,
|