Skip to content

Commit d93ffbb

Browse files
authored
MemoryGraph - revamped (supermemoryai#627)
1 parent 85b97b7 commit d93ffbb

17 files changed

Lines changed: 2304 additions & 714 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ yarn-error.log*
4040
# Misc
4141
.DS_Store
4242
*.pem
43-
43+
.claude
4444
.venv
4545
__pycache__

apps/memory-graph-playground/src/app/page.tsx

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export default function Home() {
2929
// State for controlled space selection
3030
const [selectedSpace, setSelectedSpace] = useState<string>("all")
3131

32+
// State for slideshow
33+
const [isSlideshowActive, setIsSlideshowActive] = useState(false)
34+
const [currentSlideshowNode, setCurrentSlideshowNode] = useState<string | null>(null)
35+
3236
const PAGE_SIZE = 500
3337

3438
const fetchDocuments = useCallback(
@@ -109,6 +113,23 @@ export default function Home() {
109113
setSelectedSpace("all")
110114
}
111115

116+
// Toggle slideshow
117+
const handleToggleSlideshow = () => {
118+
setIsSlideshowActive((prev) => !prev)
119+
}
120+
121+
// Handle slideshow node change
122+
const handleSlideshowNodeChange = useCallback((nodeId: string | null) => {
123+
// Track which node is being shown in slideshow
124+
setCurrentSlideshowNode(nodeId)
125+
console.log("Slideshow showing node:", nodeId)
126+
}, [])
127+
128+
// Handle slideshow stop (when user clicks outside)
129+
const handleSlideshowStop = useCallback(() => {
130+
setIsSlideshowActive(false)
131+
}, [])
132+
112133
return (
113134
<div className="flex flex-col h-screen bg-zinc-950">
114135
{/* Header */}
@@ -158,12 +179,49 @@ export default function Home() {
158179
</span>
159180
</div>
160181
</div>
161-
<button
162-
onClick={handleReset}
163-
className="rounded-lg border border-zinc-700 px-3 py-1 text-xs font-medium text-zinc-300 transition-colors hover:bg-zinc-800"
164-
>
165-
Reset Filters
166-
</button>
182+
<div className="flex items-center gap-3">
183+
<button
184+
onClick={handleToggleSlideshow}
185+
className={`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors flex items-center gap-1.5 ${
186+
isSlideshowActive
187+
? "bg-blue-600 text-white hover:bg-blue-700"
188+
: "border border-zinc-700 text-zinc-300 hover:bg-zinc-800"
189+
}`}
190+
>
191+
{isSlideshowActive ? (
192+
<>
193+
<svg
194+
width="12"
195+
height="12"
196+
viewBox="0 0 24 24"
197+
fill="currentColor"
198+
>
199+
<rect x="6" y="6" width="12" height="12" />
200+
</svg>
201+
Slideshow
202+
</>
203+
) : (
204+
<>
205+
<svg
206+
width="12"
207+
height="12"
208+
viewBox="0 0 24 24"
209+
fill="currentColor"
210+
>
211+
<path d="M8 5v14l11-7z" />
212+
</svg>
213+
Slideshow
214+
</>
215+
)}
216+
</button>
217+
<div className="h-6 w-px bg-zinc-700" />
218+
<button
219+
onClick={handleReset}
220+
className="rounded-lg border border-zinc-700 px-3 py-1.5 text-xs font-medium text-zinc-300 transition-colors hover:bg-zinc-800"
221+
>
222+
Reset Filters
223+
</button>
224+
</div>
167225
</div>
168226
</div>
169227
)}
@@ -225,6 +283,12 @@ export default function Home() {
225283
// Controlled space selection
226284
selectedSpace={selectedSpace}
227285
onSpaceChange={handleSpaceChange}
286+
// Node limit - prevents performance issues with large graphs
287+
maxNodes={500}
288+
// Slideshow control
289+
isSlideshowActive={isSlideshowActive}
290+
onSlideshowNodeChange={handleSlideshowNodeChange}
291+
onSlideshowStop={handleSlideshowStop}
228292
>
229293
<div className="flex h-full items-center justify-center">
230294
<p className="text-zinc-400">

bun.lock

Lines changed: 129 additions & 333 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@scalar/hono-api-reference": "^0.9.11",
3232
"@vanilla-extract/recipes": "^0.5.7",
3333
"ai": "^5.0.59",
34-
"alchemy": "^0.55.2",
34+
"alchemy": "^0.81.4",
3535
"atmn": "^0.0.16",
3636
"better-auth": "^1.3.3",
3737
"boxen": "^8.0.1",
@@ -61,7 +61,7 @@
6161
"drizzle-kit": "^0.31.4",
6262
"turbo": "^2.5.4",
6363
"typescript": "5.8.3",
64-
"wrangler": "4.22.0"
64+
"wrangler": "^4.42.2"
6565
},
6666
"workerd": {
6767
"import": "./esm/index.mjs",

packages/memory-graph/CHANGELOG.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Memory Graph Changelog
2+
3+
## Development Setup
4+
5+
To test changes, run these commands in separate terminals:
6+
7+
**Terminal 1** - Install the required dependencies:
8+
```bash
9+
bun install
10+
```
11+
12+
**Terminal 1** - Build memory-graph in watch mode:
13+
```bash
14+
cd packages/memory-graph && bun run dev
15+
```
16+
17+
**Terminal 2** - Run the playground:
18+
```bash
19+
cd apps/memory-graph-playground && bun run dev
20+
```
21+
22+
Then open http://localhost:3000 in your browser.
23+
24+
---
25+
26+
### Features
27+
28+
#### Slideshow Mode
29+
Auto-cycling through nodes with smooth animations and physics simulation
30+
- Random node selection every 3.5s (avoids consecutive duplicates)
31+
- Smooth pan-to-node animation with automatic popover
32+
- Brief physics pulse (1s) on each selection
33+
- Background dimming animation
34+
- Single-click to stop
35+
36+
#### Node Popover with Background Dimming
37+
Floating popover with smart positioning and focus dimming effect
38+
- Smooth 1.5s cubic ease-out dimming animation
39+
- Non-selected nodes: 20% opacity, unconnected edges: 10% opacity
40+
- Smart edge detection with 20px gap from node
41+
- Auto-flips to avoid viewport edges
42+
- Close via backdrop click, X button, or Escape key
43+
- Shows: title, summary, type, memory count, URL, date, ID
44+
45+
#### Document Type Icons
46+
Canvas-rendered icons centered on document cards
47+
- Supported: TXT, PDF, MD, DOC/DOCX, RTF, CSV, JSON
48+
- Scales with card size (40% of height)
49+
- Only renders when zoomed in
50+
51+
#### Physics-Driven Layout
52+
Simplified initial positioning, letting physics create natural layouts
53+
- Simple grid with random offsets (no concentric rings)
54+
- 50 quick pre-ticks + smooth animation
55+
- Eliminates teleportation on node interaction
56+
- Faster, non-blocking initial render
57+
58+
#### Updated Color Scheme
59+
Refined palette for better contrast and readability
60+
61+
### Bug Fixes
62+
63+
#### Edge Viewport Culling
64+
Fixed edges disappearing during zoom/pan
65+
- Now checks both X and Y axis bounds
66+
- Only culls when BOTH endpoints off-screen in same direction
67+
- 100px margin on all sides
68+
69+
#### Memory Nodes Follow Parents
70+
Memory nodes now move with parent documents when dragged
71+
- Store relative offset instead of absolute position
72+
- Automatically repositions based on parent location
73+
74+
### Performance
75+
76+
#### k-NN Similarity Algorithm
77+
Reduced from O(n²) to O(n·k)
78+
- 3x faster: ~50ms → ~17ms for 100 docs
79+
- 4,950 → 1,500 comparisons for 100 docs
80+
- Separated into own memo (doesn't recalculate on UI interactions)
81+
82+
#### Memory Leak Fix
83+
NodeCache now cleans up deleted nodes properly
84+
85+
#### Race Condition Fix
86+
Atomic node/edge updates eliminate NaN positions
87+
88+
#### Canvas Rendering Optimizations
89+
Reduced per-frame overhead and improved rendering efficiency
90+
- Spatial grid for hit detection
91+
- Batched edge rendering by type (fewer canvas state changes)
92+
- Canvas quality settings initialized once instead of every frame
93+
- Optimized render key using fast hash instead of string concatenation
94+
- Memoized nodeMap to avoid rebuilding every frame
95+
96+
#### Node Limiting & Memory Management
97+
Smart memory limiting prevents performance issues with large datasets
98+
- `maxNodes` prop limits total memory nodes (default: 500 in playground)
99+
- Dynamic per-document cap distributes budget across documents
100+
- Prioritizes recent memories and high-relevance scores
101+
- k-NN similarity limit reduced from 15 to 10 connections per document
102+
103+
---

packages/memory-graph/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"@vanilla-extract/css": "^1.17.4",
6666
"@vanilla-extract/recipes": "^0.5.7",
6767
"@vanilla-extract/sprinkles": "^1.6.5",
68+
"d3-force": "^3.0.0",
6869
"lucide-react": "^0.552.0",
6970
"motion": "^12.23.24"
7071
},

0 commit comments

Comments
 (0)