[web] Embeddings diff improvements (#1735)

- Do not rely on the server sending back exactly as many entries as we
requested, it may return less in case some of the embeddings cannot be
fetched temporarily.

- Stop relying on the sort order - Instead of the last value, take the
max from amongst all returned values.

/cc @ua741
This commit is contained in:
Manav Rathi 2024-05-16 10:22:36 +05:30 committed by GitHub
commit 0752800ecf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -141,15 +141,16 @@ export const syncCLIPEmbeddings = async () => {
...allEmbeddings,
...newEmbeddings,
]);
if (response.diff.length) {
modelLastSinceTime = response.diff.slice(-1)[0].updatedAt;
}
modelLastSinceTime = response.diff.reduce(
(max, { updatedAt }) => Math.max(max, updatedAt),
modelLastSinceTime,
);
await localForage.setItem(clipEmbeddingsLSKey, allEmbeddings);
await setModelEmbeddingSyncTime(model, modelLastSinceTime);
log.info(
`Syncing embeddings syncedEmbeddingsCount: ${allEmbeddings.length}`,
);
} while (response.diff.length === DIFF_LIMIT);
} while (response.diff.length > 0);
} catch (e) {
log.error("Sync embeddings failed", e);
}
@ -218,15 +219,16 @@ export const syncFaceEmbeddings = async () => {
...allEmbeddings,
...newEmbeddings,
]);
if (response.diff.length) {
modelLastSinceTime = response.diff.slice(-1)[0].updatedAt;
}
modelLastSinceTime = response.diff.reduce(
(max, { updatedAt }) => Math.max(max, updatedAt),
modelLastSinceTime,
);
await localForage.setItem(FILE_EMBEDING_TABLE, allEmbeddings);
await setModelEmbeddingSyncTime(model, modelLastSinceTime);
log.info(
`Syncing embeddings syncedEmbeddingsCount: ${allEmbeddings.length}`,
);
} while (response.diff.length === DIFF_LIMIT);
} while (response.diff.length > 0);
} catch (e) {
log.error("Sync embeddings failed", e);
}