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