Order results from structured data stores

Ordering is a type of ranking mechanism that dynamically changes the sequence in which results are returned after an initial ranking that's established during the retrieval process. During retrieval, Agent Search fetches the relevant documents from the data store in the order of thousands (subject to the size of the data store). After this the top results are served according to the condition specified for reordering. For more information, see About retrieval and ranking.

This page explains how to order the results of a search query made on structured data stores and on unstructured data stores with metadata.

Supported data types for ordering the results

These are the field types that you can have your search results ordered by:

Before you begin

Make sure that you have an app with a data store that contains structured data or unstructured data with metadata.

Order your search results

To order the search results for a structured data store or for an unstructured data store with metadata, follow these steps:

REST

To use the API to order your search results for an app with structured data or unstructured data with metadata, use the engines.servingConfigs.search method:

  • 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.

  • Make a search query and include the orderBy field.

    curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    "https://discoveryengine.googleapis.com/v1alpha/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",
    "query": "QUERY",
    "orderBy": "ORDER_BY"
    }'
    

    Replace the following:

    orderBy examples

    To order on a string field called title:

    To order on a number field called rating:

    To order on a datetime field called available_date:

    To order according to geolocation on a field called location: