π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add an LRU cache for queries
vishnukvmdd4ebb5c49331
diff --git a/lib/services/semantic_search/semantic_search_service.dart b/lib/services/semantic_search/semantic_search_service.dartindex 24ab05ed2c..b8af659259 100644--- a/lib/services/semantic_search/semantic_search_service.dart+++ b/lib/services/semantic_search/semantic_search_service.dart@@ -4,6 +4,7 @@ import "dart:math";import "package:computer/computer.dart";import "package:logging/logging.dart";+import "package:photos/core/cache/lru_map.dart";import "package:photos/core/configuration.dart";import "package:photos/core/event_bus.dart";import "package:photos/db/files_db.dart";@@ -27,6 +28,7 @@ class SemanticSearchService {static final SemanticSearchService instance =SemanticSearchService._privateConstructor();static final Computer _computer = Computer.shared();+ static final LRUMap<String, List<double>> _queryCache = LRUMap(50);static const kModelName = "clip";static const kEmbeddingLength = 512;@@ -269,8 +271,13 @@ class SemanticSearchService {Future<List<double>> _getTextEmbedding(String query) async {_logger.info("Searching for " + query);+ final cachedResult = _queryCache.get(query);+ if (cachedResult != null) {+ return cachedResult;+ }try {final result = await _mlFramework.getTextEmbedding(query);+ _queryCache.put(query, result);return result;} catch (e) {_logger.severe("Could not get text embedding", e);