Search for images on websites

With Vertex AI Search, you can search for images using a app with website data. You supply a query in the form of a text string or an image, and the default_config.search method returns images for that query.

Before you begin

Make sure you satisfy the following prerequisites. Requirements vary depending on whether you search using a text query or an image query.

To use the command line to preview image results for a website, use the engines.servingConfigs.search method:

  1. Find your app ID. If you already have your app ID, skip to the next step.

    1. In the Google Cloud console, go to the AI Applications page.

      Go to Apps

    2. On the Apps page, find the name of your app and get the app's ID from the ID column.

  2. Call the engines.servingConfigs.search method, specifying 1 for the search_type. Choose the method syntax depending on whether your query is text or image bytes.

    Query is a text string

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/engines/APP_ID/servingConfigs/default_config:search" \
    -d '{
    "servingConfig": "projects/PROJECT_ID/locations/global/collections/default_collection/engines/APP_ID/servingConfigs/default_search",
    "query": "QUERY",
    "pageSize": "PAGE_SIZE",
    "offset": "OFFSET",
    "params": {"search_type": 1}
    }'
    

    Query is an image

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/collections/default_collection/engines/APP_ID/servingConfigs/default_search:search" \
    -d '{
    "servingConfig": "projects/PROJECT_ID/locations/global/collections/default_collection/engines/APP_ID/servingConfigs/default_search",
    "imageQuery": {"imageBytes":"IMAGE_BYTES"},
    "pageSize": "PAGE_SIZE",
    "offset": "OFFSET",
    "params": {"search_type": 1}
    }'
    

    Replace the following:

    • PROJECT_ID: the ID of your project.

    • APP_ID: the ID of your app.

    • QUERY: the search query text. For example, "Round headlight cars" or "show me dress with stripes."

    • IMAGE_BYTES: the image in Base64 encoded bytes. Supported formats are JPEG, PNG, and BMP.

    • PAGE_SIZE: optional. The number of results returned by the search. The default value is 10 for website search.

      • Values below 0 cause an error.
      • Values above 100 cause the value to be set to 100.
    • OFFSET: optional. The starting index of the results. The default value is 0.

      For example, if the offset is 2 and the page size is 10, results 2 through 11 are returned.

  3. Review the response. See the following table for field descriptions:

    FieldDescription
    titleThe plain text title of the web page that contains the image
    htmlTitleThe title, in HTML, of the web page that contains the image
    displayLinkAn abridged version of this search's result URL, usually the domain name—for example, www.example.com
    linkThe URL of the image
    image.contextLinkContext link: A URL pointing to the web page that contains the image
    image.byteSizeThe size of the image, in bytes
    image.widthThe width of the image, in pixels
    image.heightThe height of the image, in pixels
    image.thumbnailWidthThe width of the thumbnail image, in pixels
    image.thumbnailHeightThe height of the thumbnail image, in pixels
    image.thumbnailLinkThe URL of the thumbnail image
    mimeThe MIME type of the image
    fileFormatThe file format of the image