@retrivora-ai/rag-engine 1.9.2 → 1.9.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.
@@ -1090,12 +1090,15 @@ var init_MongoDBProvider = __esm({
1090
1090
  }
1091
1091
  );
1092
1092
  const results = await this.collection.aggregate(pipeline).toArray();
1093
- return results.map((res) => ({
1094
- id: res._id,
1095
- content: res[this.contentKey],
1096
- metadata: res[this.metadataKey] || {},
1097
- score: res.score
1098
- }));
1093
+ return results.map((res) => {
1094
+ const normalizedScore = res.score * 2 - 1;
1095
+ return {
1096
+ id: res._id,
1097
+ content: res[this.contentKey],
1098
+ metadata: res[this.metadataKey] || {},
1099
+ score: normalizedScore
1100
+ };
1101
+ });
1099
1102
  }
1100
1103
  async delete(id, namespace) {
1101
1104
  await this.collection.deleteOne(__spreadValues({ _id: id }, namespace ? { namespace } : {}));
@@ -6387,7 +6390,8 @@ ${m.content}`).join("\n\n---\n\n") : "No relevant context found.";
6387
6390
  if (hasMetadataFilter) {
6388
6391
  displayCount = fullSources.length;
6389
6392
  } else {
6390
- const highlyRelevant = fullSources.filter((m) => m.score >= 0.4);
6393
+ const baseThreshold = Math.max(scoreThreshold, 0.4);
6394
+ const highlyRelevant = fullSources.filter((m) => m.score >= baseThreshold);
6391
6395
  displayCount = Math.max(highlyRelevant.length, topK);
6392
6396
  if (displayCount > 15) {
6393
6397
  displayCount = 15;
@@ -1069,12 +1069,15 @@ var init_MongoDBProvider = __esm({
1069
1069
  }
1070
1070
  );
1071
1071
  const results = await this.collection.aggregate(pipeline).toArray();
1072
- return results.map((res) => ({
1073
- id: res._id,
1074
- content: res[this.contentKey],
1075
- metadata: res[this.metadataKey] || {},
1076
- score: res.score
1077
- }));
1072
+ return results.map((res) => {
1073
+ const normalizedScore = res.score * 2 - 1;
1074
+ return {
1075
+ id: res._id,
1076
+ content: res[this.contentKey],
1077
+ metadata: res[this.metadataKey] || {},
1078
+ score: normalizedScore
1079
+ };
1080
+ });
1078
1081
  }
1079
1082
  async delete(id, namespace) {
1080
1083
  await this.collection.deleteOne(__spreadValues({ _id: id }, namespace ? { namespace } : {}));
@@ -6350,7 +6353,8 @@ ${m.content}`).join("\n\n---\n\n") : "No relevant context found.";
6350
6353
  if (hasMetadataFilter) {
6351
6354
  displayCount = fullSources.length;
6352
6355
  } else {
6353
- const highlyRelevant = fullSources.filter((m) => m.score >= 0.4);
6356
+ const baseThreshold = Math.max(scoreThreshold, 0.4);
6357
+ const highlyRelevant = fullSources.filter((m) => m.score >= baseThreshold);
6354
6358
  displayCount = Math.max(highlyRelevant.length, topK);
6355
6359
  if (displayCount > 15) {
6356
6360
  displayCount = 15;
package/dist/server.js CHANGED
@@ -1090,12 +1090,15 @@ var init_MongoDBProvider = __esm({
1090
1090
  }
1091
1091
  );
1092
1092
  const results = await this.collection.aggregate(pipeline).toArray();
1093
- return results.map((res) => ({
1094
- id: res._id,
1095
- content: res[this.contentKey],
1096
- metadata: res[this.metadataKey] || {},
1097
- score: res.score
1098
- }));
1093
+ return results.map((res) => {
1094
+ const normalizedScore = res.score * 2 - 1;
1095
+ return {
1096
+ id: res._id,
1097
+ content: res[this.contentKey],
1098
+ metadata: res[this.metadataKey] || {},
1099
+ score: normalizedScore
1100
+ };
1101
+ });
1099
1102
  }
1100
1103
  async delete(id, namespace) {
1101
1104
  await this.collection.deleteOne(__spreadValues({ _id: id }, namespace ? { namespace } : {}));
@@ -6464,7 +6467,8 @@ ${m.content}`).join("\n\n---\n\n") : "No relevant context found.";
6464
6467
  if (hasMetadataFilter) {
6465
6468
  displayCount = fullSources.length;
6466
6469
  } else {
6467
- const highlyRelevant = fullSources.filter((m) => m.score >= 0.4);
6470
+ const baseThreshold = Math.max(scoreThreshold, 0.4);
6471
+ const highlyRelevant = fullSources.filter((m) => m.score >= baseThreshold);
6468
6472
  displayCount = Math.max(highlyRelevant.length, topK);
6469
6473
  if (displayCount > 15) {
6470
6474
  displayCount = 15;
package/dist/server.mjs CHANGED
@@ -1069,12 +1069,15 @@ var init_MongoDBProvider = __esm({
1069
1069
  }
1070
1070
  );
1071
1071
  const results = await this.collection.aggregate(pipeline).toArray();
1072
- return results.map((res) => ({
1073
- id: res._id,
1074
- content: res[this.contentKey],
1075
- metadata: res[this.metadataKey] || {},
1076
- score: res.score
1077
- }));
1072
+ return results.map((res) => {
1073
+ const normalizedScore = res.score * 2 - 1;
1074
+ return {
1075
+ id: res._id,
1076
+ content: res[this.contentKey],
1077
+ metadata: res[this.metadataKey] || {},
1078
+ score: normalizedScore
1079
+ };
1080
+ });
1078
1081
  }
1079
1082
  async delete(id, namespace) {
1080
1083
  await this.collection.deleteOne(__spreadValues({ _id: id }, namespace ? { namespace } : {}));
@@ -6395,7 +6398,8 @@ ${m.content}`).join("\n\n---\n\n") : "No relevant context found.";
6395
6398
  if (hasMetadataFilter) {
6396
6399
  displayCount = fullSources.length;
6397
6400
  } else {
6398
- const highlyRelevant = fullSources.filter((m) => m.score >= 0.4);
6401
+ const baseThreshold = Math.max(scoreThreshold, 0.4);
6402
+ const highlyRelevant = fullSources.filter((m) => m.score >= baseThreshold);
6399
6403
  displayCount = Math.max(highlyRelevant.length, topK);
6400
6404
  if (displayCount > 15) {
6401
6405
  displayCount = 15;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "1.9.2",
3
+ "version": "1.9.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",
@@ -525,7 +525,8 @@ You are a helpful assistant. Use the provided context to answer questions accura
525
525
  displayCount = fullSources.length;
526
526
  } else {
527
527
  // For general semantic queries, count the number of matches meeting high relevance threshold
528
- const highlyRelevant = fullSources.filter(m => m.score >= 0.4);
528
+ const baseThreshold = Math.max(scoreThreshold, 0.4);
529
+ const highlyRelevant = fullSources.filter(m => m.score >= baseThreshold);
529
530
  displayCount = Math.max(highlyRelevant.length, topK);
530
531
  // Cap non-metadata semantic searches to a maximum of 15 to keep the UI clean
531
532
  if (displayCount > 15) {
@@ -191,12 +191,19 @@ export class MongoDBProvider extends BaseVectorProvider {
191
191
 
192
192
  const results = await this.collection!.aggregate(pipeline).toArray();
193
193
 
194
- return (results as unknown as Array<{ _id: string; score: number; [key: string]: unknown }>).map((res) => ({
195
- id: res._id,
196
- content: res[this.contentKey] as string,
197
- metadata: (res[this.metadataKey] as Record<string, unknown>) || {},
198
- score: res.score,
199
- }));
194
+ return (results as unknown as Array<{ _id: string; score: number; [key: string]: unknown }>).map((res) => {
195
+ // Normalize MongoDB's vectorSearchScore (which is shifted to [0, 1] e.g. (1+cos)/2)
196
+ // back to the standard [-1, 1] cosine space. This ensures the global relevance
197
+ // threshold (e.g. 0.4) properly filters out random orthogonal matches.
198
+ const normalizedScore = (res.score * 2) - 1;
199
+
200
+ return {
201
+ id: res._id,
202
+ content: res[this.contentKey] as string,
203
+ metadata: (res[this.metadataKey] as Record<string, unknown>) || {},
204
+ score: normalizedScore,
205
+ };
206
+ });
200
207
  }
201
208
 
202
209
  async delete(id: string | number, namespace?: string): Promise<void> {