MemTree Memory Module¶
The MemTree Memory Module (MemTreeModule) builds a hierarchical tree of content and embeddings, supporting long-term semantic memory. As new messages arrive, it routes them into semantically related branches and merges node content for summarized, structured retention.
Purpose¶
- Maintain long-horizon context with hierarchical summarization.
- Enables hierarchical aggregation, semantic retrieval, and continuous integration of new information.
- Supports efficient long-term context management and structured recall across extended interactions.
Parameters¶
top(optional): Number of top similar nodes to retrieve. If not specified, defaults to 3.max_depth(optional): Maximum tree depth; If not specified, defaults to -1 = unlimited.threshold(optional): Similarity cutoff for retrieval. If not specified, defaults to 0.2.max_context(optional): Maximum total character count for retrieved memory. If not specified, defaults to 10,000 characters.embedding_config(optional): Per-module embedding configuration for embedding inference. If not specified, defaults to global memory embedding configuration.
Example¶
# To customize MemTreeModule, define memory_config and include it in the memory_modules.
# Otherwise, omit this block to use defaults.
memory_config:
memory_modules:
- memory_name: chat_history_memtree # Required. Unique identifier for this memory module.
memory_class: MemTreeModule # Required. Memory module class.
config: # Optional. Specified per-module configuration.
top: 3 # Optional. Number of top similar nodes to retrieve.
max_depth: 2 # Optional. Maximum tree depth. Defaults to unlimited.
threshold: 0.3 # Optional. Similarity cutoff for retrieval
max_context: 4000 # Optional. Maximum total character count. Must be a positive integer. Defaults to 10,000.
embedding_config: # Optional. Specify the per-module embedding configuration.
model: "Qwen/Qwen3-Embedding-0.6B"
How It Works¶
- Tree Structure: Maintains a Pandas DataFrame with columns
node_id,parent_id,depth, andcontent, plus an aligned embedding table. - Adding: Embeds new content, routes it to the most similar branch (if similarity ≥ adaptive threshold), or attaches it to the root.
- Merging: Uses an internal
MemoryUpdateAgentto merge ancestor content asynchronously. - Retrieval: Embeds the query, finds top-k similar nodes above threshold, and aggregates their contents up to
max_contextcharacters.
More details can be found in the research paper MemTree.