-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathuser_profile.mnm
More file actions
89 lines (80 loc) · 2.14 KB
/
Copy pathuser_profile.mnm
File metadata and controls
89 lines (80 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# user_profile.mnm — User profile with preferences and access tracking
#
# Tracks user preferences, expertise, and interaction patterns.
# Demonstrates multiple memories, update rules, and varied queries.
#
# Usage:
# synapse apply examples/user_profile.mnm --port 9090
#
# # Record a preference
# synapse emit set_preference '{"user_id": "u1", "key": "theme", "value": "dark"}'
# synapse emit set_preference '{"user_id": "u1", "key": "language", "value": "python"}'
#
# # Record an interaction
# synapse emit interaction '{"user_id": "u1", "topic": "machine learning", "sentiment": 0.9}'
#
# # Query user preferences
# synapse query GetPreferences '{"user_id": "u1"}'
#
# # Query interactions
# synapse query TopTopics '{"user_id": "u1"}'
config {
storage: sqlite("./data/profiles.db")
}
# User preference key-value store
memory Preference {
user_id: string
key: string
value: string
updated_at: timestamp
}
# User interaction log
memory Interaction {
user_id: string
topic: string
sentiment: float[0.0,1.0]
created_at: timestamp
}
# Set or update a user preference
on set_preference(user_id: string, key: string, value: string) {
store(Preference {
user_id: user_id,
key: key,
value: value,
updated_at: now()
})
}
# Log a user interaction
on interaction(user_id: string, topic: string, sentiment: float) {
store(Interaction {
user_id: user_id,
topic: topic,
sentiment: sentiment,
created_at: now()
})
}
# Get all preferences for a user
query GetPreferences(user_id: string): Preference[] {
from Preference
where user_id == user_id
order by updated_at desc
}
# Get a specific preference
query GetPreference(user_id: string, key: string): Preference[] {
from Preference
where user_id == user_id
limit 1
}
# Get top interaction topics for a user
query TopTopics(user_id: string): Interaction[] {
from Interaction
where user_id == user_id
order by sentiment desc
limit 10
}
# Preferences auto-update on conflict (newer wins)
update Preference {
on_conflict(old, new) {
supersede(old, new)
}
}