This commit is contained in:
johnpccd 2025-05-25 13:18:37 +02:00
parent d3d6e9050c
commit a80550bdf6
9 changed files with 133 additions and 443 deletions

View File

@ -344,7 +344,7 @@ vector_db = VectorDatabaseService(
# Add image vector # Add image vector
point_id = vector_db.add_image_vector( point_id = vector_db.add_image_vector(
image_id="img_123", image_id="img_123",
vector=[0.1, 0.2, ...], # 512-dimensional vector vector=[0.1, 0.2, ...], # 1408-dimensional vector
metadata={"filename": "image.jpg", "size": 1024} metadata={"filename": "image.jpg", "size": 1024}
) )

View File

@ -1,62 +0,0 @@
#!/bin/bash
set -e
# Container Image Cleanup Script
# This script cleans up container images from Google Container Registry
# Images are not managed by Terraform, so this provides a manual cleanup option
PROJECT_ID=$(gcloud config get-value project)
IMAGE_NAME="sereact-api"
if [ -z "$PROJECT_ID" ]; then
echo "ERROR: No Google Cloud project is set. Run 'gcloud config set project YOUR_PROJECT_ID'"
exit 1
fi
echo "Cleaning up container images for project: $PROJECT_ID"
echo "Image repository: gcr.io/$PROJECT_ID/$IMAGE_NAME"
echo ""
# Check if repository exists
if ! gcloud container images list-tags "gcr.io/$PROJECT_ID/$IMAGE_NAME" > /dev/null 2>&1; then
echo "No container images found for $IMAGE_NAME"
exit 0
fi
echo "Found container images. Listing current images:"
gcloud container images list-tags "gcr.io/$PROJECT_ID/$IMAGE_NAME"
echo ""
read -p "Do you want to delete ALL images for $IMAGE_NAME? (yes/no): " confirm
if [ "$confirm" != "yes" ]; then
echo "Cleanup cancelled."
exit 0
fi
echo "Deleting container images..."
# Get all image digests and delete them
DIGESTS=$(gcloud container images list-tags "gcr.io/$PROJECT_ID/$IMAGE_NAME" --format="get(digest)" --filter="tags:*" 2>/dev/null || true)
UNTAGGED_DIGESTS=$(gcloud container images list-tags "gcr.io/$PROJECT_ID/$IMAGE_NAME" --format="get(digest)" --filter="-tags:*" 2>/dev/null || true)
# Delete tagged images
if [ ! -z "$DIGESTS" ]; then
echo "Deleting tagged images..."
for digest in $DIGESTS; do
gcloud container images delete "gcr.io/$PROJECT_ID/$IMAGE_NAME@$digest" --force-delete-tags --quiet || echo "Failed to delete $digest"
done
fi
# Delete untagged images
if [ ! -z "$UNTAGGED_DIGESTS" ]; then
echo "Deleting untagged images..."
for digest in $UNTAGGED_DIGESTS; do
gcloud container images delete "gcr.io/$PROJECT_ID/$IMAGE_NAME@$digest" --quiet || echo "Failed to delete $digest"
done
fi
echo "Container image cleanup completed."
echo ""
echo "Note: The repository gcr.io/$PROJECT_ID/$IMAGE_NAME may still exist but should be empty."
echo "You can verify with: gcloud container images list-tags gcr.io/$PROJECT_ID/$IMAGE_NAME"

View File

@ -1,107 +0,0 @@
#!/usr/bin/env python3
"""
Simple test script to verify Vertex AI multimodal embeddings work correctly.
Run this script to test the embedding generation before deploying.
"""
import os
import sys
import logging
from PIL import Image
import io
import numpy as np
# Add the current directory to the path so we can import main
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def create_test_image():
"""Create a simple test image"""
# Create a simple 100x100 RGB image with a red square
img = Image.new('RGB', (100, 100), color='white')
pixels = img.load()
# Draw a red square in the center
for i in range(25, 75):
for j in range(25, 75):
pixels[i, j] = (255, 0, 0) # Red
# Convert to bytes
img_bytes = io.BytesIO()
img.save(img_bytes, format='PNG')
return img_bytes.getvalue()
def test_vertex_ai_embeddings():
"""Test Vertex AI embedding generation"""
try:
# Set required environment variables for testing
os.environ['GOOGLE_CLOUD_PROJECT'] = os.environ.get('GOOGLE_CLOUD_PROJECT', 'your-project-id')
os.environ['VERTEX_AI_LOCATION'] = os.environ.get('VERTEX_AI_LOCATION', 'us-central1')
# Import the function we want to test
from main import generate_image_embeddings
# Create test image
logger.info("Creating test image...")
test_image_data = create_test_image()
logger.info(f"Created test image with {len(test_image_data)} bytes")
# Generate embeddings
logger.info("Generating embeddings using Vertex AI...")
embeddings = generate_image_embeddings(test_image_data)
if embeddings is None:
logger.error("Failed to generate embeddings!")
return False
# Verify embeddings
logger.info(f"Generated embeddings with shape: {embeddings.shape}")
logger.info(f"Embeddings dtype: {embeddings.dtype}")
logger.info(f"Embeddings range: [{embeddings.min():.4f}, {embeddings.max():.4f}]")
logger.info(f"Embeddings norm: {np.linalg.norm(embeddings):.4f}")
# Basic validation
assert isinstance(embeddings, np.ndarray), "Embeddings should be numpy array"
assert embeddings.dtype == np.float32, "Embeddings should be float32"
assert len(embeddings.shape) == 1, "Embeddings should be 1D array"
assert embeddings.shape[0] == 1408, f"Expected 1408 dimensions, got {embeddings.shape[0]}"
# Check if normalized (should be close to 1.0)
norm = np.linalg.norm(embeddings)
assert 0.9 <= norm <= 1.1, f"Embeddings should be normalized, norm is {norm}"
logger.info("✅ All tests passed! Vertex AI embeddings are working correctly.")
return True
except ImportError as e:
logger.error(f"Import error: {e}")
logger.error("Make sure you have installed the required dependencies:")
logger.error("pip install google-cloud-aiplatform")
return False
except Exception as e:
logger.error(f"Test failed with error: {e}")
return False
if __name__ == "__main__":
logger.info("Testing Vertex AI multimodal embeddings...")
# Check if required environment variables are set
project_id = os.environ.get('GOOGLE_CLOUD_PROJECT')
if not project_id:
logger.error("Please set GOOGLE_CLOUD_PROJECT environment variable")
logger.error("Example: export GOOGLE_CLOUD_PROJECT=your-project-id")
sys.exit(1)
logger.info(f"Using project: {project_id}")
success = test_vertex_ai_embeddings()
if success:
logger.info("🎉 Test completed successfully!")
sys.exit(0)
else:
logger.error("❌ Test failed!")
sys.exit(1)

View File

@ -1,135 +0,0 @@
#!/bin/bash
set -e
# Configuration
PROJECT_ID="gen-lang-client-0424120530"
REGION="us-central1"
SERVICE_NAME="sereact"
echo "=== Cloud Run Deployment Fix Script ==="
echo "Project: $PROJECT_ID"
echo "Region: $REGION"
echo "Service: $SERVICE_NAME"
echo ""
# Function to check if gcloud is authenticated
check_auth() {
if ! gcloud auth list --filter=status:ACTIVE --format="value(account)" | grep -q .; then
echo "ERROR: No active gcloud authentication found."
echo "Please run: gcloud auth login"
exit 1
fi
}
# Function to clean up problematic revisions
cleanup_revisions() {
echo "Step 1: Cleaning up problematic revisions..."
# Get all revisions for the service
REVISIONS=$(gcloud run revisions list --service=$SERVICE_NAME --region=$REGION --project=$PROJECT_ID --format="value(metadata.name)" 2>/dev/null || echo "")
if [ -z "$REVISIONS" ]; then
echo "No revisions found or service doesn't exist."
return 0
fi
echo "Found revisions:"
echo "$REVISIONS"
echo ""
# Delete old revisions (keep the latest one for now)
REVISION_COUNT=$(echo "$REVISIONS" | wc -l)
if [ $REVISION_COUNT -gt 1 ]; then
echo "Deleting old revisions to prevent conflicts..."
echo "$REVISIONS" | head -n -1 | while read revision; do
if [ ! -z "$revision" ]; then
echo "Deleting revision: $revision"
gcloud run revisions delete "$revision" --region=$REGION --project=$PROJECT_ID --quiet || echo "Failed to delete $revision (may be in use)"
fi
done
fi
}
# Function to force a new deployment
force_redeploy() {
echo "Step 2: Forcing a new deployment with Terraform..."
cd "$(dirname "$0")/terraform"
# Taint the Cloud Run service to force recreation
echo "Tainting Cloud Run service to force recreation..."
terraform taint google_cloud_run_service.sereact || echo "Service not in state or already tainted"
# Apply the configuration
echo "Applying Terraform configuration..."
terraform apply -auto-approve
cd - > /dev/null
}
# Function to verify deployment
verify_deployment() {
echo "Step 3: Verifying deployment..."
# Wait a moment for the service to be ready
sleep 10
# Check service status
SERVICE_URL=$(gcloud run services describe $SERVICE_NAME --region=$REGION --project=$PROJECT_ID --format="value(status.url)" 2>/dev/null || echo "")
if [ ! -z "$SERVICE_URL" ]; then
echo "✅ Service deployed successfully!"
echo "Service URL: $SERVICE_URL"
# Test the service
echo "Testing service health..."
if curl -s -o /dev/null -w "%{http_code}" "$SERVICE_URL/health" | grep -q "200"; then
echo "✅ Service is responding correctly!"
else
echo "⚠️ Service deployed but health check failed. Check logs:"
echo "gcloud logging read \"resource.type=cloud_run_revision AND resource.labels.service_name=$SERVICE_NAME\" --limit=10 --project=$PROJECT_ID"
fi
else
echo "❌ Service deployment failed."
exit 1
fi
}
# Main execution
main() {
echo "Starting Cloud Run deployment fix..."
echo ""
check_auth
cleanup_revisions
force_redeploy
verify_deployment
echo ""
echo "=== Deployment Fix Complete ==="
echo "If you continue to have issues, try:"
echo "1. Building a new image: ./deployment/deploy.sh --deploy --build"
echo "2. Checking logs: gcloud logging read \"resource.type=cloud_run_revision AND resource.labels.service_name=$SERVICE_NAME\" --limit=10 --project=$PROJECT_ID"
}
# Help function
show_help() {
echo "Usage: $0 [--help]"
echo ""
echo "This script fixes Cloud Run deployment issues by:"
echo "1. Cleaning up problematic revisions"
echo "2. Forcing a new deployment with Terraform"
echo "3. Verifying the deployment"
echo ""
echo "Options:"
echo " --help Show this help message"
}
# Parse arguments
if [ "$1" = "--help" ]; then
show_help
exit 0
fi
# Run main function
main

View File

@ -172,7 +172,7 @@ curl -X PUT "http://localhost:6333/collections/image_vectors" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
"vectors": { "vectors": {
"size": 512, "size": 1408,
"distance": "Cosine" "distance": "Cosine"
}, },
"optimizers_config": { "optimizers_config": {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -7,6 +7,7 @@ google-cloud-storage==2.12.0
google-cloud-vision==3.4.5 google-cloud-vision==3.4.5
google-cloud-firestore==2.11.1 google-cloud-firestore==2.11.1
google-cloud-pubsub==2.18.4 google-cloud-pubsub==2.18.4
google-cloud-aiplatform==1.38.0
python-multipart==0.0.6 python-multipart==0.0.6
python-jose==3.3.0 python-jose==3.3.0
passlib==1.7.4 passlib==1.7.4

View File

@ -1,14 +0,0 @@
#!/bin/bash
set -e
# Source the build environment to reuse variables
source "$(dirname "$0")/build.sh"
# Push the Docker image to the registry
echo "Pushing image: ${FULL_IMAGE_NAME} to registry..."
docker push "${FULL_IMAGE_NAME}"
echo "Image pushed successfully"
echo ""
echo "Image pushed to: ${FULL_IMAGE_NAME}"
echo ""