From b7d275675400c65e09f163a69be9a356bdc9a774 Mon Sep 17 00:00:00 2001
From: Sayan Gupta <155448490+isayandev@users.noreply.github.com>
Date: Fri, 5 Jan 2024 06:09:43 +0530
Subject: [PATCH] Issue #204 Added a check to ensure that 'chunk.payload'
 exists and contains the 'id' property (#526)

* Issue #204 Added a check to ensure that 'chunk.payload' exists and contains the 'id' property before attempting to destructure it

* run linter

* simplify condition and comment

---------

Co-authored-by: timothycarambat <rambat1010@gmail.com>
---
 server/utils/vectorDbProviders/qdrant/index.js | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/server/utils/vectorDbProviders/qdrant/index.js b/server/utils/vectorDbProviders/qdrant/index.js
index 54f53927a..49b25a3d6 100644
--- a/server/utils/vectorDbProviders/qdrant/index.js
+++ b/server/utils/vectorDbProviders/qdrant/index.js
@@ -152,13 +152,20 @@ const QDrant = {
 
           // Before sending to Qdrant and saving the records to our db
           // we need to assign the id of each chunk that is stored in the cached file.
+          // The id property must be defined or else it will be unable to be managed by ALLM.
           chunk.forEach((chunk) => {
             const id = uuidv4();
-            const { id: _id, ...payload } = chunk.payload;
-            documentVectors.push({ docId, vectorId: id });
-            submission.ids.push(id);
-            submission.vectors.push(chunk.vector);
-            submission.payloads.push(payload);
+            if (chunk?.payload?.hasOwnProperty("id")) {
+              const { id: _id, ...payload } = chunk.payload;
+              documentVectors.push({ docId, vectorId: id });
+              submission.ids.push(id);
+              submission.vectors.push(chunk.vector);
+              submission.payloads.push(payload);
+            } else {
+              console.error(
+                "The 'id' property is not defined in chunk.payload - it will be omitted from being inserted in QDrant collection."
+              );
+            }
           });
 
           const additionResult = await client.upsert(namespace, {