use search with keys in ml computer

This commit is contained in:
laurenspriem
2025-08-12 11:38:25 +05:30
parent cb2b33eedb
commit 5f4cf302a1
2 changed files with 33 additions and 0 deletions

View File

@@ -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();

View File

@@ -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>;