This is the unified documentation for Retail API. This includes Recommendations AI, Retail Search, and the unified Retail console (which is applicable to both Recommendations AI and Retail Search users). To use the new console or Retail Search while they are in the restricted GA phase, submit a form here to contact Cloud sales. If you are using the v1beta version of Recommendations AI, migrate to the GA version: Migrating to the Retail API from beta.

To see documentation for only Recommendations AI and the Recommendations AI-only console, go to the How-to guides for Recommendations AI and the API reference documentation for Recommendations AI.

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 submit a form here to contact cloud sales if you are interested in using Retail placements.search.

HTTP request

GET https://retail.googleapis.com/v2beta/{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

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 list of languages of the query. 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 allowed characters is 255. Only "en-US" is currently supported.

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 additional allowlisting. Before using cloud-retail, contact Cloud Retail support team first.

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 SearchRequest 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)

Additional custom attributes ingested through BigQuery.

attributes[].text[]

string

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

At most 400 values are allowed. Empty values are not allowed. Each value must be a UTF-8 encoded string with a length limit of 256 characters. 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".

At most 400 values are 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[].searchable

boolean

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

boolean

If true, custom attribute values are indexed, so that it 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