Cluster Aggregate

How to run a cluster aggregate

Open In ColabOpen In Colab

It is often important to figure out the characteristics of each cluster. The best way to do this is through an aggregation query that summarises different fields within the cluster.

This can only can be used after a vector field has been clustered.

What you will need

You will need to have followed the quickstart clustering guide.
You will also need to have knowledge of aggregations.

Code Example

Open In ColabOpen In Colab

The following code example finds the average retail price, maximum retail price and total retail price of each cluster.

DATASET_ID = "quickstart_clustering"
VECTOR_FIELD = "product_name_default_vector_"

# Aggregate based on the eclusters
client.services.cluster.aggregate(
    dataset_id="quickstart_clustering",
    metrics=[
      {"name": "average_retail_price", "field": "retail_price", "agg": "avg"},
      {"name": "max_retail_price", "field": "retail_price", "agg": "max"},
      {'name':'total_price','field':"retail_price", 'agg':'sum'},
    ],
    vector_field=VECTOR_FIELD
)

Did this page help you?