Best Practices
Guidelines for building production-ready AI applications with MemoryStack.
Memory Management
Store atomic, meaningful memories
Each memory should represent a single fact, preference, or piece of information. Avoid storing entire conversations as single memories.
✓ Good:
"User prefers dark mode in all applications"✗ Avoid:
"User said they like dark mode and also mentioned they work late..."Use metadata for filtering
Add structured metadata to memories for efficient filtering. Use memory_type, tags, and custom fields to categorize information.
Regularly consolidate memories
Use the consolidation API to merge similar memories and reduce redundancy. This improves search quality and reduces storage costs.
Performance Optimization
Use batch operations for bulk inserts
When importing multiple memories, use the batch API instead of individual calls. This reduces latency and API usage.
Limit search results appropriately
Request only the number of results you need. Use the limit parameter to control response size and improve latency.
Cache frequently accessed memories
For high-traffic applications, implement client-side caching for commonly retrieved memories to reduce API calls.
Security
Never expose API keys in client-side code
Always make API calls from your backend. Use environment variables to store API keys securely.
Use user_id for data isolation
Always include user_id when storing and retrieving memories in B2B applications. This ensures complete data isolation between end users.
Sanitize user input before storing
Validate and sanitize any user-provided content before storing as memories to prevent injection attacks.
Multi-Agent Systems
Use agent_id for agent-specific memories
Assign unique agent_id values to differentiate memories created by different agents in your system.
Implement proper handoff protocols
When transferring context between agents, use the handoff API to ensure seamless memory sharing and context preservation.
