User Preference Recall
Category: Retrieval
Problem
Users expect AI assistants to remember their preferences — communication style, tool choices, formatting preferences, dietary restrictions, time zones. Without persistent memory, every conversation starts from scratch, forcing users to repeat themselves.
Architecture
This pattern uses a dedicated preferences namespace per user. Preferences are stored with high importance scores so they surface above general conversation memories. The hybrid retrieval ensures both semantic matches ("What language do they code in?") and exact matches ("timezone") work reliably.
Flow
- Detect preference statements in user messages (explicit or implicit)
- Store with high importance in user-specific namespace
- On each new conversation, recall top preferences relevant to current context
- Inject as system context for personalization
Implementation
from dakera import Dakera
client = Dakera(base_url="http://localhost:3300", api_key="dk-...")
# Store a user preference with high importance
client.memory.store(
content="User prefers Python over JavaScript for backend code",
namespace="user-alice-prefs",
metadata={
"type": "preference",
"category": "programming",
"importance": 0.95
}
)
# Store another preference
client.memory.store(
content="User wants concise responses, no lengthy explanations",
namespace="user-alice-prefs",
metadata={
"type": "preference",
"category": "communication",
"importance": 0.9
}
)
# Recall preferences relevant to current conversation
def get_user_preferences(user_id: str, current_query: str) -> list:
"""Retrieve relevant user preferences for context injection."""
results = client.memory.recall(
query=current_query,
namespace=f"user-{user_id}-prefs",
top_k=10
)
return [r["content"] for r in results["results"]]
# Usage: before generating a response
preferences = get_user_preferences("alice", "Help me build an API")
# Returns: ["User prefers Python over JavaScript for backend code",
# "User wants concise responses, no lengthy explanations"]
When to Use This Pattern
- Personalized assistants that serve returning users
- Customer support bots that remember account preferences
- Coding assistants that remember language/framework choices
- Any application where "remembering" improves the experience
Key Considerations
- Use high importance scores (0.8-1.0) for preferences so they rank above general memories
- Separate preferences namespace from conversation history to avoid noise
- Handle preference conflicts (user changed their mind) by storing with timestamps and recalling most recent
- Consider metadata categories for filtering (communication, tools, formatting, etc.)