Get started with media search

You can quickly build a state-of-the-art media search app.Media search enables your audiences to discover content, with Google-qualityresults.

For general information about Vertex AI Search for media, seeIntroduction to media search and recommendations.

In this getting-started tutorial, you will use theMovielens dataset to demonstratehow to upload your media content catalog into Vertex AI Search. TheMovielens dataset contains a catalog of movies (documents).

After uploading the movie data, you'll create a search app and test it throughthe preview page.

If you completed theGet started with media recommendations tutorial and you still have the data store (suggested namequickstart-media-data-store), then you can use that data store instead ofcreating another. In this case, you should begin the tutorial atCreate an app for media search.

Estimated time to complete this tutorial: ~1 hour.

Objectives

  • Learn how to import media documents to create a media data store.
  • Create, configure, and test a search app.

Before following this tutorial, make sure you have done the steps inBefore youbegin.


To follow step-by-step guidance for this task directly in the Google Cloud console, clickGuide me:

Guide me


Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI Search (Discovery Engine), Cloud Storage, BigQuery APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the APIs

  5. Make sure that you have the following role or roles on the project: Discovery Engine Admin and BigQuery Admin.

    Check for the roles

    1. In the Google Cloud console, go to theIAM page.

      Go to IAM
    2. Select the project.
    3. In thePrincipal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check theRole column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to theIAM page.

      Go to IAM
    2. Select the project.
    3. ClickGrant access.
    4. In theNew principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. ClickSelect a role, then search for the role.
    6. To grant additional roles, clickAdd another role and add each additional role.
    7. ClickSave.
  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  7. Verify that billing is enabled for your Google Cloud project.

  8. Enable the Vertex AI Search (Discovery Engine), Cloud Storage, BigQuery APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the APIs

  9. Make sure that you have the following role or roles on the project: Discovery Engine Admin and BigQuery Admin.

    Check for the roles

    1. In the Google Cloud console, go to theIAM page.

      Go to IAM
    2. Select the project.
    3. In thePrincipal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check theRole column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to theIAM page.

      Go to IAM
    2. Select the project.
    3. ClickGrant access.
    4. In theNew principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. ClickSelect a role, then search for the role.
    6. To grant additional roles, clickAdd another role and add each additional role.
    7. ClickSave.

Prepare the dataset

Note: If you completed theGet started with media recommendations tutorial and you still have the data store (suggested namequickstart-media-data-store), skip toCreate an app for media search.

You use the Cloud Shell to import the Movielens dataset and restructure thedataset for Vertex AI Search for media.

Open the Cloud Shell

  1. OpenGoogle Cloud console.
  2. Select your Google Cloud project.
  3. Take note of the project ID in theProject info card on the dashboardpage. You will need the project ID for the following procedures.
  4. Click theActivate Cloud Shell button at the top of the console. ACloud Shell session opens inside a new frame at the bottom of theGoogle Cloud console and displays a command-line prompt. For other ways tolaunch the Cloud Shell, seeLaunch Cloud Shell.

    Cloud Shell

Import the dataset

The Movielens dataset is available in a public Cloud Storage bucket to make it easier to import.

  1. Run the following using your project ID to set the default project for the command-line.

    gcloudconfigsetprojectPROJECT_ID
  2. Create a BigQuery dataset:

    bqmkmovielens
  3. Loadmovies.csv into a newmovies BigQuery table:

    bqload--skip_leading_rows=1movielens.movies\gs://cloud-samples-data/gen-app-builder/media-recommendations/movies.csv\movieId:integer,title,genres
  4. Loadratings.csv into a newratings BigQuery table:

    bqload--skip_leading_rows=1movielens.ratings\gs://cloud-samples-data/gen-app-builder/media-recommendations/ratings.csv\userId:integer,movieId:integer,rating:float,time:timestamp

Create BigQuery views

In this step, you restructure the Movielens dataset so it follows the expectedformat for media data stores.

For this guide, you create fakeview-item user events during the past 90 daysfrom positive ratings (>= 4).

  1. Create a view that converts the movies table into theDocument schema:

    bqmk--project_id=PROJECT_ID \--use_legacy_sql=false \--view 'WITHtAS(SELECTCAST(movieIdASstring)ASid,SUBSTR(title,0,128)AStitle,SPLIT(genres,"|")AScategoriesFROM`PROJECT_ID.movielens.movies`)SELECTid,"default_schema"asschemaId,nullasparentDocumentId,TO_JSON_STRING(STRUCT(titleastitle,categoriesascategories,CONCAT("http://mytestdomain.movie/content/",id)asuri,"2023-01-01T00:00:00Z"asavailable_time,"2033-01-01T00:00:00Z"asexpire_time,"movie"asmedia_type))asjsonDataFROMt;'\movielens.movies_view

    Now the new view has the schema that the Discovery Engine API expects.

  2. Go to theBigQuery page in Google Cloud console.

    Go to BigQuery

  3. In theExplorer pane, expand your project name, clickDatasets,select themovielens dataset, and clickmovies_view to open theschema page for this view.

    Alternatively, in theExplorer pane, select theClassic explorer tab,expand your project name, expand themovielensdataset and clickmovies_view to open the schema page for this view.Products view

  4. Go to theTable explorer tab.Products view

  5. In theGenerated query pane, click theCopy to query button. The query editor opens.

  6. ClickRun to see movie data in the view that you created.

  7. Create fictitioususer events from movie ratings by running the following Cloud Shell command:

    bqmk--project_id=PROJECT_ID \--use_legacy_sql=false \--view 'WITHtAS(SELECTMIN(UNIX_SECONDS(time))ASold_start,MAX(UNIX_SECONDS(time))ASold_end,UNIX_SECONDS(TIMESTAMP_SUB(CURRENT_TIMESTAMP(),INTERVAL90DAY))ASnew_start,UNIX_SECONDS(CURRENT_TIMESTAMP())ASnew_endFROM`PROJECT_ID.movielens.ratings`)SELECTCAST(userIdASSTRING)ASuserPseudoId,"view-item"ASeventType,FORMAT_TIMESTAMP("%Y-%m-%dT%X%Ez",TIMESTAMP_SECONDS(CAST((t.new_start+(UNIX_SECONDS(time)-t.old_start)*(t.new_end-t.new_start)/(t.old_end-t.old_start))ASint64)))ASeventTime,[STRUCT(movieIdASid,nullASname)]ASdocuments,FROM`PROJECT_ID.movielens.ratings`,tWHERErating>=4;'\movielens.user_events

Activate Vertex AI Search

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

    AI Applications

  2. Optional: ClickAllow Google to selectively sample model input andresponses.

  3. ClickContinue and activate the API.

Create an app for media search

The procedures in this section guide you through creating and deploying a mediasearch app.

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

    AI Applications

  2. ClickCreate app.

  3. On theCreate App page, underMedia catalog search, clickCreate.

  4. In theYour app name field, enter a name for your app such asquickstart-media-search. Your app ID appears under the engine name.

  5. ClickContinue.

  6. If you completed theGet started with media recommendations tutorial and you still have the data store (suggested namequickstart-media-data-store), then select it, clickCreate, and skip toPreview search.

  7. If you don't have a data store that contains the movielens dataset, createa new data store and select it:

    1. On theData Stores page, clickCreate data store.

    2. Enter a display name for your data store, such asquickstart-media-data-store, and then clickCreate.

    3. Select the data store you just created, and then clickCreate to createyour app. You will be redirected to theSelect a data source page.

Import data

Next, import the movies and user events data that were formatted earlier.

Import documents

  1. If you are not automatically redirected to theSelect a data source page:

    • Open theDocuments tab.
    • ClickImport Data.
  2. On theSelect a data source page, selectBigQuery.

  3. Enter the name of themovies BigQuery view you created and clickImport.

    PROJECT_ID.movielens.movies_view
  4. Wait until all documents have been imported, which should take about 15 minutes.There should be 86537 documents when complete.

    You can check theActivity tab for the import operation status. When theimport is complete, the import operation status changes toCompleted.

Import user events

  1. Open theEvents tab.

  2. ClickImport Events.

  3. SelectBigQuery.

  4. Enter the name of theuser_events BigQuery view you created and clickImport.

    PROJECT_ID.movielens.user_events
  5. You can proceed to the next step before the events are imported, but the search results won't yet contain the full dataset.

    You can check theActivity tab for the operation status. The process takesabout an hour to complete because you are importing millions of rows.

Preview and configure search

  1. In the navigation menu, clickConfigurations.

  2. In theSearch here box, type the name of a movie, such as "The Lord of the Rings".

  3. Notice that the search results are relevant to the movie title entered.

  4. On this page, you can customize how the search widget displays the search result information. SeeConfigure results for the search widget to learn more.

    For media search apps, you can:

    After making changes clickSave and publish to update the widget.

Deploy the search widget

  1. In the navigation menu, clickIntegration.

  2. Make sure theWidget tab is selected.

  3. SelectJWT or OAuth based as the widget authorization type.

  4. In theDomain field, enter the domain name for web page where you willput the widget. For example, if you are going to copy the widget to the webpageexample.com/ai.html, enterexample.com as the domain.

  5. ClickAdd, and then clickSave.

  6. Copy the code snippet provided in theCopy the following code to yourweb application section.

  7. In your codebase, generate an authorization token.

  8. To pass the authorization token to your widget, use the "Setauthorization token" code snippet provided in theCopy the following codeto your web application section and replace the text<JWT or OAuth tokenprovided by you backend> with your authorization token.

  9. For help integrating the search app into your web app,see the code samples atGet search results.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used on this page, follow these steps.

You can reuse the data store you created for media recommendations in theGet started with media recommendations tutorial.Try that tutorial before doing this clean up procedure.

  1. To avoid unnecessary Google Cloud charges, use theGoogle Cloud console to delete your project if you don't need it.
  2. If you created a new project to learn about Vertex AI Search and youno longer need the project,delete the project.
  3. If you used an existing Google Cloud project, delete the resources youcreated to avoid incurring charges to your account. For more information,seeDelete an app,Purge data from a data store,andDelete a data store.
  4. Follow the steps inTurn off Vertex AI Search.
  5. If you created a BigQuery dataset, delete it in Cloud Shell:

    bqrm--recursive--datasetmovielens

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.