University of Toronto's SegTreeMem Beats Every Memory Baseline by 20%
SegTreeMem organizes conversation history as a chronologically ordered tree, beating flat retrieval and graph memory by up to 20% on long-horizon QA benchmarks.
Takeaways
- SegTreeMem is a new memory architecture for long-horizon conversational agents that organizes conversation history as a temporally ordered segment tree, guaranteeing every internal node covers a contiguous span of utterances.
- It beats flat retrieval, graph memory (HippoRAG, A-MEM, Mem0), and tree memory (RAPTOR, MemTree) baselines by up to 20% LLM-judge accuracy across three benchmarks and two LLM backbones.
- A temporal permutation ablation confirms the gains are specifically due to preserving order: randomly swapping 30% of utterance pairs drops SegTreeMem by 10-14 points, versus only 2-5 points for non-temporal baselines.
- Retrieval uses score propagation through the tree (top-down or bottom-up), acting as a granularity dial: top-down favors specific factual recall, bottom-up favors broader contextual state.
- Cosine-based construction is 10x cheaper in tokens and 5x faster than the LLM-based variant while remaining competitive in accuracy, making it the practical default for latency-sensitive deployments.
- Known limitations include difficulty connecting long-range topical recurrences and potential loss of exact details (dates, names) in internal node summaries; code is available.
Most memory systems for conversational AI agents work like a topic-indexed filing cabinet: they group past exchanges by what they're about, not when they happened. That design choice turns out to be a significant limitation. A new paper from the University of Toronto and the Vector Institute argues that temporal order is a first-class structure for agent memory, and backs that claim with a new architecture called Segment Tree Memory (SegTreeMem) that beats every major memory baseline by up to 20% on long-horizon conversational QA.
The problem with topic-first memory
Long-horizon agents accumulate hundreds or thousands of utterances over time. The standard approach is to embed each utterance and retrieve the most semantically similar ones at query time. More sophisticated systems like RAPTOR, MemTree, A-MEM, and HippoRAG build hierarchical or graph-based structures on top of those embeddings. But nearly all of them organize memory by topical similarity, which means utterances from completely different moments in a conversation can end up grouped together under the same internal node.
The problem is subtle but real. Existing tree-based memory systems mostly focus on topically structured hierarchies and often ignore temporal sequencing, leaving two key design questions for temporally ordered memory underexplored: how to update a temporally ordered tree online as new utterances arrive, and how to exploit the resulting temporal hierarchy along with topical structure during retrieval. When a user asks "what did we decide last Tuesday about the project budget?", the answer depends on when something was said, not just what topic it touched.

The segment tree as a memory index
A segment tree is a classical computer science data structure for range queries over intervals. SegTreeMem adapts it to conversation history: every node in the tree covers a contiguous, chronologically ordered span of utterances. Leaf nodes hold individual utterances; internal nodes hold LLM-generated summaries of the spans covered by their children. The root summarizes the entire conversation history.
This is the key structural guarantee that separates SegTreeMem from prior work. SegTreeMem represents conversation history as a Segment Tree over utterances while preserving temporal order, and incrementally incorporates new utterances into the Segment Tree while maintaining temporally contiguous interaction segments. No two children of the same parent can cover non-adjacent utterances. That invariant is enforced at every insertion.
How it works, step by step
The system has two main algorithms: online construction and structure-aware retrieval.
Construction (online, per utterance):
- A new utterance arrives. The system identifies the rightmost frontier of the current tree: the set of nodes whose interval ends at the most recent utterance. These are the only valid attachment points.
- A compatibility model scores each frontier node against the new utterance and picks the best match. Three options are available: cosine similarity between embeddings, a pointwise LLM call per candidate, or a single batch LLM call that compares all candidates at once.
- The new utterance is attached as a child of the selected frontier node. Only nodes along the affected path to the root need their summaries regenerated. The rest of the tree is untouched.
- If no frontier node is compatible, a new root is created, making the entire previous tree the left subtree and the new utterance the right subtree.
This update is O(log N) in the number of nodes, making it practical for real-time use. The cosine variant requires zero LLM calls for insertion, while the batch LLM variant uses roughly one call per utterance.
Retrieval (per query):
- Every node in the tree is scored against the query using cosine similarity on its LLM-generated annotation embedding.
- Scores are normalized into a probability distribution across all nodes.
- The distribution is propagated through the tree for up to H hops using a sparse transition matrix. Two directions are supported: top-down (relevance flows from parent summaries to child spans) and bottom-up (relevance flows from specific utterances up to their enclosing context).
- Final scores blend the original distribution with propagated distributions, weighted by a decay factor alpha. The top-K nodes by final score are returned as evidence.

This propagation mechanism is inspired by PageRank-style graph ranking. The key difference is that the underlying graph is a temporal hierarchy, so every structural move has a chronological interpretation: moving up means broadening temporal context, moving down means zooming into a specific episode.
Benchmarks and baselines
The paper evaluates on three long-horizon memory benchmarks:
- LoCoMo: 10 multi-session conversation groups, 1,986 queries covering facts, preferences, and events across extended histories.
- LongMemEval-MAB: 5 context groups, 300 queries, reformulated as an incremental memory-building task where memory is queried repeatedly as the conversation grows.
- RealMem: 10 personas, 1,415 queries in realistic user-facing scenarios involving evolving project state and preferences.
Baselines span three categories: flat retrieval (BM25, dense retrieval), tree-structured memory (RAPTOR, MemTree), and graph/agentic memory (A-MEM, Mem0, HippoRAG). All methods use the same evidence budget of K=10 nodes per query, and two LLM backbones are tested: GPT-5.4-mini and Qwen-3.5-flash.

Results: temporal order is load-bearing
Across three datasets and two LLM backbones, SegTreeMem improves LLM-judge accuracy by nearly 20% over non-temporal tree baselines and other strong memory baselines. The gains are consistent across both GPT and Qwen backbones, which rules out the possibility that the improvement is an artifact of a particular answer model.
The paper also runs a targeted ablation to isolate the contribution of temporal order specifically. They randomly swap 30% of utterance pairs before building the tree, then measure how much performance drops. The result is striking: permuting the order causes SegTreeMem's accuracy to drop by 10-14 percentage points across benchmarks, while the same permutation barely affects a non-temporal similarity-clustering baseline (2-5 point drop). This directly confirms that SegTreeMem's gains come from using temporal order, not just from having a hierarchical structure.
On the construction side, batch LLM produces the highest-quality trees, but cosine similarity is about 10x cheaper in token usage and 5x faster in latency while remaining competitive in accuracy. For latency-sensitive applications, cosine is the practical default.
The real breakthrough: retrieval as granularity control
The most interesting finding is not just that SegTreeMem wins, but why different retrieval configurations win on different datasets. Top-down propagation (broad summary to specific spans) works best on LoCoMo, which has many detail-oriented single-hop questions. Bottom-up propagation (specific utterance to broader context) works best on RealMem, which requires recovering evolving project state. LongMemEval-MAB sits in between.
This means the propagation direction is effectively a temporal granularity dial. The decay factor alpha and horizon H control how far retrieval moves from the initial semantic match. Setting H=0 recovers standard flat retrieval. Setting H=1 or H=2 with moderate alpha gives the best results in most cases. Very large alpha values hurt performance by pushing too much probability mass away from the answer-bearing node.
Where it falls short
Two failure modes are documented honestly in the paper. First, when a topic recurs after a long gap (e.g., a user returns to a project after weeks of unrelated conversation), the two occurrences end up in structurally distant subtrees. Finite-horizon propagation may not bridge the gap, and the system can miss the connection. Second, internal node summaries can compress away exact details like dates or names. When the question requires literal recall of a specific fact, the answer-bearing utterance may not receive enough score to enter the top-K evidence budget.
The paper also identifies a worst-case structural degeneration: if every incoming utterance is judged incompatible with every frontier node, the tree grows quadratically in node count. This is a constructed adversarial case that does not appear on any real benchmark, but it sets a bound on the algorithm's guarantees.
Practical takeaways
SegTreeMem is a drop-in memory architecture for any agent that accumulates multi-turn conversation history. The anonymized implementation is available with reproduction instructions. Key decisions when deploying it:
- Use cosine construction when latency or token budget is the constraint. Use batch LLM when retrieval quality is the priority.
- Use top-down propagation for tasks that require specific factual recall (single-hop, temporal, multi-hop questions).
- Use bottom-up propagation for tasks that require recovering broader state or project context.
- Keep alpha small to moderate (0.05-0.20) and horizon at H=1 or H=2. Larger values risk diluting the answer-bearing evidence.
- The system is not well-suited to conversations where the same topic recurs frequently across long gaps, or to questions requiring exact literal recall of compressed details.
The broader implication is that the field has been underweighting a simple structural property of conversation: things happen in order, and that order carries meaning. Graph-based memory systems like HippoRAG capture entity relationships but not chronology. Topic-clustering trees like RAPTOR capture abstraction levels but not sequence. SegTreeMem is the first system to make temporal contiguity a hard invariant of the memory index itself, and the benchmark numbers suggest that constraint is worth enforcing.