This Recommendations AI documentation references the Recommendations console. We recommend switching to the Retail console and using the Retail documentation, which documents Recommendations AI, the Retail console, and Retail Search.

If you are using the v1beta version of Recommendations AI, migrate to the Retail API version.

Method: projects.locations.catalogs.completeQuery

Completes the specified prefix with keyword suggestions.

This feature is only available for users who have Retail placements.search enabled. Please enable Retail placements.search on Cloud Console before using this feature.

HTTP request

GET https://retail.googleapis.com/v2/{catalog=projects/*/locations/*/catalogs/*}:completeQuery

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
catalog

string

Required. Catalog for which the completion is performed.

Full resource name of catalog, such as projects/*/locations/global/catalogs/default_catalog.

Query parameters

Parameters
query

string

Required. The query used to generate suggestions.

The maximum number of allowed characters is 255.

visitorId

string

Required field. A unique identifier for tracking visitors. For example, this could be implemented with an HTTP cookie, which should be able to uniquely identify a visitor on a single device. This unique identifier should not change if the visitor logs in or out of the website.

The field must be a UTF-8 encoded string with a length limit of 128 characters. Otherwise, an INVALID_ARGUMENT error is returned.

languageCodes[]

string

The language filters applied to the output suggestions. If set, it should contain the language of the query. If not set, suggestions are returned without considering language restrictions. This is the BCP-47 language code, such as "en-US" or "sr-Latn". For more information, see Tags for Identifying Languages. The maximum number of language codes is 3.

deviceType

string

The device type context for completion suggestions. It is useful to apply different suggestions on different device types, e.g. DESKTOP, MOBILE. If it is empty, the suggestions are across all device types.

Supported formats:

  • UNKNOWN_DEVICE_TYPE

  • DESKTOP

  • MOBILE

  • A customized string starts with OTHER_, e.g. OTHER_IPHONE.

dataset

string

Determines which dataset to use for fetching completion. "user-data" will use the imported dataset through CompletionService.ImportCompletionData. "cloud-retail" will use the dataset generated by cloud retail based on user events. If leave empty, it will use the "user-data".

Current supported values:

  • user-data

  • cloud-retail: This option requires enabling auto-learning function first. See guidelines.

maxSuggestions

integer

Completion max suggestions. If left unset or set to 0, then will fallback to the configured value [CompletionConfig.max_suggestions][].

The maximum allowed max suggestions is 20. If it is set higher, it will be capped by 20.

Request body

The request body must be empty.

Response body

If successful, the response body contains data with the following structure:

Response of the auto-complete query.

JSON representation
{
  "completionResults": [
    {
      object (CompletionResult)
    }
  ],
  "attributionToken": string,
  "recentSearchResults": [
    {
      object (RecentSearchResult)
    }
  ]
}
Fields
completionResults[]

object (CompletionResult)

Results of the matching suggestions. The result list is ordered and the first result is top suggestion.

attributionToken

string

A unique complete token. This should be included in the UserEvent.completion_detail for search events resulting from this completion, which enables accurate attribution of complete model performance.

recentSearchResults[]

object (RecentSearchResult)

Matched recent searches of this user. The maximum number of recent searches is 10. This field is a restricted feature. Contact Retail placements.search support team if you are interested in enabling it.

This feature is only available when CompleteQueryRequest.visitor_id field is set and UserEvent is imported. The recent searches satisfy the follow rules: * They are ordered from latest to oldest. * They are matched with CompleteQueryRequest.query case insensitively. * They are transformed to lower cases. * They are UTF-8 safe.

Recent searches are deduplicated. More recent searches will be reserved when duplication happens.

Authorization Scopes

Requires the following OAuth scope:

  • https://www.googleapis.com/auth/cloud-platform

For more information, see the Authentication Overview.

IAM Permissions

Requires the following IAM permission on the catalog resource:

  • retail.catalogs.completeQuery

For more information, see the IAM documentation.

CompletionResult

Resource that represents completion results.

JSON representation
{
  "suggestion": string,
  "attributes": {
    string: {
      "text": [
        string
      ],
      "numbers": [
        number
      ],
      "searchable": boolean,
      "indexable": boolean
    },
    ...
  }
}
Fields
suggestion

string

The suggestion for the query.

attributes[]

map (key: string, value: object)

Custom attributes for the suggestion term. * For "user-data", the attributes are additional custom attributes ingested through BigQuery. * For "cloud-retail", the attributes are product attributes generated by Cloud Retail.

attributes[].text[]

string

The textual values of this custom attribute. For example, ["yellow", "green"] when the key is "color".

Empty string is not allowed. Otherwise, an INVALID_ARGUMENT error is returned.

Exactly one of text or numbers should be set. Otherwise, an INVALID_ARGUMENT error is returned.

attributes[].numbers[]

number

The numerical values of this custom attribute. For example, [2.3, 15.4] when the key is "lengths_cm".

Exactly one of text or numbers should be set. Otherwise, an INVALID_ARGUMENT error is returned.

attributes[].searchable
(deprecated)

boolean

This field is normally ignored unless [AttributesConfig.attribute_config_level][] of the Catalog is set to the deprecated 'PRODUCT_LEVEL_ATTRIBUTE_CONFIG' mode. For information about product-level attribute configuration, see Configuration modes. If true, custom attribute values are searchable by text queries in SearchService.Search.

This field is ignored in a UserEvent.

Only set if type text is set. Otherwise, a INVALID_ARGUMENT error is returned.

attributes[].indexable
(deprecated)

boolean

This field is normally ignored unless [AttributesConfig.attribute_config_level][] of the Catalog is set to the deprecated 'PRODUCT_LEVEL_ATTRIBUTE_CONFIG' mode. For information about product-level attribute configuration, see Configuration modes. If true, custom attribute values are indexed, so that they can be filtered, faceted or boosted in SearchService.Search.

This field is ignored in a UserEvent.

See SearchRequest.filter, SearchRequest.facet_specs and SearchRequest.boost_spec for more details.

RecentSearchResult

Recent search of this user.

JSON representation
{
  "recentSearch": string
}
Fields