@retrivora-ai/rag-engine 0.2.7 → 0.2.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/{MongoDBProvider-QHMGD2LZ.mjs → MongoDBProvider-KGO6N23T.mjs} +1 -1
- package/dist/{PostgreSQLProvider-PJ5ER5Z4.mjs → PostgreSQLProvider-ILWADFAP.mjs} +1 -1
- package/dist/{RagConfig-Ttch1N4d.d.mts → RagConfig--ibz0b3W.d.mts} +4 -0
- package/dist/{RagConfig-Ttch1N4d.d.ts → RagConfig--ibz0b3W.d.ts} +4 -0
- package/dist/{chunk-6Q7DNWTG.mjs → chunk-5U2DHPIX.mjs} +75 -21
- package/dist/{chunk-IUTAZ7QR.mjs → chunk-6GSARSCP.mjs} +9 -2
- package/dist/{chunk-5HXNKSCR.mjs → chunk-IFPISZ2S.mjs} +8 -1
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +90 -22
- package/dist/handlers/index.mjs +1 -1
- package/dist/{index-rK0KAr2S.d.ts → index-Dr1HN0se.d.ts} +1 -1
- package/dist/{index-sbCtrIRT.d.mts → index-w8qIEFvi.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 +195 -33
- package/dist/server.mjs +108 -14
- package/package.json +1 -1
- package/src/config/RagConfig.ts +4 -0
- package/src/core/Pipeline.ts +114 -21
- package/src/providers/vectordb/MongoDBProvider.ts +12 -1
- package/src/providers/vectordb/MultiTablePostgresProvider.ts +161 -19
- package/src/providers/vectordb/PostgreSQLProvider.ts +11 -2
|
@@ -44,6 +44,10 @@ interface VectorDBConfig {
|
|
|
44
44
|
* - idPath?: string (e.g. '_id')
|
|
45
45
|
* - scorePath?: string (e.g. 'similarity')
|
|
46
46
|
* - contentPath?: string (e.g. 'text')
|
|
47
|
+
*
|
|
48
|
+
* For multi-table PostgreSQL search, the following options are also supported:
|
|
49
|
+
* - tables?: string[] | string
|
|
50
|
+
* - searchFields?: string[] // optional override for which columns receive exact-match boosts
|
|
47
51
|
*/
|
|
48
52
|
options: Record<string, unknown>;
|
|
49
53
|
}
|
|
@@ -44,6 +44,10 @@ interface VectorDBConfig {
|
|
|
44
44
|
* - idPath?: string (e.g. '_id')
|
|
45
45
|
* - scorePath?: string (e.g. 'similarity')
|
|
46
46
|
* - contentPath?: string (e.g. 'text')
|
|
47
|
+
*
|
|
48
|
+
* For multi-table PostgreSQL search, the following options are also supported:
|
|
49
|
+
* - tables?: string[] | string
|
|
50
|
+
* - searchFields?: string[] // optional override for which columns receive exact-match boosts
|
|
47
51
|
*/
|
|
48
52
|
options: Record<string, unknown>;
|
|
49
53
|
}
|
|
@@ -1198,11 +1198,11 @@ var ProviderRegistry = class {
|
|
|
1198
1198
|
}
|
|
1199
1199
|
case "pgvector":
|
|
1200
1200
|
case "postgresql": {
|
|
1201
|
-
const { PostgreSQLProvider } = await import("./PostgreSQLProvider-
|
|
1201
|
+
const { PostgreSQLProvider } = await import("./PostgreSQLProvider-ILWADFAP.mjs");
|
|
1202
1202
|
return new PostgreSQLProvider(config);
|
|
1203
1203
|
}
|
|
1204
1204
|
case "mongodb": {
|
|
1205
|
-
const { MongoDBProvider } = await import("./MongoDBProvider-
|
|
1205
|
+
const { MongoDBProvider } = await import("./MongoDBProvider-KGO6N23T.mjs");
|
|
1206
1206
|
return new MongoDBProvider(config);
|
|
1207
1207
|
}
|
|
1208
1208
|
case "milvus": {
|
|
@@ -1553,25 +1553,80 @@ var EmbeddingStrategyResolver = class {
|
|
|
1553
1553
|
};
|
|
1554
1554
|
|
|
1555
1555
|
// src/core/Pipeline.ts
|
|
1556
|
-
function
|
|
1557
|
-
|
|
1558
|
-
|
|
1556
|
+
function normalizeHintValue(value) {
|
|
1557
|
+
return value.replace(/\s+/g, " ").trim();
|
|
1558
|
+
}
|
|
1559
|
+
function isLikelyPromptPhrase(value) {
|
|
1560
|
+
return /^(what|which|who|where|when|why|how)\b/i.test(value.trim());
|
|
1561
|
+
}
|
|
1562
|
+
function extractQueryFieldHints(question) {
|
|
1563
|
+
var _a, _b, _c;
|
|
1564
|
+
if (!question.trim()) return [];
|
|
1565
|
+
const hints = /* @__PURE__ */ new Map();
|
|
1566
|
+
const addHint = (value, field) => {
|
|
1567
|
+
const normalizedValue = normalizeHintValue(value);
|
|
1568
|
+
if (!normalizedValue) return;
|
|
1569
|
+
const normalizedField = field ? field.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim() : void 0;
|
|
1570
|
+
const key = `${normalizedField != null ? normalizedField : "*"}::${normalizedValue.toLowerCase()}`;
|
|
1571
|
+
if (!hints.has(key)) {
|
|
1572
|
+
hints.set(key, __spreadValues({
|
|
1573
|
+
value: normalizedValue
|
|
1574
|
+
}, normalizedField ? { field: normalizedField } : {}));
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1559
1577
|
for (const match of question.matchAll(/["']([^"']{2,100})["']/g)) {
|
|
1560
|
-
|
|
1561
|
-
if (value) hints.add(value);
|
|
1578
|
+
addHint(match[1]);
|
|
1562
1579
|
}
|
|
1563
|
-
const
|
|
1564
|
-
/\b(?:
|
|
1565
|
-
/\b(?:
|
|
1580
|
+
const naturalQuestionPatterns = [
|
|
1581
|
+
/\b(?:what|which)\s+(?:is|are|was|were)\s+(?:the\s+)?([^?.!,]{1,60}?)\s+of\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi,
|
|
1582
|
+
/\b(?:who|what)\s+(?:is|are|was|were)\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi,
|
|
1583
|
+
/\b(?:about|for|regarding)\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi
|
|
1584
|
+
];
|
|
1585
|
+
for (const pattern of naturalQuestionPatterns) {
|
|
1586
|
+
for (const match of question.matchAll(pattern)) {
|
|
1587
|
+
const value = (_a = match[2]) != null ? _a : match[1];
|
|
1588
|
+
if (value) addHint(value);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
const fieldPattern = `([^\\n:=?.!,]{1,60}?)`;
|
|
1592
|
+
const valuePattern = `([^\\n?.!,]{1,120}?)`;
|
|
1593
|
+
const fieldValuePatterns = [
|
|
1594
|
+
new RegExp(`\\b${fieldPattern}\\s*(?:=|:)\\s*["']?${valuePattern}["']?(?=[?.!,]|$)`, "gi"),
|
|
1595
|
+
new RegExp(`\\b${fieldPattern}\\s+(?:is|are|was|were|equals?|equal to|named|called)\\s+["']?${valuePattern}["']?(?=[?.!,]|$)`, "gi"),
|
|
1596
|
+
new RegExp(`\\bwith\\s+${fieldPattern}\\s+["']?${valuePattern}["']?(?=[?.!,]|$)`, "gi")
|
|
1566
1597
|
];
|
|
1567
|
-
for (const pattern of
|
|
1568
|
-
const match
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1598
|
+
for (const pattern of fieldValuePatterns) {
|
|
1599
|
+
for (const match of question.matchAll(pattern)) {
|
|
1600
|
+
const field = normalizeHintValue((_b = match[1]) != null ? _b : "");
|
|
1601
|
+
const value = (_c = match[2]) != null ? _c : "";
|
|
1602
|
+
if (field && !isLikelyPromptPhrase(field)) {
|
|
1603
|
+
addHint(value, field);
|
|
1604
|
+
} else {
|
|
1605
|
+
addHint(value);
|
|
1606
|
+
}
|
|
1572
1607
|
}
|
|
1573
1608
|
}
|
|
1574
|
-
|
|
1609
|
+
for (const match of question.matchAll(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){1,3}\b/g)) {
|
|
1610
|
+
addHint(match[0]);
|
|
1611
|
+
}
|
|
1612
|
+
return [...hints.values()];
|
|
1613
|
+
}
|
|
1614
|
+
function buildQueryFilter(question, hints) {
|
|
1615
|
+
const filter = { metadata: {}, keywords: [], queryText: question };
|
|
1616
|
+
for (const hint of hints) {
|
|
1617
|
+
if (hint.field) {
|
|
1618
|
+
filter.metadata[hint.field] = hint.value;
|
|
1619
|
+
} else {
|
|
1620
|
+
filter.keywords.push(hint.value);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
for (const match of question.matchAll(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){0,3}\b/g)) {
|
|
1624
|
+
const term = normalizeHintValue(match[0]);
|
|
1625
|
+
if (term && !filter.keywords.includes(term)) filter.keywords.push(term);
|
|
1626
|
+
}
|
|
1627
|
+
if (Object.keys(filter.metadata || {}).length === 0) delete filter.metadata;
|
|
1628
|
+
if (filter.keywords && filter.keywords.length === 0) delete filter.keywords;
|
|
1629
|
+
return filter;
|
|
1575
1630
|
}
|
|
1576
1631
|
var Pipeline = class {
|
|
1577
1632
|
constructor(config) {
|
|
@@ -1660,11 +1715,10 @@ var Pipeline = class {
|
|
|
1660
1715
|
const scoreThreshold = (_d = (_c = this.config.rag) == null ? void 0 : _c.scoreThreshold) != null ? _d : 0;
|
|
1661
1716
|
try {
|
|
1662
1717
|
const queryVector = await this.embeddingProvider.embed(question, { taskType: "query" });
|
|
1663
|
-
const
|
|
1664
|
-
const
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
});
|
|
1718
|
+
const fieldHints = extractQueryFieldHints(question);
|
|
1719
|
+
const filter = buildQueryFilter(question, fieldHints);
|
|
1720
|
+
filter.__fieldHints = fieldHints;
|
|
1721
|
+
const rawMatches = await this.vectorDB.query(queryVector, topK, ns, filter);
|
|
1668
1722
|
const sources = rawMatches.filter((m) => m.score >= scoreThreshold);
|
|
1669
1723
|
const context = sources.length ? sources.map((m, i) => `[Source ${i + 1}]
|
|
1670
1724
|
${m.content}`).join("\n\n---\n\n") : "No relevant context found.";
|
|
@@ -4,6 +4,12 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/providers/vectordb/PostgreSQLProvider.ts
|
|
6
6
|
import { Pool } from "pg";
|
|
7
|
+
function stripInternalFilterKeys(filter) {
|
|
8
|
+
if (!filter) return {};
|
|
9
|
+
return Object.fromEntries(
|
|
10
|
+
Object.entries(filter).filter(([key]) => !key.startsWith("__"))
|
|
11
|
+
);
|
|
12
|
+
}
|
|
7
13
|
var PostgreSQLProvider = class extends BaseVectorProvider {
|
|
8
14
|
constructor(config) {
|
|
9
15
|
var _a;
|
|
@@ -90,8 +96,9 @@ var PostgreSQLProvider = class extends BaseVectorProvider {
|
|
|
90
96
|
let whereClause = namespace ? `WHERE namespace = $3` : "";
|
|
91
97
|
const params = [vectorLiteral, topK];
|
|
92
98
|
if (namespace) params.push(namespace);
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
const publicFilter = stripInternalFilterKeys(filter);
|
|
100
|
+
if (Object.keys(publicFilter).length > 0) {
|
|
101
|
+
const filterConditions = Object.entries(publicFilter).map(([key, val]) => {
|
|
95
102
|
const paramIdx = params.length + 1;
|
|
96
103
|
params.push(JSON.stringify(val));
|
|
97
104
|
return `metadata->>'${key}' = $${paramIdx}`;
|
|
@@ -7,6 +7,12 @@ import {
|
|
|
7
7
|
|
|
8
8
|
// src/providers/vectordb/MongoDBProvider.ts
|
|
9
9
|
import { MongoClient } from "mongodb";
|
|
10
|
+
function stripInternalFilterKeys(filter) {
|
|
11
|
+
if (!filter) return {};
|
|
12
|
+
return Object.fromEntries(
|
|
13
|
+
Object.entries(filter).filter(([key]) => !key.startsWith("__"))
|
|
14
|
+
);
|
|
15
|
+
}
|
|
10
16
|
var MongoDBProvider = class extends BaseVectorProvider {
|
|
11
17
|
constructor(config) {
|
|
12
18
|
super(config);
|
|
@@ -52,6 +58,7 @@ var MongoDBProvider = class extends BaseVectorProvider {
|
|
|
52
58
|
await this.collection.bulkWrite(operations);
|
|
53
59
|
}
|
|
54
60
|
async query(vector, topK, namespace, filter) {
|
|
61
|
+
const publicFilter = stripInternalFilterKeys(filter);
|
|
55
62
|
const pipeline = [
|
|
56
63
|
{
|
|
57
64
|
$vectorSearch: __spreadValues({
|
|
@@ -60,7 +67,7 @@ var MongoDBProvider = class extends BaseVectorProvider {
|
|
|
60
67
|
queryVector: vector,
|
|
61
68
|
numCandidates: Math.max(topK * 10, 100),
|
|
62
69
|
limit: topK
|
|
63
|
-
},
|
|
70
|
+
}, Object.keys(publicFilter).length > 0 || namespace ? { filter: __spreadValues(__spreadValues({}, publicFilter), namespace ? { namespace } : {}) } : {})
|
|
64
71
|
},
|
|
65
72
|
{
|
|
66
73
|
$project: {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import '../RagConfig
|
|
2
|
-
export { c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from '../index-
|
|
1
|
+
import '../RagConfig--ibz0b3W.mjs';
|
|
2
|
+
export { c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from '../index-w8qIEFvi.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, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from '../index-
|
|
1
|
+
import '../RagConfig--ibz0b3W.js';
|
|
2
|
+
export { c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from '../index-Dr1HN0se.js';
|
|
3
3
|
import 'next/server';
|
package/dist/handlers/index.js
CHANGED
|
@@ -205,6 +205,12 @@ var PostgreSQLProvider_exports = {};
|
|
|
205
205
|
__export(PostgreSQLProvider_exports, {
|
|
206
206
|
PostgreSQLProvider: () => PostgreSQLProvider
|
|
207
207
|
});
|
|
208
|
+
function stripInternalFilterKeys(filter) {
|
|
209
|
+
if (!filter) return {};
|
|
210
|
+
return Object.fromEntries(
|
|
211
|
+
Object.entries(filter).filter(([key]) => !key.startsWith("__"))
|
|
212
|
+
);
|
|
213
|
+
}
|
|
208
214
|
var import_pg, PostgreSQLProvider;
|
|
209
215
|
var init_PostgreSQLProvider = __esm({
|
|
210
216
|
"src/providers/vectordb/PostgreSQLProvider.ts"() {
|
|
@@ -297,8 +303,9 @@ var init_PostgreSQLProvider = __esm({
|
|
|
297
303
|
let whereClause = namespace ? `WHERE namespace = $3` : "";
|
|
298
304
|
const params = [vectorLiteral, topK];
|
|
299
305
|
if (namespace) params.push(namespace);
|
|
300
|
-
|
|
301
|
-
|
|
306
|
+
const publicFilter = stripInternalFilterKeys(filter);
|
|
307
|
+
if (Object.keys(publicFilter).length > 0) {
|
|
308
|
+
const filterConditions = Object.entries(publicFilter).map(([key, val]) => {
|
|
302
309
|
const paramIdx = params.length + 1;
|
|
303
310
|
params.push(JSON.stringify(val));
|
|
304
311
|
return `metadata->>'${key}' = $${paramIdx}`;
|
|
@@ -348,6 +355,12 @@ var MongoDBProvider_exports = {};
|
|
|
348
355
|
__export(MongoDBProvider_exports, {
|
|
349
356
|
MongoDBProvider: () => MongoDBProvider
|
|
350
357
|
});
|
|
358
|
+
function stripInternalFilterKeys2(filter) {
|
|
359
|
+
if (!filter) return {};
|
|
360
|
+
return Object.fromEntries(
|
|
361
|
+
Object.entries(filter).filter(([key]) => !key.startsWith("__"))
|
|
362
|
+
);
|
|
363
|
+
}
|
|
351
364
|
var import_mongodb, MongoDBProvider;
|
|
352
365
|
var init_MongoDBProvider = __esm({
|
|
353
366
|
"src/providers/vectordb/MongoDBProvider.ts"() {
|
|
@@ -399,6 +412,7 @@ var init_MongoDBProvider = __esm({
|
|
|
399
412
|
await this.collection.bulkWrite(operations);
|
|
400
413
|
}
|
|
401
414
|
async query(vector, topK, namespace, filter) {
|
|
415
|
+
const publicFilter = stripInternalFilterKeys2(filter);
|
|
402
416
|
const pipeline = [
|
|
403
417
|
{
|
|
404
418
|
$vectorSearch: __spreadValues({
|
|
@@ -407,7 +421,7 @@ var init_MongoDBProvider = __esm({
|
|
|
407
421
|
queryVector: vector,
|
|
408
422
|
numCandidates: Math.max(topK * 10, 100),
|
|
409
423
|
limit: topK
|
|
410
|
-
},
|
|
424
|
+
}, Object.keys(publicFilter).length > 0 || namespace ? { filter: __spreadValues(__spreadValues({}, publicFilter), namespace ? { namespace } : {}) } : {})
|
|
411
425
|
},
|
|
412
426
|
{
|
|
413
427
|
$project: {
|
|
@@ -2663,25 +2677,80 @@ var EmbeddingStrategyResolver = class {
|
|
|
2663
2677
|
};
|
|
2664
2678
|
|
|
2665
2679
|
// src/core/Pipeline.ts
|
|
2666
|
-
function
|
|
2667
|
-
|
|
2668
|
-
|
|
2680
|
+
function normalizeHintValue(value) {
|
|
2681
|
+
return value.replace(/\s+/g, " ").trim();
|
|
2682
|
+
}
|
|
2683
|
+
function isLikelyPromptPhrase(value) {
|
|
2684
|
+
return /^(what|which|who|where|when|why|how)\b/i.test(value.trim());
|
|
2685
|
+
}
|
|
2686
|
+
function extractQueryFieldHints(question) {
|
|
2687
|
+
var _a, _b, _c;
|
|
2688
|
+
if (!question.trim()) return [];
|
|
2689
|
+
const hints = /* @__PURE__ */ new Map();
|
|
2690
|
+
const addHint = (value, field) => {
|
|
2691
|
+
const normalizedValue = normalizeHintValue(value);
|
|
2692
|
+
if (!normalizedValue) return;
|
|
2693
|
+
const normalizedField = field ? field.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim() : void 0;
|
|
2694
|
+
const key = `${normalizedField != null ? normalizedField : "*"}::${normalizedValue.toLowerCase()}`;
|
|
2695
|
+
if (!hints.has(key)) {
|
|
2696
|
+
hints.set(key, __spreadValues({
|
|
2697
|
+
value: normalizedValue
|
|
2698
|
+
}, normalizedField ? { field: normalizedField } : {}));
|
|
2699
|
+
}
|
|
2700
|
+
};
|
|
2669
2701
|
for (const match of question.matchAll(/["']([^"']{2,100})["']/g)) {
|
|
2670
|
-
|
|
2671
|
-
if (value) hints.add(value);
|
|
2702
|
+
addHint(match[1]);
|
|
2672
2703
|
}
|
|
2673
|
-
const
|
|
2674
|
-
/\b(?:
|
|
2675
|
-
/\b(?:
|
|
2704
|
+
const naturalQuestionPatterns = [
|
|
2705
|
+
/\b(?:what|which)\s+(?:is|are|was|were)\s+(?:the\s+)?([^?.!,]{1,60}?)\s+of\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi,
|
|
2706
|
+
/\b(?:who|what)\s+(?:is|are|was|were)\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi,
|
|
2707
|
+
/\b(?:about|for|regarding)\s+["']?([^"'\n?.!,]{2,120})["']?(?=[?.!,]|$)/gi
|
|
2708
|
+
];
|
|
2709
|
+
for (const pattern of naturalQuestionPatterns) {
|
|
2710
|
+
for (const match of question.matchAll(pattern)) {
|
|
2711
|
+
const value = (_a = match[2]) != null ? _a : match[1];
|
|
2712
|
+
if (value) addHint(value);
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
const fieldPattern = `([^\\n:=?.!,]{1,60}?)`;
|
|
2716
|
+
const valuePattern = `([^\\n?.!,]{1,120}?)`;
|
|
2717
|
+
const fieldValuePatterns = [
|
|
2718
|
+
new RegExp(`\\b${fieldPattern}\\s*(?:=|:)\\s*["']?${valuePattern}["']?(?=[?.!,]|$)`, "gi"),
|
|
2719
|
+
new RegExp(`\\b${fieldPattern}\\s+(?:is|are|was|were|equals?|equal to|named|called)\\s+["']?${valuePattern}["']?(?=[?.!,]|$)`, "gi"),
|
|
2720
|
+
new RegExp(`\\bwith\\s+${fieldPattern}\\s+["']?${valuePattern}["']?(?=[?.!,]|$)`, "gi")
|
|
2676
2721
|
];
|
|
2677
|
-
for (const pattern of
|
|
2678
|
-
const match
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2722
|
+
for (const pattern of fieldValuePatterns) {
|
|
2723
|
+
for (const match of question.matchAll(pattern)) {
|
|
2724
|
+
const field = normalizeHintValue((_b = match[1]) != null ? _b : "");
|
|
2725
|
+
const value = (_c = match[2]) != null ? _c : "";
|
|
2726
|
+
if (field && !isLikelyPromptPhrase(field)) {
|
|
2727
|
+
addHint(value, field);
|
|
2728
|
+
} else {
|
|
2729
|
+
addHint(value);
|
|
2730
|
+
}
|
|
2682
2731
|
}
|
|
2683
2732
|
}
|
|
2684
|
-
|
|
2733
|
+
for (const match of question.matchAll(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){1,3}\b/g)) {
|
|
2734
|
+
addHint(match[0]);
|
|
2735
|
+
}
|
|
2736
|
+
return [...hints.values()];
|
|
2737
|
+
}
|
|
2738
|
+
function buildQueryFilter(question, hints) {
|
|
2739
|
+
const filter = { metadata: {}, keywords: [], queryText: question };
|
|
2740
|
+
for (const hint of hints) {
|
|
2741
|
+
if (hint.field) {
|
|
2742
|
+
filter.metadata[hint.field] = hint.value;
|
|
2743
|
+
} else {
|
|
2744
|
+
filter.keywords.push(hint.value);
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
for (const match of question.matchAll(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+){0,3}\b/g)) {
|
|
2748
|
+
const term = normalizeHintValue(match[0]);
|
|
2749
|
+
if (term && !filter.keywords.includes(term)) filter.keywords.push(term);
|
|
2750
|
+
}
|
|
2751
|
+
if (Object.keys(filter.metadata || {}).length === 0) delete filter.metadata;
|
|
2752
|
+
if (filter.keywords && filter.keywords.length === 0) delete filter.keywords;
|
|
2753
|
+
return filter;
|
|
2685
2754
|
}
|
|
2686
2755
|
var Pipeline = class {
|
|
2687
2756
|
constructor(config) {
|
|
@@ -2770,11 +2839,10 @@ var Pipeline = class {
|
|
|
2770
2839
|
const scoreThreshold = (_d = (_c = this.config.rag) == null ? void 0 : _c.scoreThreshold) != null ? _d : 0;
|
|
2771
2840
|
try {
|
|
2772
2841
|
const queryVector = await this.embeddingProvider.embed(question, { taskType: "query" });
|
|
2773
|
-
const
|
|
2774
|
-
const
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
});
|
|
2842
|
+
const fieldHints = extractQueryFieldHints(question);
|
|
2843
|
+
const filter = buildQueryFilter(question, fieldHints);
|
|
2844
|
+
filter.__fieldHints = fieldHints;
|
|
2845
|
+
const rawMatches = await this.vectorDB.query(queryVector, topK, ns, filter);
|
|
2778
2846
|
const sources = rawMatches.filter((m) => m.score >= scoreThreshold);
|
|
2779
2847
|
const context = sources.length ? sources.map((m, i) => `[Source ${i + 1}]
|
|
2780
2848
|
${m.content}`).join("\n\n---\n\n") : "No relevant context found.";
|
package/dist/handlers/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, a as RagConfig, C as ChatResponse } from './RagConfig
|
|
1
|
+
import { c as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, a as RagConfig, C as ChatResponse } from './RagConfig--ibz0b3W.js';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, a as RagConfig, C as ChatResponse } from './RagConfig
|
|
1
|
+
import { c as VectorDBConfig, L as LLMConfig, E as EmbeddingConfig, a as RagConfig, C as ChatResponse } from './RagConfig--ibz0b3W.mjs';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
|
|
4
4
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import React$1, { ReactNode } from 'react';
|
|
3
3
|
import { C as ChatMessage } from './DocumentChunker-BICIjSuG.mjs';
|
|
4
4
|
export { a as ChatOptions, b as Chunk, c as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-BICIjSuG.mjs';
|
|
5
|
-
import { V as VectorMatch, U as UIConfig } from './RagConfig
|
|
6
|
-
export { C as ChatResponse, E as EmbeddingConfig, I as IngestDocument, L as LLMConfig, R as RAGConfig, a as RagConfig, b as UpsertDocument, c as VectorDBConfig } from './RagConfig
|
|
5
|
+
import { V as VectorMatch, U as UIConfig } from './RagConfig--ibz0b3W.mjs';
|
|
6
|
+
export { C as ChatResponse, E as EmbeddingConfig, I as IngestDocument, L as LLMConfig, R as RAGConfig, a as RagConfig, b as UpsertDocument, c as VectorDBConfig } from './RagConfig--ibz0b3W.mjs';
|
|
7
7
|
|
|
8
8
|
interface ChatWidgetProps {
|
|
9
9
|
/** Position of the floating button. Defaults to bottom-right. */
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import React$1, { ReactNode } from 'react';
|
|
3
3
|
import { C as ChatMessage } from './DocumentChunker-BICIjSuG.js';
|
|
4
4
|
export { a as ChatOptions, b as Chunk, c as ChunkOptions, E as EmbedOptions, I as ILLMProvider } from './DocumentChunker-BICIjSuG.js';
|
|
5
|
-
import { V as VectorMatch, U as UIConfig } from './RagConfig
|
|
6
|
-
export { C as ChatResponse, E as EmbeddingConfig, I as IngestDocument, L as LLMConfig, R as RAGConfig, a as RagConfig, b as UpsertDocument, c as VectorDBConfig } from './RagConfig
|
|
5
|
+
import { V as VectorMatch, U as UIConfig } from './RagConfig--ibz0b3W.js';
|
|
6
|
+
export { C as ChatResponse, E as EmbeddingConfig, I as IngestDocument, L as LLMConfig, R as RAGConfig, a as RagConfig, b as UpsertDocument, c as VectorDBConfig } from './RagConfig--ibz0b3W.js';
|
|
7
7
|
|
|
8
8
|
interface ChatWidgetProps {
|
|
9
9
|
/** Position of the floating button. Defaults to bottom-right. */
|
package/dist/server.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as RagConfig, C as ChatResponse, I as IngestDocument, c as VectorDBConfig, b as UpsertDocument, V as VectorMatch, L as LLMConfig, E as EmbeddingConfig, d as VectorDBProvider, e as LLMProvider, f as EmbeddingProvider } from './RagConfig
|
|
2
|
-
export { R as RAGConfig, U as UIConfig } from './RagConfig
|
|
1
|
+
import { a as RagConfig, C as ChatResponse, I as IngestDocument, c as VectorDBConfig, b as UpsertDocument, V as VectorMatch, L as LLMConfig, E as EmbeddingConfig, d as VectorDBProvider, e as LLMProvider, f as EmbeddingProvider } from './RagConfig--ibz0b3W.mjs';
|
|
2
|
+
export { R as RAGConfig, U as UIConfig } from './RagConfig--ibz0b3W.mjs';
|
|
3
3
|
import { C as ChatMessage, I as ILLMProvider, a as ChatOptions, E as EmbedOptions } from './DocumentChunker-BICIjSuG.mjs';
|
|
4
4
|
export { b as Chunk, c as ChunkOptions, D as DocumentChunker } from './DocumentChunker-BICIjSuG.mjs';
|
|
5
|
-
import { H as HealthCheckResult } from './index-
|
|
6
|
-
export { P as ProviderHealthCheck, c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from './index-
|
|
5
|
+
import { H as HealthCheckResult } from './index-w8qIEFvi.mjs';
|
|
6
|
+
export { P as ProviderHealthCheck, c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from './index-w8qIEFvi.mjs';
|
|
7
7
|
import 'next/server';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -706,6 +706,7 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
706
706
|
private readonly dimensions;
|
|
707
707
|
private readonly connectionString;
|
|
708
708
|
private tables;
|
|
709
|
+
private tableSearchConfig;
|
|
709
710
|
constructor(config: VectorDBConfig);
|
|
710
711
|
initialize(): Promise<void>;
|
|
711
712
|
/**
|
|
@@ -725,6 +726,8 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
725
726
|
deleteNamespace(_namespace: string): Promise<void>;
|
|
726
727
|
ping(): Promise<boolean>;
|
|
727
728
|
disconnect(): Promise<void>;
|
|
729
|
+
private loadTableSearchConfig;
|
|
730
|
+
private parseConfiguredSearchFields;
|
|
728
731
|
}
|
|
729
732
|
|
|
730
733
|
/**
|
package/dist/server.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { a as RagConfig, C as ChatResponse, I as IngestDocument, c as VectorDBConfig, b as UpsertDocument, V as VectorMatch, L as LLMConfig, E as EmbeddingConfig, d as VectorDBProvider, e as LLMProvider, f as EmbeddingProvider } from './RagConfig
|
|
2
|
-
export { R as RAGConfig, U as UIConfig } from './RagConfig
|
|
1
|
+
import { a as RagConfig, C as ChatResponse, I as IngestDocument, c as VectorDBConfig, b as UpsertDocument, V as VectorMatch, L as LLMConfig, E as EmbeddingConfig, d as VectorDBProvider, e as LLMProvider, f as EmbeddingProvider } from './RagConfig--ibz0b3W.js';
|
|
2
|
+
export { R as RAGConfig, U as UIConfig } from './RagConfig--ibz0b3W.js';
|
|
3
3
|
import { C as ChatMessage, I as ILLMProvider, a as ChatOptions, E as EmbedOptions } from './DocumentChunker-BICIjSuG.js';
|
|
4
4
|
export { b as Chunk, c as ChunkOptions, D as DocumentChunker } from './DocumentChunker-BICIjSuG.js';
|
|
5
|
-
import { H as HealthCheckResult } from './index-
|
|
6
|
-
export { P as ProviderHealthCheck, c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from './index-
|
|
5
|
+
import { H as HealthCheckResult } from './index-Dr1HN0se.js';
|
|
6
|
+
export { P as ProviderHealthCheck, c as createChatHandler, a as createHealthHandler, b as createIngestHandler, d as createUploadHandler } from './index-Dr1HN0se.js';
|
|
7
7
|
import 'next/server';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -706,6 +706,7 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
706
706
|
private readonly dimensions;
|
|
707
707
|
private readonly connectionString;
|
|
708
708
|
private tables;
|
|
709
|
+
private tableSearchConfig;
|
|
709
710
|
constructor(config: VectorDBConfig);
|
|
710
711
|
initialize(): Promise<void>;
|
|
711
712
|
/**
|
|
@@ -725,6 +726,8 @@ declare class MultiTablePostgresProvider extends BaseVectorProvider {
|
|
|
725
726
|
deleteNamespace(_namespace: string): Promise<void>;
|
|
726
727
|
ping(): Promise<boolean>;
|
|
727
728
|
disconnect(): Promise<void>;
|
|
729
|
+
private loadTableSearchConfig;
|
|
730
|
+
private parseConfiguredSearchFields;
|
|
728
731
|
}
|
|
729
732
|
|
|
730
733
|
/**
|