Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

wip towards removal

Manav Rathi45b1f82032fb
diff --git a/web/apps/photos/src/services/clip-service.ts b/web/apps/photos/src/services/clip-service.ts
index 4b9900aed5..59fb60fdcf 100644
--- a/web/apps/photos/src/services/clip-service.ts
+++ b/web/apps/photos/src/services/clip-service.ts
@@ -359,32 +359,7 @@ const getNonClipEmbeddingExtractedFiles = async (
});
};
-export const computeClipMatchScore = async (
- imageEmbedding: Float32Array,
- textEmbedding: Float32Array,
-) => {
- if (imageEmbedding.length !== textEmbedding.length) {
- throw Error("imageEmbedding and textEmbedding length mismatch");
- }
- let score = 0;
- let imageNormalization = 0;
- let textNormalization = 0;
- for (let index = 0; index < imageEmbedding.length; index++) {
- imageNormalization += imageEmbedding[index] * imageEmbedding[index];
- textNormalization += textEmbedding[index] * textEmbedding[index];
- }
- for (let index = 0; index < imageEmbedding.length; index++) {
- imageEmbedding[index] =
- imageEmbedding[index] / Math.sqrt(imageNormalization);
- textEmbedding[index] =
- textEmbedding[index] / Math.sqrt(textNormalization);
- }
- for (let index = 0; index < imageEmbedding.length; index++) {
- score += imageEmbedding[index] * textEmbedding[index];
- }
- return score;
-};
const initialIndexingStatus = async (): Promise<CLIPIndexingStatus> => {
const user = getData(LS_KEYS.USER);
diff --git a/web/apps/photos/src/services/searchService.ts b/web/apps/photos/src/services/searchService.ts
index 98e5c5e842..b2d2c6aad3 100644
--- a/web/apps/photos/src/services/searchService.ts
+++ b/web/apps/photos/src/services/searchService.ts
@@ -19,14 +19,12 @@ import {
import ComlinkSearchWorker from "utils/comlink/ComlinkSearchWorker";
import { getUniqueFiles } from "utils/file";
import { getFormattedDate } from "utils/search";
-import { clipService, computeClipMatchScore } from "./clip-service";
-import { localCLIPEmbeddings } from "./embeddingService";
import { getLatestEntities } from "./entityService";
import locationSearchService, { City } from "./locationSearchService";
const DIGITS = new Set(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]);
-const CLIP_SCORE_THRESHOLD = 0.23;
+// const CLIP_SCORE_THRESHOLD = 0.23;
export const getDefaultOptions = async () => {
return [
@@ -373,31 +371,66 @@ async function searchLocationTag(searchPhrase: string): Promise<LocationTag[]> {
}
const searchClip = async (
- searchPhrase: string,
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ _searchPhrase: string,
): Promise<ClipSearchScores | undefined> => {
- const textEmbedding =
- await clipService.getTextEmbeddingIfAvailable(searchPhrase);
- if (!textEmbedding) return undefined;
-
- const imageEmbeddings = await localCLIPEmbeddings();
- const clipSearchResult = new Map<number, number>(
- (
- await Promise.all(
- imageEmbeddings.map(
- async (imageEmbedding): Promise<[number, number]> => [
- imageEmbedding.fileID,
- await computeClipMatchScore(
- imageEmbedding.embedding,
- textEmbedding,
- ),
- ],
- ),
- )
- ).filter(([, score]) => score >= CLIP_SCORE_THRESHOLD),
- );
-
- return clipSearchResult;
+ // TODO-ML:
+ return undefined;
};
+// const textEmbedding =
+// await clipService.getTextEmbeddingIfAvailable(searchPhrase);
+// if (!textEmbedding) return undefined;
+
+// const imageEmbeddings = await localCLIPEmbeddings();
+// const clipSearchResult = new Map<number, number>(
+// (
+// await Promise.all(
+// imageEmbeddings.map(
+// async (imageEmbedding): Promise<[number, number]> => [
+// imageEmbedding.fileID,
+// await computeClipMatchScore(
+// imageEmbedding.embedding,
+// textEmbedding,
+// ),
+// ],
+// ),
+// )
+// ).filter(([, score]) => score >= CLIP_SCORE_THRESHOLD),
+// );
+
+// return clipSearchResult;
+// };
+
+// getTextEmbeddingIfAvailable = async (text: string) => {
+// return ensureElectron().computeCLIPTextEmbeddingIfAvailable(text);
+// };
+
+// export const computeClipMatchScore = async (
+// imageEmbedding: Float32Array,
+// textEmbedding: Float32Array,
+// ) => {
+// if (imageEmbedding.length !== textEmbedding.length) {
+// throw Error("imageEmbedding and textEmbedding length mismatch");
+// }
+// let score = 0;
+// let imageNormalization = 0;
+// let textNormalization = 0;
+
+// for (let index = 0; index < imageEmbedding.length; index++) {
+// imageNormalization += imageEmbedding[index] * imageEmbedding[index];
+// textNormalization += textEmbedding[index] * textEmbedding[index];
+// }
+// for (let index = 0; index < imageEmbedding.length; index++) {
+// imageEmbedding[index] =
+// imageEmbedding[index] / Math.sqrt(imageNormalization);
+// textEmbedding[index] =
+// textEmbedding[index] / Math.sqrt(textNormalization);
+// }
+// for (let index = 0; index < imageEmbedding.length; index++) {
+// score += imageEmbedding[index] * textEmbedding[index];
+// }
+// return score;
+// };
function convertSuggestionToSearchQuery(option: Suggestion): Search {
switch (option.type) {
diff --git a/web/packages/new/photos/services/ml/clip.ts b/web/packages/new/photos/services/ml/clip.ts
index 88eb49fd2d..ef59fed210 100644
--- a/web/packages/new/photos/services/ml/clip.ts
+++ b/web/packages/new/photos/services/ml/clip.ts
@@ -63,7 +63,13 @@ export interface CLIPIndex {
version: number;
/** The UA for the client which generated this embedding. */
client: string;
- /** The CLIP embedding itself. */
+ /**
+ * The CLIP embedding itself.
+ *
+ * This is an array of 512 floating point values that represent the
+ * embedding of the image in the same space where we'll embed the text so
+ * that both of them can be compared using a cosine distance.
+ */
embedding: number[];
}
diff --git a/web/packages/shared/error/index.ts b/web/packages/shared/error/index.ts
index 3dea65554b..b3f16fa648 100644
--- a/web/packages/shared/error/index.ts
+++ b/web/packages/shared/error/index.ts
@@ -71,7 +71,6 @@ export const CustomError = {
CLIENT_ERROR: "client error",
ServerError: "server error",
FILE_NOT_FOUND: "file not found",
- UNSUPPORTED_PLATFORM: "Unsupported platform",
UPDATE_URL_FILE_ID_MISMATCH: "update url file id mismatch",
URL_ALREADY_SET: "url already set",
FILE_CONVERSION_FAILED: "file conversion failed",