Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Remove duplicate simsimd dependency

laurenspriem4d38299f4923
diff --git a/mobile/apps/photos/rust/Cargo.lock b/mobile/apps/photos/rust/Cargo.lock
index 2669b80591..c118e3e30c 100644
--- a/mobile/apps/photos/rust/Cargo.lock
+++ b/mobile/apps/photos/rust/Cargo.lock
@@ -778,7 +778,6 @@ version = "0.0.1"
dependencies = [
"ente_media_inspector",
"flutter_rust_bridge",
- "simsimd",
]
[[package]]
@@ -2716,15 +2715,6 @@ dependencies = [
"quote",
]
-[[package]]
-name = "simsimd"
-version = "6.5.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "35185e4ac5ccaa9b8550d0dbdfaca87a6cabd68d5fe2db81ad270692f827bdb1"
-dependencies = [
- "cc",
-]
-
[[package]]
name = "siphasher"
version = "1.0.2"
diff --git a/mobile/apps/photos/rust/Cargo.toml b/mobile/apps/photos/rust/Cargo.toml
index 1b39cb1d4f..3d543ea51e 100644
--- a/mobile/apps/photos/rust/Cargo.toml
+++ b/mobile/apps/photos/rust/Cargo.toml
@@ -8,7 +8,6 @@ crate-type = ["cdylib", "staticlib"]
[dependencies]
flutter_rust_bridge = "=2.11.1"
-simsimd = "=6.5.5"
ente_media_inspector = { path = "../../../../rust/photos" }
[lints.rust]
diff --git a/mobile/apps/photos/rust/src/api/usearch_api.rs b/mobile/apps/photos/rust/src/api/usearch_api.rs
index 17e26b5646..abce574e1a 100644
--- a/mobile/apps/photos/rust/src/api/usearch_api.rs
+++ b/mobile/apps/photos/rust/src/api/usearch_api.rs
@@ -1,11 +1,28 @@
use ente_media_inspector::vector_db;
use flutter_rust_bridge::frb;
-use simsimd::SpatialSimilarity;
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.
+unsafe extern "C" {
+ fn simsimd_dot_f32(a: *const f32, b: *const f32, n: u64, d: *mut f64);
+}
+
+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 from 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
+}
+
#[derive(Clone, Debug)]
pub struct SemanticSearchExactRequest {
pub image_file_ids: Vec<i64>,
@@ -63,13 +80,7 @@ pub fn semantic_search_exact(
));
}
- let Some(score) = <f32 as SpatialSimilarity>::dot(image_embedding, query_embedding)
- else {
- return Err(format!(
- "failed to compute dot product for file_id {file_id} with dimension {}",
- image_embedding.len()
- ));
- };
+ let score = simsimd_dot_product(image_embedding, query_embedding);
if score >= minimum_similarity {
query_matches.push(SemanticSearchExactMatch {