π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove the exact-in-Rust semantic search debug toggle
laurenspriemd9396cb97b62
diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_computer.dart b/mobile/apps/photos/lib/services/machine_learning/ml_computer.dartindex c449a9725e..59cfaab6ac 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_computer.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_computer.dart@@ -184,36 +184,11 @@ class MLComputer extends SuperIsolate {}}- Future<Map<String, List<QueryResult>>> computeBulkSimilaritiesWithRust(- Map<String, List<double>> textQueryToEmbeddingMap,- Map<String, double> minimumSimilarityMap,- ) async {+ Future<void> cacheImageEmbeddings(List<EmbeddingVector> embeddings) async {try {- final queryToResults =- await runInIsolate(IsolateOperation.computeBulkSimilaritiesWithRust, {- "textQueryToEmbeddingMap": textQueryToEmbeddingMap,- "minimumSimilarityMap": minimumSimilarityMap,- })- as Map<String, List<QueryResult>>;- return queryToResults;- } catch (e, s) {- _logger.severe(- "Could not bulk compare embeddings with rust inside MLComputer isolate",- e,- s,- );- rethrow;- }- }-- Future<void> cacheImageEmbeddings(- List<EmbeddingVector> embeddings, {- bool cacheRustExact = false,- }) async {- try {- await runInIsolate(IsolateOperation.cacheImageEmbeddings, {- 'embeddings': embeddings,- 'cacheRustExact': cacheRustExact,+ await runInIsolate(IsolateOperation.setIsolateCache, {+ 'key': imageEmbeddingsKey,+ 'value': embeddings,})as bool;_logger.info(diff --git a/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dart b/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dartindex 421cbc1c2b..51969c8b12 100644--- a/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dart+++ b/mobile/apps/photos/lib/services/machine_learning/semantic_search/semantic_search_service.dart@@ -74,14 +74,6 @@ class SemanticSearchService {return _prepareVectorDbFuture!;}- bool get _shouldUseRustExactSearch =>- flagService.internalUser &&- flagService.usearchForSearch &&- localSettings.semanticSearchExactInRustEnabled;-- bool get _shouldUseVectorDbApproximateSearch =>- flagService.usearchForSearch && !_shouldUseRustExactSearch;-void _initializeIfNeeded() {if (_hasInitialized) {return;@@ -99,7 +91,7 @@ class SemanticSearchService {}void _scheduleWarmup({required bool delayTextModelLoad}) {- if (_shouldUseVectorDbApproximateSearch) {+ if (flagService.usearchForSearch) {unawaited(_prepareVectorDbForSearch());}@@ -112,11 +104,11 @@ class SemanticSearchService {Future<void> _prepareVectorDbForSearchInternal() async {try {- if (!_shouldUseVectorDbApproximateSearch) return;+ if (!flagService.usearchForSearch) return;if (!flagService.hasGrantedMLConsent) return;if (!await _vectorDB.isReady()) {await Future.delayed(_vectorDbMigrationDelay);- if (!_shouldUseVectorDbApproximateSearch) return;+ if (!flagService.usearchForSearch) return;if (!flagService.hasGrantedMLConsent) return;await _mlDataDB.checkMigrateFillClipVectorDB();}@@ -194,10 +186,7 @@ class SemanticSearchService {_logger.info("read all ${imageEmbeddings.length} embeddings from DB in ${DateTime.now().difference(now).inMilliseconds} ms",);- await MLComputer.instance.cacheImageEmbeddings(- imageEmbeddings,- cacheRustExact: _shouldUseRustExactSearch,- );+ await MLComputer.instance.cacheImageEmbeddings(imageEmbeddings);_imageEmbeddingsAreCached = true;_cachedEmbeddingsLocalGallery = isLocalGalleryMode;return;@@ -422,31 +411,6 @@ class SemanticSearchService {}await _cacheClipVectors();- if (_shouldUseRustExactSearch) {- final startTime = DateTime.now();- try {- final queryResults = await MLComputer.instance- .computeBulkSimilaritiesWithRust(- textQueryToEmbeddingMap,- minimumSimilarityMap,- );- final endTime = DateTime.now();- _logger.info(- "computingSimilarities (rust simsimd exact) took for ${textQueryToEmbeddingMap.length} queries " +- (endTime.millisecondsSinceEpoch -- startTime.millisecondsSinceEpoch)- .toString() +- "ms",- );- return queryResults;- } catch (e, s) {- _logger.severe(- "Rust exact similarity search failed, falling back to Dart in-memory dot-product",- e,- s,- );- }- }final startTime = DateTime.now();final Map<String, List<QueryResult>> queryResults = await MLComputer@@ -487,7 +451,7 @@ class SemanticSearchService {}Future<bool> _canUseVectorDbForSearch() async {- if (!_shouldUseVectorDbApproximateSearch) return false;+ if (!flagService.usearchForSearch) return false;if (!flagService.hasGrantedMLConsent) return false;if (await _vectorDB.isReady()) return true;// Keep interactive search responsive: prepare/migrate in the background anddiff --git a/mobile/apps/photos/lib/settings/local_settings.dart b/mobile/apps/photos/lib/settings/local_settings.dartindex ce56ac9848..8895466fc8 100644--- a/mobile/apps/photos/lib/settings/local_settings.dart+++ b/mobile/apps/photos/lib/settings/local_settings.dart@@ -124,8 +124,6 @@ class LocalSettings {"ml_debug.default_clustering_distance";static const _kRunMLDuringInteractionOverride ="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";@@ -550,13 +548,6 @@ class LocalSettings {await _prefs.setBool(_kRunMLDuringInteractionOverride, value);}- bool get semanticSearchExactInRustEnabled =>- _prefs.getBool(_kSemanticSearchExactInRustEnabled) ?? false;-- Future<void> setSemanticSearchExactInRustEnabled(bool value) async {- await _prefs.setBool(_kSemanticSearchExactInRustEnabled, value);- }-bool get rustMlDbOverride => _prefs.getBool(_kRustMlDbOverride) ?? false;Future<void> setRustMlDbOverride(bool value) async {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 ce89f15e72..008ab55257 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@@ -206,18 +206,6 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {onChanged: _onPetRecognitionChanged,),),- if (flagService.internalUser && flagService.usearchForSearch)- MenuItemWidgetNew(- title: "Exact semantic search (SimSIMD)",- leadingIconWidget: _buildIconWidget(- context,- HugeIcons.strokeRoundedAiSearch,- ),- trailingWidget: ToggleSwitchWidget(- value: () => localSettings.semanticSearchExactInRustEnabled,- onChanged: _onSemanticSearchExactChanged,- ),- ),MenuItemWidgetNew(title: "Rust ML DB",subText: "Active: ${MLDataDB.isRustBackend ? "rust" : "dart"}",@@ -801,25 +789,6 @@ class _MLDebugSettingsPageState extends State<MLDebugSettingsPage> {}}- Future<void> _onSemanticSearchExactChanged() async {- try {- final enabled = !localSettings.semanticSearchExactInRustEnabled;- await localSettings.setSemanticSearchExactInRustEnabled(enabled);- await SemanticSearchService.instance.prepareForInteractiveSearch();- logger.info(- 'exact semantic search in rust is turned ${enabled ? 'on' : 'off'}',- );- if (mounted) {- setState(() {});- }- } catch (e, s) {- logger.warning('exact semantic search toggle failed ', e, s);- if (mounted) {- await showGenericErrorDialog(context: context, error: e);- }- }- }-Future<void> _onRustMlDbChanged() async {try {final enabled = !localSettings.rustMlDbOverride;diff --git a/mobile/apps/photos/lib/utils/isolate/isolate_operations.dart b/mobile/apps/photos/lib/utils/isolate/isolate_operations.dartindex 8aa7a96963..e2fd25b7ab 100644--- a/mobile/apps/photos/lib/utils/isolate/isolate_operations.dart+++ b/mobile/apps/photos/lib/utils/isolate/isolate_operations.dart@@ -1,7 +1,5 @@import 'dart:typed_data' show Float32List, Uint8List;-import "package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart"- show Int64List;import "package:ml_linalg/linalg.dart";import "package:photos/db/ml/clip_vector_db.dart";import "package:photos/db/ml/db.dart";@@ -15,7 +13,6 @@ import "package:photos/services/machine_learning/semantic_search/query_result.daimport "package:photos/src/rust/api/image_processing_api.dart"as rust_image_processing;import "package:photos/src/rust/api/ml_indexing_api.dart" as rust_ml;-import "package:photos/src/rust/api/usearch_api.dart" as rust_usearch;import "package:photos/src/rust/frb_generated.dart" show EntePhotosRust;import "package:photos/utils/ml_util.dart";@@ -39,23 +36,14 @@ enum IsolateOperation {generateFaceThumbnails,runClipText,computeBulkSimilarities,- computeBulkSimilaritiesWithRust,bulkVectorSearch,bulkVectorSearchWithKeys,linearIncrementalClustering,- cacheImageEmbeddings,setIsolateCache,clearIsolateCache,clearAllIsolateCache,}-class _CachedImageEmbeddings {- _CachedImageEmbeddings({required this.embeddingVectors});-- final List<EmbeddingVector> embeddingVectors;- rust_usearch.SemanticSearchExactCache? rustExactCache;-}-// Return only primitives unless this operation only runs on regular Dart// isolates rather than Dart UI or Flutter isolates.// https://api.flutter.dev/flutter/dart-isolate/SendPort/send.html@@ -175,7 +163,7 @@ Future<dynamic> isolateFunction(return List<double>.from(result.embedding, growable: false);case IsolateOperation.computeBulkSimilarities:- final cachedEmbeddings = _getCachedImageEmbeddings();+ final imageEmbeddings = _getCachedImageEmbeddings();final textEmbedding =args["textQueryToEmbeddingMap"] as Map<String, List<double>>;final minimumSimilarityMap =@@ -187,7 +175,7 @@ Future<dynamic> isolateFunction(final textVector = Vector.fromList(entry.value);final minimumSimilarity = minimumSimilarityMap[query]!;final queryResults = <QueryResult>[];- for (final imageEmbedding in cachedEmbeddings.embeddingVectors) {+ for (final imageEmbedding in imageEmbeddings) {final similarity = imageEmbedding.vector.dot(textVector);if (similarity >= minimumSimilarity) {queryResults.add(QueryResult(imageEmbedding.fileID, similarity));@@ -200,122 +188,36 @@ Future<dynamic> isolateFunction(}return result;- case IsolateOperation.computeBulkSimilaritiesWithRust:- await _ensureRustLoaded();- final cachedEmbeddings = _getCachedImageEmbeddings();- final textEmbedding =- args["textQueryToEmbeddingMap"] as Map<String, List<double>>;- final minimumSimilarityMap =- args["minimumSimilarityMap"] as Map<String, double>;- final queryKeys = textEmbedding.keys.toList(growable: false);- final rustExactCache = await _ensureRustExactCache(cachedEmbeddings);- final response = await rustExactCache.search(- queryEmbeddings: queryKeys- .map((query) => Float32List.fromList(textEmbedding[query]!))- .toList(growable: false),- minimumSimilarities: Float32List.fromList(- queryKeys- .map((query) => minimumSimilarityMap[query]!)- .toList(growable: false),- ),- );- final result = <String, List<QueryResult>>{};- for (int i = 0; i < queryKeys.length; i++) {- final matches = response.matchesPerQuery[i];- result[queryKeys[i]] = matches- .map((match) => QueryResult(match.fileId, match.score))- .toList(growable: false);- }- return result;-case IsolateOperation.linearIncrementalClustering:final ClusteringResult result = runLinearClustering(args);return result;- case IsolateOperation.cacheImageEmbeddings:- final embeddings = args['embeddings'] as List<EmbeddingVector>;- final cacheRustExact = args['cacheRustExact'] as bool? ?? false;- final cachedEmbeddings = _CachedImageEmbeddings(- embeddingVectors: embeddings,- );- if (cacheRustExact) {- cachedEmbeddings.rustExactCache = await _createRustExactCache(- cachedEmbeddings,- );- }- _disposeIsolateCacheValue(_isolateCache[imageEmbeddingsKey]);- _isolateCache[imageEmbeddingsKey] = cachedEmbeddings;- return true;-case IsolateOperation.setIsolateCache:final key = args['key'] as String;final value = args['value'];- _disposeIsolateCacheValue(_isolateCache[key]);_isolateCache[key] = value;return true;case IsolateOperation.clearIsolateCache:final key = args['key'] as String;- final removedValue = _isolateCache.remove(key);- _disposeIsolateCacheValue(removedValue);+ _isolateCache.remove(key);return true;case IsolateOperation.clearAllIsolateCache:await _ensureRustDisposed();- for (final value in _isolateCache.values) {- _disposeIsolateCacheValue(value);- }_isolateCache.clear();return true;}}-_CachedImageEmbeddings _getCachedImageEmbeddings() {+List<EmbeddingVector> _getCachedImageEmbeddings() {final cachedEmbeddings = _isolateCache[imageEmbeddingsKey];- if (cachedEmbeddings is! _CachedImageEmbeddings) {+ if (cachedEmbeddings is! List<EmbeddingVector>) {throw StateError("Image embeddings are not cached in MLComputer isolate");}return cachedEmbeddings;}-Future<rust_usearch.SemanticSearchExactCache> _ensureRustExactCache(- _CachedImageEmbeddings cachedEmbeddings,-) async {- final rustExactCache = cachedEmbeddings.rustExactCache;- if (rustExactCache != null && !rustExactCache.isDisposed) {- return rustExactCache;- }-- final newCache = await _createRustExactCache(cachedEmbeddings);- cachedEmbeddings.rustExactCache = newCache;- return newCache;-}--Future<rust_usearch.SemanticSearchExactCache> _createRustExactCache(- _CachedImageEmbeddings cachedEmbeddings,-) async {- await _ensureRustLoaded();- final imageFileIds = Int64List.fromList(- cachedEmbeddings.embeddingVectors- .map((embedding) => embedding.fileID)- .toList(growable: false),- );- final imageEmbeddings = cachedEmbeddings.embeddingVectors- .map((embedding) => Float32List.fromList(embedding.vector.toList()))- .toList(growable: false);- return rust_usearch.SemanticSearchExactCache(- imageFileIds: imageFileIds,- imageEmbeddings: imageEmbeddings,- );-}--void _disposeIsolateCacheValue(dynamic value) {- if (value is _CachedImageEmbeddings) {- value.rustExactCache?.dispose();- value.rustExactCache = null;- }-}-Future<void> _ensureRustLoaded() async {final bool loaded = _isolateCache[_rustLibLoadedCacheKey] as bool? ?? false;if (!loaded) {diff --git a/rust/bindings/frb/photos/src/api/usearch_api.rs b/rust/bindings/frb/photos/src/api/usearch_api.rsindex 68f6a337c9..da12139ff1 100644--- a/rust/bindings/frb/photos/src/api/usearch_api.rs+++ b/rust/bindings/frb/photos/src/api/usearch_api.rs@@ -5,266 +5,6 @@ type SearchMatch = (Vec<u64>, Vec<f32>);type BulkSearchMatch = (Vec<Vec<u64>>, Vec<Vec<f32>>);type BulkSearchByKeyMatch = (Vec<u64>, Vec<Vec<u64>>, Vec<Vec<f32>>);-// USearch already vendors and links SimSIMD. Call that single exported symbol-// directly to avoid pulling a second copy of SimSIMD into the final app binary.-#[expect(- unsafe_code,- reason = "Declare the SimSIMD symbol already linked by USearch"-)]-unsafe extern "C" {- fn simsimd_dot_f32(a: *const f32, b: *const f32, n: u64, d: *mut f64);-}--#[expect(- unsafe_code,- reason = "Call the SimSIMD symbol already linked by USearch"-)]-fn simsimd_dot_product(a: &[f32], b: &[f32]) -> f64 {- debug_assert_eq!(a.len(), b.len());- let mut score = 0.0_f64;- // SAFETY:- // - `a` and `b` are valid, non-null slices for `a.len()` elements.- // - SimSIMD only reads the input buffers and writes one f64 to `score`.- unsafe {- simsimd_dot_f32(a.as_ptr(), b.as_ptr(), a.len() as u64, &mut score);- }- score-}--fn validate_semantic_search_exact_image_embeddings(- image_file_ids: &[i64],- image_embeddings: &[Vec<f32>],-) -> Result<Option<usize>, String> {- if image_file_ids.len() != image_embeddings.len() {- return Err(format!(- "image_file_ids length {} does not match image_embeddings length {}",- image_file_ids.len(),- image_embeddings.len()- ));- }-- let Some(first_image_embedding) = image_embeddings.first() else {- return Ok(None);- };- let expected_dimension = first_image_embedding.len();-- for (file_id, image_embedding) in image_file_ids.iter().zip(image_embeddings.iter()) {- if image_embedding.len() != expected_dimension {- return Err(format!(- "image embedding dimension mismatch for file_id {file_id}: image={} expected={expected_dimension}",- image_embedding.len(),- ));- }- }-- Ok(Some(expected_dimension))-}--fn validate_semantic_search_exact_queries(- query_embeddings: &[Vec<f32>],- minimum_similarities: &[f32],- expected_dimension: Option<usize>,-) -> Result<(), String> {- if query_embeddings.len() != minimum_similarities.len() {- return Err(format!(- "query_embeddings length {} does not match minimum_similarities length {}",- query_embeddings.len(),- minimum_similarities.len()- ));- }-- let Some(expected_dimension) = expected_dimension else {- return Ok(());- };-- for (query_index, query_embedding) in query_embeddings.iter().enumerate() {- if query_embedding.len() != expected_dimension {- return Err(format!(- "query embedding dimension mismatch at index {query_index}: query={} expected={expected_dimension}",- query_embedding.len(),- ));- }- }-- Ok(())-}--fn flatten_semantic_search_exact_image_embeddings(- image_embeddings: &[Vec<f32>],- expected_dimension: Option<usize>,-) -> Vec<f32> {- let Some(expected_dimension) = expected_dimension else {- return Vec::new();- };-- let mut flattened_image_embeddings =- Vec::with_capacity(image_embeddings.len() * expected_dimension);- for image_embedding in image_embeddings {- flattened_image_embeddings.extend_from_slice(image_embedding);- }- flattened_image_embeddings-}--fn semantic_search_exact_impl(- image_file_ids: &[i64],- image_embeddings: &[Vec<f32>],- query_embeddings: &[Vec<f32>],- minimum_similarities: &[f32],-) -> Result<SemanticSearchExactResponse, String> {- let expected_dimension =- validate_semantic_search_exact_image_embeddings(image_file_ids, image_embeddings)?;- validate_semantic_search_exact_queries(- query_embeddings,- minimum_similarities,- expected_dimension,- )?;-- let matches_per_query = query_embeddings- .iter()- .zip(minimum_similarities.iter())- .map(|(query_embedding, minimum_similarity)| {- let minimum_similarity = f64::from(*minimum_similarity);- let mut query_matches = Vec::with_capacity(image_embeddings.len());-- for (file_id, image_embedding) in image_file_ids.iter().zip(image_embeddings.iter()) {- let score = simsimd_dot_product(image_embedding, query_embedding);-- if score >= minimum_similarity {- query_matches.push(SemanticSearchExactMatch {- file_id: *file_id,- score,- });- }- }-- query_matches.sort_by(|left, right| right.score.total_cmp(&left.score));- query_matches- })- .collect();-- Ok(SemanticSearchExactResponse { matches_per_query })-}--fn semantic_search_exact_flattened_impl(- image_file_ids: &[i64],- flattened_image_embeddings: &[f32],- image_embedding_dimension: Option<usize>,- query_embeddings: &[Vec<f32>],- minimum_similarities: &[f32],-) -> Result<SemanticSearchExactResponse, String> {- validate_semantic_search_exact_queries(- query_embeddings,- minimum_similarities,- image_embedding_dimension,- )?;-- let matches_per_query = query_embeddings- .iter()- .zip(minimum_similarities.iter())- .map(|(query_embedding, minimum_similarity)| {- let minimum_similarity = f64::from(*minimum_similarity);- let mut query_matches = Vec::with_capacity(image_file_ids.len());-- if let Some(image_embedding_dimension) = image_embedding_dimension {- for (index, file_id) in image_file_ids.iter().enumerate() {- let offset = index * image_embedding_dimension;- let image_embedding =- &flattened_image_embeddings[offset..offset + image_embedding_dimension];- let score = simsimd_dot_product(image_embedding, query_embedding);-- if score >= minimum_similarity {- query_matches.push(SemanticSearchExactMatch {- file_id: *file_id,- score,- });- }- }- }-- query_matches.sort_by(|left, right| right.score.total_cmp(&left.score));- query_matches- })- .collect();-- Ok(SemanticSearchExactResponse { matches_per_query })-}--#[derive(Clone, Debug)]-pub struct SemanticSearchExactRequest {- pub image_file_ids: Vec<i64>,- pub image_embeddings: Vec<Vec<f32>>,- pub query_embeddings: Vec<Vec<f32>>,- pub minimum_similarities: Vec<f32>,-}--#[derive(Clone, Debug)]-pub struct SemanticSearchExactMatch {- pub file_id: i64,- pub score: f64,-}--#[derive(Clone, Debug)]-pub struct SemanticSearchExactResponse {- pub matches_per_query: Vec<Vec<SemanticSearchExactMatch>>,-}--#[frb(opaque)]-pub struct SemanticSearchExactCache {- image_file_ids: Vec<i64>,- image_embedding_dimension: Option<usize>,- flattened_image_embeddings: Vec<f32>,-}--impl SemanticSearchExactCache {- #[frb(sync)]- pub fn new(image_file_ids: Vec<i64>, image_embeddings: Vec<Vec<f32>>) -> Result<Self, String> {- let image_embedding_dimension =- validate_semantic_search_exact_image_embeddings(&image_file_ids, &image_embeddings)?;- let flattened_image_embeddings = flatten_semantic_search_exact_image_embeddings(- &image_embeddings,- image_embedding_dimension,- );-- Ok(Self {- image_file_ids,- image_embedding_dimension,- flattened_image_embeddings,- })- }-- pub fn search(- &self,- query_embeddings: Vec<Vec<f32>>,- minimum_similarities: Vec<f32>,- ) -> Result<SemanticSearchExactResponse, String> {- semantic_search_exact_flattened_impl(- &self.image_file_ids,- &self.flattened_image_embeddings,- self.image_embedding_dimension,- &query_embeddings,- &minimum_similarities,- )- }-}--pub fn semantic_search_exact(- req: SemanticSearchExactRequest,-) -> Result<SemanticSearchExactResponse, String> {- let SemanticSearchExactRequest {- image_file_ids,- image_embeddings,- query_embeddings,- minimum_similarities,- } = req;-- semantic_search_exact_impl(- &image_file_ids,- &image_embeddings,- &query_embeddings,- &minimum_similarities,- )-}-#[frb(opaque)]pub struct VectorDB {inner: vector_db::VectorDB,@@ -385,108 +125,3 @@ impl VectorDB {self.inner.get_index_stats()}}--#[cfg(test)]-mod tests {- use super::{SemanticSearchExactCache, SemanticSearchExactRequest, semantic_search_exact};-- #[test]- fn semantic_search_exact_filters_and_sorts_matches() {- let response = semantic_search_exact(SemanticSearchExactRequest {- image_file_ids: vec![101, 102, 103],- image_embeddings: vec![- vec![1.0, 0.0, 0.0],- vec![0.8, 0.6, 0.0],- vec![0.0, 1.0, 0.0],- ],- query_embeddings: vec![vec![1.0, 0.0, 0.0]],- minimum_similarities: vec![0.7],- })- .expect("semantic search exact should succeed");-- let matches = &response.matches_per_query[0];- assert_eq!(matches.len(), 2);- assert_eq!(matches[0].file_id, 101);- assert_eq!(matches[1].file_id, 102);- assert!(matches[0].score > matches[1].score);- }-- #[test]- fn semantic_search_exact_supports_multiple_queries() {- let response = semantic_search_exact(SemanticSearchExactRequest {- image_file_ids: vec![201, 202, 203],- image_embeddings: vec![vec![1.0, 0.0], vec![0.0, 1.0], vec![0.70710677, 0.70710677]],- query_embeddings: vec![vec![1.0, 0.0], vec![0.0, 1.0]],- minimum_similarities: vec![0.5, 0.5],- })- .expect("semantic search exact should succeed");-- assert_eq!(- response.matches_per_query[0]- .iter()- .map(|entry| entry.file_id)- .collect::<Vec<_>>(),- vec![201, 203]- );- assert_eq!(- response.matches_per_query[1]- .iter()- .map(|entry| entry.file_id)- .collect::<Vec<_>>(),- vec![202, 203]- );- }-- #[test]- fn semantic_search_exact_cache_supports_searching_multiple_queries() {- let cache = SemanticSearchExactCache::new(- vec![401, 402, 403],- vec![vec![1.0, 0.0], vec![0.0, 1.0], vec![0.70710677, 0.70710677]],- )- .expect("semantic search exact cache should succeed");-- let response = cache- .search(vec![vec![1.0, 0.0], vec![0.0, 1.0]], vec![0.5, 0.5])- .expect("semantic search exact cache search should succeed");-- assert_eq!(- response.matches_per_query[0]- .iter()- .map(|entry| entry.file_id)- .collect::<Vec<_>>(),- vec![401, 403]- );- assert_eq!(- response.matches_per_query[1]- .iter()- .map(|entry| entry.file_id)- .collect::<Vec<_>>(),- vec![402, 403]- );- }-- #[test]- fn semantic_search_exact_cache_rejects_query_dimension_mismatch() {- let cache = SemanticSearchExactCache::new(vec![501], vec![vec![1.0, 0.0]])- .expect("semantic search exact cache should succeed");-- let err = cache- .search(vec![vec![1.0, 0.0, 0.0]], vec![0.1])- .expect_err("semantic search exact cache should fail on query dimension mismatch");-- assert!(err.contains("query embedding dimension mismatch"));- }-- #[test]- fn semantic_search_exact_rejects_dimension_mismatch() {- let err = semantic_search_exact(SemanticSearchExactRequest {- image_file_ids: vec![301],- image_embeddings: vec![vec![1.0, 0.0]],- query_embeddings: vec![vec![1.0, 0.0, 0.0]],- minimum_similarities: vec![0.1],- })- .expect_err("semantic search exact should fail on dimension mismatch");-- assert!(err.contains("embedding dimension mismatch"));- }-}diff --git a/rust/checks/lint-exceptions/suppressions.json b/rust/checks/lint-exceptions/suppressions.jsonindex 97f5c94067..38938d1d01 100644--- a/rust/checks/lint-exceptions/suppressions.json+++ b/rust/checks/lint-exceptions/suppressions.json@@ -11,7 +11,6 @@"clippy::unwrap_used","unsafe_code"],- "rust/bindings/frb/photos/src/api/usearch_api.rs": ["unsafe_code"],"rust/bindings/frb/photos/src/lib.rs": ["clippy::allow_attributes","clippy::allow_attributes_without_reason",diff --git a/rust/crates/ml/Cargo.toml b/rust/crates/ml/Cargo.tomlindex 8eacd0cd6a..b2317d1590 100644--- a/rust/crates/ml/Cargo.toml+++ b/rust/crates/ml/Cargo.toml@@ -22,8 +22,6 @@ plsfix = "0.1.8"rayon = "1.12.0"regex.workspace = truethiserror.workspace = true-# The FRB photos bridge calls the SimSIMD symbol exported by usearch 2.21.x.-# Newer usearch releases switched that implementation to numkong symbols.usearch = { version = "=2.21.4", optional = true }# Cargokit sets ORT_LIB_PATH to Ente's verified iOS archive.