Skip to main content
Learn how to add memories to different indexes, perform basic operations, and organize your memory structure using common patterns and naming conventions.

Adding to Different Indexes

from gravixlayer import GravixLayer

client = GravixLayer()
memory = client.memory

# Add to different indexes
memory.add("User works as a software engineer", user_id="alice")  # Default index
memory.add("User prefers dark mode", user_id="alice", index_name="user_preferences")
memory.add("User uses Python daily", user_id="alice", index_name="work_info")

# Search in specific index
work_results = memory.search("programming", user_id="alice", index_name="work_info")
print(f"Work memories: {len(work_results['results'])}")

# List available indexes
indexes = memory.list_available_indexes()
print(f"Available indexes: {indexes}")

Searching Specific Indexes

Target your searches to specific indexes for better performance and more relevant results:
# Search only in work-related memories
work_results = memory.search("programming skills", user_id="alice", index_name="work_info")
print(f"Work-related memories: {len(work_results['results'])}")

# Search only in preferences
pref_results = memory.search("settings", user_id="alice", index_name="user_preferences")
print(f"Preference memories: {len(pref_results['results'])}")

# Search in default index (comprehensive)
all_results = memory.search("user information", user_id="alice")
print(f"All memories: {len(all_results['results'])}")

Managing Index Lists

# List all available indexes
indexes = memory.list_available_indexes()
print(f"Available indexes: {indexes}")

# Get memories from specific index
work_memories = memory.get_all(user_id="alice", index_name="work_info")
print(f"Work memories count: {len(work_memories['results'])}")

# Get current configuration
config = memory.get_current_configuration()
print(f"Current index: {config.get('index_name', 'gravixlayer_memories')}")

Common Index Patterns
Index NamePurposeExample Memories
user_preferencesSettings, UI preferences”Dark mode”, “Language: Spanish”, “Notifications off”
work_infoJob, skills, projects”Software engineer”, “Uses Python”, “Works remotely”
conversation_historyChat logs, interactions”Asked about weather”, “Discussed movies”
personal_infoBasic user data”Lives in NYC”, “Age 25”, “Married”
food_preferencesDietary info, likes/dislikes”Vegetarian”, “Allergic to nuts”, “Loves Italian food”
health_infoMedical, fitness data”Exercises daily”, “Takes vitamin D”, “Allergic to peanuts”

Use Case Examples

E-commerce Application

customer_preferences    # Shopping preferences, brands
purchase_history       # Past orders, favorite products  
support_interactions   # Customer service conversations

Content Platform

content_preferences    # Genres, topics of interest
viewing_history       # Watched/read content
social_interactions   # Comments, likes, shares

Productivity App

work_projects         # Current and past projects
meeting_notes         # Meeting summaries and action items
personal_tasks        # Personal reminders and goals

Index Naming Conventions

Good Naming Practices:
  • Use descriptive, clear names: user_preferences not prefs
  • Use underscores for separation: conversation_history not conversationhistory
  • Be consistent with pluralization: user_preferences, work_projects
  • Include context when needed: customer_support_tickets not just tickets
Avoid:
  • Generic names: data, info, stuff
  • Abbreviations: usr_prefs, conv_hist
  • Special characters: user-preferences, work@info
  • Very long names: user_application_specific_preferences_and_settings

Organizing by User Context

from gravixlayer import GravixLayer

client = GravixLayer()
memory = client.memory

# Organize by user role
memory.add("Admin access granted", user_id="alice", index_name="admin_permissions")
memory.add("Can edit user profiles", user_id="alice", index_name="admin_permissions")

# Organize by application context
memory.add("Prefers email notifications", user_id="alice", index_name="notification_settings")
memory.add("Dark theme enabled", user_id="alice", index_name="ui_preferences")

# Organize by data sensitivity
memory.add("Lives in San Francisco", user_id="alice", index_name="personal_info")
memory.add("Works at TechCorp", user_id="alice", index_name="professional_info")