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

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

Key Considerations