Skip to main content
Structure and organize your memory data using multiple indexes for improved performance, categorization, and targeted operations. Organize memories into different categories (indexes) like folders for better organization and faster searches.

Understanding Indexes

What are indexes? Think of indexes like folders on your computer. Instead of putting all memories in one big pile, you can organize them into categories:
  • Default Index: gravixlayer_memories (general storage)
  • Custom Indexes: user_preferences, work_info, food_preferences, etc.
Why use multiple indexes?
  1. Faster searches - Search only relevant memories
  2. Better organization - Keep different types of data separate
  3. Easier management - Update/delete specific categories
  4. Performance - Smaller indexes = faster operations

Basic Index Operations

  • Python SDK
  • JavaScript SDK
from gravixlayer import GravixLayer

client = GravixLayer()
memory = client.memory

# Default category (gravixlayer_memories)
memory.add("User works as a software engineer", user_id="alice")

# Switch to preferences category
memory.switch_index("user_preferences")
memory.add("User prefers dark mode", user_id="alice")
memory.add("User likes notifications off", user_id="alice")

# Switch to work category  
memory.switch_index("work_info")
memory.add("User uses Python daily", user_id="alice")
memory.add("User works remotely", user_id="alice")

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

# Get current configuration
config = memory.get_current_configuration()
print(f"Current index: {config['index_name']}")
print(f"Current embedding model: {config['embedding_model']}")
Expected Output:
✅ Switched to index: user_preferences
✅ Switched to index: work_info
Available indexes: ['gravixlayer_memories', 'user_preferences', 'work_info']
Current index: work_info
Current embedding model: baai/bge-large-en-v1.5

Practical Index Organization

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

Targeted Searching

  • Python SDK
  • JavaScript SDK
# Search only in food preferences (faster, more relevant)
memory.switch_index("food_preferences")
food_results = memory.search("dietary restrictions", user_id="alice")
print(f"Food-related memories: {len(food_results['results'])}")

# Search only in work info
memory.switch_index("work_info")
work_results = memory.search("programming skills", user_id="alice")
print(f"Work-related memories: {len(work_results['results'])}")

# Search in all indexes (slower but comprehensive)
memory.switch_index("gravixlayer_memories")  # Default index
all_results = memory.search("user information", user_id="alice")
print(f"All memories: {len(all_results['results'])}")

Cross-Index Operations

  • Python SDK
  • JavaScript SDK
# Add to multiple indexes in sequence
memory.switch_index("food_preferences")
memory.add("User likes spicy food", user_id="alice")

memory.switch_index("health_info")
memory.add("User has high blood pressure", user_id="alice")

memory.switch_index("work_info")
memory.add("User works night shifts", user_id="alice")

# Search across different indexes for comprehensive results
food_memories = memory.search("preferences", user_id="alice")
memory.switch_index("health_info")
health_memories = memory.search("medical", user_id="alice")

print(f"Food preferences: {len(food_memories['results'])}")
print(f"Health info: {len(health_memories['results'])}")
Expected Output:
✅ Switched to index: food_preferences
✅ Switched to index: health_info  
✅ Switched to index: work_info
✅ Switched to index: health_info
Food preferences: 1
Health info: 1

Best Practices

  1. Use descriptive index names - user_preferences not prefs
  2. Keep indexes focused - Don’t mix unrelated data types
  3. Start simple - Begin with 2-3 indexes, add more as needed
  4. Search specific indexes - Faster than searching everything
  5. Document your structure - Keep track of what goes where
I