Land the persistence model and HTTP surface for local face recognition.
Inference still lives in Apollo (Phase 1); this side adds the data home
plus every endpoint Apollo's UI and FileViewer-React will consume.
Schema (new migration 2026-04-29-000000_add_faces):
- persons: visual identities. Optional entity_id bridges to the
existing knowledge-graph entities table; auto-bridging is left to
the management UI (we don't muddy LLM provenance from face rows).
UNIQUE(name COLLATE NOCASE) so 'alice' / 'Alice' fold to one row.
- face_detections: keyed on content_hash (cross-library dedup), with
status='detected' carrying bbox + 512-d embedding BLOB, and
'no_faces' / 'failed' marker rows that tell Phase 3's file watcher
not to re-scan. Marker invariant enforced via CHECK; partial UNIQUE
on content_hash WHERE status='no_faces' guards against double-marks.
Schema regenerated with `diesel print-schema` against a clean migration
run; joinables added for face_detections → libraries / persons and
persons → entities.
face_client.rs (sibling of apollo_client.rs):
- reqwest multipart, 60 s timeout (CPU inference on a backlog can be
slow; bounded threadpool on Apollo serializes calls anyway).
- FaceDetectError::{Permanent, Transient, Disabled} — Phase 3 keys
its marker-row decision on this. 422 → mark failed, 5xx → defer.
- APOLLO_FACE_API_BASE_URL falls back to APOLLO_API_BASE_URL when
unset; both unset = is_enabled() false, callers no-op.
faces.rs (DAO + handlers):
- SqliteFaceDao implements the full FaceDao trait; person face counts
go through sql_query because diesel's BoxedSelectStatement +
group_by trips trait-resolver recursion.
- merge_persons re-points face rows in a transaction, copies notes
when target's are empty, deletes src.
- manual POST /image/faces resolves content_hash through image_exif,
crops the user-drawn bbox with 10% padding (detector wants context
around ears/jaw), POSTs the crop to face_client.embed for a real
ArcFace vector, then inserts source='manual'.
- Cluster-suggest (Phase 6) gets its data from
GET /faces/embeddings — base64-encoded paged BLOBs so Apollo's
DBSCAN can stream them without ImageApi pre-aggregating.
Endpoints registered alongside add_*_services in main.rs:
GET /faces/stats?library=
GET /faces/embeddings?library=&unassigned=&limit=&offset=
GET /image/faces?path=&library=
POST /image/faces (manual create via embed)
PATCH /image/faces/{id}
DELETE /image/faces/{id}
GET /persons?library=
POST /persons
GET /persons/{id}
PATCH /persons/{id}
DELETE /persons/{id}?cascade=set_null|delete (set_null default)
POST /persons/{id}/merge
GET /persons/{id}/faces?library=
The file-watch hook (Phase 3) and the rerun-on-one-photo handler
(Phase 6) live behind the FaceDao methods marked dead_code today —
they're called only when those phases land. Same shape for the trait
methods that aren't reached by Phase 2 routes.
Tests: 3 DAO unit tests cover person CRUD + case-insensitive uniqueness,
marker-row idempotency (mark_status is a no-op when any row exists),
and merge re-pointing faces.
Cargo.toml: reqwest gains the `multipart` feature.
cargo build / cargo test --lib / cargo fmt / cargo clippy --all-targets
all clean for the new code; the two pre-existing test_path_excluder
failures and the pre-existing sort_by clippy warnings are unrelated and
present on master.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
64 lines
1.8 KiB
TOML
64 lines
1.8 KiB
TOML
[package]
|
|
name = "image-api"
|
|
version = "1.0.0"
|
|
authors = ["Cameron Cordes <cameronc.dev@gmail.com>"]
|
|
edition = "2024"
|
|
|
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
|
|
[profile.release]
|
|
lto = "thin"
|
|
|
|
[dependencies]
|
|
actix = "0.13.1"
|
|
actix-web = "4"
|
|
actix-rt = "2.6"
|
|
tokio = { version = "1.42.0", features = ["default", "process", "sync", "macros", "rt-multi-thread"] }
|
|
actix-files = "0.6"
|
|
actix-cors = "0.7"
|
|
actix-multipart = "0.7.2"
|
|
actix-governor = "0.5"
|
|
futures = "0.3.5"
|
|
jsonwebtoken = "9.3.0"
|
|
serde = "1"
|
|
serde_json = "1"
|
|
diesel = { version = "2.2.10", features = ["sqlite"] }
|
|
libsqlite3-sys = { version = "0.35", features = ["bundled"] }
|
|
diesel_migrations = "2.2.0"
|
|
chrono = "0.4"
|
|
clap = { version = "4.5", features = ["derive"] }
|
|
dotenv = "0.15"
|
|
bcrypt = "0.17.1"
|
|
image = { version = "0.25.5", default-features = false, features = ["jpeg", "png", "rayon", "webp", "tiff", "avif"] }
|
|
infer = "0.16"
|
|
walkdir = "2.4.0"
|
|
rayon = "1.5"
|
|
path-absolutize = "3.1"
|
|
log = "0.4"
|
|
env_logger = "0.11.5"
|
|
actix-web-prom = "0.9.0"
|
|
prometheus = "0.13"
|
|
lazy_static = "1.5"
|
|
anyhow = "1.0"
|
|
rand = "0.8.5"
|
|
opentelemetry = { version = "0.31.0", features = ["default", "metrics", "tracing"] }
|
|
opentelemetry_sdk = { version = "0.31.0", features = ["default", "rt-tokio-current-thread", "metrics"] }
|
|
opentelemetry-otlp = { version = "0.31.0", features = ["default", "metrics", "tracing", "grpc-tonic"] }
|
|
opentelemetry-stdout = "0.31.0"
|
|
opentelemetry-appender-log = "0.31.0"
|
|
tempfile = "3.20.0"
|
|
regex = "1.11.1"
|
|
exif = { package = "kamadak-exif", version = "0.6.1" }
|
|
reqwest = { version = "0.12", features = ["json", "stream", "multipart"] }
|
|
async-stream = "0.3"
|
|
tokio-util = { version = "0.7", features = ["io"] }
|
|
bytes = "1"
|
|
urlencoding = "2.1"
|
|
zerocopy = "0.8"
|
|
ical = "0.11"
|
|
scraper = "0.20"
|
|
base64 = "0.22"
|
|
blake3 = "1.5"
|
|
async-trait = "0.1"
|
|
indicatif = "0.17"
|