Skip to content

AgentCombo/Mandol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Mandol

Mandol: An In-Memory Agent Memory System

License Python PyPI Downloads Homepage Docs Paper

English | δΈ­ζ–‡

Important

The main branch is under active refactoring and may differ from the released artifact. For exact paper reproduction, use the paper-repro branch. The current public PyPI package mandol==0.1.0a1 and the GitHub release are built from, and aligned with, paper-repro.

Mandol Overview


πŸ“‘ Table of Contents

Show/Hide

πŸ“– What is Mandol?

Mandol is a native in-memory hierarchical memory system for LLM agents such as long-term conversational agents. Its core components are:

  1. Hierarchical Memory Model β€” Organizes memory into a basic layer and a high-level abstract layer, both uniformly represented as a structured semantic graph with traceable relationships between all memory elements.
  2. In-Memory Semantic Data Structures β€” Combines SemanticMap and SemanticGraph to natively fuse key-value, vector, and graph stores into a unified hybrid retrieval interface, eliminating cross-database I/O overhead.
  3. Smart Quantitative Retrieval β€” A query-adaptive routing mechanism with two-stage denoising, conflict resolution, and token-constrained context generation β€” all operating without invoking LLMs during retrieval.

On the LoCoMo and LongMemEval long-term conversation benchmarks, Mandol achieves state-of-the-art accuracy of 92.21% and 88.40%, respectively. Compared to representative agent memory systems, Mandol delivers a 5.4Γ— retrieval speedup and a 4.8Γ— insertion speedup under 10 QPS concurrent load, while sustaining low latency on consumer-grade hardware. These results validate the system's effectiveness, efficiency, and stability in complex long-conversation scenarios.

System-level comparison of agent memory systems:

System Memory Organization Storage Retrieval Search Latency
Mem0 Text vectors + metadata VectorDB + metadata store Vector semantic retrieval + metadata filtering Medium
Zep Text vectors + temporal knowledge graph GraphDB + vector/full-text indexes Multi-step graph traversal + reranking High
MemOS Text vectors + graph/tree summaries VectorDB + GraphDB Vector retrieval + graph node matching High
EverMemOS Text vectors + memory summaries Multi-DB stack Multi-turn retrieval + query rewriting Very high
Mandol Basic + high-level memories represented as a structured semantic graph SemanticMap/Graph; DuckDB fallback Hybrid recall + smart quantitative retrieval Low

LoCoMo accuracy (%) comparison among different memory systems:

Backbone System Avg. Tok. Single Multi Temp. Open Overall
GPT-4o-mini Mem01.0k66.7158.1655.4540.6261.00
MemU4.0k72.7762.4133.9646.8861.15
MemOS2.5k81.4569.1572.2760.4275.87
Zep1.4k88.1171.9974.4566.6781.06
EverMemOS†2.5k91.6882.7479.3470.1486.13
Mandol (Ours)2.0k93.8285.1189.1065.6389.48
GPT-4.1-mini Mem01.0k68.9761.7058.2650.0064.20
MemU4.0k74.9172.3443.6154.1766.67
MemOS2.5k85.3779.4375.0864.5880.76
Zep1.4k90.8481.9177.2675.0085.22
EverMemOS†2.3k95.3289.0190.1377.4391.97
Mandol (Ours)1.9k95.3692.2087.8579.1792.21

† Reproduced using the official implementation from EverMemOS.

Mandol achieves the highest Overall accuracy on LoCoMo under both backbone settings.

LongMemEval accuracy (%) comparison among different memory systems:

Backbone System Avg. Tok. SS-Pref SS-Asst Temporal Multi-S Know. Upd. SS-User Overall
GPT-4o-mini MemU0.5k76.7019.6017.3042.1041.0067.1038.40
Mem01.1k90.0026.7872.1863.1566.6782.8666.40
Zep1.6k53.3075.0054.1047.4074.4092.9063.80
MemOS1.4k96.6767.8677.4470.6774.2695.7177.80
Mandol (Ours)2.1k96.6798.2178.9574.4488.4697.1485.00
GPT-4.1-mini EverMemOS2.8k93.3385.7177.4473.6889.7497.1483.00
Mandol (Ours)2.3k96.6798.2187.2277.4489.7498.5788.40

Mandol achieves the highest Overall accuracy on LongMemEval under both backbone settings.

Evaluation methodology. Retrieval quality is measured via QA accuracy on the two benchmarks, defined as the percentage of questions whose generated answers are judged correct or semantically consistent with the ground-truth answers. Following the evaluation protocol of prior memory-system studies, GPT-4o-mini and GPT-4.1-mini serve as the answer-generation backbones, and we adopt the released LLM-based answer correctness evaluation script from EverMemOS.
Notably, rather than using large-parameter models such as Qwen3-Embedding-4B and Qwen3-Reranker-4B, we employ lightweight alternatives β€” Qwen3-Embedding-0.6B for embedding and bge-reranker-v2-m3 for reranking.


πŸ’‘ Core Modules and Techniques

(I) Hierarchical Memory Model

Memory is organized into a basic memory layer and a high-level abstract memory layer, both uniformly represented as a structured semantic graph. The basic layer represents raw memory through memory units, spaces, and explicit/implicit relationships. The abstract layer automatically derives episodic memory (event chains), semantic memory (entity graphs), and emotional memory (user preferences) from basic memories, with traceable links that ensure evidence grounding while supporting abstract reasoning.

Layered Memory Model

(II) In-Memory Semantic Data Structures

SemanticMap and SemanticGraph form a unified in-memory data structure that natively fuses key-value storage, vector indexes, and graph representations, eliminating multi-database fragmentation. Hybrid retrieval operators combine vector matching and graph traversal through a single API surface, removing the I/O latency inherent in heterogeneous storage architectures. The data structures also connect to an underlying persistent database for cold storage and long-term retention.

Unified Storage Architecture

(III) Smart Quantitative Retrieval Mechanism

The RAG-style recall-then-rank paradigm is replaced with a proactive pipeline of Query-Adaptive Routing, two-stage denoising and conflict resolution, and token-constrained context generation. Query-Adaptive Routing dynamically selects and queries the most relevant memory sources based on query intent. Two-stage quantitative denoising and conflict resolution then remove noise and contradictory information across sources. Finally, a compact high-quality context is assembled under token constraints by jointly optimizing relevance and diversity β€” all without LLM involvement in retrieval.

Quantitative Retrieval Pipeline


✨ Implementation

Core APIs exposed by Mandol:

Scope API
Memory unit operation add/delete/update(space, [unit])
Explicit relationship add/delete/update_relationship(
unit_src, unit_target, [type])
Unit retrieval search_unit(query, memory_space, type)
Graph traversal traverse_explicit_nodes(unit, [type])
Semantic traversal traverse_implicit_nodes(unit, [top_k])
Quantitative retrieval smart_search_with_
quantification(query, [params])
Persistence save_graph([dir, build_index])
Memory construction build_memory_from_raw(sample_id,
extraction_style, [session_date])

Memory Construction and Storage

When new content is inserted, the system automatically chunks, embeds, and segments the raw data. It extracts events and causal relationships to form episodic memory, entities and their relations to form semantic memory, and user preferences and long-term states to form emotional memory. These high-level memories coexist with the underlying base memories as the system's complete memory state.

Memory Retrieval

Queries are served through the smart quantitative search API. For each query, Query-Adaptive Routing first allocates a token budget across memory spaces (basic, episodic, semantic, emotional). The system then performs algorithmic fusion, resolves conflicts, and selects high-quality memory entries within the assigned token budget.

Memory Persistence

By default, Mandol keeps memory content in the in-memory SemanticMap/Graph to support low-latency retrieval. Mandol can also persist selected memory units and graphs for checkpointing, recovery, and later reloading into the in-memory runtime. Persistence can be triggered automatically by the runtime for database-backed checkpointing, while the save_graph API explicitly exports the current in-memory graph to local storage for inspection, backup, or later restoration.


πŸ”¬ Reproduction

For detailed reproduction steps, refer to the benchmarks README.

⚑ Quick Start

Installation

Released paper-repro package

The currently released PyPI package corresponds to the paper-repro branch:

pip install mandol==0.1.0a1

For the full paper reproduction environment, use the paper-repro source checkout and install the artifact stack with:

uv sync --extra dev --extra cuda --group spacy-model

If CUDA or flash-attention is not available on your platform, omit --extra cuda:

uv sync --extra dev --group spacy-model

Main branch optional backends

The following optional dependency groups are intended for the main branch development version and may not match the released paper-repro package:

pip install mandol[faiss]                 # FAISS vector index acceleration
pip install mandol[sentence-transformers] # Local Embedding/Reranker models
pip install mandol[openai]                # OpenAI API support
pip install mandol[milvus]                # Milvus vector database
pip install mandol[neo4j]                 # Neo4j graph database
pip install mandol[all]                   # Install all optional dependencies

For exact paper reproduction, please use the paper-repro branch. For complete installation guides, configuration details, and advanced usage, see the online documentation.

Configuration

Copy the environment variable template and fill in your API key:

cp .env.example .env

Or configure fully via a YAML configuration file:

llm:
  model: "gpt-4o-mini"
  base_url: "https://api.openai.com/v1"
  api_key: "sk-..."

embedder:
  model: "Qwen/Qwen3-Embedding-0.6B"
  device: "cpu"
  use_remote: false

reranker:
  model: "BAAI/bge-reranker-v2-m3"
  # model: "Qwen/Qwen3-Reranker-4B"
  device: "cpu"
  use_remote: false

system:
  chunk_max_tokens: 512
  bfs_expansion_hops: 1
  max_context_units: 20

In remote API mode, no local model download (~8 GB) is needed β€” just set use_remote to true and configure the API endpoint to get started quickly.

Three-Step Usage

from mandol import MemorySystem, MemoryUnit, Uid

system = MemorySystem.from_yaml_config("config.yaml")

# 1. Write memories
system.add(MemoryUnit(
    uid=Uid("msg_001"),
    raw_data={"text_content": "Zhang San went to Beijing on a business trip today"},
    metadata={"timestamp": "2024-01-15T10:00:00"},
))

# 2. Build high-level memory structures
system.build_high_level(mode="auto")

# 3. Hybrid retrieval
hits = system.holistic_retrieve("Where did Zhang San go?", top_k=5)
for hit in hits:
    print(f"[{hit.final_score:.3f}] {hit.unit.raw_data['text_content']}")

system.save("./memory_snapshot")                        # Persist
system2 = MemorySystem.load("./memory_snapshot")        # Restore

Tip: The system automatically detects session boundaries during add() and triggers high-level memory construction. After inserting a small batch of data, it is recommended to manually call build_high_level() to ensure high-level memories are populated. For further configuration options and advanced usage, see the online documentation.


πŸ“š Documentation & Community

Documentation

Complete API reference, architecture design, and best practice guides are built with Sphinx and organized around three entry points β€” basic users, advanced users, and developers:

πŸ”— Online documentation: https://agentcombo.github.io/Mandol/docs (coming soon)

Build the documentation locally:

cd docs && make html

Contributing

We welcome community contributions! Please read CONTRIBUTING.md before submitting a PR to learn about development environment setup, code standards (Ruff, 100-char line length), testing requirements, and the PR process.

Feedback & Discussion

  • Issues: GitHub Issues β€” Report bugs or request new features
  • Discussions: GitHub Discussions β€” Usage questions, best practice discussions
  • Community: Scan the QR code below to join our WeChat user group

Mandol WeChat User Group


πŸ“„ Citation

If this work is helpful to your research, please cite our paper:

@misc{zhang2026mandol,
      title={Mandol: An Agglomerative Agent Memory System for Long-Term Conversations}, 
      author={Yuhan Zhang and Zhiyuan Guo and Ziheng Zeng and Wei Wang and Wentao Wu and Lijie Xu},
      year={2026},
      eprint={2606.29778},
      archivePrefix={arXiv},
      primaryClass={cs.DB},
      url={https://arxiv.org/abs/2606.29778}, 
}

πŸ“„ License

Apache License 2.0 β€” See LICENSE

About

Mandol: An Agglomerative Agent Memory System (https://arxiv.org/pdf/2606.29778)

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

32 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors