# Cloud Function for Image Processing This directory contains the source code for the Cloud Function that processes image embeddings. ## Deployment **Note: This Cloud Function is now deployed via Terraform, not the previous bash script.** The Cloud Function is automatically deployed when you run: ```bash cd deployment/terraform terraform apply ``` ## What the Cloud Function Does 1. **Triggered by Pub/Sub**: Listens to the `image-processing-topic` for new image processing tasks 2. **Downloads Images**: Retrieves images from Google Cloud Storage 3. **Generates Embeddings**: Uses Google Cloud Vision API to create image embeddings 4. **Stores Vectors**: Saves embeddings to the Qdrant vector database 5. **Updates Status**: Updates Firestore with processing status and embedding metadata ## Environment Variables The following environment variables are automatically configured by Terraform: - `QDRANT_HOST`: IP address of the vector database VM - `QDRANT_PORT`: Port for Qdrant (default: 6333) - `QDRANT_API_KEY`: API key for Qdrant authentication - `QDRANT_COLLECTION`: Collection name for storing vectors (default: image_vectors) ## Function Configuration - **Runtime**: Python 3.11 - **Memory**: 512MB - **Timeout**: 540 seconds (9 minutes) - **Max Instances**: 10 - **Min Instances**: 0 (scales to zero when not in use) - **Retry Policy**: Automatic retries on failure ## Dependencies See `requirements.txt` for the complete list of Python dependencies. ## Monitoring The function automatically logs to Google Cloud Logging. You can monitor: - Function executions - Error rates - Processing times - Pub/Sub message handling ## Manual Testing To manually trigger the function, publish a message to the Pub/Sub topic: ```json { "image_id": "test-image-123", "storage_path": "your-bucket/path/to/image.jpg", "team_id": "team-456", "retry_count": 0 } ```