Download sql/search_similar_faces.sql from Atomio/facerecog: direct link, hf CLI and curl.
- Browser
- Download file 945 Bytes
-
https://huggingface.co/spaces/Atomio/facerecog/resolve/main/sql/search_similar_faces.sql
- Command line
-
hf download hf://spaces/Atomio/facerecog/sql/search_similar_faces.sql
-
curl -L -o search_similar_faces.sql https://huggingface.co/spaces/Atomio/facerecog/resolve/main/sql/search_similar_faces.sql
945 Bytes
| -- Function to search for similar face embeddings using cosine similarity | |
| -- Run this in your Supabase SQL Editor after creating the faces table | |
| CREATE OR REPLACE FUNCTION search_similar_faces( | |
| query_embedding vector(512), | |
| similarity_threshold float DEFAULT 0.6, | |
| match_count int DEFAULT 5 | |
| ) | |
| RETURNS TABLE ( | |
| id uuid, | |
| user_id text, | |
| similarity float, | |
| created_at timestamptz, | |
| updated_at timestamptz | |
| ) | |
| LANGUAGE sql | |
| STABLE | |
| AS $$ | |
| SELECT | |
| f.id, | |
| f.user_id, | |
| 1 - (f.embedding <=> query_embedding) AS similarity, | |
| f.created_at, | |
| f.updated_at | |
| FROM faces f | |
| WHERE 1 - (f.embedding <=> query_embedding) > similarity_threshold | |
| ORDER BY f.embedding <=> query_embedding | |
| LIMIT match_count; | |
| $$; | |
| -- Grant execute permission to authenticated users | |
| GRANT EXECUTE ON FUNCTION search_similar_faces TO authenticated; | |
| GRANT EXECUTE ON FUNCTION search_similar_faces TO service_role; | |