<jupyter_start><jupyter_text>Developer-first vector platform for ML teams [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/RelevanceAI/workflows/blob/main/workflows/subclustering/basic_subclustering.ipynb)  🤖: Basic Sub-clusteringThis notebook is a quick guide on how to use Relevance AI for subclustering. Subclustering allows users to infinitely drill down into their clusters by running more clusters.Basic sub-clustering allows users to rely on clustering in simple ways.For more details, please refer to the [subclustering guide](https://colab.research.google.com/github/RelevanceAI/workflows/blob/main/workflows/subclustering/basic_subclustering.ipynb) to  [subclustering references](https://relevanceai.readthedocs.io/en/development/operations/cluster/subclustering.html).<jupyter_code>%%capture
!pip install -q RelevanceAI==2.1.8
from relevanceai import Client

client = Client()
## Sample dataset instantiation - replace this with your own dataset information

from relevanceai.utils.datasets import get_ecommerce_dataset_encoded

dataset_id = "basic_subclustering"  ## Change this to your own dataset
ds = client.Dataset('basic_subclustering')
ds.upsert_documents(get_ecommerce_dataset_encoded())
## Inputs

n_clusters = 10 # number of clusters you want
vector_field = "product_image_clip_vector_" # vector field
parent_field = "product_image_clip_vector_" # what to base clusters on
n_subclusters = 3
alias = f"kmeans_{n_clusters}"
subcluster_alias = f"kmeans_{n_clusters}_{n_subclusters}"  # What you want to call these clusters
parent_field = f'_cluster_.{vector_field}.{alias}'         ## Default parent field
from sklearn.cluster import KMeans
model = KMeans(n_clusters=n_clusters)

ds.cluster(
   model=model,
   parent_field=parent_field,
   vector_fields=[vector_field],
   alias=alias
)<jupyter_output><empty_output><jupyter_text>🫐 Running sub-clustering is then as simple as running **ds.subcluster** to the function.<jupyter_code>from sklearn.cluster import KMeans
model = KMeans(n_clusters=n_subclusters)

ds.subcluster(
   model=model,
   parent_field=parent_field,
   vector_fields=[vector_field],
   alias=subcluster_alias
)

ds.schema<jupyter_output><empty_output><jupyter_text>You should also be able to track your subclusters using<jupyter_code>ds.metadata<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup