π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Move cosine function
laurenspriem9e76c31655c8
diff --git a/mobile/lib/services/machine_learning/face_ml/face_clustering/cosine_distance.dart b/mobile/lib/services/machine_learning/face_ml/face_clustering/cosine_distance.dartindex 72b9dafead..17b783558d 100644--- a/mobile/lib/services/machine_learning/face_ml/face_clustering/cosine_distance.dart+++ b/mobile/lib/services/machine_learning/face_ml/face_clustering/cosine_distance.dart@@ -67,3 +67,21 @@ double cosineDistForNormVectors(List<double> vector1, List<double> vector2) {}return 1.0 - dotProduct;}++/// NOTE: This function assumes that both embeddings are normalized!+@pragma("vm:prefer-inline")+double computeCosineSimilarity(+ List<double> embedding1,+ List<double> embedding2,+) {+ assert(+ embedding1.length == embedding2.length,+ "The two embeddings should have the same length",+ );+ double cosineSimilarity = 0;+ final length = embedding1.length;+ for (int index = 0; index < length; index++) {+ cosineSimilarity += embedding1[index] * embedding2[index];+ }+ return cosineSimilarity;+}diff --git a/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart b/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dartindex aade953f3b..1e39e722df 100644--- a/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart+++ b/mobile/lib/services/machine_learning/semantic_search/semantic_search_service.dart@@ -18,6 +18,7 @@ import "package:photos/events/machine_learning_control_event.dart";import "package:photos/models/embedding.dart";import "package:photos/models/file/file.dart";import "package:photos/services/collections_service.dart";+import "package:photos/services/machine_learning/face_ml/face_clustering/cosine_distance.dart";import 'package:photos/services/machine_learning/semantic_search/embedding_store.dart';import 'package:photos/services/machine_learning/semantic_search/frameworks/ggml.dart';import 'package:photos/services/machine_learning/semantic_search/frameworks/ml_framework.dart';@@ -504,22 +505,6 @@ List<QueryResult> computeBulkSimilarities(Map args) {return queryResults;}-double computeCosineSimilarity(- List<double> imageEmbedding,- List<double> textEmbedding,-) {- assert(- imageEmbedding.length == textEmbedding.length,- "The two embeddings should have the same length",- );- double cosineSimilarity = 0;- final length = imageEmbedding.length;- for (int index = 0; index < length; index++) {- cosineSimilarity += imageEmbedding[index] * textEmbedding[index];- }- return cosineSimilarity;-}-class QueryResult {final int id;final double score;