In this sample, you'll learn how to store image embeddings to Firestore Vector Store and later retrieve images based on similarity search on a keyword or image.
You can see the full sample in main.py.
Make sure you're logged in:
gcloud auth application-default login
Enable Firestore API:
gcloud services enable firestore.googleapis.com
Create a Firestore database:
gcloud firestore databases create --database image-database --location=europe-west1
Create a Firestore index for retrieval later:
gcloud alpha firestore indexes composite create --project=your-project-id \
--database="image-database" --collection-group=ImageCollection --query-scope=COLLECTION \
--field-config=vector-config='{"dimension":"1408","flat": "{}"}',field-path=embedding
Let's add some images.
Add an image from a Cloud Storage url:
python main.py --project_id=genai-atamel --image_paths gs://genai-atamel-firestore-images/landmark1.png
Add other images from a local folder:
python main.py --project_id=genai-atamel --image_paths ../images/landmark2.png ../images/landmark3.png
Add another image from an HTTP url:
python main.py --project_id=genai-atamel --image_paths https://atamel.dev/img/mete-512.jpg
At this point, you should see images and their embeddings saved to Firestore:
Now, retrieve and display images with a keyword:
python main.py --project_id=genai-atamel --search_by_keyword="stadium"
python main.py --project_id=genai-atamel --search_by_keyword="temple"
python main.py --project_id=genai-atamel --search_by_keyword="statue"
python main.py --project_id=genai-atamel --search_by_keyword="man"
You can also retrieve by searching similar images:
python main.py --project_id=genai-atamel --search_by_image="../images/landmark4.png"