@retrivora-ai/rag-engine 1.1.0 → 1.1.2
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/{QdrantProvider-WWXFX2XF.mjs → QdrantProvider-RLJTNGPY.mjs} +1 -1
- package/dist/{RagConfig-DVovvPmd.d.mts → RagConfig-FyMB_UG6.d.mts} +1 -1
- package/dist/{RagConfig-DVovvPmd.d.ts → RagConfig-FyMB_UG6.d.ts} +1 -1
- package/dist/{chunk-65S4BQL2.mjs → chunk-PSFPZXHX.mjs} +13 -6
- package/dist/{chunk-G2LVK46T.mjs → chunk-XEWWAHCM.mjs} +167 -6
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +179 -11
- package/dist/handlers/index.mjs +1 -1
- package/dist/{index-CQ0zQ7Zk.d.ts → index-CYgr00ot.d.ts} +1 -1
- package/dist/{index-D0_2f-43.d.mts → index-D-lfcqlL.d.mts} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/server.d.mts +7 -4
- package/dist/server.d.ts +7 -4
- package/dist/server.js +179 -11
- package/dist/server.mjs +2 -2
- package/package.json +1 -1
- package/src/app/constants.tsx +2 -2
- package/src/config/constants.ts +1 -1
- package/src/core/Pipeline.ts +5 -1
- package/src/llm/providers/AnthropicProvider.ts +33 -0
- package/src/llm/providers/GeminiProvider.ts +36 -0
- package/src/llm/providers/OllamaProvider.ts +27 -3
- package/src/llm/providers/OpenAIProvider.ts +39 -0
- package/src/providers/vectordb/QdrantProvider.ts +21 -12
|
@@ -103,7 +103,7 @@ interface RetrievalResult {
|
|
|
103
103
|
* This file serves as the single source of truth for all statically supported
|
|
104
104
|
* providers and stylistic options in the Retrivora AI RAG Engine.
|
|
105
105
|
*/
|
|
106
|
-
declare const VECTOR_DB_PROVIDERS: readonly ["pinecone", "pgvector", "postgresql", "mongodb", "
|
|
106
|
+
declare const VECTOR_DB_PROVIDERS: readonly ["pinecone", "pgvector", "postgresql", "mongodb", "qdrant", "milvus", "chromadb", "redis", "weaviate", "rest", "universal_rest", "custom"];
|
|
107
107
|
declare const LLM_PROVIDERS: readonly ["openai", "anthropic", "ollama", "gemini", "rest", "universal_rest", "custom"];
|
|
108
108
|
declare const EMBEDDING_PROVIDERS: readonly ["openai", "ollama", "gemini", "rest", "universal_rest", "custom"];
|
|
109
109
|
declare const GRAPH_DB_PROVIDERS: readonly ["neo4j", "memgraph", "simple", "custom"];
|
|
@@ -103,7 +103,7 @@ interface RetrievalResult {
|
|
|
103
103
|
* This file serves as the single source of truth for all statically supported
|
|
104
104
|
* providers and stylistic options in the Retrivora AI RAG Engine.
|
|
105
105
|
*/
|
|
106
|
-
declare const VECTOR_DB_PROVIDERS: readonly ["pinecone", "pgvector", "postgresql", "mongodb", "
|
|
106
|
+
declare const VECTOR_DB_PROVIDERS: readonly ["pinecone", "pgvector", "postgresql", "mongodb", "qdrant", "milvus", "chromadb", "redis", "weaviate", "rest", "universal_rest", "custom"];
|
|
107
107
|
declare const LLM_PROVIDERS: readonly ["openai", "anthropic", "ollama", "gemini", "rest", "universal_rest", "custom"];
|
|
108
108
|
declare const EMBEDDING_PROVIDERS: readonly ["openai", "ollama", "gemini", "rest", "universal_rest", "custom"];
|
|
109
109
|
declare const GRAPH_DB_PROVIDERS: readonly ["neo4j", "memgraph", "simple", "custom"];
|
|
@@ -11,6 +11,7 @@ import crypto from "crypto";
|
|
|
11
11
|
var QdrantProvider = class extends BaseVectorProvider {
|
|
12
12
|
constructor(config) {
|
|
13
13
|
super(config);
|
|
14
|
+
this.schemaDiscovered = false;
|
|
14
15
|
const opts = config.options;
|
|
15
16
|
const baseUrl = opts.baseUrl;
|
|
16
17
|
if (!baseUrl) throw new Error("[QdrantProvider] baseUrl is required");
|
|
@@ -19,12 +20,15 @@ var QdrantProvider = class extends BaseVectorProvider {
|
|
|
19
20
|
this.isFlatPayload = !!opts.flatPayload;
|
|
20
21
|
this.http = axios.create({
|
|
21
22
|
baseURL: baseUrl,
|
|
23
|
+
timeout: 15e3,
|
|
24
|
+
// 15s timeout for vector DB operations
|
|
22
25
|
headers: __spreadValues({
|
|
23
26
|
"Content-Type": "application/json"
|
|
24
27
|
}, opts.apiKey ? { "api-key": opts.apiKey } : {})
|
|
25
28
|
});
|
|
26
29
|
}
|
|
27
30
|
async initialize() {
|
|
31
|
+
if (this.schemaDiscovered) return;
|
|
28
32
|
await this.ping();
|
|
29
33
|
await this.ensureCollection();
|
|
30
34
|
console.log(`[QdrantProvider] \u{1F50D} Discovering schema for collection "${this.indexName}"...`);
|
|
@@ -34,13 +38,16 @@ var QdrantProvider = class extends BaseVectorProvider {
|
|
|
34
38
|
const allFields = [.../* @__PURE__ */ new Set([...discoveredFields, ...configFields])];
|
|
35
39
|
if (allFields.length > 0) {
|
|
36
40
|
console.log(`[QdrantProvider] \u{1F6E0} Ensuring indexes for ${allFields.length} discovered fields...`);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
await Promise.all(
|
|
42
|
+
allFields.map(async (fieldInfo) => {
|
|
43
|
+
const [fieldName, schemaType] = fieldInfo.split(":");
|
|
44
|
+
return this.ensureIndex(fieldName, schemaType || "keyword");
|
|
45
|
+
})
|
|
46
|
+
);
|
|
41
47
|
} else {
|
|
42
48
|
console.log(`[QdrantProvider] \u2139\uFE0F No fields discovered for indexing.`);
|
|
43
49
|
}
|
|
50
|
+
this.schemaDiscovered = true;
|
|
44
51
|
}
|
|
45
52
|
/**
|
|
46
53
|
* Samples points from the collection to discover available payload fields.
|
|
@@ -177,7 +184,7 @@ var QdrantProvider = class extends BaseVectorProvider {
|
|
|
177
184
|
const p = res.payload || {};
|
|
178
185
|
let content = p[this.contentField] || "";
|
|
179
186
|
if (!content) {
|
|
180
|
-
const stringFields = Object.entries(p).filter(([
|
|
187
|
+
const stringFields = Object.entries(p).filter(([, v]) => typeof v === "string").map(([k, v]) => ({ key: k, val: v }));
|
|
181
188
|
if (stringFields.length > 0) {
|
|
182
189
|
const bestMatch = stringFields.sort((a, b) => b.val.length - a.val.length)[0];
|
|
183
190
|
content = bestMatch.val;
|
|
@@ -202,7 +209,7 @@ var QdrantProvider = class extends BaseVectorProvider {
|
|
|
202
209
|
});
|
|
203
210
|
return results;
|
|
204
211
|
}
|
|
205
|
-
async delete(id
|
|
212
|
+
async delete(id) {
|
|
206
213
|
await this.http.post(`/collections/${this.indexName}/points/delete`, {
|
|
207
214
|
points: [this.normalizeId(id)]
|
|
208
215
|
});
|
|
@@ -21,8 +21,8 @@ var VECTOR_DB_PROVIDERS = [
|
|
|
21
21
|
"pgvector",
|
|
22
22
|
"postgresql",
|
|
23
23
|
"mongodb",
|
|
24
|
-
"milvus",
|
|
25
24
|
"qdrant",
|
|
25
|
+
"milvus",
|
|
26
26
|
"chromadb",
|
|
27
27
|
"redis",
|
|
28
28
|
"weaviate",
|
|
@@ -333,6 +333,56 @@ ${context}`
|
|
|
333
333
|
});
|
|
334
334
|
return (_h = (_g = (_f = completion.choices[0]) == null ? void 0 : _f.message) == null ? void 0 : _g.content) != null ? _h : "";
|
|
335
335
|
}
|
|
336
|
+
chatStream(messages, context, options) {
|
|
337
|
+
return __asyncGenerator(this, null, function* () {
|
|
338
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
339
|
+
const systemContent = (_a = this.llmConfig.systemPrompt) != null ? _a : `You are a helpful assistant. Answer questions based on the provided context.
|
|
340
|
+
|
|
341
|
+
Context:
|
|
342
|
+
${context}`;
|
|
343
|
+
const systemMessage = {
|
|
344
|
+
role: "system",
|
|
345
|
+
content: systemContent.includes("{{context}}") ? systemContent.replace("{{context}}", context) : `${systemContent}
|
|
346
|
+
|
|
347
|
+
Context:
|
|
348
|
+
${context}`
|
|
349
|
+
};
|
|
350
|
+
const formattedMessages = [
|
|
351
|
+
systemMessage,
|
|
352
|
+
...messages.map((m) => ({
|
|
353
|
+
role: m.role,
|
|
354
|
+
content: m.content
|
|
355
|
+
}))
|
|
356
|
+
];
|
|
357
|
+
const stream = yield new __await(this.client.chat.completions.create({
|
|
358
|
+
model: this.llmConfig.model,
|
|
359
|
+
messages: formattedMessages,
|
|
360
|
+
max_tokens: (_c = (_b = options == null ? void 0 : options.maxTokens) != null ? _b : this.llmConfig.maxTokens) != null ? _c : 1024,
|
|
361
|
+
temperature: (_e = (_d = options == null ? void 0 : options.temperature) != null ? _d : this.llmConfig.temperature) != null ? _e : 0.7,
|
|
362
|
+
stop: options == null ? void 0 : options.stop,
|
|
363
|
+
stream: true
|
|
364
|
+
}));
|
|
365
|
+
if (!stream) {
|
|
366
|
+
throw new Error("[OpenAIProvider] completions.create stream is undefined");
|
|
367
|
+
}
|
|
368
|
+
try {
|
|
369
|
+
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
370
|
+
const chunk = temp.value;
|
|
371
|
+
const content = ((_g = (_f = chunk.choices[0]) == null ? void 0 : _f.delta) == null ? void 0 : _g.content) || "";
|
|
372
|
+
if (content) yield content;
|
|
373
|
+
}
|
|
374
|
+
} catch (temp) {
|
|
375
|
+
error = [temp];
|
|
376
|
+
} finally {
|
|
377
|
+
try {
|
|
378
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
379
|
+
} finally {
|
|
380
|
+
if (error)
|
|
381
|
+
throw error[0];
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
}
|
|
336
386
|
async embed(text, options) {
|
|
337
387
|
const results = await this.batchEmbed([text], options);
|
|
338
388
|
return results[0];
|
|
@@ -438,6 +488,50 @@ ${context}`;
|
|
|
438
488
|
const block = response.content[0];
|
|
439
489
|
return block.type === "text" ? block.text : "";
|
|
440
490
|
}
|
|
491
|
+
chatStream(messages, context, options) {
|
|
492
|
+
return __asyncGenerator(this, null, function* () {
|
|
493
|
+
var _a, _b, _c;
|
|
494
|
+
const systemPrompt = (_a = this.llmConfig.systemPrompt) != null ? _a : `You are a helpful assistant. Use the context below to answer the user's question accurately.
|
|
495
|
+
|
|
496
|
+
Context:
|
|
497
|
+
${context}`;
|
|
498
|
+
const system = systemPrompt.includes("{{context}}") ? systemPrompt.replace("{{context}}", context) : `${systemPrompt}
|
|
499
|
+
|
|
500
|
+
Context:
|
|
501
|
+
${context}`;
|
|
502
|
+
const anthropicMessages = messages.map((m) => ({
|
|
503
|
+
role: m.role === "assistant" ? "assistant" : "user",
|
|
504
|
+
content: m.content
|
|
505
|
+
}));
|
|
506
|
+
const stream = yield new __await(this.client.messages.create({
|
|
507
|
+
model: this.llmConfig.model,
|
|
508
|
+
max_tokens: (_c = (_b = options == null ? void 0 : options.maxTokens) != null ? _b : this.llmConfig.maxTokens) != null ? _c : 1024,
|
|
509
|
+
system,
|
|
510
|
+
messages: anthropicMessages,
|
|
511
|
+
stream: true
|
|
512
|
+
}));
|
|
513
|
+
if (!stream) {
|
|
514
|
+
throw new Error("[AnthropicProvider] messages.create stream is undefined");
|
|
515
|
+
}
|
|
516
|
+
try {
|
|
517
|
+
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
518
|
+
const chunk = temp.value;
|
|
519
|
+
if (chunk.type === "content_block_delta" && chunk.delta.type === "text_delta") {
|
|
520
|
+
yield chunk.delta.text;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
} catch (temp) {
|
|
524
|
+
error = [temp];
|
|
525
|
+
} finally {
|
|
526
|
+
try {
|
|
527
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
528
|
+
} finally {
|
|
529
|
+
if (error)
|
|
530
|
+
throw error[0];
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
}
|
|
441
535
|
async embed(text, options) {
|
|
442
536
|
void text;
|
|
443
537
|
void options;
|
|
@@ -543,7 +637,7 @@ var OllamaProvider = class {
|
|
|
543
637
|
}
|
|
544
638
|
chatStream(messages, context, options) {
|
|
545
639
|
return __asyncGenerator(this, null, function* () {
|
|
546
|
-
var _a, _b, _c, _d, _e;
|
|
640
|
+
var _a, _b, _c, _d, _e, _f;
|
|
547
641
|
const system = this.buildSystemPrompt(context);
|
|
548
642
|
const response = yield new __await(this.http.post("/api/chat", {
|
|
549
643
|
model: this.llmConfig.model,
|
|
@@ -557,11 +651,19 @@ var OllamaProvider = class {
|
|
|
557
651
|
...messages.map((m) => ({ role: m.role, content: m.content }))
|
|
558
652
|
]
|
|
559
653
|
}, { responseType: "stream" }));
|
|
654
|
+
let lineBuffer = "";
|
|
655
|
+
const stream = response.data;
|
|
656
|
+
if (!stream) {
|
|
657
|
+
throw new Error("[OllamaProvider] response.data is undefined for stream request. Axios might not support streams in this environment.");
|
|
658
|
+
}
|
|
560
659
|
try {
|
|
561
|
-
for (var iter = __forAwait(
|
|
660
|
+
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
562
661
|
const chunk = temp.value;
|
|
563
|
-
|
|
662
|
+
lineBuffer += chunk.toString();
|
|
663
|
+
const lines = lineBuffer.split("\n");
|
|
664
|
+
lineBuffer = lines.pop() || "";
|
|
564
665
|
for (const line of lines) {
|
|
666
|
+
if (!line.trim()) continue;
|
|
565
667
|
try {
|
|
566
668
|
const json = JSON.parse(line);
|
|
567
669
|
if ((_e = json.message) == null ? void 0 : _e.content) {
|
|
@@ -569,6 +671,7 @@ var OllamaProvider = class {
|
|
|
569
671
|
}
|
|
570
672
|
if (json.done) return;
|
|
571
673
|
} catch (e) {
|
|
674
|
+
console.warn("[OllamaProvider] Failed to parse streaming line:", line);
|
|
572
675
|
}
|
|
573
676
|
}
|
|
574
677
|
}
|
|
@@ -582,6 +685,13 @@ var OllamaProvider = class {
|
|
|
582
685
|
throw error[0];
|
|
583
686
|
}
|
|
584
687
|
}
|
|
688
|
+
if (lineBuffer.trim()) {
|
|
689
|
+
try {
|
|
690
|
+
const json = JSON.parse(lineBuffer);
|
|
691
|
+
if ((_f = json.message) == null ? void 0 : _f.content) yield json.message.content;
|
|
692
|
+
} catch (e) {
|
|
693
|
+
}
|
|
694
|
+
}
|
|
585
695
|
});
|
|
586
696
|
}
|
|
587
697
|
buildSystemPrompt(context) {
|
|
@@ -727,6 +837,53 @@ ${context}`;
|
|
|
727
837
|
});
|
|
728
838
|
return (_f = response.text) != null ? _f : "";
|
|
729
839
|
}
|
|
840
|
+
chatStream(messages, context, options) {
|
|
841
|
+
return __asyncGenerator(this, null, function* () {
|
|
842
|
+
var _a, _b, _c, _d, _e, _f;
|
|
843
|
+
const systemPrompt = (_a = this.llmConfig.systemPrompt) != null ? _a : `You are a helpful assistant. Answer questions based on the provided context.
|
|
844
|
+
|
|
845
|
+
Context:
|
|
846
|
+
${context}`;
|
|
847
|
+
const systemInstruction = systemPrompt.includes("{{context}}") ? systemPrompt.replace("{{context}}", context) : `${systemPrompt}
|
|
848
|
+
|
|
849
|
+
Context:
|
|
850
|
+
${context}`;
|
|
851
|
+
const geminiMessages = messages.map((m) => ({
|
|
852
|
+
role: m.role === "assistant" ? "model" : "user",
|
|
853
|
+
parts: [{ text: m.content }]
|
|
854
|
+
}));
|
|
855
|
+
const result = yield new __await(this.client.models.generateContentStream({
|
|
856
|
+
model: this.llmConfig.model,
|
|
857
|
+
contents: geminiMessages,
|
|
858
|
+
config: {
|
|
859
|
+
systemInstruction,
|
|
860
|
+
temperature: (_c = (_b = options == null ? void 0 : options.temperature) != null ? _b : this.llmConfig.temperature) != null ? _c : 0.7,
|
|
861
|
+
maxOutputTokens: (_e = (_d = options == null ? void 0 : options.maxTokens) != null ? _d : this.llmConfig.maxTokens) != null ? _e : 1024,
|
|
862
|
+
stopSequences: options == null ? void 0 : options.stop
|
|
863
|
+
}
|
|
864
|
+
}));
|
|
865
|
+
const stream = (_f = result == null ? void 0 : result.stream) != null ? _f : result;
|
|
866
|
+
if (!stream) {
|
|
867
|
+
throw new Error("[GeminiProvider] generateContentStream returned undefined");
|
|
868
|
+
}
|
|
869
|
+
try {
|
|
870
|
+
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
871
|
+
const chunk = temp.value;
|
|
872
|
+
const text = chunk.text;
|
|
873
|
+
if (text) yield text;
|
|
874
|
+
}
|
|
875
|
+
} catch (temp) {
|
|
876
|
+
error = [temp];
|
|
877
|
+
} finally {
|
|
878
|
+
try {
|
|
879
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
880
|
+
} finally {
|
|
881
|
+
if (error)
|
|
882
|
+
throw error[0];
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
}
|
|
730
887
|
async embed(text, options) {
|
|
731
888
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
732
889
|
const model = this.sanitizeModel(
|
|
@@ -1106,7 +1263,7 @@ var ProviderRegistry = class {
|
|
|
1106
1263
|
return MilvusProvider;
|
|
1107
1264
|
}
|
|
1108
1265
|
case "qdrant": {
|
|
1109
|
-
const { QdrantProvider } = await import("./QdrantProvider-
|
|
1266
|
+
const { QdrantProvider } = await import("./QdrantProvider-RLJTNGPY.mjs");
|
|
1110
1267
|
return QdrantProvider;
|
|
1111
1268
|
}
|
|
1112
1269
|
case "chromadb": {
|
|
@@ -2299,8 +2456,12 @@ ${context}`;
|
|
|
2299
2456
|
}
|
|
2300
2457
|
const messages = [...history, { role: "user", content: question }];
|
|
2301
2458
|
if (this.llmProvider.chatStream) {
|
|
2459
|
+
const stream = this.llmProvider.chatStream(messages, context);
|
|
2460
|
+
if (!stream) {
|
|
2461
|
+
throw new Error(`[Pipeline] ${this.config.llm.provider} chatStream returned undefined`);
|
|
2462
|
+
}
|
|
2302
2463
|
try {
|
|
2303
|
-
for (var iter = __forAwait(
|
|
2464
|
+
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
2304
2465
|
const chunk = temp.value;
|
|
2305
2466
|
yield chunk;
|
|
2306
2467
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import '../RagConfig-
|
|
2
|
-
export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-
|
|
1
|
+
import '../RagConfig-FyMB_UG6.mjs';
|
|
2
|
+
export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-D-lfcqlL.mjs';
|
|
3
3
|
import 'next/server';
|
package/dist/handlers/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import '../RagConfig-
|
|
2
|
-
export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-
|
|
1
|
+
import '../RagConfig-FyMB_UG6.js';
|
|
2
|
+
export { c as createChatHandler, d as createHealthHandler, e as createIngestHandler, f as createStreamHandler, g as createUploadHandler, s as sseErrorFrame, h as sseFrame, i as sseMetaFrame, j as sseTextFrame } from '../index-CYgr00ot.js';
|
|
3
3
|
import 'next/server';
|
package/dist/handlers/index.js
CHANGED
|
@@ -842,6 +842,7 @@ var init_QdrantProvider = __esm({
|
|
|
842
842
|
QdrantProvider = class extends BaseVectorProvider {
|
|
843
843
|
constructor(config) {
|
|
844
844
|
super(config);
|
|
845
|
+
this.schemaDiscovered = false;
|
|
845
846
|
const opts = config.options;
|
|
846
847
|
const baseUrl = opts.baseUrl;
|
|
847
848
|
if (!baseUrl) throw new Error("[QdrantProvider] baseUrl is required");
|
|
@@ -850,12 +851,15 @@ var init_QdrantProvider = __esm({
|
|
|
850
851
|
this.isFlatPayload = !!opts.flatPayload;
|
|
851
852
|
this.http = import_axios4.default.create({
|
|
852
853
|
baseURL: baseUrl,
|
|
854
|
+
timeout: 15e3,
|
|
855
|
+
// 15s timeout for vector DB operations
|
|
853
856
|
headers: __spreadValues({
|
|
854
857
|
"Content-Type": "application/json"
|
|
855
858
|
}, opts.apiKey ? { "api-key": opts.apiKey } : {})
|
|
856
859
|
});
|
|
857
860
|
}
|
|
858
861
|
async initialize() {
|
|
862
|
+
if (this.schemaDiscovered) return;
|
|
859
863
|
await this.ping();
|
|
860
864
|
await this.ensureCollection();
|
|
861
865
|
console.log(`[QdrantProvider] \u{1F50D} Discovering schema for collection "${this.indexName}"...`);
|
|
@@ -865,13 +869,16 @@ var init_QdrantProvider = __esm({
|
|
|
865
869
|
const allFields = [.../* @__PURE__ */ new Set([...discoveredFields, ...configFields])];
|
|
866
870
|
if (allFields.length > 0) {
|
|
867
871
|
console.log(`[QdrantProvider] \u{1F6E0} Ensuring indexes for ${allFields.length} discovered fields...`);
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
+
await Promise.all(
|
|
873
|
+
allFields.map(async (fieldInfo) => {
|
|
874
|
+
const [fieldName, schemaType] = fieldInfo.split(":");
|
|
875
|
+
return this.ensureIndex(fieldName, schemaType || "keyword");
|
|
876
|
+
})
|
|
877
|
+
);
|
|
872
878
|
} else {
|
|
873
879
|
console.log(`[QdrantProvider] \u2139\uFE0F No fields discovered for indexing.`);
|
|
874
880
|
}
|
|
881
|
+
this.schemaDiscovered = true;
|
|
875
882
|
}
|
|
876
883
|
/**
|
|
877
884
|
* Samples points from the collection to discover available payload fields.
|
|
@@ -1008,7 +1015,7 @@ var init_QdrantProvider = __esm({
|
|
|
1008
1015
|
const p = res.payload || {};
|
|
1009
1016
|
let content = p[this.contentField] || "";
|
|
1010
1017
|
if (!content) {
|
|
1011
|
-
const stringFields = Object.entries(p).filter(([
|
|
1018
|
+
const stringFields = Object.entries(p).filter(([, v]) => typeof v === "string").map(([k, v]) => ({ key: k, val: v }));
|
|
1012
1019
|
if (stringFields.length > 0) {
|
|
1013
1020
|
const bestMatch = stringFields.sort((a, b) => b.val.length - a.val.length)[0];
|
|
1014
1021
|
content = bestMatch.val;
|
|
@@ -1033,7 +1040,7 @@ var init_QdrantProvider = __esm({
|
|
|
1033
1040
|
});
|
|
1034
1041
|
return results;
|
|
1035
1042
|
}
|
|
1036
|
-
async delete(id
|
|
1043
|
+
async delete(id) {
|
|
1037
1044
|
await this.http.post(`/collections/${this.indexName}/points/delete`, {
|
|
1038
1045
|
points: [this.normalizeId(id)]
|
|
1039
1046
|
});
|
|
@@ -1623,8 +1630,8 @@ var VECTOR_DB_PROVIDERS = [
|
|
|
1623
1630
|
"pgvector",
|
|
1624
1631
|
"postgresql",
|
|
1625
1632
|
"mongodb",
|
|
1626
|
-
"milvus",
|
|
1627
1633
|
"qdrant",
|
|
1634
|
+
"milvus",
|
|
1628
1635
|
"chromadb",
|
|
1629
1636
|
"redis",
|
|
1630
1637
|
"weaviate",
|
|
@@ -1932,6 +1939,56 @@ ${context}`
|
|
|
1932
1939
|
});
|
|
1933
1940
|
return (_h = (_g = (_f = completion.choices[0]) == null ? void 0 : _f.message) == null ? void 0 : _g.content) != null ? _h : "";
|
|
1934
1941
|
}
|
|
1942
|
+
chatStream(messages, context, options) {
|
|
1943
|
+
return __asyncGenerator(this, null, function* () {
|
|
1944
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1945
|
+
const systemContent = (_a = this.llmConfig.systemPrompt) != null ? _a : `You are a helpful assistant. Answer questions based on the provided context.
|
|
1946
|
+
|
|
1947
|
+
Context:
|
|
1948
|
+
${context}`;
|
|
1949
|
+
const systemMessage = {
|
|
1950
|
+
role: "system",
|
|
1951
|
+
content: systemContent.includes("{{context}}") ? systemContent.replace("{{context}}", context) : `${systemContent}
|
|
1952
|
+
|
|
1953
|
+
Context:
|
|
1954
|
+
${context}`
|
|
1955
|
+
};
|
|
1956
|
+
const formattedMessages = [
|
|
1957
|
+
systemMessage,
|
|
1958
|
+
...messages.map((m) => ({
|
|
1959
|
+
role: m.role,
|
|
1960
|
+
content: m.content
|
|
1961
|
+
}))
|
|
1962
|
+
];
|
|
1963
|
+
const stream = yield new __await(this.client.chat.completions.create({
|
|
1964
|
+
model: this.llmConfig.model,
|
|
1965
|
+
messages: formattedMessages,
|
|
1966
|
+
max_tokens: (_c = (_b = options == null ? void 0 : options.maxTokens) != null ? _b : this.llmConfig.maxTokens) != null ? _c : 1024,
|
|
1967
|
+
temperature: (_e = (_d = options == null ? void 0 : options.temperature) != null ? _d : this.llmConfig.temperature) != null ? _e : 0.7,
|
|
1968
|
+
stop: options == null ? void 0 : options.stop,
|
|
1969
|
+
stream: true
|
|
1970
|
+
}));
|
|
1971
|
+
if (!stream) {
|
|
1972
|
+
throw new Error("[OpenAIProvider] completions.create stream is undefined");
|
|
1973
|
+
}
|
|
1974
|
+
try {
|
|
1975
|
+
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
1976
|
+
const chunk = temp.value;
|
|
1977
|
+
const content = ((_g = (_f = chunk.choices[0]) == null ? void 0 : _f.delta) == null ? void 0 : _g.content) || "";
|
|
1978
|
+
if (content) yield content;
|
|
1979
|
+
}
|
|
1980
|
+
} catch (temp) {
|
|
1981
|
+
error = [temp];
|
|
1982
|
+
} finally {
|
|
1983
|
+
try {
|
|
1984
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
1985
|
+
} finally {
|
|
1986
|
+
if (error)
|
|
1987
|
+
throw error[0];
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1935
1992
|
async embed(text, options) {
|
|
1936
1993
|
const results = await this.batchEmbed([text], options);
|
|
1937
1994
|
return results[0];
|
|
@@ -2037,6 +2094,50 @@ ${context}`;
|
|
|
2037
2094
|
const block = response.content[0];
|
|
2038
2095
|
return block.type === "text" ? block.text : "";
|
|
2039
2096
|
}
|
|
2097
|
+
chatStream(messages, context, options) {
|
|
2098
|
+
return __asyncGenerator(this, null, function* () {
|
|
2099
|
+
var _a, _b, _c;
|
|
2100
|
+
const systemPrompt = (_a = this.llmConfig.systemPrompt) != null ? _a : `You are a helpful assistant. Use the context below to answer the user's question accurately.
|
|
2101
|
+
|
|
2102
|
+
Context:
|
|
2103
|
+
${context}`;
|
|
2104
|
+
const system = systemPrompt.includes("{{context}}") ? systemPrompt.replace("{{context}}", context) : `${systemPrompt}
|
|
2105
|
+
|
|
2106
|
+
Context:
|
|
2107
|
+
${context}`;
|
|
2108
|
+
const anthropicMessages = messages.map((m) => ({
|
|
2109
|
+
role: m.role === "assistant" ? "assistant" : "user",
|
|
2110
|
+
content: m.content
|
|
2111
|
+
}));
|
|
2112
|
+
const stream = yield new __await(this.client.messages.create({
|
|
2113
|
+
model: this.llmConfig.model,
|
|
2114
|
+
max_tokens: (_c = (_b = options == null ? void 0 : options.maxTokens) != null ? _b : this.llmConfig.maxTokens) != null ? _c : 1024,
|
|
2115
|
+
system,
|
|
2116
|
+
messages: anthropicMessages,
|
|
2117
|
+
stream: true
|
|
2118
|
+
}));
|
|
2119
|
+
if (!stream) {
|
|
2120
|
+
throw new Error("[AnthropicProvider] messages.create stream is undefined");
|
|
2121
|
+
}
|
|
2122
|
+
try {
|
|
2123
|
+
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
2124
|
+
const chunk = temp.value;
|
|
2125
|
+
if (chunk.type === "content_block_delta" && chunk.delta.type === "text_delta") {
|
|
2126
|
+
yield chunk.delta.text;
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
} catch (temp) {
|
|
2130
|
+
error = [temp];
|
|
2131
|
+
} finally {
|
|
2132
|
+
try {
|
|
2133
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
2134
|
+
} finally {
|
|
2135
|
+
if (error)
|
|
2136
|
+
throw error[0];
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2040
2141
|
async embed(text, options) {
|
|
2041
2142
|
void text;
|
|
2042
2143
|
void options;
|
|
@@ -2142,7 +2243,7 @@ var OllamaProvider = class {
|
|
|
2142
2243
|
}
|
|
2143
2244
|
chatStream(messages, context, options) {
|
|
2144
2245
|
return __asyncGenerator(this, null, function* () {
|
|
2145
|
-
var _a, _b, _c, _d, _e;
|
|
2246
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2146
2247
|
const system = this.buildSystemPrompt(context);
|
|
2147
2248
|
const response = yield new __await(this.http.post("/api/chat", {
|
|
2148
2249
|
model: this.llmConfig.model,
|
|
@@ -2156,11 +2257,19 @@ var OllamaProvider = class {
|
|
|
2156
2257
|
...messages.map((m) => ({ role: m.role, content: m.content }))
|
|
2157
2258
|
]
|
|
2158
2259
|
}, { responseType: "stream" }));
|
|
2260
|
+
let lineBuffer = "";
|
|
2261
|
+
const stream = response.data;
|
|
2262
|
+
if (!stream) {
|
|
2263
|
+
throw new Error("[OllamaProvider] response.data is undefined for stream request. Axios might not support streams in this environment.");
|
|
2264
|
+
}
|
|
2159
2265
|
try {
|
|
2160
|
-
for (var iter = __forAwait(
|
|
2266
|
+
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
2161
2267
|
const chunk = temp.value;
|
|
2162
|
-
|
|
2268
|
+
lineBuffer += chunk.toString();
|
|
2269
|
+
const lines = lineBuffer.split("\n");
|
|
2270
|
+
lineBuffer = lines.pop() || "";
|
|
2163
2271
|
for (const line of lines) {
|
|
2272
|
+
if (!line.trim()) continue;
|
|
2164
2273
|
try {
|
|
2165
2274
|
const json = JSON.parse(line);
|
|
2166
2275
|
if ((_e = json.message) == null ? void 0 : _e.content) {
|
|
@@ -2168,6 +2277,7 @@ var OllamaProvider = class {
|
|
|
2168
2277
|
}
|
|
2169
2278
|
if (json.done) return;
|
|
2170
2279
|
} catch (e) {
|
|
2280
|
+
console.warn("[OllamaProvider] Failed to parse streaming line:", line);
|
|
2171
2281
|
}
|
|
2172
2282
|
}
|
|
2173
2283
|
}
|
|
@@ -2181,6 +2291,13 @@ var OllamaProvider = class {
|
|
|
2181
2291
|
throw error[0];
|
|
2182
2292
|
}
|
|
2183
2293
|
}
|
|
2294
|
+
if (lineBuffer.trim()) {
|
|
2295
|
+
try {
|
|
2296
|
+
const json = JSON.parse(lineBuffer);
|
|
2297
|
+
if ((_f = json.message) == null ? void 0 : _f.content) yield json.message.content;
|
|
2298
|
+
} catch (e) {
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2184
2301
|
});
|
|
2185
2302
|
}
|
|
2186
2303
|
buildSystemPrompt(context) {
|
|
@@ -2326,6 +2443,53 @@ ${context}`;
|
|
|
2326
2443
|
});
|
|
2327
2444
|
return (_f = response.text) != null ? _f : "";
|
|
2328
2445
|
}
|
|
2446
|
+
chatStream(messages, context, options) {
|
|
2447
|
+
return __asyncGenerator(this, null, function* () {
|
|
2448
|
+
var _a, _b, _c, _d, _e, _f;
|
|
2449
|
+
const systemPrompt = (_a = this.llmConfig.systemPrompt) != null ? _a : `You are a helpful assistant. Answer questions based on the provided context.
|
|
2450
|
+
|
|
2451
|
+
Context:
|
|
2452
|
+
${context}`;
|
|
2453
|
+
const systemInstruction = systemPrompt.includes("{{context}}") ? systemPrompt.replace("{{context}}", context) : `${systemPrompt}
|
|
2454
|
+
|
|
2455
|
+
Context:
|
|
2456
|
+
${context}`;
|
|
2457
|
+
const geminiMessages = messages.map((m) => ({
|
|
2458
|
+
role: m.role === "assistant" ? "model" : "user",
|
|
2459
|
+
parts: [{ text: m.content }]
|
|
2460
|
+
}));
|
|
2461
|
+
const result = yield new __await(this.client.models.generateContentStream({
|
|
2462
|
+
model: this.llmConfig.model,
|
|
2463
|
+
contents: geminiMessages,
|
|
2464
|
+
config: {
|
|
2465
|
+
systemInstruction,
|
|
2466
|
+
temperature: (_c = (_b = options == null ? void 0 : options.temperature) != null ? _b : this.llmConfig.temperature) != null ? _c : 0.7,
|
|
2467
|
+
maxOutputTokens: (_e = (_d = options == null ? void 0 : options.maxTokens) != null ? _d : this.llmConfig.maxTokens) != null ? _e : 1024,
|
|
2468
|
+
stopSequences: options == null ? void 0 : options.stop
|
|
2469
|
+
}
|
|
2470
|
+
}));
|
|
2471
|
+
const stream = (_f = result == null ? void 0 : result.stream) != null ? _f : result;
|
|
2472
|
+
if (!stream) {
|
|
2473
|
+
throw new Error("[GeminiProvider] generateContentStream returned undefined");
|
|
2474
|
+
}
|
|
2475
|
+
try {
|
|
2476
|
+
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
2477
|
+
const chunk = temp.value;
|
|
2478
|
+
const text = chunk.text;
|
|
2479
|
+
if (text) yield text;
|
|
2480
|
+
}
|
|
2481
|
+
} catch (temp) {
|
|
2482
|
+
error = [temp];
|
|
2483
|
+
} finally {
|
|
2484
|
+
try {
|
|
2485
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
2486
|
+
} finally {
|
|
2487
|
+
if (error)
|
|
2488
|
+
throw error[0];
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
});
|
|
2492
|
+
}
|
|
2329
2493
|
async embed(text, options) {
|
|
2330
2494
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2331
2495
|
const model = this.sanitizeModel(
|
|
@@ -3854,8 +4018,12 @@ ${context}`;
|
|
|
3854
4018
|
}
|
|
3855
4019
|
const messages = [...history, { role: "user", content: question }];
|
|
3856
4020
|
if (this.llmProvider.chatStream) {
|
|
4021
|
+
const stream = this.llmProvider.chatStream(messages, context);
|
|
4022
|
+
if (!stream) {
|
|
4023
|
+
throw new Error(`[Pipeline] ${this.config.llm.provider} chatStream returned undefined`);
|
|
4024
|
+
}
|
|
3857
4025
|
try {
|
|
3858
|
-
for (var iter = __forAwait(
|
|
4026
|
+
for (var iter = __forAwait(stream), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
3859
4027
|
const chunk = temp.value;
|
|
3860
4028
|
yield chunk;
|
|
3861
4029
|
}
|
package/dist/handlers/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as RagConfig, C as ChatMessage, b as ChatResponse, e as IngestDocument } from './RagConfig-
|
|
1
|
+
import { g as RagConfig, C as ChatMessage, b as ChatResponse, e as IngestDocument } from './RagConfig-FyMB_UG6.js';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
|
|
4
4
|
interface ValidationError {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as RagConfig, C as ChatMessage, b as ChatResponse, e as IngestDocument } from './RagConfig-
|
|
1
|
+
import { g as RagConfig, C as ChatMessage, b as ChatResponse, e as IngestDocument } from './RagConfig-FyMB_UG6.mjs';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
|
|
4
4
|
interface ValidationError {
|