Skip to content

armgit / ente

Public Imported from GitHub
0

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

Fix null pointer crash

laurenspriem120dbeb4fcc6
diff --git a/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart b/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart
index 809249ff3d..cb616decc0 100644
--- a/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart
+++ b/mobile/lib/ui/settings/debug/ml_debug_section_widget.dart
@@ -89,7 +89,7 @@ class _MLDebugSectionWidgetState extends State<MLDebugSectionWidget> {
final tenKeys =
Uint64List.fromList(tenVectors.map((e) => e.fileID).toList());
final indexPath = (await getApplicationSupportDirectory()).path +
- "/ml/test/vector_db";
+ "/ml/test1/vector_db";
final stats = await getIndexStats(indexPath: indexPath);
logger.info("vector_db stats: $stats");
await bulkAddVectors(
diff --git a/mobile/rust/src/api/usearch_api.rs b/mobile/rust/src/api/usearch_api.rs
index f105ff2c61..7405bb0b26 100644
--- a/mobile/rust/src/api/usearch_api.rs
+++ b/mobile/rust/src/api/usearch_api.rs
@@ -3,7 +3,7 @@ use usearch::{Index, IndexOptions, MetricKind, ScalarKind};
// Create DB index
fn create_index() -> Index {
let mut options = IndexOptions::default();
- options.dimensions = 192; // Set the number of dimensions for vectors
+ options.dimensions = 512; // Set the number of dimensions for vectors
options.metric = MetricKind::Cos; // Use cosine similarity for distance measurement
options.quantization = ScalarKind::F32; // Use 32-bit floating point numbers
options.connectivity = 0; // zero for auto
@@ -20,25 +20,23 @@ fn get_index(file_path: &str) -> Index {
let file_exists: bool = std::path::Path::new(file_path).try_exists().unwrap();
let index = create_index();
if file_exists {
- let index = load_index(index, file_path);
- index
+ // Load into the existing index instead of creating a new variable
+ index.load(file_path).expect("Failed to load index.");
} else {
save_index(&index, file_path);
- index
}
+ index
}
// Save to disk
fn save_index(index: &Index, file_path: &str) {
+ // Ensure directory exists
+ if let Some(parent) = std::path::Path::new(file_path).parent() {
+ std::fs::create_dir_all(parent).expect("Failed to create directory for index.");
+ }
index.save(file_path).expect("Failed to save index.");
}
-// Load from disk
-fn load_index(index: Index, file_path: &str) -> Index {
- index.load(file_path).expect("Failed to load index.");
- index
-}
-
// Changes to DB index
fn ensure_capacity(index: &Index, margin: usize) {
let current_size = index.size();