Skip to content

Commit

Permalink
Issue #204 Added a check to ensure that 'chunk.payload' exists and co…
Browse files Browse the repository at this point in the history
…ntains 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 <[email protected]>
  • Loading branch information
isayandev and timothycarambat authored Jan 5, 2024
1 parent a1b4ed4 commit b7d2756
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions server/utils/vectorDbProviders/qdrant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit b7d2756

Please sign in to comment.