From 5f4cf302a1d9fa6c273e2e1b702b79d65debad4c Mon Sep 17 00:00:00 2001 From: laurenspriem Date: Tue, 12 Aug 2025 11:38:25 +0530 Subject: [PATCH] use search with keys in ml computer --- .../services/machine_learning/ml_computer.dart | 18 ++++++++++++++++++ .../lib/utils/isolate/isolate_operations.dart | 15 +++++++++++++++ 2 files changed, 33 insertions(+) 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, List)> + 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> 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 isolateFunction( Map 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;