You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: "TreeTextMemory: Tree-Structured Plain Text Memory"
3
3
desc: >
4
-
Let’s build your first **graph-based, tree-structured memory** in MemOS!
4
+
Let's build your first **graph-based, tree-structured plain text memory** in MemOS!
5
5
<br>
6
-
**TreeTextMemory** helps you organize, link, and retrieve memories with rich context and explainability.
6
+
**TreeTextMemory** supports organizing, associating, and retrieving memories in a structured way while preserving rich contextual information and good interpretability.
7
7
<br>
8
-
[Neo4j](/open_source/modules/memories/neo4j_graph_db) is the current backend, with support for additional graph stores planned in the future.
8
+
MemOS currently uses [Neo4j](/open_source/modules/memories/neo4j_graph_db) as the backend, with plans to support more graph databases in the future.
9
9
---
10
10
11
-
12
11
## Table of Contents
13
12
14
13
-[What You’ll Learn](#what-youll-learn)
@@ -32,6 +31,7 @@ desc: >
32
31
## What You’ll Learn
33
32
34
33
By the end of this guide, you will:
34
+
35
35
- Extract structured memories from raw text or conversations.
36
36
- Store them as **nodes** in a graph database.
37
37
- Link memories into **hierarchies** and semantic graphs.
@@ -42,6 +42,7 @@ By the end of this guide, you will:
42
42
### Memory Structure
43
43
44
44
Every node in your `TreeTextMemory` is a `TextualMemoryItem`:
45
+
45
46
-`id`: Unique memory ID (auto-generated if omitted).
46
47
-`memory`: the main text.
47
48
-`metadata`: includes hierarchy info, embeddings, tags, entities, source, and status.
@@ -64,7 +65,6 @@ Every node in your `TreeTextMemory` is a `TextualMemoryItem`:
64
65
|`usage`|`list[str]`| Usage history |
65
66
|`background`|`str`| Additional context |
66
67
67
-
68
68
::note
69
69
**Best Practice**<br>
70
70
Use meaningful tags and background — they help organize your graph for
@@ -77,16 +77,12 @@ When you run this example, your workflow will:
77
77
78
78
1.**Extract:** Use an LLM to pull structured memories from raw text.
79
79
80
-
81
80
2.**Embed:** Generate vector embeddings for similarity search.
82
81
83
-
84
82
3.**Store & Link:** Add nodes to your graph database (Neo4j) with relationships.
85
83
86
-
87
84
4.**Search:** Query by vector similarity, then expand results by graph hops.
88
85
89
-
90
86
::note
91
87
**Hint**<br>Graph links help retrieve context that pure vector search might miss!
92
88
::
@@ -134,7 +130,9 @@ This file contains a JSON structure with `nodes` and `edges`. It can be reloaded
134
130
::steps{}
135
131
136
132
### Create TreeTextMemory Config
133
+
137
134
Define:
135
+
138
136
- your embedder (to create vectors),
139
137
- your graph DB backend (Neo4j),
140
138
- and your extractor LLM (optional).
@@ -145,7 +143,6 @@ from memos.configs.memory import TreeTextMemoryConfig
-**Context Preservation**: Uses sliding window to maintain context continuity between chunks
320
319
::
321
-
322
320
::note
323
321
**Configuration Tips**<br>
324
-
- Use the `direct_markdown_hostnames` parameter to specify which domains should return Markdown format<br>
322
+
323
+
::note
324
+
**Configuration Tip**<br>
325
+
325
326
- Supports both `mode="fast"` and `mode="fine"` extraction modes; fine mode extracts more details<br>
326
327
- See complete examples: `/examples/mem_reader/multimodal_struct_reader.py`
327
328
::
328
-
329
329
### Search Memories
330
330
331
331
Try a vector + graph search:
332
+
332
333
```python
333
334
results = tree_memory.search("Talk about the garden", top_k=5)
334
335
for i, node inenumerate(results):
@@ -394,10 +395,10 @@ Alternatively, you can configure the `internet_retriever` field directly in the
394
395
395
396
With this setup, when you call `tree_memory.search(query)`, the system will automatically trigger an internet search (via BochaAI, Google, or Bing), and merge the results with local memory nodes in a unified ranked list — no need to manually call `retriever.retrieve_from_internet`.
396
397
397
-
398
398
### Replace Working Memory
399
399
400
400
Replace your current `WorkingMemory` nodes with new ones:
-**Structured Hierarchy:** Organize memories like a mind map — nodes can
492
494
have parents, children, and cross-links.
495
+
493
496
-**Graph-Style Linking:** Beyond pure hierarchy — build multi-hop reasoning
494
497
chains.
495
498
-**Semantic Search + Graph Expansion:** Combine the best of vectors and
496
499
graphs.
497
500
-**Explainability:** Trace how memories connect, merge, or evolve over time.
498
-
499
501
::note
500
502
**Try This**<br>Add memory nodes from documents or web content. Link them
501
503
manually or auto-merge similar nodes!
@@ -505,11 +507,13 @@ manually or auto-merge similar nodes!
505
507
506
508
-**Know more about [Neo4j](/open_source/modules/memories/neo4j_graph_db):** TreeTextMemory is powered by a graph database backend.
507
509
Understanding how Neo4j handles nodes, edges, and traversal will help you design more efficient memory hierarchies, multi-hop reasoning, and context linking strategies.
0 commit comments