feat(api): pgvector native embeddings + HNSW kNN for person ranking (spec 043) #826
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/pgvector-embedding-index"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Native pgvector storage for face embeddings + HNSW cosine kNN (Immich-parity), with JSONB kept as source of truth.
Image (the one breaking change, handled)
deploy/postgres/Dockerfile:postgis/postgis:16-3.4(Debian) +postgresql-16-pgvector(PGDG, v0.8.6). PostGIS untouched/reverse-lookup unaffected.memories-postgresfrom it; same PG16 + samememories-postgres-datavolume → recreate keeps all data.Migration V136
CREATE EXTENSION vector;
embedding_vec vector(512)trigger-maintained from the JSONB (512-length guard, NULL on invalid — write never fails); one-time backfill; HNSW index (vector_cosine_ops, m=16, ef=300); dropped the unused 568 MB GIN placeholder. No data loss possible; JSONB rows unchanged.Consumer (first, per spec)
personRanking steps 2+3 now use
EmbeddingKnnService: one SQLGROUP BY person MIN(embedding <=> q)per candidate vector — identicalclamp(1 - min pairwise distance)score with ZERO vectors loaded into Java. Scope/semantics preserved (dominant model pair, active persons, accepted face annotations, null for embedding-less/zero-norm/mismatched). Merge suggestion + worker weak matching stay brute-force (next spec: worker incremental matching).Verification
Index Scan using e_hnsw, 0.48 ms @ 5k rowsDeploy note: merging this recreates memories-postgres (data preserved, verified path). Post-merge deploy run will be watched explicitly.