From 8fbcef42218c14dc7a979e5393ee3a2b17e11948 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 9 Jul 2024 16:01:52 +0530 Subject: [PATCH] tsc --- web/packages/new/photos/services/ml/clip.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/packages/new/photos/services/ml/clip.ts b/web/packages/new/photos/services/ml/clip.ts index 21794431ba..5f5df66713 100644 --- a/web/packages/new/photos/services/ml/clip.ts +++ b/web/packages/new/photos/services/ml/clip.ts @@ -197,10 +197,10 @@ export const clipMatches = async ( searchPhrase: string, electron: Electron, ): Promise | undefined> => { - const textEmbedding = await electron - .computeCLIPTextEmbeddingIfAvailable(searchPhrase) - .then((e) => (e ? normalizedEmbedding(e) : e)); - if (!textEmbedding) return undefined; + const t = await electron.computeCLIPTextEmbeddingIfAvailable(searchPhrase); + if (!t) return undefined; + + const textEmbedding = normalizedEmbedding(t); return new Map( (await clipIndexes()) @@ -215,11 +215,12 @@ export const clipMatches = async ( const clipMatchScore = (imageEmbedding: number[], textEmbedding: number[]) => { if (imageEmbedding.length != textEmbedding.length) throw Error( - `CLIP image embeddings (${imageEmbedding.length}) and text embeddings (${textEmbedding.length}) length mismatch`, + `CLIP image embedding (${imageEmbedding.length}) and text embedding (${textEmbedding.length}) length mismatch`, ); let score = 0; for (let i = 0; i < imageEmbedding.length; i++) { + // We checked the length above. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion score += imageEmbedding[i]! * textEmbedding[i]!; }