π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Add Rust-backed ML DB behind rustMlDb flag
laurenspriem22527ffae05b
diff --git a/mobile/apps/photos/lib/db/ml/db.dart b/mobile/apps/photos/lib/db/ml/db.dartindex 5aa5405076..37a453e91a 100644--- a/mobile/apps/photos/lib/db/ml/db.dart+++ b/mobile/apps/photos/lib/db/ml/db.dart@@ -13,16 +13,19 @@ import "package:photos/db/ml/cluster_centroid_vector_db.dart";import "package:photos/db/ml/db_model_mappers.dart";import "package:photos/db/ml/db_pet_model_mappers.dart";import "package:photos/db/ml/ml_data_db_orchestration.dart";+import "package:photos/db/ml/rust_db.dart";import 'package:photos/db/ml/schema.dart';import "package:photos/models/ml/clip.dart";import "package:photos/models/ml/face/face.dart";import "package:photos/models/ml/face/face_with_embedding.dart";import "package:photos/models/ml/ml_versions.dart";import "package:photos/models/ml/vector.dart";+import "package:photos/service_locator.dart";import "package:photos/services/filedata/model/file_data.dart";import "package:photos/services/machine_learning/face_ml/face_clustering/face_db_info_for_clustering.dart";import 'package:photos/services/machine_learning/face_ml/face_filtering/face_filtering_constants.dart';import "package:photos/services/machine_learning/ml_result.dart";+import "package:photos/src/rust/api/ml_db_api.dart" show decideMlDbBackend;import "package:photos/utils/ml_util.dart";import 'package:sqlite_async/sqlite_async.dart';@@ -2187,7 +2190,24 @@ class DartMLDataDBclass MLDataDB {MLDataDB._();- static final IMLDataDB<int> instance = DartMLDataDB.instance;- static final IMLDataDB<int> localGalleryInstance =- DartMLDataDB.localGalleryInstance;+ static final Logger _logger = Logger("MLDataDB");+ static final bool _useRust = _decideBackend();++ static final IMLDataDB<int> instance = _useRust+ ? RustMLDataDB.instance+ : DartMLDataDB.instance;+ static final IMLDataDB<int> localGalleryInstance = _useRust+ ? RustMLDataDB.localGalleryInstance+ : DartMLDataDB.localGalleryInstance;++ static bool get isRustBackend => _useRust;++ static bool _decideBackend() {+ final wantsRust = flagService.rustMlDb || localSettings.rustMlDbOverride;+ final useRust = decideMlDbBackend(preferRust: wantsRust);+ _logger.info(+ "ML DB backend: ${useRust ? "rust" : "dart"} (wantsRust: $wantsRust)",+ );+ return useRust;+ }}diff --git a/mobile/apps/photos/lib/db/ml/rust_db.dart b/mobile/apps/photos/lib/db/ml/rust_db.dartnew file mode 100644index 0000000000..bc24ce0008--- /dev/null+++ b/mobile/apps/photos/lib/db/ml/rust_db.dart@@ -0,0 +1,887 @@+import "dart:convert";+import "dart:typed_data" hide Int64List;++import "package:flutter_rust_bridge/flutter_rust_bridge.dart" show Int64List;+import "package:logging/logging.dart";+import "package:path/path.dart" show join;+import "package:path_provider/path_provider.dart";+import "package:photos/db/common/base.dart";+import "package:photos/db/ml/base.dart";+import "package:photos/db/ml/clip_vector_db.dart";+import "package:photos/db/ml/cluster_centroid_vector_db.dart";+import "package:photos/db/ml/db_pet_model_mappers.dart";+import "package:photos/db/ml/ml_data_db_orchestration.dart";+import "package:photos/models/ml/clip.dart";+import "package:photos/models/ml/face/detection.dart";+import "package:photos/models/ml/face/face.dart";+import "package:photos/models/ml/face/face_with_embedding.dart";+import "package:photos/models/ml/ml_versions.dart";+import "package:photos/models/ml/vector.dart";+import "package:photos/services/filedata/model/file_data.dart";+import "package:photos/services/machine_learning/face_ml/face_clustering/face_db_info_for_clustering.dart";+import "package:photos/src/rust/api/ml_db_api.dart" as rust;+import "package:photos/utils/ml_util.dart";++class RustMLDataDB with MLDataDBOrchestration implements IMLDataDB<int> {+ static final Logger _logger = Logger("MLDataDB");++ final String _databaseName;+ final ClipVectorDB _clipVectorDB;+ final ClusterCentroidVectorDB _clusterCentroidVectorDB;+ final bool _isLocalGallery;++ RustMLDataDB._privateConstructor({+ String databaseName = "ente.ml.db",+ ClipVectorDB? clipVectorDB,+ ClusterCentroidVectorDB? clusterCentroidVectorDB,+ bool isLocalGallery = false,+ }) : _databaseName = databaseName,+ _clipVectorDB = clipVectorDB ?? ClipVectorDB.instance,+ _clusterCentroidVectorDB =+ clusterCentroidVectorDB ?? ClusterCentroidVectorDB.instance,+ _isLocalGallery = isLocalGallery;++ static final RustMLDataDB instance = RustMLDataDB._privateConstructor();+ static final RustMLDataDB localGalleryInstance =+ RustMLDataDB._privateConstructor(+ databaseName: "ente.ml.offline.db",+ clipVectorDB: ClipVectorDB.localGalleryInstance,+ clusterCentroidVectorDB: ClusterCentroidVectorDB.localGalleryInstance,+ isLocalGallery: true,+ );++ @override+ ClipVectorDB get clipVectorDB => _clipVectorDB;++ @override+ ClusterCentroidVectorDB get clusterCentroidVectorDB =>+ _clusterCentroidVectorDB;++ @override+ bool get isLocalGallery => _isLocalGallery;++ @override+ Logger get logger => _logger;++ Future<rust.MlDb>? _dbFuture;++ Future<rust.MlDb> get _db async {+ final future = _dbFuture ??= _openDatabase();+ try {+ return await future;+ } catch (e) {+ if (e is! DatabaseDowngradeError && identical(_dbFuture, future)) {+ _dbFuture = null;+ }+ rethrow;+ }+ }++ Future<rust.MlDb> _openDatabase() async {+ final documentsDirectory = await getApplicationDocumentsDirectory();+ final String path = join(documentsDirectory.path, _databaseName);+ _logger.info("Opening rust ML DB access: DB path $path");+ try {+ return await rust.MlDb.open(path: path);+ } on rust.MlDbError_Downgrade catch (e) {+ throw DatabaseDowngradeError(e.message);+ }+ }++ @override+ Future<void> bulkInsertFaces(List<Face> faces) async =>+ (await _db).bulkInsertFaces(faces: faces.map(_toFaceRow).toList());++ @override+ Future<void> bulkInsertPetFaces(List<DBPetFace> petFaces) async => (await _db)+ .bulkInsertPetFaces(petFaces: petFaces.map(_toPetFaceRow).toList());++ @override+ Future<void> bulkInsertPetBodies(List<DBPetBody> petBodies) async =>+ (await _db).bulkInsertPetBodies(+ petBodies: petBodies.map(_toPetBodyRow).toList(),+ );++ @override+ Future<void> updatePetFaceVectorIds(+ Map<String, int> petFaceIdToVectorId,+ ) async => (await _db).updatePetFaceVectorIds(+ petFaceIdToVectorId: petFaceIdToVectorId,+ );++ @override+ Future<void> updatePetBodyVectorIds(+ Map<String, int> petBodyIdToVectorId,+ ) async => (await _db).updatePetBodyVectorIds(+ petBodyIdToVectorId: petBodyIdToVectorId,+ );++ @override+ Future<Map<String, int>> getPetFaceVectorIdMap(+ Iterable<String> petFaceIds, {+ bool createIfMissing = false,+ }) async => (await _db).getPetFaceVectorIdMap(+ petFaceIds: petFaceIds.toList(),+ createIfMissing: createIfMissing,+ );++ @override+ Future<Map<String, int>> getPetBodyVectorIdMap(+ Iterable<String> petBodyIds, {+ bool createIfMissing = false,+ }) async => (await _db).getPetBodyVectorIdMap(+ petBodyIds: petBodyIds.toList(),+ createIfMissing: createIfMissing,+ );++ @override+ Future<void> updateFaceIdToClusterId(+ Map<String, String> faceIDToClusterID,+ ) async =>+ (await _db).updateFaceIdToClusterId(faceIdToClusterId: faceIDToClusterID);++ @override+ Future<Map<int, int>> faceIndexedFileIds({+ int minimumMlVersion = faceMlVersion,+ }) async =>+ (await _db).faceIndexedFileIds(minimumMlVersion: minimumMlVersion);++ @override+ Future<int> getFaceIndexedFileCount({+ int minimumMlVersion = faceMlVersion,+ }) async =>+ (await _db).getFaceIndexedFileCount(minimumMlVersion: minimumMlVersion);++ @override+ Future<Map<String, int>> clusterIdToFaceCount() async =>+ (await _db).clusterIdToFaceCount();++ @override+ Future<Set<String>> getBadFaceSingletonClusterIDs() async =>+ (await _db).getBadFaceSingletonClusterIds();++ @override+ Future<Set<String>> getClustersWithThreeOrMoreNotPersonFeedback() async =>+ (await _db).getClustersWithThreeOrMoreNotPersonFeedback();++ @override+ Future<Set<String>> getPersonIgnoredClusters(String personID) async =>+ (await _db).getPersonIgnoredClusters(personId: personID);++ @override+ Future<Map<String, Set<String>>> getPersonToRejectedSuggestions() async =>+ (await _db).getPersonToRejectedSuggestions();++ @override+ Future<Set<String>> getPersonClusterIDs(String personID) async =>+ (await _db).getPersonClusterIds(personId: personID);++ @override+ Future<Set<String>> getPersonsClusterIDs(List<String> personID) async =>+ (await _db).getPersonsClusterIds(personIds: personID);++ @override+ Future<void> clearNonPetTables() async => (await _db).clearNonPetTables();++ @override+ Future<void> clearPetTables() async => (await _db).clearPetTables();++ @override+ Future<Iterable<Uint8List>> getFaceEmbeddingsForCluster(+ String clusterID, {+ int? limit,+ }) async => (await _db).getFaceEmbeddingsForCluster(+ clusterId: clusterID,+ limit: limit,+ );++ @override+ Future<Map<String, Iterable<Uint8List>>> getFaceEmbeddingsForClusters(+ Iterable<String> clusterIDs, {+ int? limit,+ }) async => (await _db).getFaceEmbeddingsForClusters(+ clusterIds: clusterIDs.toList(),+ limit: limit,+ );++ @override+ Future<Face?> getCoverFaceForPerson({+ required int recentFileID,+ String? personID,+ String? avatarFaceId,+ String? clusterID,+ }) async {+ final db = await _db;+ final row = await db.getCoverFaceForPerson(+ recentFileId: recentFileID,+ personId: personID,+ avatarFaceId: avatarFaceId,+ clusterId: clusterID,+ );+ return row == null ? null : _toFace(row);+ }++ @override+ Future<List<Face>?> getFacesForGivenFileID(int fileUploadID) async {+ final db = await _db;+ final rows = await db.getFacesForGivenFileId(fileUploadId: fileUploadID);+ return rows.isEmpty ? null : rows.map(_toFace).toList();+ }++ @override+ Future<List<DBPetFace>?> getPetFacesForFileID(int fileUploadID) async {+ final db = await _db;+ final rows = await db.getPetFacesForFileId(fileUploadId: fileUploadID);+ return rows.isEmpty ? null : rows.map(_toDBPetFace).toList();+ }++ @override+ Future<List<DBPetBody>?> getPetBodiesForFileID(int fileUploadID) async {+ final db = await _db;+ final rows = await db.getPetBodiesForFileId(fileUploadId: fileUploadID);+ return rows.isEmpty ? null : rows.map(_toDBPetBody).toList();+ }++ @override+ Future<Map<int, List<FaceWithoutEmbedding>>>+ getFileIDsToFacesWithoutEmbedding() async {+ final db = await _db;+ final rows = await db.getFileIdsToFacesWithoutEmbedding();+ return rows.map(+ (fileID, faces) =>+ MapEntry(fileID, faces.map(_toFaceWithoutEmbedding).toList()),+ );+ }++ @override+ Future<Map<String, Iterable<String>>> getClusterToFaceIDs(+ Set<String> clusterIDs,+ ) async => (await _db).getClusterToFaceIds(clusterIds: clusterIDs);++ @override+ Future<String?> getClusterIDForFaceID(String faceID) async =>+ (await _db).getClusterIdForFaceId(faceId: faceID);++ @override+ Future<Map<String, Iterable<String>>> getAllClusterIdToFaceIDs() async =>+ (await _db).getAllClusterIdToFaceIds();++ @override+ Future<Iterable<String>> getFaceIDsForCluster(String clusterID) async =>+ (await _db).getFaceIdsForCluster(clusterId: clusterID);++ @override+ Future<List<String>> getFaceIDsForClusterOrderedByScore(+ String clusterID, {+ int limit = 10,+ }) async => (await _db).getFaceIdsForClusterOrderedByScore(+ clusterId: clusterID,+ limit: limit,+ );++ @override+ Future<Map<String, Map<String, Set<String>>>>+ getPersonToClusterIdToFaceIds() async =>+ (await _db).getPersonToClusterIdToFaceIds();++ @override+ Future<Map<String, Set<String>>> getPersonToClusterIDs() async =>+ (await _db).getPersonToClusterIds();++ @override+ Future<Map<String, String>> getFaceIdToPersonIdForFaces(+ Iterable<String> faceIDs,+ ) async => (await _db).getFaceIdToPersonIdForFaces(faceIds: faceIDs.toList());++ @override+ Future<Map<String, Set<String>>> getClusterIdToFaceIdsForPerson(+ String personID,+ ) async => (await _db).getClusterIdToFaceIdsForPerson(personId: personID);++ @override+ Future<Set<String>> getFaceIDsForPerson(String personID) async =>+ (await _db).getFaceIdsForPerson(personId: personID);++ @override+ Future<List<String>> getFaceIDsForPersonOrderedByScore(+ String personID, {+ int limit = 10,+ }) async => (await _db).getFaceIdsForPersonOrderedByScore(+ personId: personID,+ limit: limit,+ );++ @override+ Future<Iterable<double>> getBlurValuesForCluster(String clusterID) async =>+ (await _db).getBlurValuesForCluster(clusterId: clusterID);++ @override+ Future<Map<String, String?>> getFaceIdsToClusterIds(+ Iterable<String> faceIds,+ ) async => (await _db).getFaceIdsToClusterIds(faceIds: faceIds.toList());++ @override+ Future<Map<int, Set<String>>> getFileIdToClusterIds() async =>+ (await _db).getFileIdToClusterIds();++ @override+ Future<void> forceUpdateClusterIds(+ Map<String, String> faceIDToClusterID,+ ) async =>+ (await _db).forceUpdateClusterIds(faceIdToClusterId: faceIDToClusterID);++ @override+ Future<void> removeFaceIdToClusterId(+ Map<String, String> faceIDToClusterID,+ ) async =>+ (await _db).removeFaceIdToClusterId(faceIdToClusterId: faceIDToClusterID);++ @override+ Future<void> removePerson(String personID) async =>+ (await _db).removePerson(personId: personID);++ @override+ Future<List<FaceDbInfoForClustering>> getFaceInfoForClustering({+ int maxFaces = 20000,+ int offset = 0,+ int batchSize = 10000,+ }) async {+ final db = await _db;+ final rows = await db.getFaceInfoForClustering(+ maxFaces: maxFaces,+ offset: offset,+ batchSize: batchSize,+ );+ return rows.map(_toFaceDbInfoForClustering).toList();+ }++ @override+ Future<Map<String, Uint8List>> getFaceEmbeddingMapForFaces(+ Iterable<String> faceIDs,+ ) async {+ final db = await _db;+ final rows = await db.getFaceEmbeddingRowsForFaces(+ faceIds: faceIDs.toList(),+ );+ return {for (final (faceID, embedding) in rows) faceID: embedding};+ }++ @override+ Future<int> getTotalFaceCount() async => (await _db).getTotalFaceCount();++ @override+ Future<int> getErroredFaceCount() async => (await _db).getErroredFaceCount();++ @override+ Future<Set<int>> getErroredFileIDs() async => (await _db).getErroredFileIds();++ @override+ Future<void> pruneResolvedFaceErrorResults(List<int> fileIDs) async =>+ (await _db).pruneResolvedFaceErrorResults(+ fileIds: Int64List.fromList(fileIDs),+ );++ @override+ Future<Set<int>> getFileIDsWithErrorResults(List<int> fileIDs) async =>+ (await _db).getFileIdsWithErrorResults(+ fileIds: Int64List.fromList(fileIDs),+ );++ @override+ Future<void> deleteFaceIndexForFiles(List<int> fileIDs) async =>+ (await _db).deleteFaceIndexForFiles(fileIds: Int64List.fromList(fileIDs));++ @override+ Future<void> deleteUnclusteredFaceIndexForFiles(List<int> fileIDs) async =>+ (await _db).deleteUnclusteredFaceIndexForFiles(+ fileIds: Int64List.fromList(fileIDs),+ );++ @override+ Future<int> getClusteredOrFacelessFileCount() async =>+ (await _db).getClusteredOrFacelessFileCount();++ @override+ Future<double> getClusteredToIndexableFilesRatio() async {+ final int indexableFiles = await getIndexableFileCount();+ final int clusteredFiles = await getClusteredOrFacelessFileCount();++ return clusteredFiles / indexableFiles;+ }++ @override+ Future<int> getUnclusteredFaceCount() async =>+ (await _db).getUnclusteredFaceCount();++ @override+ Future<void> assignClusterToPerson({+ required String personID,+ required String clusterID,+ }) async => (await _db).assignClusterToPerson(+ personId: personID,+ clusterId: clusterID,+ );++ @override+ Future<void> bulkAssignClusterToPersonID(+ Map<String, String> clusterToPersonID,+ ) async => (await _db).bulkAssignClusterToPersonId(+ clusterToPersonId: clusterToPersonID,+ );++ @override+ Future<void> captureNotPersonFeedback({+ required String personID,+ required String clusterID,+ }) async => (await _db).captureNotPersonFeedback(+ personId: personID,+ clusterId: clusterID,+ );++ @override+ Future<void> bulkCaptureNotPersonFeedback(+ Map<String, String> clusterToPersonID,+ ) async => (await _db).bulkCaptureNotPersonFeedback(+ clusterToPersonId: clusterToPersonID,+ );++ @override+ Future<void> removeNotPersonFeedback({+ required String personID,+ required String clusterID,+ }) async => (await _db).removeNotPersonFeedback(+ personId: personID,+ clusterId: clusterID,+ );++ @override+ Future<void> removeClusterToPerson({+ required String personID,+ required String clusterID,+ }) async => (await _db).removeClusterToPerson(+ personId: personID,+ clusterId: clusterID,+ );++ @override+ Future<Map<int, Set<String>>> getFileIdToClusterIDSet(+ String personID,+ ) async => (await _db).getFileIdToClusterIdSet(personId: personID);++ @override+ Future<Map<int, Set<String>>> getFileIdToClusterIDSetForCluster(+ Set<String> clusterIDs,+ ) async =>+ (await _db).getFileIdToClusterIdSetForCluster(clusterIds: clusterIDs);++ @override+ Future<Map<String, int>> getClusterCentroidVectorIdMap(+ Iterable<String> clusterIDs, {+ bool createIfMissing = false,+ }) async => (await _db).getClusterCentroidVectorIdMap(+ clusterIds: clusterIDs.toList(),+ createIfMissing: createIfMissing,+ );++ @override+ Future<void> deleteClusterCentroidVectorIdMapping(String clusterID) async =>+ (await _db).deleteClusterCentroidVectorIdMapping(clusterId: clusterID);++ @override+ Future<void> clearClusterCentroidVectorIdMappings() async =>+ (await _db).clearClusterCentroidVectorIdMappings();++ @override+ Future<void> upsertClusterSummaryRows(+ Map<String, (Uint8List, int)> summary,+ ) async => (await _db).upsertClusterSummaryRows(+ summary: summary.map(+ (clusterID, value) => MapEntry(clusterID, _toClusterSummaryRow(value)),+ ),+ );++ @override+ Future<void> deleteClusterSummaryRow(String clusterID) async =>+ (await _db).deleteClusterSummaryRow(clusterId: clusterID);++ @override+ Future<Map<String, (Uint8List, int)>> getAllClusterSummary([+ int? minClusterSize,+ ]) async {+ final db = await _db;+ final rows = await db.getAllClusterSummary(minClusterSize: minClusterSize);+ return rows.map(+ (clusterID, summary) =>+ MapEntry(clusterID, _toClusterSummaryRecord(summary)),+ );+ }++ @override+ Future<Map<String, (Uint8List, int)>> getClusterToClusterSummary(+ Iterable<String> clusterIDs,+ ) async {+ final db = await _db;+ final rows = await db.getClusterToClusterSummary(+ clusterIds: clusterIDs.toList(),+ );+ return rows.map(+ (clusterID, summary) =>+ MapEntry(clusterID, _toClusterSummaryRecord(summary)),+ );+ }++ @override+ Future<Map<String, String>> getClusterIDToPersonID() async =>+ (await _db).getClusterIdToPersonId();++ @override+ Future<void> resetClusterTables({required bool faces}) async =>+ (await _db).resetClusterTables(faces: faces);++ @override+ Future<void> dropFacesFeedbackTables() async {+ try {+ final db = await _db;+ await db.dropFacesFeedbackTables();+ } catch (e) {+ _logger.severe('Error dropping feedback tables', e);+ }+ }++ @override+ Future<List<int>> getFileIDsOfPersonID(String personID) async {+ final db = await _db;+ final fileIDs = await db.getFileIdsOfPersonId(personId: personID);+ return fileIDs.inner.toList();+ }++ @override+ Future<List<int>> getFileIDsOfClusterID(String clusterID) async {+ final db = await _db;+ final fileIDs = await db.getFileIdsOfClusterId(clusterId: clusterID);+ return fileIDs.inner.toList();+ }++ @override+ Future<Set<int>> getAllFileIDsOfFaceIDsNotInAnyCluster() async =>+ (await _db).getAllFileIdsOfFaceIdsNotInAnyCluster();++ @override+ Future<Set<int>> getAllFilesAssociatedWithAllClusters({+ List<String>? exceptClusters,+ }) async => (await _db).getAllFilesAssociatedWithAllClusters(+ exceptClusters: exceptClusters,+ );++ @override+ Future<List<EmbeddingVector>> getAllClipVectors() async {+ final db = await _db;+ final rows = await db.getAllClipVectors();+ return rows.map(_toEmbeddingVector).toList();+ }++ @override+ Future<int> countClusterSummaries() async =>+ (await _db).countClusterSummaries();++ @override+ Future<List<(String, Uint8List)>> getClusterSummaryPage({+ String? beforeClusterID,+ required int limit,+ }) async {+ final db = await _db;+ final rows = await db.getClusterSummaryPage(+ beforeClusterId: beforeClusterID,+ limit: limit,+ );+ return [for (final row in rows) (row.clusterId, row.avg)];+ }++ @override+ Future<int> countClipRows() async => (await _db).countClipRows();++ @override+ Future<List<(int, Uint8List)>> getClipRowsPage({+ required int limit,+ required int offset,+ }) async {+ final db = await _db;+ final rows = await db.getClipRowsPage(limit: limit, offset: offset);+ return [for (final row in rows) (row.fileId, row.embedding)];+ }++ @override+ Future<Map<int, int>> clipIndexedFileWithVersion() async =>+ (await _db).clipIndexedFileWithVersion();++ @override+ Future<int> getClipIndexedFileCount({+ int minimumMlVersion = clipMlVersion,+ }) async =>+ (await _db).getClipIndexedFileCount(minimumMlVersion: minimumMlVersion);++ @override+ Future<int> getClipVectorizableFileCount({+ int minimumMlVersion = clipMlVersion,+ }) async => (await _db).getClipVectorizableFileCount(+ minimumMlVersion: minimumMlVersion,+ );++ @override+ Future<Map<int, int>> petIndexedFileIds({+ int minimumMlVersion = petMlVersion,+ }) async => (await _db).petIndexedFileIds(minimumMlVersion: minimumMlVersion);++ @override+ Future<int> getPetIndexedFileCount({+ int minimumMlVersion = petMlVersion,+ }) async =>+ (await _db).getPetIndexedFileCount(minimumMlVersion: minimumMlVersion);++ @override+ Future<Set<int>> getFullyIndexedFileIds({required bool includePets}) async =>+ (await _db).getFullyIndexedFileIds(includePets: includePets);++ @override+ Future<(List<(String, int?, int)>, List<(String, int?, int)>)>+ getPetRowsForFiles(List<int> fileIDs) async {+ final db = await _db;+ final rows = await db.getPetRowsForFiles(+ fileIds: Int64List.fromList(fileIDs),+ );+ return (+ [+ for (final row in rows.faces)+ (row.petFaceId, row.faceVectorId, row.species),+ ],+ [+ for (final row in rows.bodies)+ (row.petBodyId, row.bodyVectorId, row.species),+ ],+ );+ }++ @override+ Future<void> deletePetRowsForFiles({+ required List<int> fileIDs,+ required List<String> petFaceIds,+ required List<String> petBodyIds,+ }) async => (await _db).deletePetRowsForFiles(+ fileIds: Int64List.fromList(fileIDs),+ petFaceIds: petFaceIds,+ petBodyIds: petBodyIds,+ );++ @override+ Future<void> insertClipRows(List<ClipEmbedding> embeddings) async =>+ (await _db).insertClipRows(+ embeddings: embeddings.map(_toClipEmbeddingRow).toList(),+ );++ @override+ Future<void> putRepeatedTextEmbeddingCache(+ String query,+ List<double> embedding,+ ) async => (await _db).putRepeatedTextEmbeddingCache(+ query: query,+ embedding: embedding,+ );++ @override+ Future<List<double>?> getRepeatedTextEmbeddingCache(String query) async =>+ (await _db).getRepeatedTextEmbeddingCache(query: query);++ @override+ Future<void> deleteClipRows(List<int> fileIDs) async =>+ (await _db).deleteClipRows(fileIds: Int64List.fromList(fileIDs));++ @override+ Future<void> deleteAllClipRows() async => (await _db).deleteAllClipRows();++ @override+ Future<void> putFaceIdCachedForPersonOrCluster(+ String personOrClusterId,+ String faceID,+ ) async => (await _db).putFaceIdCachedForPersonOrCluster(+ personOrClusterId: personOrClusterId,+ faceId: faceID,+ );++ @override+ Future<String?> getFaceIdUsedForPersonOrCluster(+ String personOrClusterId,+ ) async => (await _db).getFaceIdUsedForPersonOrCluster(+ personOrClusterId: personOrClusterId,+ );++ @override+ Future<void> removeFaceIdCachedForPersonOrCluster(+ String personOrClusterID,+ ) async => (await _db).removeFaceIdCachedForPersonOrCluster(+ personOrClusterId: personOrClusterID,+ );++ @override+ Future<Set<String>> getClustersForMemoryLane(Set<String> assigned) async =>+ (await _db).getClustersForMemoryLane(assigned: assigned);++ @override+ Future<void> putFDStatus(List<FDStatus> fdStatusList) async => (await _db)+ .putFdStatus(fdStatusList: fdStatusList.map(_toFdStatusRow).toList());++ @override+ Future<Map<int, PreviewInfo>> getFileIDsVidPreview() async {+ final db = await _db;+ final rows = await db.getFileIdsVidPreview();+ return rows.map((fileID, info) => MapEntry(fileID, _toPreviewInfo(info)));+ }++ @override+ Future<Set<int>> getFileIDsWithFDData({DataType? type}) async =>+ (await _db).getFileIdsWithFdData(dataType: type?.toJson());+}++rust.FaceRow _toFaceRow(Face face) {+ return rust.FaceRow(+ fileId: face.fileID,+ faceId: face.faceID,+ detectionJson: json.encode(face.detection.toJson()),+ embedding: Float64List.fromList(face.embedding),+ score: face.score,+ blur: face.blur,+ isSideways: face.detection.faceIsSideways(),+ imageHeight: face.fileInfo?.imageHeight ?? 0,+ imageWidth: face.fileInfo?.imageWidth ?? 0,+ mlVersion: faceMlVersion,+ );+}++Face _toFace(rust.FaceRow row) {+ return Face(+ row.faceId,+ row.fileId,+ row.embedding,+ row.score,+ Detection.fromJson(json.decode(row.detectionJson) as Map<String, dynamic>),+ row.blur,+ fileInfo: FileInfo(+ imageWidth: row.imageWidth,+ imageHeight: row.imageHeight,+ ),+ );+}++FaceWithoutEmbedding _toFaceWithoutEmbedding(rust.FaceWithoutEmbedding row) {+ return FaceWithoutEmbedding(+ row.faceId,+ row.fileId,+ row.score,+ Detection.fromJson(json.decode(row.detectionJson) as Map<String, dynamic>),+ row.blur,+ );+}++FaceDbInfoForClustering _toFaceDbInfoForClustering(+ rust.FaceDbInfoForClustering row,+) {+ return FaceDbInfoForClustering(+ faceID: row.faceId,+ clusterId: row.clusterId,+ embeddingBytes: row.embeddingBytes,+ faceScore: row.faceScore,+ blurValue: row.blurValue,+ isSideways: row.isSideways,+ );+}++rust.PetFaceRow _toPetFaceRow(DBPetFace petFace) {+ return rust.PetFaceRow(+ fileId: petFace.fileId,+ petFaceId: petFace.petFaceId,+ detectionJson: petFace.detection,+ faceVectorId: petFace.faceVectorId,+ species: petFace.species,+ faceScore: petFace.faceScore,+ imageHeight: petFace.imageHeight,+ imageWidth: petFace.imageWidth,+ mlVersion: petFace.mlVersion,+ );+}++DBPetFace _toDBPetFace(rust.PetFaceRow row) {+ return DBPetFace(+ fileId: row.fileId,+ petFaceId: row.petFaceId,+ detection: row.detectionJson,+ faceVectorId: row.faceVectorId,+ species: row.species,+ faceScore: row.faceScore,+ imageHeight: row.imageHeight,+ imageWidth: row.imageWidth,+ mlVersion: row.mlVersion,+ );+}++rust.PetBodyRow _toPetBodyRow(DBPetBody petBody) {+ return rust.PetBodyRow(+ fileId: petBody.fileId,+ petBodyId: petBody.petBodyId,+ detectionJson: petBody.detection,+ bodyVectorId: petBody.bodyVectorId,+ species: petBody.species,+ score: petBody.score,+ imageHeight: petBody.imageHeight,+ imageWidth: petBody.imageWidth,+ mlVersion: petBody.mlVersion,+ );+}++DBPetBody _toDBPetBody(rust.PetBodyRow row) {+ return DBPetBody(+ fileId: row.fileId,+ petBodyId: row.petBodyId,+ detection: row.detectionJson,+ bodyVectorId: row.bodyVectorId,+ species: row.species,+ score: row.score,+ imageHeight: row.imageHeight,+ imageWidth: row.imageWidth,+ mlVersion: row.mlVersion,+ );+}++rust.ClipEmbedding _toClipEmbeddingRow(ClipEmbedding embedding) {+ return rust.ClipEmbedding(+ fileId: embedding.fileID,+ embedding: Float64List.fromList(embedding.embedding),+ version: embedding.version,+ );+}++EmbeddingVector _toEmbeddingVector(rust.EmbeddingVector vector) {+ return EmbeddingVector(fileID: vector.fileId, embedding: vector.embedding);+}++rust.ClusterSummary _toClusterSummaryRow((Uint8List, int) summary) {+ return rust.ClusterSummary(avg: summary.$1, count: summary.$2);+}++(Uint8List, int) _toClusterSummaryRecord(rust.ClusterSummary summary) {+ return (summary.avg, summary.count);+}++rust.FdStatus _toFdStatusRow(FDStatus status) {+ return rust.FdStatus(+ fileId: status.fileID,+ userId: status.userID,+ dataType: status.type,+ size: status.size,+ objectId: status.objectID,+ objectNonce: status.objectNonce,+ updatedAt: status.updatedAt,+ );+}++PreviewInfo _toPreviewInfo(rust.PreviewInfo info) {+ return PreviewInfo(objectId: info.objectId, objectSize: info.objectSize);+}diff --git a/mobile/apps/photos/lib/settings/local_settings.dart b/mobile/apps/photos/lib/settings/local_settings.dartindex 9ee733bef3..9c3601c852 100644--- a/mobile/apps/photos/lib/settings/local_settings.dart+++ b/mobile/apps/photos/lib/settings/local_settings.dart@@ -110,6 +110,7 @@ class LocalSettings {"ml_debug.run_ml_during_interaction";static const _kSemanticSearchExactInRustEnabled ="ml_debug.semantic_search_exact_in_rust";+ static const _kRustMlDbOverride = "ls.rust_ml_db_override";static const _kAppMode = "ls.app_mode";static const _kShowLocalGalleryModeOption = "ls.show_offline_mode_option";static const _kDeletePreference = "delete_preference";@@ -408,6 +409,12 @@ class LocalSettings {await _prefs.setBool(_kSemanticSearchExactInRustEnabled, value);}+ bool get rustMlDbOverride => _prefs.getBool(_kRustMlDbOverride) ?? false;++ Future<void> setRustMlDbOverride(bool value) async {+ await _prefs.setBool(_kRustMlDbOverride, value);+ }+Future<bool> setSmartMemories(bool value) async {await _prefs.setBool(kCuratedMemoriesEnabled, value);return value;diff --git a/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dart b/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dartindex b1b3f7d9cd..67e0ac45e6 100644--- a/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dart+++ b/mobile/apps/photos/lib/ui/settings/debug/ml_debug_settings_page.dart@@ -213,6 +213,18 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {onChanged: _onSemanticSearchExactChanged,),),+ MenuItemWidgetNew(+ title: "Rust ML DB",+ subText: "Active: ${MLDataDB.isRustBackend ? "rust" : "dart"}",+ leadingIconWidget: _buildIconWidget(+ context,+ HugeIcons.strokeRoundedDatabase,+ ),+ trailingWidget: ToggleSwitchWidget(+ value: () => localSettings.rustMlDbOverride,+ onChanged: _onRustMlDbChanged,+ ),+ ),],);}@@ -775,6 +787,27 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {}}+ Future<void> _onRustMlDbChanged() async {+ try {+ final enabled = !localSettings.rustMlDbOverride;+ await localSettings.setRustMlDbOverride(enabled);+ logger.info('Rust ML DB override is turned ${enabled ? 'on' : 'off'}');+ if (!mounted) return;+ setState(() {});+ showShortToast(+ context,+ enabled+ ? "Rust ML DB enabled. Restart app."+ : "Rust ML DB disabled. Restart app.",+ );+ } catch (e, s) {+ logger.warning('Rust ML DB toggle failed ', e, s);+ if (mounted) {+ await showGenericErrorDialog(context: context, error: e);+ }+ }+ }+Future<void> _onTriggerRunML(BuildContext context) async {try {MLService.instance.debugIndexingDisabled = false;diff --git a/mobile/packages/feature_flag/lib/src/flag_service.dart b/mobile/packages/feature_flag/lib/src/flag_service.dartindex 8dd44c3758..9428a2f1b3 100644--- a/mobile/packages/feature_flag/lib/src/flag_service.dart+++ b/mobile/packages/feature_flag/lib/src/flag_service.dart@@ -83,6 +83,11 @@ class FlagService {bool get usearchForSuggestions => true;+ // Kept false until the heavy ML DB queries no longer round-trip data between+ // Rust and Dart. Then internal users; then everyone, once no heavy queries+ // run in Dart at all and internal users have soaked it for a while.+ bool get rustMlDb => false;+String get castUrl => flags.castUrl;String get customDomain => flags.customDomain;diff --git a/rust/bindings/frb/photos/src/api/ml_db_api.rs b/rust/bindings/frb/photos/src/api/ml_db_api.rsnew file mode 100644index 0000000000..60a87eed58--- /dev/null+++ b/rust/bindings/frb/photos/src/api/ml_db_api.rs@@ -0,0 +1,838 @@+use std::collections::{HashMap, HashSet};+use std::sync::OnceLock;++use ente_photos::db;+use ente_photos::ml_db;+pub use ente_photos::ml_db::{+ ClipEmbedding, ClipRow, ClusterCentroidRow, ClusterSummary, EmbeddingVector,+ FaceDbInfoForClustering, FaceRow, FaceWithoutEmbedding, FdStatus, PetBodyRow, PetBodyVectorRow,+ PetFaceRow, PetFaceVectorRow, PetRowsForFiles, PreviewInfo,+};+use flutter_rust_bridge::frb;++static BACKEND: OnceLock<bool> = OnceLock::new();++#[frb(sync)]+pub fn decide_ml_db_backend(prefer_rust: bool) -> bool {+ *BACKEND.get_or_init(|| prefer_rust)+}++#[frb]+pub enum MlDbError {+ Downgrade { message: String },+ Other { message: String },+}++impl From<ml_db::Error> for MlDbError {+ fn from(error: ml_db::Error) -> Self {+ let message = ente_core::error::chain(&error);+ match error {+ ml_db::Error::Database(db::Error::Downgrade { .. }) => Self::Downgrade { message },+ _ => Self::Other { message },+ }+ }+}++#[frb(mirror(FaceRow))]+pub struct _FaceRow {+ pub file_id: i64,+ pub face_id: String,+ pub detection_json: String,+ pub embedding: Vec<f64>,+ pub score: f64,+ pub blur: f64,+ pub is_sideways: bool,+ pub image_height: i64,+ pub image_width: i64,+ pub ml_version: i64,+}++#[frb(mirror(FaceWithoutEmbedding))]+pub struct _FaceWithoutEmbedding {+ pub face_id: String,+ pub file_id: i64,+ pub score: f64,+ pub detection_json: String,+ pub blur: f64,+}++#[frb(mirror(FaceDbInfoForClustering))]+pub struct _FaceDbInfoForClustering {+ pub face_id: String,+ pub cluster_id: Option<String>,+ pub embedding_bytes: Vec<u8>,+ pub face_score: f64,+ pub blur_value: f64,+ pub is_sideways: bool,+}++#[frb(mirror(PetFaceRow))]+pub struct _PetFaceRow {+ pub file_id: i64,+ pub pet_face_id: String,+ pub detection_json: String,+ pub face_vector_id: Option<i64>,+ pub species: i64,+ pub face_score: f64,+ pub image_height: i64,+ pub image_width: i64,+ pub ml_version: i64,+}++#[frb(mirror(PetBodyRow))]+pub struct _PetBodyRow {+ pub file_id: i64,+ pub pet_body_id: String,+ pub detection_json: String,+ pub body_vector_id: Option<i64>,+ pub species: i64,+ pub score: f64,+ pub image_height: i64,+ pub image_width: i64,+ pub ml_version: i64,+}++#[frb(mirror(PetFaceVectorRow))]+pub struct _PetFaceVectorRow {+ pub pet_face_id: String,+ pub face_vector_id: Option<i64>,+ pub species: i64,+}++#[frb(mirror(PetBodyVectorRow))]+pub struct _PetBodyVectorRow {+ pub pet_body_id: String,+ pub body_vector_id: Option<i64>,+ pub species: i64,+}++#[frb(mirror(PetRowsForFiles))]+pub struct _PetRowsForFiles {+ pub faces: Vec<PetFaceVectorRow>,+ pub bodies: Vec<PetBodyVectorRow>,+}++#[frb(mirror(ClipEmbedding))]+pub struct _ClipEmbedding {+ pub file_id: i64,+ pub embedding: Vec<f64>,+ pub version: i64,+}++#[frb(mirror(EmbeddingVector))]+pub struct _EmbeddingVector {+ pub file_id: i64,+ pub embedding: Vec<f32>,+}++#[frb(mirror(ClipRow))]+pub struct _ClipRow {+ pub file_id: i64,+ pub embedding: Vec<u8>,+}++#[frb(mirror(ClusterSummary))]+pub struct _ClusterSummary {+ pub avg: Vec<u8>,+ pub count: i64,+}++#[frb(mirror(ClusterCentroidRow))]+pub struct _ClusterCentroidRow {+ pub cluster_id: String,+ pub avg: Vec<u8>,+}++#[frb(mirror(FdStatus))]+pub struct _FdStatus {+ pub file_id: i64,+ pub user_id: i64,+ pub data_type: String,+ pub size: i64,+ pub object_id: Option<String>,+ pub object_nonce: Option<String>,+ pub updated_at: i64,+}++#[frb(mirror(PreviewInfo))]+pub struct _PreviewInfo {+ pub object_id: String,+ pub object_size: i64,+}++#[frb(opaque)]+pub struct MlDb {+ inner: ml_db::MlDb,+}++impl MlDb {+ pub fn open(path: String) -> Result<MlDb, MlDbError> {+ Ok(Self {+ inner: ml_db::MlDb::open(path)?,+ })+ }++ pub fn clear_non_pet_tables(&self) -> Result<(), MlDbError> {+ Ok(self.inner.clear_non_pet_tables()?)+ }++ pub fn clear_pet_tables(&self) -> Result<(), MlDbError> {+ Ok(self.inner.clear_pet_tables()?)+ }++ pub fn bulk_insert_faces(&self, faces: Vec<FaceRow>) -> Result<(), MlDbError> {+ Ok(self.inner.bulk_insert_faces(&faces)?)+ }++ pub fn face_indexed_file_ids(+ &self,+ minimum_ml_version: i64,+ ) -> Result<HashMap<i64, i64>, MlDbError> {+ Ok(self.inner.face_indexed_file_ids(minimum_ml_version)?)+ }++ pub fn get_face_indexed_file_count(&self, minimum_ml_version: i64) -> Result<i64, MlDbError> {+ Ok(self.inner.get_face_indexed_file_count(minimum_ml_version)?)+ }++ pub fn get_face_embeddings_for_cluster(+ &self,+ cluster_id: String,+ limit: Option<i64>,+ ) -> Result<Vec<Vec<u8>>, MlDbError> {+ Ok(self+ .inner+ .get_face_embeddings_for_cluster(&cluster_id, limit)?)+ }++ pub fn get_face_embeddings_for_clusters(+ &self,+ cluster_ids: Vec<String>,+ limit: Option<i64>,+ ) -> Result<HashMap<String, Vec<Vec<u8>>>, MlDbError> {+ Ok(self+ .inner+ .get_face_embeddings_for_clusters(&cluster_ids, limit)?)+ }++ pub fn get_cover_face_for_person(+ &self,+ recent_file_id: i64,+ person_id: Option<String>,+ avatar_face_id: Option<String>,+ cluster_id: Option<String>,+ ) -> Result<Option<FaceRow>, MlDbError> {+ Ok(self.inner.get_cover_face_for_person(+ recent_file_id,+ person_id.as_deref(),+ avatar_face_id.as_deref(),+ cluster_id.as_deref(),+ )?)+ }++ pub fn get_faces_for_given_file_id(+ &self,+ file_upload_id: i64,+ ) -> Result<Vec<FaceRow>, MlDbError> {+ Ok(self.inner.get_faces_for_given_file_id(file_upload_id)?)+ }++ pub fn get_file_ids_to_faces_without_embedding(+ &self,+ ) -> Result<HashMap<i64, Vec<FaceWithoutEmbedding>>, MlDbError> {+ Ok(self.inner.get_file_ids_to_faces_without_embedding()?)+ }++ pub fn get_face_info_for_clustering(+ &self,+ max_faces: i64,+ offset: i64,+ batch_size: i64,+ ) -> Result<Vec<FaceDbInfoForClustering>, MlDbError> {+ Ok(self+ .inner+ .get_face_info_for_clustering(max_faces, offset, batch_size)?)+ }++ pub fn get_face_embedding_rows_for_faces(+ &self,+ face_ids: Vec<String>,+ ) -> Result<Vec<(String, Vec<u8>)>, MlDbError> {+ Ok(self.inner.get_face_embedding_rows_for_faces(&face_ids)?)+ }++ pub fn get_total_face_count(&self) -> Result<i64, MlDbError> {+ Ok(self.inner.get_total_face_count()?)+ }++ pub fn get_errored_face_count(&self) -> Result<i64, MlDbError> {+ Ok(self.inner.get_errored_face_count()?)+ }++ pub fn get_errored_file_ids(&self) -> Result<HashSet<i64>, MlDbError> {+ Ok(self.inner.get_errored_file_ids()?)+ }++ pub fn prune_resolved_face_error_results(&self, file_ids: Vec<i64>) -> Result<(), MlDbError> {+ Ok(self.inner.prune_resolved_face_error_results(&file_ids)?)+ }++ pub fn get_file_ids_with_error_results(+ &self,+ file_ids: Vec<i64>,+ ) -> Result<HashSet<i64>, MlDbError> {+ Ok(self.inner.get_file_ids_with_error_results(&file_ids)?)+ }++ pub fn delete_face_index_for_files(&self, file_ids: Vec<i64>) -> Result<(), MlDbError> {+ Ok(self.inner.delete_face_index_for_files(&file_ids)?)+ }++ pub fn delete_unclustered_face_index_for_files(+ &self,+ file_ids: Vec<i64>,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .delete_unclustered_face_index_for_files(&file_ids)?)+ }++ pub fn get_clustered_or_faceless_file_count(&self) -> Result<i64, MlDbError> {+ Ok(self.inner.get_clustered_or_faceless_file_count()?)+ }++ pub fn get_unclustered_face_count(&self) -> Result<i64, MlDbError> {+ Ok(self.inner.get_unclustered_face_count()?)+ }++ pub fn get_all_file_ids_of_face_ids_not_in_any_cluster(+ &self,+ ) -> Result<HashSet<i64>, MlDbError> {+ Ok(self+ .inner+ .get_all_file_ids_of_face_ids_not_in_any_cluster()?)+ }++ pub fn get_all_files_associated_with_all_clusters(+ &self,+ except_clusters: Option<Vec<String>>,+ ) -> Result<HashSet<i64>, MlDbError> {+ Ok(self+ .inner+ .get_all_files_associated_with_all_clusters(except_clusters.as_deref())?)+ }++ pub fn get_fully_indexed_file_ids(+ &self,+ include_pets: bool,+ ) -> Result<HashSet<i64>, MlDbError> {+ Ok(self.inner.get_fully_indexed_file_ids(include_pets)?)+ }++ pub fn update_face_id_to_cluster_id(+ &self,+ face_id_to_cluster_id: HashMap<String, String>,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .update_face_id_to_cluster_id(&face_id_to_cluster_id)?)+ }++ pub fn cluster_id_to_face_count(&self) -> Result<HashMap<String, i64>, MlDbError> {+ Ok(self.inner.cluster_id_to_face_count()?)+ }++ pub fn get_bad_face_singleton_cluster_ids(&self) -> Result<HashSet<String>, MlDbError> {+ Ok(self.inner.get_bad_face_singleton_cluster_ids()?)+ }++ pub fn get_cluster_to_face_ids(+ &self,+ cluster_ids: HashSet<String>,+ ) -> Result<HashMap<String, Vec<String>>, MlDbError> {+ Ok(self.inner.get_cluster_to_face_ids(&cluster_ids)?)+ }++ pub fn get_cluster_id_for_face_id(&self, face_id: String) -> Result<Option<String>, MlDbError> {+ Ok(self.inner.get_cluster_id_for_face_id(&face_id)?)+ }++ pub fn get_all_cluster_id_to_face_ids(+ &self,+ ) -> Result<HashMap<String, Vec<String>>, MlDbError> {+ Ok(self.inner.get_all_cluster_id_to_face_ids()?)+ }++ pub fn get_face_ids_for_cluster(&self, cluster_id: String) -> Result<Vec<String>, MlDbError> {+ Ok(self.inner.get_face_ids_for_cluster(&cluster_id)?)+ }++ pub fn get_face_ids_for_cluster_ordered_by_score(+ &self,+ cluster_id: String,+ limit: i64,+ ) -> Result<Vec<String>, MlDbError> {+ Ok(self+ .inner+ .get_face_ids_for_cluster_ordered_by_score(&cluster_id, limit)?)+ }++ pub fn get_blur_values_for_cluster(&self, cluster_id: String) -> Result<Vec<f64>, MlDbError> {+ Ok(self.inner.get_blur_values_for_cluster(&cluster_id)?)+ }++ pub fn get_face_ids_to_cluster_ids(+ &self,+ face_ids: Vec<String>,+ ) -> Result<HashMap<String, Option<String>>, MlDbError> {+ Ok(self.inner.get_face_ids_to_cluster_ids(&face_ids)?)+ }++ pub fn get_file_id_to_cluster_ids(&self) -> Result<HashMap<i64, HashSet<String>>, MlDbError> {+ Ok(self.inner.get_file_id_to_cluster_ids()?)+ }++ pub fn force_update_cluster_ids(+ &self,+ face_id_to_cluster_id: HashMap<String, String>,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .force_update_cluster_ids(&face_id_to_cluster_id)?)+ }++ pub fn remove_face_id_to_cluster_id(+ &self,+ face_id_to_cluster_id: HashMap<String, String>,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .remove_face_id_to_cluster_id(&face_id_to_cluster_id)?)+ }++ pub fn get_file_id_to_cluster_id_set_for_cluster(+ &self,+ cluster_ids: HashSet<String>,+ ) -> Result<HashMap<i64, HashSet<String>>, MlDbError> {+ Ok(self+ .inner+ .get_file_id_to_cluster_id_set_for_cluster(&cluster_ids)?)+ }++ pub fn get_file_ids_of_cluster_id(&self, cluster_id: String) -> Result<Vec<i64>, MlDbError> {+ Ok(self.inner.get_file_ids_of_cluster_id(&cluster_id)?)+ }++ pub fn get_cluster_centroid_vector_id_map(+ &self,+ cluster_ids: Vec<String>,+ create_if_missing: bool,+ ) -> Result<HashMap<String, i64>, MlDbError> {+ Ok(self+ .inner+ .get_cluster_centroid_vector_id_map(&cluster_ids, create_if_missing)?)+ }++ pub fn delete_cluster_centroid_vector_id_mapping(+ &self,+ cluster_id: String,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .delete_cluster_centroid_vector_id_mapping(&cluster_id)?)+ }++ pub fn clear_cluster_centroid_vector_id_mappings(&self) -> Result<(), MlDbError> {+ Ok(self.inner.clear_cluster_centroid_vector_id_mappings()?)+ }++ pub fn upsert_cluster_summary_rows(+ &self,+ summary: HashMap<String, ClusterSummary>,+ ) -> Result<(), MlDbError> {+ Ok(self.inner.upsert_cluster_summary_rows(&summary)?)+ }++ pub fn delete_cluster_summary_row(&self, cluster_id: String) -> Result<(), MlDbError> {+ Ok(self.inner.delete_cluster_summary_row(&cluster_id)?)+ }++ pub fn get_all_cluster_summary(+ &self,+ min_cluster_size: Option<i64>,+ ) -> Result<HashMap<String, ClusterSummary>, MlDbError> {+ Ok(self.inner.get_all_cluster_summary(min_cluster_size)?)+ }++ pub fn get_cluster_to_cluster_summary(+ &self,+ cluster_ids: Vec<String>,+ ) -> Result<HashMap<String, ClusterSummary>, MlDbError> {+ Ok(self.inner.get_cluster_to_cluster_summary(&cluster_ids)?)+ }++ pub fn count_cluster_summaries(&self) -> Result<i64, MlDbError> {+ Ok(self.inner.count_cluster_summaries()?)+ }++ pub fn get_cluster_summary_page(+ &self,+ before_cluster_id: Option<String>,+ limit: i64,+ ) -> Result<Vec<ClusterCentroidRow>, MlDbError> {+ Ok(self+ .inner+ .get_cluster_summary_page(before_cluster_id.as_deref(), limit)?)+ }++ pub fn reset_cluster_tables(&self, faces: bool) -> Result<(), MlDbError> {+ Ok(self.inner.reset_cluster_tables(faces)?)+ }++ pub fn get_clusters_for_memory_lane(+ &self,+ assigned: HashSet<String>,+ ) -> Result<HashSet<String>, MlDbError> {+ Ok(self.inner.get_clusters_for_memory_lane(&assigned)?)+ }++ pub fn get_clusters_with_three_or_more_not_person_feedback(+ &self,+ ) -> Result<HashSet<String>, MlDbError> {+ Ok(self+ .inner+ .get_clusters_with_three_or_more_not_person_feedback()?)+ }++ pub fn get_person_ignored_clusters(+ &self,+ person_id: String,+ ) -> Result<HashSet<String>, MlDbError> {+ Ok(self.inner.get_person_ignored_clusters(&person_id)?)+ }++ pub fn get_person_to_rejected_suggestions(+ &self,+ ) -> Result<HashMap<String, HashSet<String>>, MlDbError> {+ Ok(self.inner.get_person_to_rejected_suggestions()?)+ }++ pub fn get_person_cluster_ids(&self, person_id: String) -> Result<HashSet<String>, MlDbError> {+ Ok(self.inner.get_person_cluster_ids(&person_id)?)+ }++ pub fn get_persons_cluster_ids(+ &self,+ person_ids: Vec<String>,+ ) -> Result<HashSet<String>, MlDbError> {+ Ok(self.inner.get_persons_cluster_ids(&person_ids)?)+ }++ pub fn get_person_to_cluster_id_to_face_ids(+ &self,+ ) -> Result<HashMap<String, HashMap<String, HashSet<String>>>, MlDbError> {+ Ok(self.inner.get_person_to_cluster_id_to_face_ids()?)+ }++ pub fn get_person_to_cluster_ids(&self) -> Result<HashMap<String, HashSet<String>>, MlDbError> {+ Ok(self.inner.get_person_to_cluster_ids()?)+ }++ pub fn get_face_id_to_person_id_for_faces(+ &self,+ face_ids: Vec<String>,+ ) -> Result<HashMap<String, String>, MlDbError> {+ Ok(self.inner.get_face_id_to_person_id_for_faces(&face_ids)?)+ }++ pub fn get_cluster_id_to_face_ids_for_person(+ &self,+ person_id: String,+ ) -> Result<HashMap<String, HashSet<String>>, MlDbError> {+ Ok(self+ .inner+ .get_cluster_id_to_face_ids_for_person(&person_id)?)+ }++ pub fn get_face_ids_for_person(&self, person_id: String) -> Result<HashSet<String>, MlDbError> {+ Ok(self.inner.get_face_ids_for_person(&person_id)?)+ }++ pub fn get_face_ids_for_person_ordered_by_score(+ &self,+ person_id: String,+ limit: i64,+ ) -> Result<Vec<String>, MlDbError> {+ Ok(self+ .inner+ .get_face_ids_for_person_ordered_by_score(&person_id, limit)?)+ }++ pub fn remove_person(&self, person_id: String) -> Result<(), MlDbError> {+ Ok(self.inner.remove_person(&person_id)?)+ }++ pub fn assign_cluster_to_person(+ &self,+ person_id: String,+ cluster_id: String,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .assign_cluster_to_person(&person_id, &cluster_id)?)+ }++ pub fn bulk_assign_cluster_to_person_id(+ &self,+ cluster_to_person_id: HashMap<String, String>,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .bulk_assign_cluster_to_person_id(&cluster_to_person_id)?)+ }++ pub fn capture_not_person_feedback(+ &self,+ person_id: String,+ cluster_id: String,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .capture_not_person_feedback(&person_id, &cluster_id)?)+ }++ pub fn bulk_capture_not_person_feedback(+ &self,+ cluster_to_person_id: HashMap<String, String>,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .bulk_capture_not_person_feedback(&cluster_to_person_id)?)+ }++ pub fn remove_not_person_feedback(+ &self,+ person_id: String,+ cluster_id: String,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .remove_not_person_feedback(&person_id, &cluster_id)?)+ }++ pub fn remove_cluster_to_person(+ &self,+ person_id: String,+ cluster_id: String,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .remove_cluster_to_person(&person_id, &cluster_id)?)+ }++ pub fn get_file_id_to_cluster_id_set(+ &self,+ person_id: String,+ ) -> Result<HashMap<i64, HashSet<String>>, MlDbError> {+ Ok(self.inner.get_file_id_to_cluster_id_set(&person_id)?)+ }++ pub fn get_cluster_id_to_person_id(&self) -> Result<HashMap<String, String>, MlDbError> {+ Ok(self.inner.get_cluster_id_to_person_id()?)+ }++ pub fn drop_faces_feedback_tables(&self) -> Result<(), MlDbError> {+ Ok(self.inner.drop_faces_feedback_tables()?)+ }++ pub fn get_file_ids_of_person_id(&self, person_id: String) -> Result<Vec<i64>, MlDbError> {+ Ok(self.inner.get_file_ids_of_person_id(&person_id)?)+ }++ pub fn get_all_clip_vectors(&self) -> Result<Vec<EmbeddingVector>, MlDbError> {+ Ok(self.inner.get_all_clip_vectors()?)+ }++ pub fn clip_indexed_file_with_version(&self) -> Result<HashMap<i64, i64>, MlDbError> {+ Ok(self.inner.clip_indexed_file_with_version()?)+ }++ pub fn get_clip_indexed_file_count(&self, minimum_ml_version: i64) -> Result<i64, MlDbError> {+ Ok(self.inner.get_clip_indexed_file_count(minimum_ml_version)?)+ }++ pub fn get_clip_vectorizable_file_count(+ &self,+ minimum_ml_version: i64,+ ) -> Result<i64, MlDbError> {+ Ok(self+ .inner+ .get_clip_vectorizable_file_count(minimum_ml_version)?)+ }++ pub fn insert_clip_rows(&self, embeddings: Vec<ClipEmbedding>) -> Result<(), MlDbError> {+ Ok(self.inner.insert_clip_rows(&embeddings)?)+ }++ pub fn delete_clip_rows(&self, file_ids: Vec<i64>) -> Result<(), MlDbError> {+ Ok(self.inner.delete_clip_rows(&file_ids)?)+ }++ pub fn delete_all_clip_rows(&self) -> Result<(), MlDbError> {+ Ok(self.inner.delete_all_clip_rows()?)+ }++ pub fn count_clip_rows(&self) -> Result<i64, MlDbError> {+ Ok(self.inner.count_clip_rows()?)+ }++ pub fn get_clip_rows_page(&self, limit: i64, offset: i64) -> Result<Vec<ClipRow>, MlDbError> {+ Ok(self.inner.get_clip_rows_page(limit, offset)?)+ }++ pub fn bulk_insert_pet_faces(&self, pet_faces: Vec<PetFaceRow>) -> Result<(), MlDbError> {+ Ok(self.inner.bulk_insert_pet_faces(&pet_faces)?)+ }++ pub fn bulk_insert_pet_bodies(&self, pet_bodies: Vec<PetBodyRow>) -> Result<(), MlDbError> {+ Ok(self.inner.bulk_insert_pet_bodies(&pet_bodies)?)+ }++ pub fn update_pet_face_vector_ids(+ &self,+ pet_face_id_to_vector_id: HashMap<String, i64>,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .update_pet_face_vector_ids(&pet_face_id_to_vector_id)?)+ }++ pub fn update_pet_body_vector_ids(+ &self,+ pet_body_id_to_vector_id: HashMap<String, i64>,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .update_pet_body_vector_ids(&pet_body_id_to_vector_id)?)+ }++ pub fn get_pet_faces_for_file_id(+ &self,+ file_upload_id: i64,+ ) -> Result<Vec<PetFaceRow>, MlDbError> {+ Ok(self.inner.get_pet_faces_for_file_id(file_upload_id)?)+ }++ pub fn get_pet_bodies_for_file_id(+ &self,+ file_upload_id: i64,+ ) -> Result<Vec<PetBodyRow>, MlDbError> {+ Ok(self.inner.get_pet_bodies_for_file_id(file_upload_id)?)+ }++ pub fn pet_indexed_file_ids(+ &self,+ minimum_ml_version: i64,+ ) -> Result<HashMap<i64, i64>, MlDbError> {+ Ok(self.inner.pet_indexed_file_ids(minimum_ml_version)?)+ }++ pub fn get_pet_indexed_file_count(&self, minimum_ml_version: i64) -> Result<i64, MlDbError> {+ Ok(self.inner.get_pet_indexed_file_count(minimum_ml_version)?)+ }++ pub fn get_pet_rows_for_files(&self, file_ids: Vec<i64>) -> Result<PetRowsForFiles, MlDbError> {+ Ok(self.inner.get_pet_rows_for_files(&file_ids)?)+ }++ pub fn delete_pet_rows_for_files(+ &self,+ file_ids: Vec<i64>,+ pet_face_ids: Vec<String>,+ pet_body_ids: Vec<String>,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .delete_pet_rows_for_files(&file_ids, &pet_face_ids, &pet_body_ids)?)+ }++ pub fn get_pet_face_vector_id_map(+ &self,+ pet_face_ids: Vec<String>,+ create_if_missing: bool,+ ) -> Result<HashMap<String, i64>, MlDbError> {+ Ok(self+ .inner+ .get_pet_face_vector_id_map(&pet_face_ids, create_if_missing)?)+ }++ pub fn get_pet_body_vector_id_map(+ &self,+ pet_body_ids: Vec<String>,+ create_if_missing: bool,+ ) -> Result<HashMap<String, i64>, MlDbError> {+ Ok(self+ .inner+ .get_pet_body_vector_id_map(&pet_body_ids, create_if_missing)?)+ }++ pub fn put_repeated_text_embedding_cache(+ &self,+ query: String,+ embedding: Vec<f64>,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .put_repeated_text_embedding_cache(&query, &embedding)?)+ }++ pub fn get_repeated_text_embedding_cache(+ &self,+ query: String,+ ) -> Result<Option<Vec<f32>>, MlDbError> {+ Ok(self.inner.get_repeated_text_embedding_cache(&query)?)+ }++ pub fn put_face_id_cached_for_person_or_cluster(+ &self,+ person_or_cluster_id: String,+ face_id: String,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .put_face_id_cached_for_person_or_cluster(&person_or_cluster_id, &face_id)?)+ }++ pub fn get_face_id_used_for_person_or_cluster(+ &self,+ person_or_cluster_id: String,+ ) -> Result<Option<String>, MlDbError> {+ Ok(self+ .inner+ .get_face_id_used_for_person_or_cluster(&person_or_cluster_id)?)+ }++ pub fn remove_face_id_cached_for_person_or_cluster(+ &self,+ person_or_cluster_id: String,+ ) -> Result<(), MlDbError> {+ Ok(self+ .inner+ .remove_face_id_cached_for_person_or_cluster(&person_or_cluster_id)?)+ }++ pub fn put_fd_status(&self, fd_status_list: Vec<FdStatus>) -> Result<(), MlDbError> {+ Ok(self.inner.put_fd_status(&fd_status_list)?)+ }++ pub fn get_file_ids_vid_preview(&self) -> Result<HashMap<i64, PreviewInfo>, MlDbError> {+ Ok(self.inner.get_file_ids_vid_preview()?)+ }++ pub fn get_file_ids_with_fd_data(+ &self,+ data_type: Option<String>,+ ) -> Result<HashSet<i64>, MlDbError> {+ Ok(self.inner.get_file_ids_with_fd_data(data_type.as_deref())?)+ }+}diff --git a/rust/bindings/frb/photos/src/api/mod.rs b/rust/bindings/frb/photos/src/api/mod.rsindex ca7005748f..b4e97a960a 100644--- a/rust/bindings/frb/photos/src/api/mod.rs+++ b/rust/bindings/frb/photos/src/api/mod.rs@@ -5,6 +5,7 @@ pub mod location_api;#[cfg(any(feature = "flutter", frb_expand))]pub mod log;pub mod map_cluster_api;+pub mod ml_db_api;pub mod ml_indexing_api;pub mod motion_photo_api;pub mod ocr_api;