Skip to content

armgit / ente

Public Imported from GitHub
0

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

Move score computation to app layer

vishnukvmddc16c52ff6cb
diff --git a/lib/services/semantic_search/semantic_search_service.dart b/lib/services/semantic_search/semantic_search_service.dart
index 42fef3b1ca..efe002aef1 100644
--- a/lib/services/semantic_search/semantic_search_service.dart
+++ b/lib/services/semantic_search/semantic_search_service.dart
@@ -303,7 +303,7 @@ List<QueryResult> computeBulkScore(Map args) {
final imageEmbeddings = args["imageEmbeddings"] as List<Embedding>;
final textEmbedding = args["textEmbedding"] as List<double>;
for (final imageEmbedding in imageEmbeddings) {
- final score = CLIP.computeScore(
+ final score = computeScore(
imageEmbedding.embedding,
textEmbedding,
);
@@ -316,6 +316,18 @@ List<QueryResult> computeBulkScore(Map args) {
return queryResults;
}
+double computeScore(List<double> imageEmbedding, List<double> textEmbedding) {
+ assert(
+ imageEmbedding.length == textEmbedding.length,
+ "The two embeddings should have the same length",
+ );
+ double score = 0;
+ for (int index = 0; index < imageEmbedding.length; index++) {
+ score += imageEmbedding[index] * textEmbedding[index];
+ }
+ return score;
+}
+
class QueryResult {
final int id;
final double score;