Configure Gemini Code Assist code customization

This document describes how to set up Gemini Code Assist code customization in the Google Cloud console, with the Google Cloud CLI, or with Terraform by connecting Gemini Code Assist to your private code repositories. Gemini Code Assist code customization feature lets you receive code recommendations, which draw from the internal libraries, private APIs, and coding style of your organization.

Before you begin

  1. Set up Gemini Code Assist with an Enterprise subscription.

  2. Verify that you have the following Identity and Access Management (IAM) roles on the project that owns the subscription:

    • Code Repository Indexes Admin (roles/cloudaicompanion.codeRepositoryIndexesAdmin)
    • Gemini for Google Cloud User (roles/cloudaicompanion.user)
  3. Create or configure user accounts. Every developer in your organization who is using Gemini Code Assist must have a user identity in Google Cloud that has permission to access your Google Cloud project. For more information, see Grant roles in the Google Cloud console. Verify each user has the following roles:

  4. The code customization feature uses Developer Connect to access and index your private repositories. Ensure that the Developer Connect region where your Developer Connect repository connection is located is also a supported location for code customization. The code customization feature cannot be used if the Developer Connect connection is in an unsupported region. For the list of supported regions, see code customization limitations.

Choose which repositories are indexed

As a best practice, you should index repositories that have the following characteristics:

  • Code that's of a similar style or structure to what you want your developers to write.
  • Private libraries or APIs that you would like to call from your current codebase.

Optional: Choose which files are not indexed

By default, code customization indexes all the supported code files in your specified repositories.

To prevent exposure of code that you don't want to index, you can use branch patterns to control access to your index and use a stable branch, such as main.

Alternatively, you can also exclude files from the index by creating an .aiexclude file.

Configure Gemini Code Assist code customization

Select one of the following options:

Console

  1. In the Google Cloud console, go to the Code Customization page.

    Go to Code customization for Gemini Code Assist

    The Code customization for Gemini Code Assist page loads.

  2. Create an index. Code customization relies on an index to analyze and parse your repository for quicker code generation suggestions and lookups.

    1. Click Create and configure the index details:

      • Select the region that is configured in Developer Connect in your Google Cloud project.
      • Enter a name for your index. Note your index name. You need it for several steps in this document.
    2. Click Create.

    Index creation generally takes 30 minutes to complete, but it might take up to an hour. When indexing completes, you receive a notification in the Google Cloud console.

    Google limits the number of code repository indexes to one for each project and organization.

  3. Control access to your index using repository groups.

    A repository group is a container for the indexing configuration, which includes repositories and their branch patterns. Repository groups are designed for granular IAM control, giving developers access to the indexed data from those groups, where they have the cloudaicompanion.repositoryGroups.use permission.

    Repository groups contain Developer Connect repositories, or links, from the same project and location.

  4. On the Code customization for Gemini Code Assist page, click Add repositories, and then select Add source repositories.

    A list displays of existing repositories in Developer Connect for the region you configured in the previous step to create the index.

    If you need to add new repositories to the repository group, then click Link repository and follow the steps in the Google Cloud console.

    Additionally, you can select and then edit one or more repositories to add a new branch.

  5. Select the repository group to which you want to add new repositories. Alternatively, click Create a new repository group to create and configure a new repository group.

  6. To begin indexing the selected repositories, click Index.

    Indexing time varies depending on the size of repositories.

CLI

  1. Verify that you have configured Developer Connect and connected to your repository:
  2. In a shell environment, run the gcloud components update command to verify that you have updated all installed components of the gcloud CLI to the latest version. For this step, you can install and initialize the gcloud CLI, or you can use Cloud Shell Editor.

    gcloud components update