Skip to content

Alimustoofaa/FaceSearch_PostreSQL_Vector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง  Face Search with PostgreSQL & pgvector

This project demonstrates how to build a face search system using face embeddings, deep learning, and PostgreSQL vector search with the pgvector extension. Face search enables rapid and accurate similarity-based retrieval of face images from a database โ€” useful for surveillance, access control, e-commerce, and social platforms.

๐Ÿ“ธ What is Face Embedding?

Face embedding is a fixed-length vector representation of a face. Generated via deep learning models like FaceNet or ArcFace, it allows:

  • ๐Ÿ‘ฅ Similar faces โ†’ embeddings close in vector space
  • ๐Ÿงโ€โ™‚๏ธ๐Ÿงโ€โ™€๏ธ Different faces โ†’ embeddings far apart

๐Ÿงฎ What is PostgreSQL Vector Search?

Using the pgvector extension, PostgreSQL can:

  • Store high-dimensional vectors (like 512D face embeddings)
  • Perform similarity search using:
    • Euclidean Distance (<->)
    • Cosine Similarity (<#>)
    • Inner Product (<=>)
  • Support Approximate Nearest Neighbor (ANN) search (optional)

๐Ÿ› ๏ธ System Architecture

  1. ๐Ÿ“ฅ Collect Face Images via DuckDuckGo
  2. ๐Ÿ“ Extract Face Embeddings using facenet-pytorch
  3. ๐Ÿ—ƒ Store Embeddings in PostgreSQL (pgvector)
  4. ๐Ÿ” Search Similar Faces via SQL
  5. ๐Ÿ–ฅ Deploy Web UI with Streamlit
  6. ๐Ÿณ Deploy with Docker Compose

๐Ÿ” Step-by-Step Guide

Running pgvector with docker compose

cd docker
docker compose up -d
  1. ๐Ÿ“ธ Collecting Face Image Data
    notebook/1. collecting_data.ipynb
    
  2. ๐Ÿ“ Embedding Face Images
    notebook/2. embedding_faces.ipynb
    
  3. ๐Ÿ—ƒ๏ธ Storing Embeddings in PostgreSQL
    notebook/3. storing_pgvector.ipynb
    

Run Streamlit UI

Streamlit run src/app.py

๐Ÿ“š References

facenet-pytorch: https://github.com/timesler/facenet-pytorch

pgvector: https://github.com/pgvector/pgvector

DuckDuckGo Search: https://pypi.org/project/duckduckgo-search/