Skip to main content

What You’re Building

An AI that remembers user preferences and past conversations automatically. Without Memory:
With Memory:

Prerequisites

  • Alchemyst account (sign up)
  • Your ALCHEMYST_AI_API_KEY
  • Node.js 18+ or Python 3.9+
Time to complete: 15 minutes

Choose Your Approach


Quick Start: TypeScript

Step 1: Set Up Memory

What this does:
  1. Retrieves past conversations for this user
  2. Includes them in the prompt automatically
  3. Stores the new conversation

Step 2: Use Memory

Memory works across:
  • Different sessions (profile_setup → cooking_monday)
  • Different topics (preferences → recipes)
  • Days or weeks apart

Complete TypeScript Example

Verify it worked:
  1. Visit platform.getalchemystai.com/context
  2. You should see stored conversations for user “bob”
  3. Click to view memory contents

Quick Start: Python

Start with this simplified version to understand the basics:
Expected Output:

Step 2: Full Integration with OpenAI

Now integrate with OpenAI for complete chat functionality:
Expected Output:

Understanding userId and sessionId

These two parameters control memory scope:

Real-World Examples

Pro Tip: Use descriptive sessionIds like "recipe_planning_2024_02" instead of "session_1" for easier debugging and analytics.
Rule: Same userId + same sessionId = same conversation thread

Advanced Features

Stream Responses with Memory

For real-time chat experiences:
Expected Output:

Manage Memory

Update or delete conversations as needed:

Multi-User Conversations

Handle group chats where multiple users participate in the same thread:
Key insight: Using the same sessionId across different userId values creates a shared memory space for team conversations.

Configuration Options

Customize memory retrieval and storage behavior:

Configuration Reference

Recommendation: Start with similarityThreshold: 0.7. Lower to 0.5 if you get no results, raise to 0.9 if results are too broad.

Troubleshooting

Error Message:
Cause: Both parameters are required for memory operations.Fix: Always provide both:
Symptoms: AI doesn’t remember past conversations.Causes:
  1. Threshold too high
  2. Wrong userId/sessionId
  3. Memory wasn’t stored correctly
Fixes:1. Lower threshold:
2. Verify exact same IDs:
3. Test retrieval directly:
Expected Output:
Symptoms: AI references unrelated past conversations or gets confused.Causes:
  1. Threshold too low
  2. Mixing unrelated conversations in same session
Fixes:1. Raise threshold:
2. Use separate sessions by topic:
3. Limit memory retrieval:
Error Message:
Common Causes:
  1. Invalid API key
  2. Rate limit exceeded
  3. Content too large
Fixes:1. Verify API key:
2. Check rate limits:
  • Free tier: 100 operations/day
  • Pro tier: Unlimited
3. Reduce content size:

Best Practices

1. Session Naming Convention

2. Memory Retention Limits

3. Privacy-Aware Memory

4. Error Handling


Verify Your Setup

After implementing memory, verify it’s working:

1. Check Platform UI

  1. Visit platform.getalchemystai.com/context
  2. Filter by your userId
  3. You should see stored memories with timestamps
  4. Click to view conversation content

2. Test with Code


What’s Next?

Add Context Search

Combine memory with document search for powerful RAG

Vercel AI SDK Guide

Deep dive into AI SDK integration

TypeScript SDK Reference

Complete API reference for TypeScript

Python SDK Reference

Complete API reference for Python

Learn Advanced Patterns

User Profiling

Build rich user profiles from memory

Memory Use Cases

Customer support, personal assistants, chatbots

Memory API Reference

Complete REST API documentation

Sample Projects

Community-built memory applications

Need Help?

Discord Community

Get real-time help from our community

Documentation

Browse guides and API references

Email Support

Contact our support team

GitHub Issues

Report bugs or request features