ente/lib/services/semantic_search/embedding_service.dart
2023-12-05 21:31:25 +05:30

17 lines
537 B
Dart

abstract class EmbeddingService {
Future<List<double>> getImageEmbedding(String imagePath);
Future<List<double>> getTextEmbedding(String text);
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;
}
}