Browse Source

updated the vectorSearch to include score results for vectoer queries

Dr-Swopt 1 month ago
parent
commit
70f7e3f81b
2 changed files with 12 additions and 23 deletions
  1. 2 1
      src/FFB/ffb-vector.service.ts
  2. 10 22
      src/mongo/mongo-ffb-production.repository.ts

+ 2 - 1
src/FFB/ffb-vector.service.ts

@@ -60,7 +60,8 @@ export class FFBVectorService implements OnModuleInit {
 
     // Step 2: Use repository aggregation for vector search
     const results = await this.repo.vectorSearch(vector, k, 50); // numCandidates = 50
-
+    console.log(results)
+    // results.forEach(e => console.log(e.score))
     // Step 3: Return results directly (they now include the full document + score)
     return results.map(r => ({
       ...r,      // all FFBProduction fields

+ 10 - 22
src/mongo/mongo-ffb-production.repository.ts

@@ -56,33 +56,21 @@ export class FFBProductionRepository {
             limit: k
           }
         },
-        {
-          $lookup: {
-            from: this.collectionName,
-            localField: "_id",
-            foreignField: "_id",
-            as: "doc"
-          }
-        },
-        { $unwind: "$doc" },
         {
           $project: {
-            _id: "$doc._id",
-            productionDate: "$doc.productionDate",
-            site: "$doc.site",
-            phase: "$doc.phase",
-            block: "$doc.block",
-            quantity: "$doc.quantity",
-            quantityUom: "$doc.quantityUom",
-            weight: "$doc.weight",
-            weightUom: "$doc.weightUom",
-            // vector: "$doc.vector",
-            score: "$_score"
+            _id: 1,
+            productionDate: 1,
+            site: 1,
+            phase: 1,
+            block: 1,
+            quantity: 1,
+            quantityUom: 1,
+            weight: 1,
+            weightUom: 1,
+            score: { "$meta": "vectorSearchScore" }  // correctly get the score
           }
         }
       ])
       .toArray();
   }
-
-
 }