# How we built automatic clustering for LLM traces

DevFeed: [How we built automatic clustering for LLM traces](<https://devfeed.tech/articles/how-we-built-automatic-clustering-for-llm-traces-80557.md>)

Original publisher: [Read original article](<https://posthog.com/blog/llm-analytics-clustering-how-it-works>)

Author: Andy Maguire

Published: 2026-03-11T00:00:00Z

Content type: article

Language: en

Sources: [PostHog](<https://devfeed.tech/sources/posthog.md>)

Topics: [clustering](<https://devfeed.tech/topics/clustering.md>), [ai observability](<https://devfeed.tech/topics/ai-observability.md>), [LLM observability](<https://devfeed.tech/topics/llm-observability.md>), [Large Language Model](<https://devfeed.tech/topics/llm.md>), [product analytics](<https://devfeed.tech/topics/product-analytics.md>)

Tags: [2](<https://devfeed.tech/tags/2.md>), [3](<https://devfeed.tech/tags/3.md>), [about](<https://devfeed.tech/tags/about.md>), [added](<https://devfeed.tech/tags/added.md>), [agent](<https://devfeed.tech/tags/agent.md>), [agent-tools](<https://devfeed.tech/tags/agent-tools.md>), [analytics](<https://devfeed.tech/tags/analytics.md>), [automatic](<https://devfeed.tech/tags/automatic.md>), [build](<https://devfeed.tech/tags/build.md>), [button](<https://devfeed.tech/tags/button.md>), [clicks](<https://devfeed.tech/tags/clicks.md>), [clustering](<https://devfeed.tech/tags/clustering.md>), [datasets](<https://devfeed.tech/tags/datasets.md>), [important](<https://devfeed.tech/tags/important.md>), [like](<https://devfeed.tech/tags/like.md>), [llm](<https://devfeed.tech/tags/llm.md>), [llm-traces](<https://devfeed.tech/tags/llm-traces.md>), [product](<https://devfeed.tech/tags/product.md>), [product-analytics](<https://devfeed.tech/tags/product-analytics.md>), [traces](<https://devfeed.tech/tags/traces.md>)

## AI overview

PostHog turns sampled LLM traces and generations into clusters by rendering each event as readable, line-numbered text, downsampling oversized traces, and using GPT-4.1 nano to produce structured summaries. It embeds those summaries with OpenAI text-embedding-3-large, reduces the vectors with UMAP, then uses HDBSCAN to find density-based clusters and mark outliers. A GPT-5.2 LangGraph agent labels and describes the clusters. The pipeline runs through Temporal workflows and emits events for the Clusters UI. Sampling and downsampling help control cost and context size but can reduce coverage or detail. PostHog chose summarization and embedding over building a full RAG system for clustering; the general summary schema is not yet user-customizable. Clustering runs by default once enough data exists, while projects can define up to five jobs with trace or generation targets and event filters. Privacy mode controls what trace data is sent.

## Source excerpt

Traditional clickstream product analytics (like button clicks and page views) is one of the most important datasets for anyone trying to build a...