Skip to content

armgit / ente

Public Imported from GitHub
0

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

use search with keys in ml computer

laurenspriem5f4cf302a1d9
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_computer.dart b/mobile/apps/photos/lib/services/machine_learning/ml_computer.dart
index d89b5d5a4a..443cb5308b 100644
--- a/mobile/apps/photos/lib/services/machine_learning/ml_computer.dart
+++ b/mobile/apps/photos/lib/services/machine_learning/ml_computer.dart
@@ -50,6 +50,24 @@ class MLComputer extends SuperIsolate {
}
}
+ Future<(Uint64List, List<Uint64List>, List<Float32List>)>
+ bulkVectorSearchWithKeys(
+ Uint64List potentialKeys,
+ bool exact,
+ ) async {
+ try {
+ final result =
+ await runInIsolate(IsolateOperation.bulkVectorSearchWithKeys, {
+ "potentialKeys": potentialKeys,
+ "exact": exact,
+ });
+ return result;
+ } catch (e, s) {
+ _logger.severe("Could not run bulk vector search in MLComputer", e, s);
+ rethrow;
+ }
+ }
+
Future<List<double>> runClipText(String query) async {
try {
await _ensureLoadedClipTextModel();
diff --git a/mobile/apps/photos/lib/utils/isolate/isolate_operations.dart b/mobile/apps/photos/lib/utils/isolate/isolate_operations.dart
index 7ace292438..6deba3d97a 100644
--- a/mobile/apps/photos/lib/utils/isolate/isolate_operations.dart
+++ b/mobile/apps/photos/lib/utils/isolate/isolate_operations.dart
@@ -1,5 +1,6 @@
import 'dart:typed_data' show Uint8List, Float32List;
+import "package:flutter_rust_bridge/flutter_rust_bridge.dart" show Uint64List;
import "package:ml_linalg/linalg.dart";
import "package:photos/db/ml/clip_vector_db.dart";
import "package:photos/models/ml/face/box.dart";
@@ -45,6 +46,9 @@ enum IsolateOperation {
/// [MLComputer]
bulkVectorSearch,
+ /// [MLComputer]
+ bulkVectorSearchWithKeys,
+
/// [FaceClusteringService]
linearIncrementalClustering,
@@ -62,6 +66,17 @@ Future<dynamic> isolateFunction(
Map<String, dynamic> args,
) async {
switch (function) {
+ case IsolateOperation.bulkVectorSearchWithKeys:
+ await _ensureRustLoaded();
+ final potentialKeys = args["potentialKeys"] as Uint64List;
+ final exact = args["exact"] as bool;
+
+ return ClipVectorDB.instance.bulkSearchWithKeys(
+ potentialKeys,
+ BigInt.from(100),
+ exact: exact,
+ );
+
case IsolateOperation.bulkVectorSearch:
await _ensureRustLoaded();
final clipFloat32 = args["clipFloat32"] as List<Float32List>;