1.  [](/)
2.  [Code examples](/recipes)
3.  Content Clustering Pipeline

Back to code examples

Enhanced

# Content Clustering Pipeline

Automatically group similar content together using embedding-based clustering. Discover themes, identify duplicates, and organize large content libraries.

text

image

video

Multi-Tier

[Run in Builder](/build?recipe=clustering-pipeline)

Python

cURL

import requests

from mixpeek import Mixpeek

client \= Mixpeek(api\_key\="YOUR\_API\_KEY", namespace\="clusters")

API \= "https://api.mixpeek.com/v1"

HEADERS \= {"Authorization": "Bearer YOUR\_API\_KEY", "X-Namespace": "clusters"}

\# 1. A bucket for articles, and a collection that embeds each one

bucket \= client.buckets.create(

    bucket\_name\="articles",

    bucket\_schema\={"properties": {"article": {"type": "text"}}},

)

collection \= client.collections.create(

    collection\_name\="articles",

    source\={"type": "bucket", "bucket\_ids": \[bucket\["bucket\_id"\]\]},

    feature\_extractor\={

        "feature\_extractor\_name": "text\_extractor",

        "version": "v1",

    },

)

client.buckets.upload(

    bucket\["bucket\_id"\],

    blobs\=\[{"property": "article", "type": "text", "data": "s3://your-bucket/articles/cloud-costs.md"}\],

)

client.collections.trigger(collection\["collection\_id"\])

\# 2. A k-means cluster over the embeddings, with LLM-written labels. The SDK has no

\#    clusters resource, so this is REST.

cluster \= requests.post(API + "/clusters", headers\=HEADERS, json\={

    "cluster\_name": "article-themes",

    "collection\_ids": \[collection\["collection\_id"\]\],

    "cluster\_type": "vector",

    "vector\_config": {

        "feature\_uris": \["mixpeek://text\_extractor@v1/multilingual\_e5\_large\_instruct\_v1"\],

        "clustering\_method": "kmeans",

        "algorithm\_params": {"n\_clusters": 20},

    },

    "llm\_labeling": {"enabled": True, "provider": "openai", "model\_name": "gpt-4o-mini-2024-07-18"},

}).json()

requests.post(API + "/clusters/" + cluster\["cluster\_id"\] + "/execute", headers\=HEADERS, json\={})

\# 3. Once the execution finishes, read the groups

groups \= requests.get(API + "/clusters/" + cluster\["cluster\_id"\] + "/groups", headers\=HEADERS).json()

for group in groups\["groups"\]:

    print(group)

### Feature Extractors

Text Embedding

Extract semantic embeddings from documents, transcripts and text content

### Retriever Stages

## Frequently asked questions

### How do I choose the number of clusters?

Start with 10-20 clusters and adjust based on your content volume. Mixpeek can also auto-detect the optimal number using silhouette analysis.

### Can I cluster across modalities?

Yes. If documents have multimodal embeddings, clustering works across text, images, and video using shared embedding spaces.

### How are cluster labels generated?

Mixpeek uses an LLM to analyze representative documents from each cluster and generate descriptive labels automatically.

## Related code examples and resources

Pages on the same stages, extractors and patterns.

[

Extractor

### Text Embedding

Extract semantic embeddings from documents, transcripts and text content

Learn more





](/extractors/text)[

Recipe

### Multimodal RAG Pipeline

Build a retrieval-augmented generation system that works with text, images, and video. Feed relevant multimodal context to LLMs for grounded responses.

Learn more





](/recipes/multimodal-rag-pipeline)[

Recipe

### Taxonomy Enrichment Pipeline

Automatically classify and tag content using custom taxonomies. Map your content to IAB categories, custom hierarchies, or industry-specific classifications.

Learn more





](/recipes/taxonomy-enrichment-pipeline)[

Recipe

### Metadata Enrichment Pipeline

Automatically enrich your data with extracted metadata: entities, topics, sentiment, language, and custom attributes. Transform raw content into structured, queryable data.

Learn more





](/recipes/metadata-enrichment-pipeline)[

Recipe

### Multimodal Hybrid Search Pipeline

Combine vector search with keyword search (BM25) across text, images, and video for the most comprehensive multimodal retrieval system.

Learn more





](/recipes/multimodal-hybrid-search)[

Recipe

### Clinical Documentation Structuring

Production-grade pipeline for ingesting clinical documents, scanned charts, EHR exports, wound photos, and therapy notes, and structuring them into coded fields aligned with MDS 3.0, PDPM, and CMS audit requirements. Combines OCR, clinical NER, taxonomy classification, and hybrid retrieval to turn unstructured bedside documentation into queryable, auditable data.

Learn more





](/recipes/clinical-documentation-structuring)