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>
This commit is contained in:
Sayan Gupta 2024-01-05 06:09:43 +05:30 committed by GitHub
parent a1b4ed43ba
commit b7d2756754
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -152,13 +152,20 @@ const QDrant = {
// Before sending to Qdrant and saving the records to our db // 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. // 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) => { chunk.forEach((chunk) => {
const id = uuidv4(); const id = uuidv4();
const { id: _id, ...payload } = chunk.payload; if (chunk?.payload?.hasOwnProperty("id")) {
documentVectors.push({ docId, vectorId: id }); const { id: _id, ...payload } = chunk.payload;
submission.ids.push(id); documentVectors.push({ docId, vectorId: id });
submission.vectors.push(chunk.vector); submission.ids.push(id);
submission.payloads.push(payload); 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, { const additionResult = await client.upsert(namespace, {