Skip to content

perf: add hnsw vector index for pgvector - #76

Merged
ademboukabes merged 1 commit into
developfrom
perf/add-hnsw-indexes
Aug 5, 2026
Merged

perf: add hnsw vector index for pgvector#76
ademboukabes merged 1 commit into
developfrom
perf/add-hnsw-indexes

Conversation

@ademboukabes

Copy link
Copy Markdown
Collaborator

Description
Adds HNSW (Hierarchical Navigable Small World) vector indexes to the users and photo_faces tables for the pgvector embeddings.

Reasoning
Currently, queries executing face_embedding <=> $1 (Cosine Distance) are performing full sequential scans across the entire table. As the dataset of uploaded photos and user faces grows, this will result in O(N) search complexity, causing severe CPU spikes and degraded API latency.

Adding an HNSW index with vector_cosine_ops reduces the search complexity to O(log N), allowing the AI matching pipeline to scale efficiently with minimal performance overhead.

Changes

  • Created Alembic migration 9ec59aeb192b_add_hnsw_indexes
  • Added CREATE INDEX using hnsw on users.face_embedding
  • Added CREATE INDEX using hnsw on photo_faces.embedding

@ademboukabes
ademboukabes merged commit 1fdf1fb into develop Aug 5, 2026
2 checks passed
@ademboukabes
ademboukabes deleted the perf/add-hnsw-indexes branch August 5, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant