We are moving towards a web where content curation shouldn't require human babysitting. If you are building any platform that relies on User-Generated Content (UGC), you know the nightmare of unstructured data.
Recently, I was architecting the backend for Figurinha WhatsApp a platform designed to help users discover and download specific sticker packs for messaging apps. The goal was to build a system that could ingest thousands of random image uploads, understand their visual context, and autonomously group them into highly cohesive thematic packs (e.g., "Tech Memes", "Morning Coffee", "Anime Reactions").
To do this, we built a modern AI pipeline using Vision-Language Models (like SigLIP-2) to extract vector embeddings from the images. But generating embeddings is only half the battle. The real challenge is clustering them effectively.
Here is why standard algorithms failed us, and how HDBSCAN became the backbone of our autonomous categorization.
The K-Means Trap
Our first instinct was to use K-Means. It's the industry standard, but it requires you to define K (the exact number of clusters) upfront.
In a dynamic platform where new internet trends and memes are born daily, guessing the number of categories is impossible. Are there 50 meme genres today, or 5,000? K-Means also forces all outliers into a cluster, meaning a random upload of a blurred photo would be forcefully injected into a "Good Morning" pack. It was a disaster.
The DBSCAN Illusion
We needed an algorithm that could discover clusters based on data density and filter out the noise. We migrated to DBSCAN (Density-Based Spatial Clustering of Applications with Noise).
DBSCAN was a massive improvement. It doesn't need a predefined number of clusters, and it gracefully isolates noise. However, it relies heavily on a global parameter called Epsilon (the search radius).
This is where DBSCAN breaks down in real-world UGC applications: density varies wildly.
Dense Clusters: Think of "Good Morning" text images. They are visually highly repetitive and form tightly packed clusters in the vector space.
Sparse Clusters:
Think of "Reaction Memes". They share a semantic theme but visually span a much wider, scattered area.
If we set Epsilon too small, DBSCAN perfectly isolated the dense text images but shattered the scattered memes into dozens of useless micro-clusters. If we increased Epsilon, it grouped the memes but merged unrelated dense clusters together. We were trapped fighting a single global parameter.
Enter HDBSCAN:
The Autonomous Solution
The breakthrough happened when we deployed HDBSCAN (Hierarchical DBSCAN) on our VPS infrastructure.
HDBSCAN eliminates the need for a global Epsilon. Instead, it computes a complete hierarchical cluster tree across all possible density scales and dynamically extracts the most stable clusters. It understands that a dataset can have both incredibly dense hot-spots and broadly diffused neighborhoods at the same time.
The architectural impact on our platform:
Variable Density Mastery: It easily formed a tight pack of 50 identical "Coffee" images while simultaneously grouping a loose, diverse set of 200 "Gaming Memes", without one interfering with the rules of the other.
Zero Parameter Babysitting:
The only intuitive parameter we had to tune was min_cluster_size (e.g., we tell the algorithm: "A valid sticker pack must have at least 8 images").
Aggressive Noise Filtering:
Bizarre, out-of-context uploads are flagged as outliers (label = -1) and automatically purged from the public feed, maintaining high curation quality without human moderation.
The Pipeline Architecture
Our current microservice looks somewhat like this:
import hdbscan
import numpy as np
# 1. 'image_embeddings' are extracted via Vision Models (e.g., SigLIP-2)
embeddings = np.array(image_embeddings)
# 2. HDBSCAN dynamically finds the semantic packs
# We enforce a minimum pack size to ensure quality
clusterer = hdbscan.HDBSCAN(min_cluster_size=8, metric='euclidean')
cluster_labels = clusterer.fit_predict(embeddings)
# 3. Post-processing
# Items with label '-1' are discarded as noise.
# The rest are automatically published to the database as new thematic packs.
If you are building recommendation engines, vector search pipelines, or dealing with any unstructured data, trying to fight with K-Means or tune the Epsilon of DBSCAN is a waste of engineering hours.
HDBSCAN allows your application to adapt to the natural, chaotic topology of human-generated data. It transformed our unstructured storage bucket into a clean, navigable platform.
You can see the final result of this AI clustering pipeline live at Figurinha WhatsApp, where new thematic packs are continuously and automatically generated based on user uploads.
Top comments (0)