@retrivora-ai/rag-engine 0.4.1 → 0.4.3
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-HMCEDIHH.mjs → MongoDBProvider-ZKW34AEL.mjs} +1 -1
- package/dist/{chunk-MIG2VGPL.mjs → chunk-IWHCAQEA.mjs} +11 -10
- package/dist/{chunk-7MIY23YT.mjs → chunk-UUZ3F4WK.mjs} +4 -4
- package/dist/handlers/index.js +14 -13
- package/dist/handlers/index.mjs +1 -1
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +14 -13
- package/dist/server.mjs +2 -2
- package/package.json +1 -1
- package/src/llm/providers/OllamaProvider.ts +3 -2
- package/src/providers/vectordb/MongoDBProvider.ts +16 -12
|
@@ -65,18 +65,20 @@ var MongoDBProvider = class extends BaseVectorProvider {
|
|
|
65
65
|
},
|
|
66
66
|
{
|
|
67
67
|
$project: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
_id: 1,
|
|
69
|
+
[this.contentKey]: 1,
|
|
70
|
+
[this.metadataKey]: 1,
|
|
71
|
+
namespace: 1,
|
|
72
|
+
score: { $meta: "vectorSearchScore" }
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
];
|
|
74
76
|
const results = await this.collection.aggregate(pipeline).toArray();
|
|
75
77
|
return results.map((res) => ({
|
|
76
|
-
id: res
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
id: res._id,
|
|
79
|
+
content: res[this.contentKey],
|
|
80
|
+
metadata: res[this.metadataKey],
|
|
81
|
+
score: res.score
|
|
80
82
|
}));
|
|
81
83
|
}
|
|
82
84
|
async delete(id, namespace) {
|
|
@@ -86,11 +88,10 @@ var MongoDBProvider = class extends BaseVectorProvider {
|
|
|
86
88
|
await this.collection.deleteMany({ namespace });
|
|
87
89
|
}
|
|
88
90
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
+
* Sanitise and flatten filter for MongoDB.
|
|
92
|
+
* Strips internal engine fields and keywords.
|
|
91
93
|
*/
|
|
92
94
|
sanitizeFilter(filter) {
|
|
93
|
-
if (!filter) return {};
|
|
94
95
|
const sanitized = super.sanitizeFilter(filter);
|
|
95
96
|
const mongoFilter = {};
|
|
96
97
|
for (const [key, value] of Object.entries(sanitized)) {
|
|
@@ -963,13 +963,13 @@ ${context}`;
|
|
|
963
963
|
return data.message.content;
|
|
964
964
|
}
|
|
965
965
|
async embed(text, options) {
|
|
966
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
966
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
967
967
|
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";
|
|
968
968
|
const baseURL = (_f = (_e = (_d = this.embeddingConfig) == null ? void 0 : _d.baseUrl) != null ? _e : this.llmConfig.baseUrl) != null ? _f : "http://localhost:11434";
|
|
969
969
|
const client = baseURL !== ((_g = this.llmConfig.baseUrl) != null ? _g : "http://localhost:11434") ? axios.create({ baseURL, timeout: 6e4 }) : this.http;
|
|
970
970
|
let prompt = text;
|
|
971
|
-
const queryPrefix = (_h = this.embeddingConfig) == null ? void 0 : _h.queryPrefix;
|
|
972
|
-
const docPrefix = (
|
|
971
|
+
const queryPrefix = (_i = (_h = this.embeddingConfig) == null ? void 0 : _h.queryPrefix) != null ? _i : model.includes("nomic") ? "search_query: " : "";
|
|
972
|
+
const docPrefix = (_k = (_j = this.embeddingConfig) == null ? void 0 : _j.documentPrefix) != null ? _k : model.includes("nomic") ? "search_document: " : "";
|
|
973
973
|
if ((options == null ? void 0 : options.taskType) === "query" && queryPrefix) {
|
|
974
974
|
if (!prompt.startsWith(queryPrefix)) {
|
|
975
975
|
prompt = `${queryPrefix}${text}`;
|
|
@@ -1378,7 +1378,7 @@ var ProviderRegistry = class {
|
|
|
1378
1378
|
return new PostgreSQLProvider(config);
|
|
1379
1379
|
}
|
|
1380
1380
|
case "mongodb": {
|
|
1381
|
-
const { MongoDBProvider } = await import("./MongoDBProvider-
|
|
1381
|
+
const { MongoDBProvider } = await import("./MongoDBProvider-ZKW34AEL.mjs");
|
|
1382
1382
|
return new MongoDBProvider(config);
|
|
1383
1383
|
}
|
|
1384
1384
|
case "milvus": {
|
package/dist/handlers/index.js
CHANGED
|
@@ -433,18 +433,20 @@ var init_MongoDBProvider = __esm({
|
|
|
433
433
|
},
|
|
434
434
|
{
|
|
435
435
|
$project: {
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
436
|
+
_id: 1,
|
|
437
|
+
[this.contentKey]: 1,
|
|
438
|
+
[this.metadataKey]: 1,
|
|
439
|
+
namespace: 1,
|
|
440
|
+
score: { $meta: "vectorSearchScore" }
|
|
439
441
|
}
|
|
440
442
|
}
|
|
441
443
|
];
|
|
442
444
|
const results = await this.collection.aggregate(pipeline).toArray();
|
|
443
445
|
return results.map((res) => ({
|
|
444
|
-
id: res
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
446
|
+
id: res._id,
|
|
447
|
+
content: res[this.contentKey],
|
|
448
|
+
metadata: res[this.metadataKey],
|
|
449
|
+
score: res.score
|
|
448
450
|
}));
|
|
449
451
|
}
|
|
450
452
|
async delete(id, namespace) {
|
|
@@ -454,11 +456,10 @@ var init_MongoDBProvider = __esm({
|
|
|
454
456
|
await this.collection.deleteMany({ namespace });
|
|
455
457
|
}
|
|
456
458
|
/**
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
+
* Sanitise and flatten filter for MongoDB.
|
|
460
|
+
* Strips internal engine fields and keywords.
|
|
459
461
|
*/
|
|
460
462
|
sanitizeFilter(filter) {
|
|
461
|
-
if (!filter) return {};
|
|
462
463
|
const sanitized = super.sanitizeFilter(filter);
|
|
463
464
|
const mongoFilter = {};
|
|
464
465
|
for (const [key, value] of Object.entries(sanitized)) {
|
|
@@ -2158,13 +2159,13 @@ ${context}`;
|
|
|
2158
2159
|
return data.message.content;
|
|
2159
2160
|
}
|
|
2160
2161
|
async embed(text, options) {
|
|
2161
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2162
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2162
2163
|
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";
|
|
2163
2164
|
const baseURL = (_f = (_e = (_d = this.embeddingConfig) == null ? void 0 : _d.baseUrl) != null ? _e : this.llmConfig.baseUrl) != null ? _f : "http://localhost:11434";
|
|
2164
2165
|
const client = baseURL !== ((_g = this.llmConfig.baseUrl) != null ? _g : "http://localhost:11434") ? import_axios.default.create({ baseURL, timeout: 6e4 }) : this.http;
|
|
2165
2166
|
let prompt = text;
|
|
2166
|
-
const queryPrefix = (_h = this.embeddingConfig) == null ? void 0 : _h.queryPrefix;
|
|
2167
|
-
const docPrefix = (
|
|
2167
|
+
const queryPrefix = (_i = (_h = this.embeddingConfig) == null ? void 0 : _h.queryPrefix) != null ? _i : model.includes("nomic") ? "search_query: " : "";
|
|
2168
|
+
const docPrefix = (_k = (_j = this.embeddingConfig) == null ? void 0 : _j.documentPrefix) != null ? _k : model.includes("nomic") ? "search_document: " : "";
|
|
2168
2169
|
if ((options == null ? void 0 : options.taskType) === "query" && queryPrefix) {
|
|
2169
2170
|
if (!prompt.startsWith(queryPrefix)) {
|
|
2170
2171
|
prompt = `${queryPrefix}${text}`;
|
package/dist/handlers/index.mjs
CHANGED
package/dist/server.d.mts
CHANGED
|
@@ -753,8 +753,8 @@ declare class MongoDBProvider extends BaseVectorProvider {
|
|
|
753
753
|
delete(id: string | number, namespace?: string): Promise<void>;
|
|
754
754
|
deleteNamespace(namespace: string): Promise<void>;
|
|
755
755
|
/**
|
|
756
|
-
*
|
|
757
|
-
*
|
|
756
|
+
* Sanitise and flatten filter for MongoDB.
|
|
757
|
+
* Strips internal engine fields and keywords.
|
|
758
758
|
*/
|
|
759
759
|
protected sanitizeFilter(filter?: Record<string, unknown>): Record<string, unknown>;
|
|
760
760
|
ping(): Promise<boolean>;
|
package/dist/server.d.ts
CHANGED
|
@@ -753,8 +753,8 @@ declare class MongoDBProvider extends BaseVectorProvider {
|
|
|
753
753
|
delete(id: string | number, namespace?: string): Promise<void>;
|
|
754
754
|
deleteNamespace(namespace: string): Promise<void>;
|
|
755
755
|
/**
|
|
756
|
-
*
|
|
757
|
-
*
|
|
756
|
+
* Sanitise and flatten filter for MongoDB.
|
|
757
|
+
* Strips internal engine fields and keywords.
|
|
758
758
|
*/
|
|
759
759
|
protected sanitizeFilter(filter?: Record<string, unknown>): Record<string, unknown>;
|
|
760
760
|
ping(): Promise<boolean>;
|
package/dist/server.js
CHANGED
|
@@ -445,18 +445,20 @@ var init_MongoDBProvider = __esm({
|
|
|
445
445
|
},
|
|
446
446
|
{
|
|
447
447
|
$project: {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
448
|
+
_id: 1,
|
|
449
|
+
[this.contentKey]: 1,
|
|
450
|
+
[this.metadataKey]: 1,
|
|
451
|
+
namespace: 1,
|
|
452
|
+
score: { $meta: "vectorSearchScore" }
|
|
451
453
|
}
|
|
452
454
|
}
|
|
453
455
|
];
|
|
454
456
|
const results = await this.collection.aggregate(pipeline).toArray();
|
|
455
457
|
return results.map((res) => ({
|
|
456
|
-
id: res
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
458
|
+
id: res._id,
|
|
459
|
+
content: res[this.contentKey],
|
|
460
|
+
metadata: res[this.metadataKey],
|
|
461
|
+
score: res.score
|
|
460
462
|
}));
|
|
461
463
|
}
|
|
462
464
|
async delete(id, namespace) {
|
|
@@ -466,11 +468,10 @@ var init_MongoDBProvider = __esm({
|
|
|
466
468
|
await this.collection.deleteMany({ namespace });
|
|
467
469
|
}
|
|
468
470
|
/**
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
+
* Sanitise and flatten filter for MongoDB.
|
|
472
|
+
* Strips internal engine fields and keywords.
|
|
471
473
|
*/
|
|
472
474
|
sanitizeFilter(filter) {
|
|
473
|
-
if (!filter) return {};
|
|
474
475
|
const sanitized = super.sanitizeFilter(filter);
|
|
475
476
|
const mongoFilter = {};
|
|
476
477
|
for (const [key, value] of Object.entries(sanitized)) {
|
|
@@ -2202,13 +2203,13 @@ ${context}`;
|
|
|
2202
2203
|
return data.message.content;
|
|
2203
2204
|
}
|
|
2204
2205
|
async embed(text, options) {
|
|
2205
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2206
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2206
2207
|
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";
|
|
2207
2208
|
const baseURL = (_f = (_e = (_d = this.embeddingConfig) == null ? void 0 : _d.baseUrl) != null ? _e : this.llmConfig.baseUrl) != null ? _f : "http://localhost:11434";
|
|
2208
2209
|
const client = baseURL !== ((_g = this.llmConfig.baseUrl) != null ? _g : "http://localhost:11434") ? import_axios.default.create({ baseURL, timeout: 6e4 }) : this.http;
|
|
2209
2210
|
let prompt = text;
|
|
2210
|
-
const queryPrefix = (_h = this.embeddingConfig) == null ? void 0 : _h.queryPrefix;
|
|
2211
|
-
const docPrefix = (
|
|
2211
|
+
const queryPrefix = (_i = (_h = this.embeddingConfig) == null ? void 0 : _h.queryPrefix) != null ? _i : model.includes("nomic") ? "search_query: " : "";
|
|
2212
|
+
const docPrefix = (_k = (_j = this.embeddingConfig) == null ? void 0 : _j.documentPrefix) != null ? _k : model.includes("nomic") ? "search_document: " : "";
|
|
2212
2213
|
if ((options == null ? void 0 : options.taskType) === "query" && queryPrefix) {
|
|
2213
2214
|
if (!prompt.startsWith(queryPrefix)) {
|
|
2214
2215
|
prompt = `${queryPrefix}${text}`;
|
package/dist/server.mjs
CHANGED
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
createIngestHandler,
|
|
35
35
|
createUploadHandler,
|
|
36
36
|
getRagConfig
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-UUZ3F4WK.mjs";
|
|
38
38
|
import "./chunk-EDLTMSNY.mjs";
|
|
39
39
|
import {
|
|
40
40
|
PineconeProvider
|
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
} from "./chunk-LJWWPTWE.mjs";
|
|
45
45
|
import {
|
|
46
46
|
MongoDBProvider
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-IWHCAQEA.mjs";
|
|
48
48
|
import {
|
|
49
49
|
MilvusProvider
|
|
50
50
|
} from "./chunk-3QWAK3RZ.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retrivora-ai/rag-engine",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Retrivora AI is a plug-and-play AI engine for RAG chat experiences — generic vector DB + LLM provider, embeddable or standalone.",
|
|
5
5
|
"author": "Abhinav Alkuchi",
|
|
6
6
|
"license": "MIT",
|
|
@@ -76,8 +76,9 @@ export class OllamaProvider implements ILLMProvider {
|
|
|
76
76
|
let prompt = text;
|
|
77
77
|
|
|
78
78
|
// Dynamically apply prefixes from configuration if they exist
|
|
79
|
-
|
|
80
|
-
const
|
|
79
|
+
// Fallback to standard nomic-embed-text prefixes if not provided
|
|
80
|
+
const queryPrefix = this.embeddingConfig?.queryPrefix ?? (model.includes('nomic') ? 'search_query: ' : '');
|
|
81
|
+
const docPrefix = this.embeddingConfig?.documentPrefix ?? (model.includes('nomic') ? 'search_document: ' : '');
|
|
81
82
|
|
|
82
83
|
if (options?.taskType === 'query' && queryPrefix) {
|
|
83
84
|
if (!prompt.startsWith(queryPrefix)) {
|
|
@@ -83,18 +83,22 @@ export class MongoDBProvider extends BaseVectorProvider {
|
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
85
|
$project: {
|
|
86
|
+
_id: 1,
|
|
87
|
+
[this.contentKey]: 1,
|
|
88
|
+
[this.metadataKey]: 1,
|
|
89
|
+
namespace: 1,
|
|
86
90
|
score: { $meta: 'vectorSearchScore' },
|
|
87
|
-
content: `$${this.contentKey}`,
|
|
88
|
-
metadata: `$${this.metadataKey}`,
|
|
89
91
|
},
|
|
90
92
|
},
|
|
91
93
|
];
|
|
94
|
+
|
|
92
95
|
const results = await this.collection!.aggregate(pipeline).toArray();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
content: res[
|
|
97
|
-
metadata: res[
|
|
96
|
+
|
|
97
|
+
return results.map((res: any) => ({
|
|
98
|
+
id: res._id,
|
|
99
|
+
content: res[this.contentKey],
|
|
100
|
+
metadata: res[this.metadataKey],
|
|
101
|
+
score: res.score,
|
|
98
102
|
}));
|
|
99
103
|
}
|
|
100
104
|
|
|
@@ -107,16 +111,15 @@ export class MongoDBProvider extends BaseVectorProvider {
|
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
114
|
+
* Sanitise and flatten filter for MongoDB.
|
|
115
|
+
* Strips internal engine fields and keywords.
|
|
112
116
|
*/
|
|
113
|
-
protected
|
|
114
|
-
if (!filter) return {};
|
|
117
|
+
protected sanitizeFilter(filter?: Record<string, unknown>): Record<string, unknown> {
|
|
115
118
|
const sanitized = super.sanitizeFilter(filter);
|
|
116
119
|
const mongoFilter: Record<string, unknown> = {};
|
|
117
120
|
|
|
118
121
|
for (const [key, value] of Object.entries(sanitized)) {
|
|
119
|
-
// Skip internal engine fields and generic keywords
|
|
122
|
+
// Skip internal engine fields and generic keywords that don't exist in metadata
|
|
120
123
|
if (key.startsWith('__') || key === 'keywords' || key === 'queryText') continue;
|
|
121
124
|
|
|
122
125
|
// If the key is already a special key, keep it (e.g. namespace)
|
|
@@ -127,6 +130,7 @@ export class MongoDBProvider extends BaseVectorProvider {
|
|
|
127
130
|
mongoFilter[`${this.metadataKey}.${key}`] = value;
|
|
128
131
|
}
|
|
129
132
|
}
|
|
133
|
+
|
|
130
134
|
return mongoFilter;
|
|
131
135
|
}
|
|
132
136
|
|