botserver/docs/src/chapter-05/keyword-remember.md

5.8 KiB

REMEMBER

Store information in bot's long-term memory for future conversations.

Syntax

REMEMBER key, value

Parameters

Parameter Type Description
key String Memory key/identifier
value String Information to remember

Description

The REMEMBER keyword stores information persistently across conversations. Unlike session variables that expire, remembered data persists:

  • Across multiple conversations
  • Between user sessions
  • After bot restarts
  • Indefinitely until explicitly forgotten

This enables bots to build user profiles, track preferences, and maintain context over time.

Examples

Store User Preferences

name = HEAR "What's your name?"
REMEMBER "user_name", name
TALK "Nice to meet you, " + name + ". I'll remember that!"

Remember User Choices

language = HEAR "Preferred language? (English/Spanish/French)"
REMEMBER "preferred_language", language
TALK "I'll communicate in " + language + " from now on"

Build User Profile

REMEMBER "signup_date", TODAY()
REMEMBER "user_tier", "premium"
REMEMBER "last_contact", NOW()
REMEMBER "interaction_count", interaction_count + 1

Store Complex Information

' Store JSON-like data
preferences = "{theme: 'dark', notifications: true, timezone: 'EST'}"
REMEMBER "user_preferences", preferences

' Store lists
interests = "technology, science, sports"
REMEMBER "interests", interests

Retrieval

Use RECALL to retrieve remembered information:

' In a future conversation
name = RECALL("user_name")
IF name != "" THEN
    TALK "Welcome back, " + name + "!"
ELSE
    TALK "Hello! I don't think we've met before."
END IF

Memory Scope

Memories are scoped by:

  • User ID (each user has separate memory)
  • Bot ID (memories don't cross bots)
  • Optional namespace (for organizing memories)

Memory Management

List All Memories

memories = GET_ALL_MEMORIES()
FOR EACH memory IN memories
    PRINT memory.key + ": " + memory.value
NEXT

Forget Specific Memory

FORGET "temporary_data"

Clear All Memories

CLEAR_ALL_MEMORIES()
TALK "Memory wiped clean!"

Memory with Expiration

' Remember for 30 days
REMEMBER_TEMP "trial_status", "active", 30

Use Cases

Customer Service

' Remember customer issues
issue = HEAR "What problem are you experiencing?"
REMEMBER "last_issue", issue
REMEMBER "issue_date", TODAY()

' In follow-up conversation
last_issue = RECALL("last_issue")
IF last_issue != "" THEN
    TALK "Following up on your issue: " + last_issue
END IF

Personal Assistant

' Remember important dates
birthday = HEAR "When is your birthday?"
REMEMBER "birthday", birthday

' Check on birthday
IF TODAY() = RECALL("birthday") THEN
    TALK "Happy Birthday! 🎉"
END IF

Learning System

' Track user corrections
correction = HEAR "Actually, that's not correct..."
REMEMBER "correction_" + topic, correction
corrections_count = RECALL("total_corrections") + 1
REMEMBER "total_corrections", corrections_count

Preferences Tracking

' Remember communication preferences
IF time_of_day = "morning" AND response_time < 5 THEN
    REMEMBER "active_time", "morning"
END IF

preferred_channel = GET_CHANNEL()
REMEMBER "preferred_channel", preferred_channel

Performance Considerations

  • Memories are indexed for fast retrieval
  • Large values (>1MB) should be stored as files
  • Frequently accessed memories are cached
  • Memory operations are asynchronous

Privacy and Security

Data Protection

  • Memories are encrypted at rest
  • PII should be marked as sensitive
  • Comply with data retention policies
  • Support user data deletion requests

GDPR Compliance

' Allow users to export their data
IF request = "export_my_data" THEN
    data = EXPORT_USER_MEMORIES()
    SEND_MAIL user_email, "Your Data", data
END IF

' Allow users to delete their data
IF request = "forget_me" THEN
    DELETE_USER_MEMORIES()
    TALK "Your data has been deleted"
END IF

Best Practices

  1. Use descriptive keys: Make memory keys self-documenting
  2. Validate before storing: Check data quality
  3. Handle missing memories: Always check if memory exists
  4. Organize with namespaces: Group related memories
  5. Clean up old data: Remove outdated memories
  6. Respect privacy: Ask permission for sensitive data
  7. Document memories: Keep track of what's stored

Advanced Features

Structured Memory

' Store structured data
user_profile = CREATE_MAP()
user_profile["name"] = name
user_profile["age"] = age
user_profile["interests"] = interests
REMEMBER "profile", JSON_STRINGIFY(user_profile)

' Retrieve and parse
profile_json = RECALL("profile")
profile = JSON_PARSE(profile_json)
' Search memories by pattern
matching_memories = SEARCH_MEMORIES("pref_*")
FOR EACH mem IN matching_memories
    PRINT mem.key + ": " + mem.value
NEXT

Memory Analytics

' Track memory usage
stats = GET_MEMORY_STATS()
PRINT "Total memories: " + stats.count
PRINT "Storage used: " + stats.size_mb + "MB"
PRINT "Oldest memory: " + stats.oldest_date

Error Handling

TRY
    REMEMBER "important_data", data
CATCH "storage_full"
    ' Clean up old memories
    DELETE_OLD_MEMORIES(30)  ' Delete memories older than 30 days
    RETRY
CATCH "invalid_data"
    LOG "Cannot store invalid data"
END TRY

Implementation

Located in src/basic/keywords/remember.rs

Uses persistent storage (PostgreSQL) with caching layer (Redis) for performance.