π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Use GGML on Graphene
vishnukvmdafc6b4c35299
diff --git a/lib/services/semantic_search/semantic_search_service.dart b/lib/services/semantic_search/semantic_search_service.dartindex a780015f0c..16408db309 100644--- a/lib/services/semantic_search/semantic_search_service.dart+++ b/lib/services/semantic_search/semantic_search_service.dart@@ -34,8 +34,6 @@ class SemanticSearchService {static const kEmbeddingLength = 512;static const kScoreThreshold = 0.23;static const kShouldPushEmbeddings = true;- static const kCurrentModel = Model.onnxClip;- static const kIsGraphene = true;static const kDebounceDuration = Duration(milliseconds: 4000);final _logger = Logger("SemanticSearchService");@@ -44,6 +42,7 @@ class SemanticSearchService {final _embeddingLoaderDebouncer =Debouncer(kDebounceDuration, executionInterval: kDebounceDuration);+ late Model _currentModel;late MLFramework _mlFramework;bool _hasInitialized = false;bool _isComputingEmbeddings = false;@@ -78,7 +77,8 @@ class SemanticSearchService {_hasInitialized = true;final shouldDownloadOverMobileData =Configuration.instance.shouldBackupOverMobileData();- _mlFramework = (kCurrentModel == Model.onnxClip && !kIsGraphene)+ _currentModel = await _getCurrentModel();+ _mlFramework = _currentModel == Model.onnxClip? ONNX(shouldDownloadOverMobileData): GGML(shouldDownloadOverMobileData);await EmbeddingsDB.instance.init();@@ -111,7 +111,6 @@ class SemanticSearchService {if (shouldSyncImmediately) {unawaited(sync());}- initDeviceSpec().ignore();}Future<void> release() async {@@ -125,7 +124,7 @@ class SemanticSearchService {return;}_isSyncing = true;- await EmbeddingStore.instance.pullEmbeddings(kCurrentModel);+ await EmbeddingStore.instance.pullEmbeddings(_currentModel);await _backFill();_isSyncing = false;}@@ -174,14 +173,14 @@ class SemanticSearchService {}Future<void> clearIndexes() async {- await EmbeddingStore.instance.clearEmbeddings(kCurrentModel);- _logger.info("Indexes cleared for $kCurrentModel");+ await EmbeddingStore.instance.clearEmbeddings(_currentModel);+ _logger.info("Indexes cleared for $_currentModel");}Future<void> _loadEmbeddings() async {_logger.info("Pulling cached embeddings");final startTime = DateTime.now();- _cachedEmbeddings = await EmbeddingsDB.instance.getAll(kCurrentModel);+ _cachedEmbeddings = await EmbeddingsDB.instance.getAll(_currentModel);final endTime = DateTime.now();_logger.info("Loading ${_cachedEmbeddings.length} took: ${(endTime.millisecondsSinceEpoch - startTime.millisecondsSinceEpoch)}ms",@@ -315,7 +314,7 @@ class SemanticSearchService {final embedding = Embedding(fileID: file.uploadedFileID!,- model: kCurrentModel,+ model: _currentModel,embedding: result,);await EmbeddingStore.instance.storeEmbedding(@@ -362,6 +361,14 @@ class SemanticSearchService {);return queryResults;}++ Future<Model> _getCurrentModel() async {+ if (await isGrapheneOS()) {+ return Model.ggmlClip;+ } else {+ return Model.onnxClip;+ }+ }}List<QueryResult> computeBulkScore(Map args) {diff --git a/lib/utils/device_info.dart b/lib/utils/device_info.dartindex ce7c9f14e5..b7acada278 100644--- a/lib/utils/device_info.dart+++ b/lib/utils/device_info.dart@@ -42,11 +42,12 @@ Future<bool> isLowSpecDevice() async {return false;}-Future<void> initDeviceSpec() async {+Future<bool> isGrapheneOS() async {if (Platform.isAndroid) {final androidInfo = await deviceInfoPlugin.androidInfo;- Logger("DeviceInfo").info("androidInfo $androidInfo");+ return androidInfo.host == "grapheneos";}+ return false;}Future<bool> isAndroidSDKVersionLowerThan(int inputSDK) async {