Introduction
Standard Large Language Models (LLMs) are inherently limited by their context windows, leading to a "forgetting" problem in long-term interactions. Existing solutions typically involve external memory caches that store raw conversation history or tokens. However, this approach introduces a significant challenge: repeated reasoning. Every time a user asks a new question, the model must re-read and re-interpret the entire history, which is computationally expensive and often results in inconsistent reasoning paths or "hallucinations."
To address these issues, we propose Think-in-Memory (TiM), a framework that equips LLMs with a human-like long-term memory. Instead of raw text, TiM stores distilled "inductive thoughts"—pre-digested conclusions that act as a consistent logic anchor for the model.
The Think-in-Memory Framework
TiM introduces a dynamic memory mechanism that operates in two primary stages: Recalling and Post-thinking. This cycle ensures that the model both leverages past conclusions and continuously refines its internal knowledge base.
Recalling and Generation
Before generating a response, the LLM agent performs a Recalling step. It retrieves relevant inductive thoughts from its memory cache based on the current user query. By using these pre-processed conclusions, the model can answer questions directly without the need to re-process raw historical text. This not only saves computation but also ensures that the model's logic remains consistent with previous turns.
Post-thinking and Memory Management
After providing a response, the model enters the Post-thinking stage. It reflects on the recent interaction to extract new inductive thoughts, typically formatted as natural language triples (subject-relation-object). These thoughts are then integrated into the long-term memory using three key operations:
- Insert: Adding new insights to the cache.
- Forget: Identifying and removing contradictory or obsolete information to maintain memory integrity.
- Merge: Consolidating similar thoughts about the same entity to keep the memory concise.
To ensure scalability, TiM utilizes Locality-Sensitive Hashing (LSH). LSH groups similar thoughts into buckets, allowing for near-constant time retrieval even as the conversation history grows to massive proportions.
Experimental Evaluation
The TiM framework was evaluated across three distinct scenarios to test its robustness and consistency:
- Generated Virtual Dataset (GVD): A long-term multi-user conversation dataset.
- KdConv: A knowledge-driven benchmark covering film, music, and travel.
- Real-world Medical Dataset (RMD): A dataset of doctor-patient interactions designed to test diagnostic consistency.
Key Results
- Enhanced Accuracy: On the GVD Chinese dataset, TiM improved Response Correctness from a baseline of 0.418 to 0.605.
- Operational Efficiency: The use of LSH-based retrieval reduced latency by approximately 15% compared to standard pairwise similarity methods.
- Clinical Reliability: In the medical domain, TiM-equipped models were significantly more effective at recalling early symptoms, leading to more accurate and consistent clinical diagnoses compared to models that "forgot" details due to context limits.
Conclusion
Think-in-Memory (TiM) represents a shift in AI memory management from raw data storage to the retention of distilled "thoughts." By mimicking human metacognition through Recalling and Post-thinking, TiM provides a scalable, efficient, and logically consistent framework for long-term human-AI interaction. Future work will focus on improving the resolution of complex contradictions and automating memory organization further.
Summary updated