@retrivora-ai/rag-engine 0.1.7 → 0.1.9
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/{ChromaDBProvider-QNI7UCX4.mjs → ChromaDBProvider-T7TK3ONZ.mjs} +2 -2
- package/dist/{MilvusProvider-OO6QGZDZ.mjs → MilvusProvider-Y5FV5EAE.mjs} +2 -2
- package/dist/{MongoDBProvider-WWVJG3WT.mjs → MongoDBProvider-QHMGD2LZ.mjs} +2 -2
- package/dist/{PineconeProvider-ZRAFNFEC.mjs → PineconeProvider-A47MRRYJ.mjs} +2 -2
- package/dist/{PostgreSQLProvider-ZNXA67IM.mjs → PostgreSQLProvider-PJ5ER5Z4.mjs} +1 -1
- package/dist/{QdrantProvider-VAED5VA7.mjs → QdrantProvider-OLPJK7CY.mjs} +2 -2
- package/dist/{RagConfig-hBGXJmSx.d.mts → RagConfig-D_rSf8ep.d.mts} +1 -1
- package/dist/{RagConfig-hBGXJmSx.d.ts → RagConfig-D_rSf8ep.d.ts} +1 -1
- package/dist/{RedisProvider-ASONNYBI.mjs → RedisProvider-ANEJ3BHR.mjs} +2 -2
- package/dist/UniversalVectorProvider-QJIV2AJJ.mjs +9 -0
- package/dist/{WeaviateProvider-PSDCUGC7.mjs → WeaviateProvider-WIK2QN23.mjs} +2 -2
- package/dist/{chunk-7YQWGERZ.mjs → chunk-2VR5ZMXV.mjs} +740 -193
- package/dist/{chunk-QEYVWVT5.mjs → chunk-5HXNKSCR.mjs} +1 -1
- package/dist/{chunk-ZM6TYIDH.mjs → chunk-BMHJTWSU.mjs} +4 -2
- package/dist/{chunk-UKDXCXW7.mjs → chunk-EDLTMSNY.mjs} +1 -1
- package/dist/{chunk-I4E63NIC.mjs → chunk-FWCSY2DS.mjs} +14 -1
- package/dist/{chunk-VPNRDXIA.mjs → chunk-HOMXEE3M.mjs} +17 -11
- package/dist/{chunk-V75V7BT2.mjs → chunk-RUKZC3ON.mjs} +3 -3
- package/dist/{chunk-7NXI6ZWX.mjs → chunk-VEJNRS4B.mjs} +9 -6
- package/dist/{chunk-HUGLYKD6.mjs → chunk-VKE5ZW7Y.mjs} +28 -10
- package/dist/chunk-VV2ML6TM.mjs +156 -0
- package/dist/{chunk-CWQQHAF6.mjs → chunk-W2PQR3UK.mjs} +4 -6
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +877 -625
- package/dist/handlers/index.mjs +3 -4
- package/dist/index-BJ8CUArE.d.mts +114 -0
- package/dist/index-DtNprGGj.d.ts +114 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +67 -58
- package/dist/index.mjs +74 -47
- package/dist/server.d.mts +601 -17
- package/dist/server.d.ts +601 -17
- package/dist/server.js +1426 -708
- package/dist/server.mjs +429 -18
- package/package.json +11 -2
- package/src/app/constants.tsx +220 -0
- package/src/app/page.tsx +193 -363
- package/src/app/types.ts +30 -0
- package/src/components/ChatWindow.tsx +3 -11
- package/src/config/ConfigBuilder.ts +373 -0
- package/src/config/EmbeddingStrategy.ts +147 -0
- package/src/config/serverConfig.ts +51 -18
- package/src/core/ConfigValidator.ts +67 -50
- package/src/core/Pipeline.ts +28 -26
- package/src/core/PluginManager.ts +277 -0
- package/src/core/ProviderHealthCheck.ts +75 -139
- package/src/core/ProviderRegistry.ts +38 -15
- package/src/providers/vectordb/ChromaDBProvider.ts +37 -12
- package/src/providers/vectordb/MilvusProvider.ts +25 -10
- package/src/providers/vectordb/MultiTablePostgresProvider.ts +164 -0
- package/src/providers/vectordb/PineconeProvider.ts +17 -2
- package/src/providers/vectordb/QdrantProvider.ts +3 -6
- package/src/providers/vectordb/RedisProvider.ts +34 -11
- package/src/providers/vectordb/UniversalVectorProvider.ts +220 -0
- package/src/providers/vectordb/WeaviateProvider.ts +17 -10
- package/src/server.ts +29 -10
- package/dist/LLMFactory-JFOY2V4X.mjs +0 -8
- package/dist/chunk-JI6VD5TJ.mjs +0 -387
- package/dist/index-Bx182KKn.d.ts +0 -64
- package/dist/index-Ck2pt7-8.d.mts +0 -64
- package/src/test-refactor.ts +0 -59
package/src/server.ts
CHANGED
|
@@ -1,38 +1,57 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Server-only entry point for
|
|
3
|
-
*
|
|
2
|
+
* Server-only entry point for @retrivora-ai/rag-engine.
|
|
3
|
+
*
|
|
4
|
+
* Import this in Next.js API routes, Server Components, or any Node.js server.
|
|
5
|
+
* Do NOT import this in client-side code — use the default export ('@retrivora-ai/rag-engine') instead.
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
|
-
// ── Shared Types
|
|
7
|
-
export type { RagConfig, VectorDBConfig, LLMConfig, EmbeddingConfig, UIConfig, RAGConfig } from './config/RagConfig';
|
|
8
|
-
export type { VectorMatch, UpsertDocument } from './types';
|
|
8
|
+
// ── Shared Types ──────────────────────────────────────────────
|
|
9
|
+
export type { RagConfig, VectorDBConfig, LLMConfig, EmbeddingConfig, UIConfig, RAGConfig, VectorDBProvider, LLMProvider, EmbeddingProvider } from './config/RagConfig';
|
|
10
|
+
export type { VectorMatch, UpsertDocument, IngestDocument, ChatResponse } from './types';
|
|
9
11
|
export type { ILLMProvider, ChatMessage, ChatOptions, EmbedOptions } from './llm/ILLMProvider';
|
|
10
|
-
export type { IngestDocument, ChatResponse } from './types';
|
|
11
12
|
export type { Chunk, ChunkOptions } from './rag/DocumentChunker';
|
|
13
|
+
export type { HealthCheckResult } from './core/ProviderHealthCheck';
|
|
14
|
+
export type { ValidationError } from './core/ConfigValidator';
|
|
15
|
+
export type { BatchOptions, BatchResult } from './core/BatchProcessor';
|
|
12
16
|
|
|
13
|
-
// ──
|
|
17
|
+
// ── Core Orchestration ─────────────────────────────────────────
|
|
14
18
|
export { VectorPlugin } from './core/VectorPlugin';
|
|
15
19
|
export { Pipeline } from './core/Pipeline';
|
|
16
20
|
export { ConfigResolver } from './core/ConfigResolver';
|
|
17
21
|
export { ProviderRegistry } from './core/ProviderRegistry';
|
|
18
|
-
export {
|
|
22
|
+
export { ConfigValidator } from './core/ConfigValidator';
|
|
23
|
+
export { ProviderHealthCheck } from './core/ProviderHealthCheck';
|
|
24
|
+
export { BatchProcessor } from './core/BatchProcessor';
|
|
25
|
+
|
|
26
|
+
// ── Configuration Helpers ──────────────────────────────────────
|
|
19
27
|
export { getRagConfig } from './config/serverConfig';
|
|
28
|
+
export { ConfigBuilder, PRESETS, createFromPreset } from './config/ConfigBuilder';
|
|
29
|
+
export { EmbeddingStrategyResolver, EmbeddingStrategy } from './config/EmbeddingStrategy';
|
|
30
|
+
export { LLM_PROFILES, VECTOR_PROFILES } from './config/UniversalProfiles';
|
|
31
|
+
|
|
32
|
+
// ── RAG Utilities ──────────────────────────────────────────────
|
|
33
|
+
export { DocumentChunker } from './rag/DocumentChunker';
|
|
34
|
+
export { DocumentParser } from './utils/DocumentParser';
|
|
20
35
|
|
|
21
|
-
// ──
|
|
36
|
+
// ── Vector DB Providers ────────────────────────────────────────
|
|
22
37
|
export { BaseVectorProvider } from './providers/vectordb/BaseVectorProvider';
|
|
23
38
|
export { PineconeProvider } from './providers/vectordb/PineconeProvider';
|
|
24
39
|
export { PostgreSQLProvider } from './providers/vectordb/PostgreSQLProvider';
|
|
40
|
+
export { MultiTablePostgresProvider } from './providers/vectordb/MultiTablePostgresProvider';
|
|
25
41
|
export { MongoDBProvider } from './providers/vectordb/MongoDBProvider';
|
|
26
42
|
export { MilvusProvider } from './providers/vectordb/MilvusProvider';
|
|
27
43
|
export { QdrantProvider } from './providers/vectordb/QdrantProvider';
|
|
28
44
|
export { ChromaDBProvider } from './providers/vectordb/ChromaDBProvider';
|
|
29
45
|
export { RedisProvider } from './providers/vectordb/RedisProvider';
|
|
30
46
|
export { WeaviateProvider } from './providers/vectordb/WeaviateProvider';
|
|
47
|
+
export { UniversalVectorProvider } from './providers/vectordb/UniversalVectorProvider';
|
|
31
48
|
|
|
49
|
+
// ── LLM Providers ─────────────────────────────────────────────
|
|
32
50
|
export { LLMFactory } from './llm/LLMFactory';
|
|
33
51
|
export { OpenAIProvider } from './llm/providers/OpenAIProvider';
|
|
34
52
|
export { AnthropicProvider } from './llm/providers/AnthropicProvider';
|
|
35
53
|
export { OllamaProvider } from './llm/providers/OllamaProvider';
|
|
54
|
+
export { UniversalLLMAdapter } from './llm/providers/UniversalLLMAdapter';
|
|
36
55
|
|
|
37
|
-
// ── Route
|
|
56
|
+
// ── Next.js Route Handler Factories ───────────────────────────
|
|
38
57
|
export { createChatHandler, createIngestHandler, createHealthHandler, createUploadHandler } from './handlers';
|
package/dist/chunk-JI6VD5TJ.mjs
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildPayload,
|
|
3
|
-
resolvePath
|
|
4
|
-
} from "./chunk-UKDXCXW7.mjs";
|
|
5
|
-
import {
|
|
6
|
-
__spreadProps,
|
|
7
|
-
__spreadValues
|
|
8
|
-
} from "./chunk-I4E63NIC.mjs";
|
|
9
|
-
|
|
10
|
-
// src/llm/providers/OpenAIProvider.ts
|
|
11
|
-
import OpenAI from "openai";
|
|
12
|
-
var OpenAIProvider = class {
|
|
13
|
-
constructor(llmConfig, embeddingConfig) {
|
|
14
|
-
if (!llmConfig.apiKey) throw new Error("[OpenAIProvider] llmConfig.apiKey is required");
|
|
15
|
-
this.client = new OpenAI({ apiKey: llmConfig.apiKey });
|
|
16
|
-
this.llmConfig = llmConfig;
|
|
17
|
-
this.embeddingConfig = embeddingConfig;
|
|
18
|
-
}
|
|
19
|
-
async chat(messages, context, options) {
|
|
20
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
21
|
-
const systemContent = (_a = this.llmConfig.systemPrompt) != null ? _a : `You are a helpful assistant. Answer questions based on the provided context.
|
|
22
|
-
|
|
23
|
-
Context:
|
|
24
|
-
${context}`;
|
|
25
|
-
const systemMessage = {
|
|
26
|
-
role: "system",
|
|
27
|
-
content: systemContent.includes("{{context}}") ? systemContent.replace("{{context}}", context) : `${systemContent}
|
|
28
|
-
|
|
29
|
-
Context:
|
|
30
|
-
${context}`
|
|
31
|
-
};
|
|
32
|
-
const formattedMessages = [
|
|
33
|
-
systemMessage,
|
|
34
|
-
...messages.map((m) => ({
|
|
35
|
-
role: m.role,
|
|
36
|
-
content: m.content
|
|
37
|
-
}))
|
|
38
|
-
];
|
|
39
|
-
const completion = await this.client.chat.completions.create({
|
|
40
|
-
model: this.llmConfig.model,
|
|
41
|
-
messages: formattedMessages,
|
|
42
|
-
max_tokens: (_c = (_b = options == null ? void 0 : options.maxTokens) != null ? _b : this.llmConfig.maxTokens) != null ? _c : 1024,
|
|
43
|
-
temperature: (_e = (_d = options == null ? void 0 : options.temperature) != null ? _d : this.llmConfig.temperature) != null ? _e : 0.7,
|
|
44
|
-
stop: options == null ? void 0 : options.stop
|
|
45
|
-
});
|
|
46
|
-
return (_h = (_g = (_f = completion.choices[0]) == null ? void 0 : _f.message) == null ? void 0 : _g.content) != null ? _h : "";
|
|
47
|
-
}
|
|
48
|
-
async embed(text, options) {
|
|
49
|
-
const results = await this.batchEmbed([text], options);
|
|
50
|
-
return results[0];
|
|
51
|
-
}
|
|
52
|
-
async batchEmbed(texts, options) {
|
|
53
|
-
var _a, _b, _c, _d, _e;
|
|
54
|
-
const model = (_c = (_b = options == null ? void 0 : options.model) != null ? _b : (_a = this.embeddingConfig) == null ? void 0 : _a.model) != null ? _c : "text-embedding-3-small";
|
|
55
|
-
const apiKey = (_e = (_d = this.embeddingConfig) == null ? void 0 : _d.apiKey) != null ? _e : this.llmConfig.apiKey;
|
|
56
|
-
const client = apiKey !== this.llmConfig.apiKey ? new OpenAI({ apiKey }) : this.client;
|
|
57
|
-
const response = await client.embeddings.create({ model, input: texts });
|
|
58
|
-
return response.data.map((d) => d.embedding);
|
|
59
|
-
}
|
|
60
|
-
async ping() {
|
|
61
|
-
try {
|
|
62
|
-
await this.client.models.list();
|
|
63
|
-
return true;
|
|
64
|
-
} catch (err) {
|
|
65
|
-
console.error("[OpenAIProvider] Ping failed:", err);
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
// src/llm/providers/AnthropicProvider.ts
|
|
72
|
-
import Anthropic from "@anthropic-ai/sdk";
|
|
73
|
-
var AnthropicProvider = class {
|
|
74
|
-
constructor(llmConfig, embeddingConfig) {
|
|
75
|
-
if (!llmConfig.apiKey) throw new Error("[AnthropicProvider] llmConfig.apiKey is required");
|
|
76
|
-
this.client = new Anthropic({ apiKey: llmConfig.apiKey });
|
|
77
|
-
this.llmConfig = llmConfig;
|
|
78
|
-
this.embeddingConfig = embeddingConfig;
|
|
79
|
-
}
|
|
80
|
-
async chat(messages, context, options) {
|
|
81
|
-
var _a, _b, _c;
|
|
82
|
-
const systemPrompt = (_a = this.llmConfig.systemPrompt) != null ? _a : `You are a helpful assistant. Use the context below to answer the user's question accurately.
|
|
83
|
-
|
|
84
|
-
Context:
|
|
85
|
-
${context}`;
|
|
86
|
-
const system = systemPrompt.includes("{{context}}") ? systemPrompt.replace("{{context}}", context) : `${systemPrompt}
|
|
87
|
-
|
|
88
|
-
Context:
|
|
89
|
-
${context}`;
|
|
90
|
-
const anthropicMessages = messages.map((m) => ({
|
|
91
|
-
role: m.role === "assistant" ? "assistant" : "user",
|
|
92
|
-
content: m.content
|
|
93
|
-
}));
|
|
94
|
-
const response = await this.client.messages.create({
|
|
95
|
-
model: this.llmConfig.model,
|
|
96
|
-
max_tokens: (_c = (_b = options == null ? void 0 : options.maxTokens) != null ? _b : this.llmConfig.maxTokens) != null ? _c : 1024,
|
|
97
|
-
system,
|
|
98
|
-
messages: anthropicMessages
|
|
99
|
-
});
|
|
100
|
-
const block = response.content[0];
|
|
101
|
-
return block.type === "text" ? block.text : "";
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Anthropic does not offer an embedding API.
|
|
105
|
-
* This method throws with a clear error so developers know to configure
|
|
106
|
-
* a separate embedding provider (OpenAI or Ollama).
|
|
107
|
-
*/
|
|
108
|
-
async embed(text, options) {
|
|
109
|
-
void text;
|
|
110
|
-
void options;
|
|
111
|
-
throw new Error(
|
|
112
|
-
'[AnthropicProvider] Anthropic does not provide an embedding API. Set embedding.provider to "openai" or "ollama" in your RagConfig.'
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
async batchEmbed(texts, options) {
|
|
116
|
-
void texts;
|
|
117
|
-
void options;
|
|
118
|
-
throw new Error(
|
|
119
|
-
"[AnthropicProvider] Anthropic does not provide an embedding API."
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
async ping() {
|
|
123
|
-
try {
|
|
124
|
-
await this.client.models.list();
|
|
125
|
-
return true;
|
|
126
|
-
} catch (err) {
|
|
127
|
-
console.error("[AnthropicProvider] Ping failed:", err);
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// src/llm/providers/OllamaProvider.ts
|
|
134
|
-
import axios from "axios";
|
|
135
|
-
var OllamaProvider = class {
|
|
136
|
-
constructor(llmConfig, embeddingConfig) {
|
|
137
|
-
var _a;
|
|
138
|
-
const baseURL = (_a = llmConfig.baseUrl) != null ? _a : "http://localhost:11434";
|
|
139
|
-
this.http = axios.create({ baseURL, timeout: 12e4 });
|
|
140
|
-
this.llmConfig = llmConfig;
|
|
141
|
-
this.embeddingConfig = embeddingConfig;
|
|
142
|
-
}
|
|
143
|
-
async chat(messages, context, options) {
|
|
144
|
-
var _a, _b, _c, _d, _e;
|
|
145
|
-
const systemPrompt = (_a = this.llmConfig.systemPrompt) != null ? _a : `You are a helpful assistant. Use the provided context to answer the user's question.
|
|
146
|
-
|
|
147
|
-
Context:
|
|
148
|
-
${context}`;
|
|
149
|
-
const system = systemPrompt.includes("{{context}}") ? systemPrompt.replace("{{context}}", context) : `${systemPrompt}
|
|
150
|
-
|
|
151
|
-
Context:
|
|
152
|
-
${context}`;
|
|
153
|
-
const { data } = await this.http.post("/api/chat", {
|
|
154
|
-
model: this.llmConfig.model,
|
|
155
|
-
stream: false,
|
|
156
|
-
options: {
|
|
157
|
-
temperature: (_c = (_b = options == null ? void 0 : options.temperature) != null ? _b : this.llmConfig.temperature) != null ? _c : 0.7,
|
|
158
|
-
num_predict: (_e = (_d = options == null ? void 0 : options.maxTokens) != null ? _d : this.llmConfig.maxTokens) != null ? _e : 1024
|
|
159
|
-
},
|
|
160
|
-
messages: [
|
|
161
|
-
{ role: "system", content: system },
|
|
162
|
-
...messages.map((m) => ({ role: m.role, content: m.content }))
|
|
163
|
-
]
|
|
164
|
-
});
|
|
165
|
-
return data.message.content;
|
|
166
|
-
}
|
|
167
|
-
async embed(text, options) {
|
|
168
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
169
|
-
const model = (_c = (_b = options == null ? void 0 : options.model) != null ? _b : (_a = this.embeddingConfig) == null ? void 0 : _a.model) != null ? _c : "nomic-embed-text";
|
|
170
|
-
const baseURL = (_f = (_e = (_d = this.embeddingConfig) == null ? void 0 : _d.baseUrl) != null ? _e : this.llmConfig.baseUrl) != null ? _f : "http://localhost:11434";
|
|
171
|
-
const client = baseURL !== ((_g = this.llmConfig.baseUrl) != null ? _g : "http://localhost:11434") ? axios.create({ baseURL, timeout: 6e4 }) : this.http;
|
|
172
|
-
const { data } = await client.post("/api/embeddings", {
|
|
173
|
-
model,
|
|
174
|
-
prompt: text
|
|
175
|
-
});
|
|
176
|
-
return data.embedding;
|
|
177
|
-
}
|
|
178
|
-
async batchEmbed(texts, options) {
|
|
179
|
-
const vectors = [];
|
|
180
|
-
for (const text of texts) {
|
|
181
|
-
vectors.push(await this.embed(text, options));
|
|
182
|
-
}
|
|
183
|
-
return vectors;
|
|
184
|
-
}
|
|
185
|
-
async ping() {
|
|
186
|
-
try {
|
|
187
|
-
await this.http.get("/api/tags");
|
|
188
|
-
return true;
|
|
189
|
-
} catch (err) {
|
|
190
|
-
console.error("[OllamaProvider] Ping failed:", err);
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// src/llm/providers/UniversalLLMAdapter.ts
|
|
197
|
-
import axios2 from "axios";
|
|
198
|
-
|
|
199
|
-
// src/config/UniversalProfiles.ts
|
|
200
|
-
var OPENAI_BASE = {
|
|
201
|
-
chatPath: "/chat/completions",
|
|
202
|
-
embedPath: "/embeddings",
|
|
203
|
-
responseExtractPath: "choices[0].message.content",
|
|
204
|
-
embedExtractPath: "data[0].embedding",
|
|
205
|
-
chatPayloadTemplate: '{"model":"{{model}}","messages":{{messages}},"max_tokens":{{maxTokens}},"temperature":{{temperature}}}'
|
|
206
|
-
};
|
|
207
|
-
var LLM_PROFILES = {
|
|
208
|
-
"openai-compatible": OPENAI_BASE,
|
|
209
|
-
"litellm": __spreadProps(__spreadValues({}, OPENAI_BASE), {
|
|
210
|
-
chatPayloadTemplate: '{"model":"{{model}}","messages":{{messages}},"max_tokens":{{maxTokens}},"temperature":{{temperature}},"stream":false}'
|
|
211
|
-
}),
|
|
212
|
-
"anthropic-claude": {
|
|
213
|
-
chatPath: "/v1/messages",
|
|
214
|
-
responseExtractPath: "content[0].text",
|
|
215
|
-
headers: { "anthropic-version": "2023-06-01" },
|
|
216
|
-
chatPayloadTemplate: '{"model":"{{model}}","messages":{{messages}},"max_tokens":{{maxTokens}}}'
|
|
217
|
-
},
|
|
218
|
-
"google-gemini": {
|
|
219
|
-
chatPath: "/v1beta/models/{{model}}:generateContent",
|
|
220
|
-
responseExtractPath: "candidates[0].content.parts[0].text",
|
|
221
|
-
chatPayloadTemplate: '{"contents":[{"parts":[{"text":"{{messages}}"}]}]}'
|
|
222
|
-
},
|
|
223
|
-
"github-copilot": __spreadProps(__spreadValues({}, OPENAI_BASE), {
|
|
224
|
-
chatPayloadTemplate: '{"model":"{{model}}","messages":{{messages}},"temperature":{{temperature}}}'
|
|
225
|
-
}),
|
|
226
|
-
"ollama-standard": {
|
|
227
|
-
chatPath: "/api/chat",
|
|
228
|
-
embedPath: "/api/embeddings",
|
|
229
|
-
responseExtractPath: "message.content",
|
|
230
|
-
embedExtractPath: "embedding",
|
|
231
|
-
chatPayloadTemplate: '{"model":"{{model}}","messages":{{messages}},"stream":false}',
|
|
232
|
-
embedPayloadTemplate: '{"model":"{{model}}","prompt":"{{input}}"}'
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
// src/llm/providers/UniversalLLMAdapter.ts
|
|
237
|
-
var UniversalLLMAdapter = class {
|
|
238
|
-
constructor(config) {
|
|
239
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
240
|
-
this.model = config.model;
|
|
241
|
-
const llmConfig = config;
|
|
242
|
-
const options = (_a = llmConfig.options) != null ? _a : {};
|
|
243
|
-
let profile = {};
|
|
244
|
-
if (typeof options.profile === "string") {
|
|
245
|
-
profile = LLM_PROFILES[options.profile] || {};
|
|
246
|
-
} else if (typeof options.profile === "object" && options.profile !== null) {
|
|
247
|
-
profile = options.profile;
|
|
248
|
-
}
|
|
249
|
-
this.opts = __spreadValues(__spreadValues({}, profile), (_b = llmConfig.options) != null ? _b : {});
|
|
250
|
-
this.systemPrompt = (_c = llmConfig.systemPrompt) != null ? _c : "You are a helpful AI assistant. Use the provided context to answer the user.";
|
|
251
|
-
this.maxTokens = (_d = llmConfig.maxTokens) != null ? _d : 1024;
|
|
252
|
-
this.temperature = (_e = llmConfig.temperature) != null ? _e : 0;
|
|
253
|
-
const baseUrl = (_f = llmConfig.baseUrl) != null ? _f : this.opts.baseUrl;
|
|
254
|
-
if (!baseUrl) {
|
|
255
|
-
throw new Error("[UniversalLLMAdapter] baseUrl is required in config or config.options");
|
|
256
|
-
}
|
|
257
|
-
this.http = axios2.create({
|
|
258
|
-
baseURL: baseUrl,
|
|
259
|
-
headers: __spreadValues(__spreadValues({
|
|
260
|
-
"Content-Type": "application/json"
|
|
261
|
-
}, config.apiKey ? { Authorization: `Bearer ${config.apiKey}` } : {}), this.opts.headers || {}),
|
|
262
|
-
timeout: (_g = this.opts.timeout) != null ? _g : 6e4
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
async chat(messages, context) {
|
|
266
|
-
var _a, _b;
|
|
267
|
-
const path = (_a = this.opts.chatPath) != null ? _a : "/chat/completions";
|
|
268
|
-
const formattedMessages = [
|
|
269
|
-
{ role: "system", content: `${this.systemPrompt}
|
|
270
|
-
|
|
271
|
-
Context:
|
|
272
|
-
${context != null ? context : "None"}` },
|
|
273
|
-
...messages
|
|
274
|
-
];
|
|
275
|
-
let payload;
|
|
276
|
-
if (this.opts.chatPayloadTemplate) {
|
|
277
|
-
payload = buildPayload(this.opts.chatPayloadTemplate, {
|
|
278
|
-
model: this.model,
|
|
279
|
-
messages: formattedMessages,
|
|
280
|
-
maxTokens: this.maxTokens,
|
|
281
|
-
temperature: this.temperature
|
|
282
|
-
});
|
|
283
|
-
} else {
|
|
284
|
-
payload = {
|
|
285
|
-
model: this.model,
|
|
286
|
-
messages: formattedMessages,
|
|
287
|
-
max_tokens: this.maxTokens,
|
|
288
|
-
temperature: this.temperature
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
const { data } = await this.http.post(path, payload);
|
|
292
|
-
const extractPath = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
|
|
293
|
-
const result = resolvePath(data, extractPath);
|
|
294
|
-
if (result === void 0) {
|
|
295
|
-
throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
|
|
296
|
-
}
|
|
297
|
-
return String(result);
|
|
298
|
-
}
|
|
299
|
-
async embed(text) {
|
|
300
|
-
var _a, _b;
|
|
301
|
-
const path = (_a = this.opts.embedPath) != null ? _a : "/embeddings";
|
|
302
|
-
let payload;
|
|
303
|
-
if (this.opts.embedPayloadTemplate) {
|
|
304
|
-
payload = buildPayload(this.opts.embedPayloadTemplate, {
|
|
305
|
-
model: this.model,
|
|
306
|
-
input: text
|
|
307
|
-
});
|
|
308
|
-
} else {
|
|
309
|
-
payload = {
|
|
310
|
-
model: this.model,
|
|
311
|
-
input: text
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
const { data } = await this.http.post(path, payload);
|
|
315
|
-
const extractPath = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
|
|
316
|
-
const vector = resolvePath(data, extractPath);
|
|
317
|
-
if (!Array.isArray(vector)) {
|
|
318
|
-
throw new Error(`[UniversalLLMAdapter] Expected a number array at '${extractPath}' for embeddings.`);
|
|
319
|
-
}
|
|
320
|
-
return vector;
|
|
321
|
-
}
|
|
322
|
-
async batchEmbed(texts) {
|
|
323
|
-
const vectors = [];
|
|
324
|
-
for (const text of texts) {
|
|
325
|
-
vectors.push(await this.embed(text));
|
|
326
|
-
}
|
|
327
|
-
return vectors;
|
|
328
|
-
}
|
|
329
|
-
async ping() {
|
|
330
|
-
try {
|
|
331
|
-
if (this.opts.pingPath) {
|
|
332
|
-
await this.http.get(this.opts.pingPath);
|
|
333
|
-
}
|
|
334
|
-
return true;
|
|
335
|
-
} catch (err) {
|
|
336
|
-
console.error("[UniversalLLMAdapter] Ping failed:", err);
|
|
337
|
-
return false;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
// src/llm/LLMFactory.ts
|
|
343
|
-
var LLMFactory = class _LLMFactory {
|
|
344
|
-
static create(llmConfig, embeddingConfig) {
|
|
345
|
-
var _a;
|
|
346
|
-
switch (llmConfig.provider) {
|
|
347
|
-
case "openai":
|
|
348
|
-
return new OpenAIProvider(llmConfig, embeddingConfig);
|
|
349
|
-
case "anthropic":
|
|
350
|
-
return new AnthropicProvider(llmConfig, embeddingConfig);
|
|
351
|
-
case "ollama":
|
|
352
|
-
return new OllamaProvider(llmConfig, embeddingConfig);
|
|
353
|
-
case "rest":
|
|
354
|
-
case "universal_rest":
|
|
355
|
-
case "custom":
|
|
356
|
-
return new UniversalLLMAdapter(llmConfig);
|
|
357
|
-
default:
|
|
358
|
-
if (llmConfig.baseUrl || ((_a = llmConfig.options) == null ? void 0 : _a.baseUrl)) {
|
|
359
|
-
return new UniversalLLMAdapter(llmConfig);
|
|
360
|
-
}
|
|
361
|
-
throw new Error(
|
|
362
|
-
`[LLMFactory] Unknown provider "${llmConfig.provider}". Supported: openai | anthropic | ollama | rest | custom`
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Creates a dedicated embedding-only provider.
|
|
368
|
-
* Useful when the LLM provider (e.g. Anthropic) doesn't support embeddings.
|
|
369
|
-
*/
|
|
370
|
-
static createEmbeddingProvider(embeddingConfig) {
|
|
371
|
-
const fakeLLMConfig = {
|
|
372
|
-
provider: embeddingConfig.provider,
|
|
373
|
-
model: embeddingConfig.model,
|
|
374
|
-
apiKey: embeddingConfig.apiKey,
|
|
375
|
-
baseUrl: embeddingConfig.baseUrl,
|
|
376
|
-
options: embeddingConfig.options
|
|
377
|
-
};
|
|
378
|
-
return _LLMFactory.create(fakeLLMConfig, embeddingConfig);
|
|
379
|
-
}
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
export {
|
|
383
|
-
OpenAIProvider,
|
|
384
|
-
AnthropicProvider,
|
|
385
|
-
OllamaProvider,
|
|
386
|
-
LLMFactory
|
|
387
|
-
};
|
package/dist/index-Bx182KKn.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { a as RagConfig, C as ChatResponse } from './RagConfig-hBGXJmSx.js';
|
|
2
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* ProviderHealthCheck.ts — Pre-flight validation for vector DB and LLM providers.
|
|
6
|
-
*
|
|
7
|
-
* Performs connectivity tests, credential validation, and capability checks
|
|
8
|
-
* before initializing providers.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
interface HealthCheckResult {
|
|
12
|
-
healthy: boolean;
|
|
13
|
-
provider: string;
|
|
14
|
-
version?: string;
|
|
15
|
-
capabilities?: Record<string, unknown>;
|
|
16
|
-
error?: string;
|
|
17
|
-
timestamp: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* createChatHandler — factory that returns a Next.js App Router POST handler
|
|
22
|
-
*/
|
|
23
|
-
declare function createChatHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
24
|
-
error: string;
|
|
25
|
-
}> | NextResponse<ChatResponse>>;
|
|
26
|
-
/**
|
|
27
|
-
* createIngestHandler — factory for the document ingestion endpoint.
|
|
28
|
-
*/
|
|
29
|
-
declare function createIngestHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
30
|
-
error: string;
|
|
31
|
-
}> | NextResponse<{
|
|
32
|
-
results: {
|
|
33
|
-
docId: string | number;
|
|
34
|
-
chunksIngested: number;
|
|
35
|
-
}[];
|
|
36
|
-
}>>;
|
|
37
|
-
/**
|
|
38
|
-
* createHealthHandler — factory for the health-check endpoint.
|
|
39
|
-
*/
|
|
40
|
-
declare function createHealthHandler(config?: Partial<RagConfig>): () => Promise<NextResponse<{
|
|
41
|
-
timestamp: string;
|
|
42
|
-
vectorDb: HealthCheckResult;
|
|
43
|
-
llm: HealthCheckResult;
|
|
44
|
-
embedding?: HealthCheckResult;
|
|
45
|
-
allHealthy: boolean;
|
|
46
|
-
status: string;
|
|
47
|
-
}> | NextResponse<{
|
|
48
|
-
status: string;
|
|
49
|
-
error: string;
|
|
50
|
-
}>>;
|
|
51
|
-
/**
|
|
52
|
-
* createUploadHandler — factory for the file upload ingestion endpoint.
|
|
53
|
-
*/
|
|
54
|
-
declare function createUploadHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
55
|
-
error: string;
|
|
56
|
-
}> | NextResponse<{
|
|
57
|
-
message: string;
|
|
58
|
-
results: {
|
|
59
|
-
docId: string | number;
|
|
60
|
-
chunksIngested: number;
|
|
61
|
-
}[];
|
|
62
|
-
}>>;
|
|
63
|
-
|
|
64
|
-
export { type HealthCheckResult as H, createHealthHandler as a, createIngestHandler as b, createChatHandler as c, createUploadHandler as d };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { a as RagConfig, C as ChatResponse } from './RagConfig-hBGXJmSx.mjs';
|
|
2
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* ProviderHealthCheck.ts — Pre-flight validation for vector DB and LLM providers.
|
|
6
|
-
*
|
|
7
|
-
* Performs connectivity tests, credential validation, and capability checks
|
|
8
|
-
* before initializing providers.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
interface HealthCheckResult {
|
|
12
|
-
healthy: boolean;
|
|
13
|
-
provider: string;
|
|
14
|
-
version?: string;
|
|
15
|
-
capabilities?: Record<string, unknown>;
|
|
16
|
-
error?: string;
|
|
17
|
-
timestamp: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* createChatHandler — factory that returns a Next.js App Router POST handler
|
|
22
|
-
*/
|
|
23
|
-
declare function createChatHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
24
|
-
error: string;
|
|
25
|
-
}> | NextResponse<ChatResponse>>;
|
|
26
|
-
/**
|
|
27
|
-
* createIngestHandler — factory for the document ingestion endpoint.
|
|
28
|
-
*/
|
|
29
|
-
declare function createIngestHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
30
|
-
error: string;
|
|
31
|
-
}> | NextResponse<{
|
|
32
|
-
results: {
|
|
33
|
-
docId: string | number;
|
|
34
|
-
chunksIngested: number;
|
|
35
|
-
}[];
|
|
36
|
-
}>>;
|
|
37
|
-
/**
|
|
38
|
-
* createHealthHandler — factory for the health-check endpoint.
|
|
39
|
-
*/
|
|
40
|
-
declare function createHealthHandler(config?: Partial<RagConfig>): () => Promise<NextResponse<{
|
|
41
|
-
timestamp: string;
|
|
42
|
-
vectorDb: HealthCheckResult;
|
|
43
|
-
llm: HealthCheckResult;
|
|
44
|
-
embedding?: HealthCheckResult;
|
|
45
|
-
allHealthy: boolean;
|
|
46
|
-
status: string;
|
|
47
|
-
}> | NextResponse<{
|
|
48
|
-
status: string;
|
|
49
|
-
error: string;
|
|
50
|
-
}>>;
|
|
51
|
-
/**
|
|
52
|
-
* createUploadHandler — factory for the file upload ingestion endpoint.
|
|
53
|
-
*/
|
|
54
|
-
declare function createUploadHandler(config?: Partial<RagConfig>): (req: NextRequest) => Promise<NextResponse<{
|
|
55
|
-
error: string;
|
|
56
|
-
}> | NextResponse<{
|
|
57
|
-
message: string;
|
|
58
|
-
results: {
|
|
59
|
-
docId: string | number;
|
|
60
|
-
chunksIngested: number;
|
|
61
|
-
}[];
|
|
62
|
-
}>>;
|
|
63
|
-
|
|
64
|
-
export { type HealthCheckResult as H, createHealthHandler as a, createIngestHandler as b, createChatHandler as c, createUploadHandler as d };
|
package/src/test-refactor.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { VectorPlugin } from './core/VectorPlugin';
|
|
2
|
-
|
|
3
|
-
async function testRefactor() {
|
|
4
|
-
console.log('🚀 Starting VectorPlugin Refactor Test...\n');
|
|
5
|
-
|
|
6
|
-
// Test 1: Initialization with Empty Config (should use env defaults or fallbacks)
|
|
7
|
-
console.log('--- Test 1: Default Config ---');
|
|
8
|
-
try {
|
|
9
|
-
const pluginDefault = new VectorPlugin();
|
|
10
|
-
const config = pluginDefault.getConfig();
|
|
11
|
-
console.log('✅ Resolved Project ID:', config.projectId);
|
|
12
|
-
console.log('✅ Resolved Vector DB Provider:', config.vectorDb.provider);
|
|
13
|
-
} catch (err) {
|
|
14
|
-
console.error('❌ Test 1 Failed:', (err as Error).message);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Test 2: Overriding Config from Host
|
|
18
|
-
console.log('\n--- Test 2: Host Override Config ---');
|
|
19
|
-
try {
|
|
20
|
-
const pluginOverride = new VectorPlugin({
|
|
21
|
-
projectId: 'host-override-test',
|
|
22
|
-
vectorDb: {
|
|
23
|
-
provider: 'milvus',
|
|
24
|
-
indexName: 'milvus-index',
|
|
25
|
-
options: { uri: 'http://localhost:19530' }
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
const config = pluginOverride.getConfig();
|
|
29
|
-
console.log('✅ Resolved Project ID (Overridden):', config.projectId);
|
|
30
|
-
console.log('✅ Resolved Vector DB Provider (Overridden):', config.vectorDb.provider);
|
|
31
|
-
} catch (err) {
|
|
32
|
-
console.error('❌ Test 2 Failed:', (err as Error).message);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Test 3: Provider Registry Loading
|
|
36
|
-
console.log('\n--- Test 3: Provider Registry Loading ---');
|
|
37
|
-
try {
|
|
38
|
-
const { ProviderRegistry } = await import('./core/ProviderRegistry');
|
|
39
|
-
const milvusProvider = await ProviderRegistry.createVectorProvider({
|
|
40
|
-
provider: 'milvus',
|
|
41
|
-
indexName: 'test',
|
|
42
|
-
options: { uri: 'http://localhost' }
|
|
43
|
-
});
|
|
44
|
-
console.log('✅ Milvus Provider Instantiated:', milvusProvider.constructor.name);
|
|
45
|
-
|
|
46
|
-
const redisProvider = await ProviderRegistry.createVectorProvider({
|
|
47
|
-
provider: 'redis',
|
|
48
|
-
indexName: 'test',
|
|
49
|
-
options: { baseUrl: 'http://localhost', apiKey: 'test' }
|
|
50
|
-
});
|
|
51
|
-
console.log('✅ Redis Provider Instantiated:', redisProvider.constructor.name);
|
|
52
|
-
} catch (err) {
|
|
53
|
-
console.error('❌ Test 3 Failed:', (err as Error).message);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
console.log('\n✨ Refactor Test Completed.');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
testRefactor().catch(console.error);
|