Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use all possible files for clip memories

laurenspriemfa99adf6796d
diff --git a/mobile/apps/photos/lib/services/smart_memories_service.dart b/mobile/apps/photos/lib/services/smart_memories_service.dart
index ffc12ad414..5aa61957cb 100644
--- a/mobile/apps/photos/lib/services/smart_memories_service.dart
+++ b/mobile/apps/photos/lib/services/smart_memories_service.dart
@@ -786,12 +786,8 @@ class SmartMemoriesService {
);
// Clip memories
- final clipFiles = _collectAvailableFiles(
- allFileIdsToFile,
- usedMemoryFileIds,
- );
final clipMemories = await _getClipResults(
- clipFiles,
+ fullSourceFiles,
now,
oldCache.clipShownLogs,
surfaceAll: debugSurfaceAll,
diff --git a/mobile/apps/photos/test/services/memories/smart_memories_source_selection_test.dart b/mobile/apps/photos/test/services/memories/smart_memories_source_selection_test.dart
index c197e72005..0a3274a311 100644
--- a/mobile/apps/photos/test/services/memories/smart_memories_source_selection_test.dart
+++ b/mobile/apps/photos/test/services/memories/smart_memories_source_selection_test.dart
@@ -3,6 +3,7 @@ import "package:ml_linalg/vector.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/models/location/location.dart";
+import "package:photos/models/memories/clip_memory.dart";
import "package:photos/models/memories/memories_cache.dart";
import "package:photos/models/memories/time_memory.dart";
import "package:photos/models/ml/face/face_with_embedding.dart";
@@ -28,6 +29,12 @@ EnteFile _file({
Vector get _positiveTextVector => Vector.fromList([1.0]);
+Vector _normalizedVector(List<double> values) {
+ final vector = Vector.fromList(values);
+ final norm = vector.norm();
+ return Vector.fromList(values.map((value) => value / norm).toList());
+}
+
void main() {
group("smart memories source selection", () {
test(
@@ -137,5 +144,64 @@ void main() {
expect(distinctDays.length, greaterThanOrEqualTo(4));
},
);
+
+ test(
+ "ClipMemoriesCalculator surfaces a memory from the full source set",
+ () async {
+ final currentTime = DateTime.utc(2026, 4, 10);
+ final fullSourceFiles = <EnteFile>[
+ for (int i = 0; i < 12; i++)
+ _file(
+ id: i + 1,
+ createdAt: DateTime.utc(2024, 6, 1 + (i ~/ 4), 9 + i),
+ ),
+ ];
+ final depletedRemainingFiles = fullSourceFiles.take(6).toList();
+ final selectedClipType = ClipMemoryType.values.first;
+ final queryVector = _normalizedVector(
+ List<double>.filled(fullSourceFiles.length, 1.0),
+ );
+ final fileIDToImageEmbedding = <int, EmbeddingVector>{
+ for (int i = 0; i < fullSourceFiles.length; i++)
+ fullSourceFiles[i].uploadedFileID!: EmbeddingVector(
+ fileID: fullSourceFiles[i].uploadedFileID!,
+ embedding: List<double>.generate(
+ fullSourceFiles.length,
+ (index) => index == i ? 1.0 : 0.0,
+ ),
+ ),
+ };
+
+ final fullClipMemories = await ClipMemoriesCalculator.compute(
+ fullSourceFiles,
+ currentTime,
+ <ClipShownLog>[],
+ surfaceAll: true,
+ isOfflineMode: false,
+ seenTimes: const <int, int>{},
+ fileIDToImageEmbedding: fileIDToImageEmbedding,
+ clipMemoryTypeVectors: <ClipMemoryType, Vector>{
+ selectedClipType: queryVector,
+ },
+ );
+
+ final depletedClipMemories = await ClipMemoriesCalculator.compute(
+ depletedRemainingFiles,
+ currentTime,
+ <ClipShownLog>[],
+ surfaceAll: true,
+ isOfflineMode: false,
+ seenTimes: const <int, int>{},
+ fileIDToImageEmbedding: fileIDToImageEmbedding,
+ clipMemoryTypeVectors: <ClipMemoryType, Vector>{
+ selectedClipType: queryVector,
+ },
+ );
+
+ expect(fullClipMemories, hasLength(1));
+ expect(fullClipMemories.first.memories, hasLength(10));
+ expect(depletedClipMemories, isEmpty);
+ },
+ );
});
}