List closest to centroids

List the documents closest to center

Open In ColabOpen In Colab

Another method of finding the characteristics of a cluster is to examine the cluster centroid which represents the 'average' of the cluster. With RelevanceAI, it is possible to retrieve the document which is closest to the centroid of your cluster.

However, use this with caution as sometimes, the 'average' document may not be representative of its cluster.

What you will need

You will need to have followed the quickstart clustering guide.

Code Example

DATASET_ID = "quickstart_clustering"
VECTOR_FIELD = "product_name_default_vector_"

client.services.cluster.centroids.list_closest_to_center(
  dataset_id = DATASET_ID, 
  vector_field = VECTOR_FIELD, 
  cluster_ids = [], # Leave this as an empty list if you want all of the clusters
  alias = "default"
)

Did this page help you?