Abstract
Large Language Models (LLMs) are reshaping unsupervised learning by offering an unprecedented ability to perform text clustering based on their deep semantic understanding. However, their direct application is fundamentally limited by a lack of stateful memory for iterative refinement and the difficulty of managing cluster granularity. As a result, existing methods often rely on complex pipelines with external modules, sacrificing a truly end-to-end approach. We introduce LLM-MemCluster, a novel framework that reconceptualizes clustering as a fully LLM-native task. It leverages a Dynamic Memory to instill state awareness and a Dual-Prompt Strategy to enable the model to reason about and determine the number of clusters. Evaluated on several benchmark datasets, our tuning-free framework significantly and consistently outperforms strong baselines. LLM-MemCluster presents an effective, interpretable, and truly end-to-end paradigm for LLM-based text clustering.
Introduction
Text clustering—the unsupervised grouping of documents by semantic similarity—is a foundational NLP task. While Large Language Models (LLMs) possess sophisticated reasoning capabilities, their application to clustering has been hindered by two primary architectural challenges: statelessness and granularity control.
Standard LLMs operate within a limited context window, requiring large datasets to be processed in batches. Because they are inherently stateless, they "forget" previously established clusters when moving to a new batch, leading to inconsistent labeling and redundant groups. Furthermore, LLMs often struggle with granularity; without explicit constraints, they may produce either overly broad or hyper-specific categories, resulting in unstable outputs. To address these issues, we propose LLM-MemCluster, an LLM-native framework that transforms the model into a stateful clustering agent.
The LLM-MemCluster Framework
LLM-MemCluster operates through three core innovations designed to provide the model with a persistent state and a mechanism for controlling the evolution of clusters.
Dynamic Memory Mechanism
The framework maintains a "working memory" of descriptive cluster labels. For every new text instance, the LLM retrieves this memory and performs one of three operations:
- Assign Item: Map the text to an existing label.
- Merge Labels: Consolidate two or more existing labels if they have become semantically redundant.
- Retroactive Update: When a merge occurs, the system automatically updates all previous document assignments to ensure global consistency in a single pass.
Dual-Prompt Strategy
To manage cluster granularity, the system monitors the current label count against a target range $[K_{min}, K_{max}]$. It dynamically toggles between two modes:
- Relaxed Mode: Triggered when the label count is below $K_{max}$, this mode provides a "soft guideline" encouraging the model to discover new topics while still preferring existing labels.
- Strict Mode: Triggered when the count reaches $K_{max}$, this mode issues a "critical guideline" forbidding new label creation unless absolutely necessary, forcing the model to consolidate or reuse existing categories.
Experimental Evaluation
We evaluated LLM-MemCluster on six diverse benchmark datasets: ArxivS2S (scientific abstracts), Massive-I & Massive-D (intent detection), MTOP-I (intent detection), FewNerd (NER), and FewRel (relation extraction). These datasets are characterized by high cardinality (large numbers of ground-truth clusters), making them particularly challenging for traditional methods.
Key Results
LLM-MemCluster consistently outperformed strong baselines, including K-Means, BERTopic, and ClusterLLM. On average, our framework surpassed the strongest baseline by 11.5% in Accuracy and 20.8% in Adjusted Rand Index (ARI). The performance gains were most pronounced on high-cardinality datasets like MTOP-I ($K=102$), where LLM-MemCluster achieved an ARI of 68.9, more than doubling the performance of the next best method (30.0).
Key Insights and Ablation Studies
- The Necessity of Memory: Ablation studies (Figure 6a) demonstrate that without the Dynamic Memory module, performance collapses. The ARI plummeted from ~54% to ~7% on Massive-D when memory was removed, confirming that statefulness is the primary barrier to effective LLM clustering.
- Granularity Control: The Dual-Prompt Strategy effectively balances cluster discovery and consolidation. As shown in Figure 6(c-f), the strategy allows the model to converge near the ground-truth cluster count while maintaining high ARI, whereas using only a Relaxed prompt often leads to "cluster explosion."
- Model Agnostic Robustness: While GPT-4o-mini was used as the default, the framework remained robust across other models like Gemini 1.5-flash and DeepSeek-V3, suggesting that the architectural design is more critical than the specific underlying LLM.
Conclusion
LLM-MemCluster presents a truly end-to-end, tuning-free paradigm for text clustering. By introducing state awareness through dynamic memory and granularity control via dual-prompting, it overcomes the traditional limitations of LLMs in unsupervised settings. Future work will focus on optimizing merge logic for even larger label spaces and exploring the impact of document ordering on cluster formation.
Summary updated