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
Copy file name to clipboardExpand all lines: src/uc/ai_assistant.md
+59-51Lines changed: 59 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,35 +5,55 @@ What you get:
5
5
- **Semantic Search**: Recall relevant info by meaning using vector search
6
6
- **Zero Maintenance**: Auto-expiring short-term memory without a need to track timestamps manually
7
7
- **Multi-User**: Isolated memory per user
8
-
- **Learning**: Assistant can "understand" each user better the more it's used
8
+
- **Learning**: Assistant learns user preferences and context over time.
9
9
10
10
**Note**: Requires [Redis 8](https://hub.docker.com/_/redis/tags) for `HSETEX`, which adds per-field TTL for hashes, which is ideal for managing short-term memory with precision.
|`Knowledge Base`|`Persistent facts, user preferences`|
16
+
|`Knowledge Base`|`Long-term memory: persistent facts and preferences`|
17
17
|`Vector Search`|`Unified semantic recall across both layers`|
18
18
19
19
### Working Memory (Ephemeral)
20
-
Stores recent user messages with TTL based on importance. Automatically expires to prevent bloat.
21
-
This uses `HSETEX`, a Redis 8 command that adds field-level expiration to hashes. It allows storing all temporary messages in a single key while managing TTLs per message, simplifying short-term memory management without needing multiple keys.
20
+
Stores recent user and assistant messages with per-message TTL. Uses:
21
+
- `HSETEX` to add field-level expiration to hashes to store all temporary messages in a single key while managing TTLs per message, simplifying short-term memory management without needing multiple keys.
22
+
- `ZADD` for message ordering (based on timestamp)
22
23
23
-
```redis:[run_confirmation=true] Recent Conversations with TTL Based on Importance.
24
-
// Quick exchanges (5 min)
24
+
```redis:[run_confirmation=true] Recent conversations with TTL based on importance
25
+
// Step 1: Add message with TTL (5 mins)
25
26
HSETEX user:alice:session:001 EX 300 FIELDS 1 msg:001 "What's the weather?"
26
-
// Session context (30 min)
27
+
// Step 2: Track order with timestamp (epoch seconds)
```redis:[run_confirmation=true] ZSET cleanup (recommended in background):
46
+
// For each msg:XXX in the ZSET, check if it still exists
47
+
HEXISTS user:alice:session:001 msg:003
48
+
// If not, clean up:
49
+
ZREM user:alice:session:001:zorder msg:003
30
50
```
31
51
32
52
### Knowledge Base (Persistent)
33
53
Long-term memory: stores important facts, user preferences, and context across sessions. These never expire.
34
54
`embedding` is a binary-encoded `FLOAT32[]` used for vector similarity that can be generated using sentence-transformers or similar libraries. Demo uses 8-dim vectors; production models typically use 128–1536 dimensions.
35
55
36
-
```redis:[run_confirmation=true] Important User Information That Never Expires.
56
+
```redis:[run_confirmation=true] Important user information that never expires
37
57
// User preferences - need vector fields for search
### Search Working Memory Excluding Messages Older Than a Certain Timestamp
112
+
Retrieve the most similar knowledge memories for user "alice" that were created after a given timestamp (e.g., 1717935000), ensuring you only get recent context:
0 commit comments