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