Recommendation Systems

Leverage user preferences and constraints to power intelligent recommendation engines that respect user boundaries and provide relevant suggestions.

The Challenge

Building effective recommendation systems requires understanding user preferences while respecting constraints and boundaries. Traditional approaches often struggle with:

  • Merging preferences from multiple sources
  • Respecting user constraints (dietary restrictions, budget limits, etc.)
  • Ensuring recommendations are only used for allowed purposes
  • Handling user privacy and data control

The Memory Scope API provides policy-enforced access to preferences and constraints, making it easy to build recommendation systems that respect user boundaries.

Implementation Example

Here's how to build a recommendation system using the Memory Scope API:

Recommendation System
from memory_scope import MemoryScopeClient memory_client = MemoryScopeClient(api_key="your-api-key") def get_recommendations(user_id: str, category: str): """Get personalized recommendations based on user preferences and constraints""" # Read user preferences for the category preferences = memory_client.read_memory( user_id=user_id, scope="preferences", domain=category, purpose="generate recommendations" ) # Read user constraints constraints = memory_client.read_memory( user_id=user_id, scope="constraints", domain=category, purpose="filter recommendations" ) # Extract preferences and constraints likes = preferences.summary_struct.get("likes", []) dislikes = preferences.summary_struct.get("dislikes", []) rules = constraints.summary_struct.get("rules", []) # Generate recommendations (your recommendation logic) all_items = get_all_items(category) # Filter based on preferences and constraints recommendations = [] for item in all_items: # Skip items user dislikes if item in dislikes: continue # Check constraints if violates_constraints(item, rules): continue # Score based on preferences score = calculate_score(item, likes) recommendations.append((item, score)) # Sort by score and return top recommendations recommendations.sort(key=lambda x: x[1], reverse=True) return [item for item, score in recommendations[:10]]
Key Benefits

Policy Enforcement

The API ensures preferences are only accessed for recommendation purposes, protecting user privacy.

Automatic Merging

Multiple preference sources are automatically merged, simplifying your recommendation logic.

Constraint Respect

Easily access user constraints to filter recommendations and respect boundaries.

User Control

Users can revoke access to their preferences at any time, ensuring compliance and trust.

Use Case: Food Recommendations

Example: Building a food recommendation system that respects dietary restrictions:

Food Recommendations Example
# Store dietary constraints memory_client.create_memory( user_id="user123", scope="constraints", domain="dietary", source="explicit_user_input", value_json={ "rules": ["vegetarian", "no nuts", "gluten-free"] } ) # Store food preferences memory_client.create_memory( user_id="user123", scope="preferences", domain="food", source="explicit_user_input", value_json={ "likes": ["pizza", "sushi", "pasta"], "dislikes": ["broccoli"] } ) # Get recommendations (automatically respects constraints) recommendations = get_recommendations("user123", "food") # Only returns vegetarian, nut-free, gluten-free options that user likes