1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use serde::{Deserialize, Serialize};
/// Where a background embedding pass over one library stands.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum EmbeddingPassState {
/// Sent before the model is loaded and, the first time, downloaded.
Started,
/// Sent after each media.
Running,
Completed,
/// Left because the library was paused; resuming starts a new pass.
Paused,
/// Left because embeddings were turned off for the library, or it was removed.
Stopped,
/// Left early after too many failures in a row; a later pass carries on.
Interrupted,
/// Could not run, for example because the model cannot be loaded.
Failed,
}
/// Payload of the `embedding_progress` event. A pass sends `started` once, `running`
/// after each media, then exactly one of `completed`, `paused`, `stopped`,
/// `interrupted` or `failed`.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct EmbeddingProgressMessage {
pub library: String,
pub state: EmbeddingPassState,
pub embedder: String,
/// Medias tried so far in this pass.
pub processed: u64,
/// Of which embedded; the others failed.
pub embedded: u64,
/// Medias this pass covers: those pending when it started, kept in step with
/// uploads and deletions since. Never below `processed`.
pub total: u64,
}
/// Where the embedding model stands on the server.
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum EmbeddingModelState {
/// In memory, ready to embed.
Loaded,
/// On disk, loaded on first use.
Available,
Downloading,
/// Downloaded on first use.
Missing,
}
/// How many medias of a library have a vector.
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MediaEmbeddingCounts {
/// Photos and videos in the library.
pub total: u64,
pub embedded: u64,
/// Still to embed, including failed medias that will be tried again.
pub pending: u64,
/// Gave up after too many failures.
pub failed: u64,
}
/// The media embeddings of a library (`/libraries/{id}/medias/embeddings/status`, and
/// the answer of pause and resume).
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MediaEmbeddingStatus {
pub embedder: String,
pub dimension: usize,
pub search_dimension: usize,
/// Library setting `embeddings`: new and existing medias are embedded in the background.
pub enabled: bool,
/// Library setting `embeddingsPaused`: nothing is embedded until it is resumed.
pub paused: bool,
pub model: EmbeddingModelState,
/// A backfill is running on this server (any library).
pub running: bool,
#[serde(flatten)]
pub counts: MediaEmbeddingCounts,
}
/// The answer to starting a pass (`/libraries/{id}/medias/embeddings/process`).
#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum MediaEmbeddingProcessStatus {
/// Queued to start at once.
Started,
/// A pass is already running: it handles this library, or the next one does.
AlreadyRunning,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct MediaEmbeddingProcessResult {
pub status: MediaEmbeddingProcessStatus,
pub message: String,
}